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 int 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)");
886 uint32_t cp0_write_code[] = {
895 uint32_t cp0_write_data[] = {
913 for (
size_t i = 0; i <
ARRAY_SIZE(cp0_write_code); i++) {
924 if (mips32->
fp_imp && fp_enabled) {
928 uint32_t fp_lo = fprs[i] & 0xffffffff;
929 uint32_t fp_hi = (fprs[i] >> 32) & 0xffffffff;
937 uint32_t fp_lo = fprs[i] & 0xffffffff;
948 if (mips32->
dsp_imp && dsp_enabled) {
954 for (
size_t index = 0; index != ((dsp_regs - 1) / 2); index++) {
962 size_t ac = index + 1;
976 for (
int i = 2; i < 32; i++)
1010 for (
int i = 2; i != 32; i++)
1017 uint32_t lohi_read_code[] = {
1023 for (
int i = 0; i < 2; i++) {
1035 uint32_t cp0_read_code[] = {
1043 for (
size_t i = 0; i <
ARRAY_SIZE(cp0_read_code); i++) {
1044 size_t offset = offset_cp0 + (i * 4);
1078 unsigned int offset_gpr,
unsigned int offset_cp0)
1092 unsigned int offset_gpr = ((uint8_t *)&core_regs->
gpr[0]) - (uint8_t *)core_regs;
1093 unsigned int offset_cp0 = ((uint8_t *)&core_regs->
cp0[0]) - (uint8_t *)core_regs;
1094 unsigned int offset_fpr = ((uint8_t *)&core_regs->
fpr[0]) - (uint8_t *)core_regs;
1095 unsigned int offset_fpcr = ((uint8_t *)&core_regs->
fpcr[0]) - (uint8_t *)core_regs;
1096 unsigned int offset_dsp = ((uint8_t *)&core_regs->
dsp[0]) - (uint8_t *)core_regs;
1097 bool fp_enabled, dsp_enabled;
1132 if (mips32->
fp_imp && fp_enabled) {
1149 for (
int i = 0; i != 32; i++) {
1150 size_t offset = offset_fpr + (i * 8);
1165 for (
int i = 0; i != 32; i++) {
1166 size_t offset = offset_fpr + (i * 8);
1185 if (mips32->
dsp_imp && dsp_enabled) {
1193 for (
size_t index = 0; index != ((dsp_regs - 1) / 2); index++) {
1196 size_t offset_hi = offset_dsp + ((index * 2) *
sizeof(uint32_t));
1198 size_t offset_lo = offset_dsp + (((index * 2) + 1) *
sizeof(uint32_t));
1201 size_t ac = index + 1;
1279 if (cached == 3 || cached == 0) {
1280 uint32_t start_addr =
addr;
1285 LOG_DEBUG(
"Unsupported MIPS Release ( > 5)");
1302 int write_t, uint32_t
addr,
int count, uint32_t *buf)
1304 uint32_t isa = ejtag_info->
isa ? 1 : 0;
1305 uint32_t handler_code[] = {
1353 uint32_t jmp_code[] = {
1365 for (
unsigned int i = 0; i <
ARRAY_SIZE(jmp_code); i++) {
1387 uint32_t val =
addr;
1400 unsigned int num_clocks = 0;
1401 if (ejtag_info->
mode != 0)
1404 for (
int i = 0; i <
count; i++) {
1420 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 int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_add_clocks(unsigned int num_cycles)
Function jtag_add_clocks first checks that the state in which the clocks are to be issued is stable,...
#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_DSP_MTLO(reg, ac)
#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_REG_C0_STATUS_INDEX
#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_DSP_MFHI(reg, ac)
#define MIPS32_SYNCI(isa, off, base)
#define MIPS32_DSP_MTHI(reg, ac)
#define MIPS32_DSP_MFLO(reg, ac)
#define MIPS32_ORI(isa, tar, src, val)
#define MIPS32_MFC0(isa, gpr, cpr, sel)
#define MIPS32_MFHC1(isa, gpr, cpr)
#define MIPS32_CP0_STATUS_MX_SHIFT
#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
#define MIPS32_DSP_WRDSP(rs, mask)
#define MIPS32_DSP_RDDSP(rt, 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_dsp_imp dsp_imp
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 dsp[MIPS32_REG_DSP_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.