86 LOG_DEBUG(
"DEBUGMODULE: No memory access in progress!");
120 for (
int i = 0; i != 5; i++) {
128 uint32_t data = (i == 3) ? jt_code :
MIPS32_NOP;
135 if (ejtag_info->
mode != 0)
138 for (
int i = 0; i != 2; i++) {
155 uint32_t *param_out,
bool check_last)
158 int store_pending = 0;
159 uint32_t max_store_addr = 0;
161 int restart_count = 0;
163 bool final_check = 0;
169 if (restart_count < 3) {
188 if (store_pending == 0) {
190 if (code_count < 2) {
198 ejtag_info->
pa_addr > max_store_addr) {
218 LOG_DEBUG(
"reading at unexpected address %" PRIx32
", expected %x",
223 restart_count == 0) {
224 LOG_DEBUG(
"restarting, without clean jump");
228 }
else if (code_count < 2) {
236 if (store_addr != 0) {
237 if (store_addr > max_store_addr)
238 max_store_addr = store_addr;
250 if (store_pending == 0)
255 LOG_DEBUG(
"unexpected second pass through pracc text");
260 LOG_DEBUG(
"unexpected read address in final check: %"
261 PRIx32
", expected: %x", ejtag_info->
pa_addr,
268 LOG_DEBUG(
"failed to jump back to pracc text");
272 if (code_count > 10) {
273 LOG_DEBUG(
"execution abandoned, store pending: %d", store_pending);
287 if (final_check && !check_last)
290 if (store_pending == 0 && pass) {
291 LOG_DEBUG(
"warning: store access pass pracc text");
329 if (
LOWER16(data) == 0 && optimize)
331 else if (
UPPER16(data) == 0 && optimize)
345 uint32_t *buf,
bool check_last)
356 if (ejtag_info->
mode == 0)
373 unsigned num_clocks =
383 scan_in[scan_count++].scan_96);
400 ejtag_ctrl =
buf_get_u32(scan_in[scan_count].scan_32.ctrl, 0, 32);
403 LOG_ERROR(
"Error: access not pending count: %d", scan_count);
408 LOG_ERROR(
"Not a fetch/read access, count: %d", scan_count);
412 if (
addr != fetch_addr) {
413 LOG_ERROR(
"Fetch addr mismatch, read: %" PRIx32
" expected: %" PRIx32
" count: %d",
414 addr, fetch_addr, scan_count);
424 ejtag_ctrl =
buf_get_u32(scan_in[scan_count].scan_32.ctrl, 0, 32);
428 LOG_ERROR(
"Not a store/write access, count: %d", scan_count);
432 if (
addr != store_addr) {
433 LOG_ERROR(
"Store address mismatch, read: %" PRIx32
" expected: %" PRIx32
" count: %d",
434 addr, store_addr, scan_count);
439 buf[buf_index] =
buf_get_u32(scan_in[scan_count].scan_32.data, 0, 32);
477 uint32_t *data =
NULL;
479 data = malloc(256 *
sizeof(uint32_t));
486 uint32_t *buf32 = buf;
487 uint16_t *buf16 = buf;
494 int this_round_count = (
count > 256) ? 256 :
count;
495 uint32_t last_upper_base_addr =
UPPER16((
addr + 0x8000));
500 for (
int i = 0; i != this_round_count; i++) {
501 uint32_t upper_base_addr =
UPPER16((
addr + 0x8000));
502 if (last_upper_base_addr != upper_base_addr) {
504 last_upper_base_addr = upper_base_addr;
530 buf32 += this_round_count;
536 uint32_t *data_p = data;
537 for (
int i = 0; i != this_round_count; i++) {
539 *buf16++ = *data_p++;
544 count -= this_round_count;
639 uint32_t start_addr, uint32_t end_addr,
int cached,
int rel)
688 start_addr |= clsiz - 1;
689 end_addr |= clsiz - 1;
695 uint32_t last_upper_base_addr =
UPPER16((start_addr + 0x8000));
699 while (start_addr <= end_addr) {
700 uint32_t upper_base_addr =
UPPER16((start_addr + 0x8000));
701 if (last_upper_base_addr != upper_base_addr) {
703 last_upper_base_addr = upper_base_addr;
718 if (
count == 256 && start_addr <= end_addr) {
747 const uint32_t *buf32 = buf;
748 const uint16_t *buf16 = buf;
749 const uint8_t *buf8 = buf;
755 int this_round_count = (
count > 128) ? 128 :
count;
756 uint32_t last_upper_base_addr =
UPPER16((
addr + 0x8000));
760 for (
int i = 0; i != this_round_count; i++) {
761 uint32_t upper_base_addr =
UPPER16((
addr + 0x8000));
762 if (last_upper_base_addr != upper_base_addr) {
764 last_upper_base_addr = upper_base_addr;
772 }
else if (
size == 2) {
793 count -= this_round_count;
842 if (cached == 3 || cached == 0) {
843 uint32_t start_addr =
addr;
848 LOG_DEBUG(
"Unsupported MIPS Release ( > 5)");
885 uint32_t cp0_write_code[] = {
894 uint32_t cp0_write_data[] = {
912 for (
size_t i = 0; i <
ARRAY_SIZE(cp0_write_code); i++) {
923 if (mips32->
fp_imp && fp_enabled) {
927 uint32_t fp_lo = fprs[i] & 0xffffffff;
928 uint32_t fp_hi = (fprs[i] >> 32) & 0xffffffff;
936 uint32_t fp_lo = fprs[i] & 0xffffffff;
947 for (
int i = 2; i < 32; i++)
981 for (
int i = 2; i != 32; i++)
988 uint32_t lohi_read_code[] = {
994 for (
int i = 0; i < 2; i++) {
1006 uint32_t cp0_read_code[] = {
1014 for (
size_t i = 0; i <
ARRAY_SIZE(cp0_read_code); i++) {
1015 size_t offset = offset_cp0 + (i * 4);
1049 unsigned int offset_gpr,
unsigned int offset_cp0)
1063 unsigned int offset_gpr = ((uint8_t *)&core_regs->
gpr[0]) - (uint8_t *)core_regs;
1064 unsigned int offset_cp0 = ((uint8_t *)&core_regs->
cp0[0]) - (uint8_t *)core_regs;
1065 unsigned int offset_fpr = ((uint8_t *)&core_regs->
fpr[0]) - (uint8_t *)core_regs;
1066 unsigned int offset_fpcr = ((uint8_t *)&core_regs->
fpcr[0]) - (uint8_t *)core_regs;
1101 if (mips32->
fp_imp && fp_enabled) {
1118 for (
int i = 0; i != 32; i++) {
1119 size_t offset = offset_fpr + (i * 8);
1134 for (
int i = 0; i != 32; i++) {
1135 size_t offset = offset_fpr + (i * 8);
1204 if (cached == 3 || cached == 0) {
1205 uint32_t start_addr =
addr;
1210 LOG_DEBUG(
"Unsupported MIPS Release ( > 5)");
1227 int write_t, uint32_t
addr,
int count, uint32_t *buf)
1229 uint32_t isa = ejtag_info->
isa ? 1 : 0;
1230 uint32_t handler_code[] = {
1278 uint32_t jmp_code[] = {
1290 for (
unsigned i = 0; i <
ARRAY_SIZE(jmp_code); i++) {
1312 uint32_t val =
addr;
1325 unsigned num_clocks = 0;
1326 if (ejtag_info->
mode != 0)
1329 for (
int i = 0; i <
count; i++) {
1345 LOG_ERROR(
"mini program did not return to start");
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
void jtag_add_clocks(int num_cycles)
Function jtag_add_clocks first checks that the state in which the clocks are to be issued is stable,...
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
#define ERROR_JTAG_DEVICE_ERROR
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
bool mips32_cpu_support_sync(struct mips_ejtag *ejtag_info)
mips32_cpu_support_sync - Checks CPU supports ordering
bool mips32_cpu_support_hazard_barrier(struct mips_ejtag *ejtag_info)
mips32_cpu_support_hazard_barrier - Checks CPU supports hazard barrier
#define KUSEG
Memory segments (32bit kernel mode addresses) These are the traditional names used in the 32-bit univ...
#define MIPS32_ADDI(isa, tar, src, val)
#define MIPS32_MFHI(isa, reg)
#define MIPS32_SWC1(isa, reg, off, base)
#define MIPS32_SYNCI_STEP
#define MIPS32_MTHI(isa, reg)
#define MIPS32_CONFIG0_K0_SHIFT
#define MIPS32_MTHC1(isa, gpr, cpr)
#define MIPS32_MFC1(isa, gpr, cpr)
#define MIPS32_CP0_STATUS_CU1_SHIFT
#define MIPS32_CONFIG0_AR_SHIFT
#define MIPS32_BNE(isa, src, tar, off)
#define KSEGX(a)
Returns the kernel segment base of a given address.
#define MIPS32_CONFIG1_DL_MASK
#define MIPS32_RDHWR(isa, tar, dst)
#define MIPS32_REG_FP_COUNT
#define MIPS32_CONFIG0_KU_MASK
#define MIPS32_XORI(isa, tar, src, val)
#define MIPS32_JRHB(isa, reg)
#define MIPS32_SW(isa, reg, off, base)
#define MIPS32_MTLO(isa, reg)
#define MIPS32_CACHE_D_HIT_WRITEBACK
Cache operations definitions Operation field is 5 bits long : 1) bits 1..0 hold cache type 2) bits 4....
#define MIPS32_J(isa, tar)
#define MIPS32_LBU(isa, reg, off, base)
#define MIPS32_LHU(isa, reg, off, base)
#define MIPS32_CONFIG0_K23_SHIFT
#define MIPS32_MFLO(isa, reg)
#define MIPS32_CONFIG0_KU_SHIFT
CP0 CONFIG register fields.
#define MIPS32_SB(isa, reg, off, base)
#define MIPS32_CONFIG0_K23_MASK
#define MIPS32_MTC1(isa, gpr, cpr)
#define MIPS32_SH(isa, reg, off, base)
#define MIPS32_CFC1(isa, gpr, cpr)
#define MIPS32_MTC0(isa, gpr, cpr, sel)
#define MIPS32_CONFIG1_DL_SHIFT
#define MIPS32_CACHE_I_HIT_INVALIDATE
#define MIPS32_LUI(isa, reg, val)
#define MIPS32_CACHE(isa, op, off, base)
#define MIPS32_CONFIG0_AR_MASK
#define MIPS32_SYNCI(isa, off, base)
#define MIPS32_ORI(isa, tar, src, val)
#define MIPS32_MFC0(isa, gpr, cpr, sel)
#define MIPS32_MFHC1(isa, gpr, cpr)
#define MIPS32_JR(isa, reg)
#define MIPS32_B(isa, off)
#define MIPS32_LW(isa, reg, off, base)
#define MIPS32_CP0_STATUS_FR_SHIFT
#define MIPS32_CONFIG0_K0_MASK
static int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t *buf)
static void mips32_pracc_store_regs_set_base_addr(struct pracc_queue_info *ctx)
void pracc_queue_free(struct pracc_queue_info *ctx)
int mips32_pracc_write_regs(struct mips32_common *mips32)
static int mips32_pracc_fastdata_xfer_synchronize_cache(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count)
mips32_pracc_fastdata_xfer_synchronize_cache - Synchronize cache for fast data transfer
static int wait_for_pracc_rw(struct mips_ejtag *ejtag_info)
static int mips32_pracc_read_ctrl_addr(struct mips_ejtag *ejtag_info)
static void mips32_pracc_store_regs_restore(struct pracc_queue_info *ctx)
int mips32_pracc_write_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, const void *buf)
static int mips32_pracc_exec(struct mips_ejtag *ejtag_info, struct pracc_queue_info *ctx, uint32_t *param_out, bool check_last)
int mips32_pracc_fastdata_xfer(struct mips_ejtag *ejtag_info, struct working_area *source, int write_t, uint32_t addr, int count, uint32_t *buf)
static void pracc_add_li32(struct pracc_queue_info *ctx, uint32_t reg_num, uint32_t data, bool optimize)
int mips32_pracc_queue_exec(struct mips_ejtag *ejtag_info, struct pracc_queue_info *ctx, uint32_t *buf, bool check_last)
int mips32_pracc_read_regs(struct mips32_common *mips32)
static int mips32_pracc_synchronize_cache(struct mips_ejtag *ejtag_info, uint32_t start_addr, uint32_t end_addr, int cached, int rel)
mips32_pracc_sync_cache
void pracc_queue_init(struct pracc_queue_info *ctx)
int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf)
static int mips32_pracc_write_mem_generic(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, const void *buf)
static void mips32_pracc_finish(struct mips_ejtag *ejtag_info)
static void mips32_pracc_store_regs_gpr(struct pracc_queue_info *ctx, unsigned int offset_gpr)
static int mips32_pracc_clean_text_jump(struct mips_ejtag *ejtag_info)
static void mips32_pracc_store_regs_cp0_context(struct pracc_queue_info *ctx, unsigned int offset_cp0)
int mips32_cp0_read(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t cp0_reg, uint32_t cp0_sel)
mips32_cp0_read
static void mips32_pracc_store_regs(struct pracc_queue_info *ctx, unsigned int offset_gpr, unsigned int offset_cp0)
void pracc_add(struct pracc_queue_info *ctx, uint32_t addr, uint32_t instr)
int mips32_cp1_control_read(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t cp1_c_reg)
mips32_cp1_control_read
int mips32_cp0_write(struct mips_ejtag *ejtag_info, uint32_t val, uint32_t cp0_reg, uint32_t cp0_sel)
mips32_cp0_write
static void mips32_pracc_store_regs_lohi(struct pracc_queue_info *ctx)
#define MIPS32_PRACC_TEXT
#define PRACC_UPPER_BASE_ADDR
#define MIPS32_FASTDATA_HANDLER_SIZE
static void pracc_swap16_array(struct mips_ejtag *ejtag_info, uint32_t *buf, int count)
#define MIPS32_PRACC_FASTDATA_AREA
#define MIPS32_PRACC_PARAM_OUT
int mips_ejtag_fastdata_scan(struct mips_ejtag *ejtag_info, int write_t, uint32_t *data)
void mips_ejtag_drscan_32_out(struct mips_ejtag *ejtag_info, uint32_t data)
void mips_ejtag_set_instr(struct mips_ejtag *ejtag_info, uint32_t new_instr)
int mips_ejtag_drscan_32(struct mips_ejtag *ejtag_info, uint32_t *data)
void mips_ejtag_add_scan_96(struct mips_ejtag *ejtag_info, uint32_t ctrl, uint32_t data, uint8_t *in_scan_buf)
#define EJTAG_INST_CONTROL
#define EJTAG_INST_FASTDATA
#define EJTAG_INST_ADDRESS
target_addr_t addr
Start address to search for the control block.
struct rtt_control ctrl
Control block.
size_t size
Size of the control block search area.
enum mips32_fp_imp fp_imp
struct mips_ejtag ejtag_info
struct mips32_core_regs core_regs
uint64_t fpr[MIPS32_REG_FP_COUNT]
uint32_t gpr[MIPS32_REG_GP_COUNT]
uint32_t cp0[MIPS32_REG_C0_COUNT]
uint32_t fpcr[MIPS32_REG_FPC_COUNT]
struct pa_list * pracc_list
struct mips_ejtag * ejtag_info
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.