jtaglib: Xv2 read/write reg now (finally) working, PC gets reset every so often due to other routines

This commit is contained in:
Triss 2022-07-31 02:49:48 +02:00
parent 649d82b695
commit 37aacaca2d
2 changed files with 27 additions and 12 deletions

View File

@ -932,6 +932,12 @@ int jtag_dev_init(struct jtdev *p) {
if (!chip) { if (!chip) {
printc_err("jtaglib: unknown chip ID\n"); printc_err("jtaglib: unknown chip ID\n");
} else { } else {
// NOTE: This prevents the device_probe_id() function (defined in
// device.h) from probing the target identification again, as can
// be seen at the start of the implementation of that function in
// device.c . Thus, care needs to be taken to not let these two
// functions diverge in behavior. v3hil contains yet another
// implementation of this.
p->base.chip = chip; p->base.chip = chip;
} }

View File

@ -20,6 +20,7 @@ static int jlfxv2_check_full_emu_state_ex(struct jtdev *p, const char* fnname)
uint16_t dr; uint16_t dr;
uint8_t jtag_id; uint8_t jtag_id;
for (int i = 0; i < 1/*10*/; ++i) {
jtag_id = jtag_ir_shift(p, IR_CNTRL_SIG_CAPTURE); jtag_id = jtag_ir_shift(p, IR_CNTRL_SIG_CAPTURE);
if (((dr = jtag_dr_shift_16(p, 0)) & 0x0301) == 0x0301) { if (((dr = jtag_dr_shift_16(p, 0)) & 0x0301) == 0x0301) {
return 1; // OK return 1; // OK
@ -27,6 +28,7 @@ static int jlfxv2_check_full_emu_state_ex(struct jtdev *p, const char* fnname)
printc_err("jlfxv2: %s: not in full emu state, while expected!" printc_err("jlfxv2: %s: not in full emu state, while expected!"
" (dr=%04x jid=%02x)\n", fnname, dr, jtag_id); " (dr=%04x jid=%02x)\n", fnname, dr, jtag_id);
}
p->failed = 1; p->failed = 1;
return 0; return 0;
@ -452,9 +454,9 @@ static address_t jlfxv2_read_reg(struct jtdev *p, int reg)
{ // libmsp430 BIOS name: ReadCpuReg { // libmsp430 BIOS name: ReadCpuReg
uint16_t reglo, reghi; uint16_t reglo, reghi;
uint16_t jtag_id, jmb_addr; uint16_t jtag_id, jmb_addr;
const bool alt_addr = true; const bool alt_addr = false;//true;
if (reg == 3) return 0; // CG if (reg == 2 || reg == 3) return 0; // CG
printc_dbg("read reg %d\n", reg); printc_dbg("read reg %d\n", reg);
if (!jlfxv2_check_full_emu_state(p)) if (!jlfxv2_check_full_emu_state(p))
@ -464,7 +466,7 @@ static address_t jlfxv2_read_reg(struct jtdev *p, int reg)
jtag_tclk_clr(p); jtag_tclk_clr(p);
jtag_ir_shift(p, IR_DATA_16BIT); jtag_ir_shift(p, IR_DATA_16BIT);
jtag_tclk_set(p); jtag_tclk_set(p);
jtag_dr_shift_16(p, reg); jtag_dr_shift_16(p, ((reg << 8) & 0x0f00) | 0x0060);
jtag_ir_shift(p, IR_CNTRL_SIG_16BIT); jtag_ir_shift(p, IR_CNTRL_SIG_16BIT);
jtag_dr_shift_16(p, 0x1401); jtag_dr_shift_16(p, 0x1401);
jtag_ir_shift(p, IR_DATA_16BIT); jtag_ir_shift(p, IR_DATA_16BIT);
@ -510,6 +512,13 @@ static address_t jlfxv2_read_reg(struct jtdev *p, int reg)
jtag_tclk_set(p); jtag_tclk_set(p);
printc_dbg("read reg %d: lo=%04x hi=%04x\n", reg, reglo, reghi); printc_dbg("read reg %d: lo=%04x hi=%04x\n", reg, reglo, reghi);
jlfxv2_set_pc(p, SAFE_FRAM_PC);
jtag_ir_shift(p, IR_CNTRL_SIG_16BIT);
jtag_dr_shift_16(p, 0x0501);
jtag_tclk_set(p);
jtag_ir_shift(p, IR_ADDR_CAPTURE);
return reglo | ((address_t)reghi << 16); return reglo | ((address_t)reghi << 16);
} }
@ -519,13 +528,13 @@ static void jlfxv2_write_reg(struct jtdev *p, int reg, address_t value)
jlfxv2_check_full_emu_state(p); jlfxv2_check_full_emu_state(p);
printc_dbg("write reg %d %06x\n", reg, value); printc_dbg("write reg %d %06x\n", reg, value);
jtag_ir_shift(p, IR_CNTRL_SIG_CAPTURE); /*jtag_ir_shift(p, IR_CNTRL_SIG_CAPTURE);
jtag_dr_shift_16(p, 0); jtag_dr_shift_16(p, 0);*/
jtag_tclk_clr(p); jtag_tclk_clr(p);
jtag_ir_shift(p, IR_DATA_16BIT); jtag_ir_shift(p, IR_DATA_16BIT);
jtag_tclk_set(p); jtag_tclk_set(p);
jtag_dr_shift_16(p, 0x0080 | ((value >> 8) & 0x0f00)); jtag_dr_shift_16(p, 0x0080 | ((value >> 8) & 0x0f00) | (reg & 0xf));
//jtag_tclk_clr(p); //jtag_tclk_clr(p);
jtag_ir_shift(p, IR_CNTRL_SIG_16BIT); jtag_ir_shift(p, IR_CNTRL_SIG_16BIT);