diff options
Diffstat (limited to 'disasm.c')
-rw-r--r-- | disasm.c | 332 |
1 files changed, 174 insertions, 158 deletions
@@ -12,26 +12,161 @@ mne##_RR: case mne##_RM: case mne##_MR: case mne##_MM -void print_regs(struct sux *cpu, uint8_t lines, uint8_t thread) { +void print_info(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t thread) { for (uint8_t i = (24*thread)+2; i <= 24*(thread+1); i++) { - wmove(scr, i, 0); - waddch(scr, (i == lines) ? '>' : ' '); + wmove(w, i, 0); + waddch(w, (i == lines) ? '>' : ' '); } - wmove(scr, lines, 1); - wclrtoeol(scr); - wprintw(scr, "pc: $%04"PRIX64 , cpu->pc); - wprintw(scr, ", a: $%08"PRIX64, cpu->a); - wprintw(scr, ", b: $%08"PRIX64, cpu->b); - wprintw(scr, ", x: $%08"PRIX64, cpu->x); - wprintw(scr, ", y: $%08"PRIX64, cpu->y); - wprintw(scr, ", e: $%08"PRIX64, cpu->e); - wprintw(scr, ", sp: $%"PRIX64, cpu->sp); - wprintw(scr, ", ps: %c%c---%c%c%c", cpu->ps.u8[thread] & N ? 'N' : '-' - , cpu->ps.u8[thread] & V ? 'V' : '-' - , cpu->ps.u8[thread] & I ? 'I' : '-' - , cpu->ps.u8[thread] & Z ? 'Z' : '-' - , cpu->ps.u8[thread] & C ? 'C' : '-'); - wprintw(scr, ", inst: "); + wmove(w, lines, 1); + wclrtoeol(w); + wprintw(w, "pc: $%04"PRIX64 , cpu->pc); + wprintw(w, ", ps: %c%c---%c%c%c", cpu->ps.u8[thread] & N ? 'N' : '-' + , cpu->ps.u8[thread] & V ? 'V' : '-' + , cpu->ps.u8[thread] & I ? 'I' : '-' + , cpu->ps.u8[thread] & Z ? 'Z' : '-' + , cpu->ps.u8[thread] & C ? 'C' : '-'); + wprintw(w, ", inst: "); +} + + +void print_regs(struct sux *cpu, WINDOW *w) { + for (int i = 0; i < 9; i++) { + wmove(w, i, 0); + wclrtoeol(w); + } + wmove(w, 0, 0); + wprintw(w, "Registers:\n"); + wprintw(w, " a: $%016"PRIX64", b: $%016"PRIX64"\n", cpu->a, cpu->b); + wprintw(w, " x: $%016"PRIX64", y: $%016"PRIX64"\n", cpu->x, cpu->y); + wprintw(w, " e: $%016"PRIX64", c: $%016"PRIX64"\n", cpu->e, cpu->c); + wprintw(w, " d: $%016"PRIX64", s: $%016"PRIX64"\n", cpu->d, cpu->s); + wprintw(w, " f: $%016"PRIX64", sp: $%016"PRIX64"\n", cpu->f, cpu->sp); + wprintw(w, " bp: $%016"PRIX64", r11: $%016"PRIX64"\n", cpu->bp, cpu->r11); + wprintw(w, "r12: $%016"PRIX64", r13: $%016"PRIX64"\n", cpu->r12, cpu->r13); + wprintw(w, "r14: $%016"PRIX64", r15: $%016"PRIX64"\n", cpu->r14, cpu->r15); +} + +static void sub_dbg(struct sux *cpu, WINDOW *w, uint64_t address, uint64_t *ortho_addr, uint8_t thread) { + uint8_t ln = 5; + uint16_t line_idx = 0; + uint32_t tmpad = 0x20247; + int row, col; + uint8_t iscursor = 0; + union reg ptr; + ptr.u64 = 0; + uint32_t adr; + if (address == CTRL_ADDR || ortho_addr[1] == CTRL_ADDR || addr[STEP_ADDR]) { + adr = read_value(cpu, 0, tmpad, 7, 0, 0); + tmpad += 8; + wmove(w, 1, 0); + wprintw(w, "scr_row: %02u, scr_col: %02u, scr_str: %02u, scr_end: %02u", addr[0], addr[1], addr[2], addr[3]); + wmove(w, 2, 0); + wprintw(w, "bitabl: "); + for (uint8_t i = 0; i < 16; i++) { + wprintw(w, "%s", showbits(addr[adr+i], 7, 0)); + } + mvwprintw(w, ln++, 0, "buffer: "); + wmove(w, ln++, 0); + uint8_t maxrow = 10; + int line_offset = (addr[0]-(maxrow-1) >= 0) ? addr[0]-(maxrow-1) : 0; + adr = read_value(cpu, 0, tmpad, 7, 0, 0); + for (uint8_t i = 0; i < maxrow; i++) { + line_idx = (i+addr[2]+line_offset << 6) + (i+addr[2]+line_offset << 4); + for (uint8_t j = 0; j < 0x50; j++) { + wprintw(w, "%02X", addr[adr+j+line_idx]); + if ((addr[0] == i+line_offset) && addr[1] == j) { + iscursor=1; + getyx(w,row, col); + wmove(w, ln++, 0); + wclrtoeol(w); + wmove(w, row+1, col-2); + wprintw(w, "/\\"); + wmove(w, row, col); + } + } + wprintw(w, ", i: %02X", i); + if (!iscursor) { + wmove(w, ln, 0); + wclrtoeol(w); + } + iscursor = 0; + wmove(w, ln++, 0); + } + } + /*wclrtoeol(w); + wprintw(w, "rega: $%02X, ", addr[0x0A]); + wprintw(w, "regb: $%02X, ", addr[0x0B]); + wprintw(w, "regc: $%02X, ", addr[0x0C]); + wprintw(w, "regd: $%02X, ", addr[0x0D]); + wprintw(w, "rege: $%02X, ", addr[0x0E]); + wprintw(w, "regf: $%02X, ", addr[0x0F]); + wprintw(w, "regg: $%02X", addr[0x10]);*/ + + wmove(w, 3, 0); + wclrtoeol(w); + + adr = 0x25; + ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); + wprintw(w, "ptr1: $%04"PRIX64, ptr.u64); + + adr = 0x2D; + ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); + wprintw(w, ", ptr2: $%04"PRIX64, ptr.u64); + + adr = 0x35; + ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); + wprintw(w, ", ptr3: $%04"PRIX64, ptr.u64); + + adr = 0x02049A; + ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); + wprintw(w, ", idx0: $%04"PRIX64, ptr.u64); + + adr = 0x334BA; + ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); + wprintw(w, ", valbuf: $%016"PRIX64, ptr.u64); + + + wmove(w, 4, 0); + wclrtoeol(w); + adr = 0x200CA; + ptr.u64 = read_value(cpu, 0, adr, 3, 0, 0); + wprintw(w, "t_id: $%02X", ptr.u8[0]); + wprintw(w, ", t_type: $%02X", ptr.u8[1]); + wprintw(w, ", t_space: $%02X", ptr.u8[2]); + wprintw(w, ", t_tab: $%02X", ptr.u8[3]); + adr += 4; + ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); + wprintw(w, ", t_val: $%"PRIX64, ptr.u64); + adr += 8; + ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); + wprintw(w, ", t_str: $%"PRIX64, ptr.u64); + adr += 8; + ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); + wprintw(w, ", t_sym: $%"PRIX64, ptr.u64); + + + /* + wmove(w, 47, 0); + wclrtoeol(w); + wprintw(w, "a: $%02X,", addr[0x0A]); + wprintw(w, " b: $%02X,", addr[0x0B]); + wprintw(w, " c: $%02X,", addr[0x0C]); + wprintw(w, " d: $%02X,", addr[0x0D]); + wprintw(w, " e: $%02X,", addr[0x0E]); + wprintw(w, " f: $%02X", addr[0x0F]); + tmpad += 8; + adr = read_value(cpu, 0, tmpad, 7, 0, 0); + line_idx = 0; + wprintw(w, "cmd_buf:"); + for (uint8_t i = 0; i < 1; i++) { + wmove(w, ln++, 0); + wclrtoeol(w); + line_idx = (i << 4)+(i << 6); + for (uint8_t j = 0; j < 0x50; j++) { + wprintw(w, "%02X", addr[adr+j+line_idx]); + } + wprintw(w, ", i: %02X", i); + }*/ } static uint64_t get_offset(uint64_t value, uint8_t size, char **sign) { @@ -146,7 +281,7 @@ static int is_2op(uint8_t opcode) { return 0; } -static void disasm_ortho(struct sux *cpu, uint8_t opcode, uint8_t prefix, uint8_t prefix2, uint64_t *value, char *inst_name, char *postfix, operand *op, uint8_t rs, uint8_t thread) { +static void disasm_ortho(struct sux *cpu, WINDOW *w, uint8_t opcode, uint8_t prefix, uint8_t prefix2, uint64_t *value, char *inst_name, char *postfix, operand *op, uint8_t rs, uint8_t thread) { char opr[2][256]; char address[2][17]; char *rind[2] = {"", ""}; @@ -280,9 +415,9 @@ static void disasm_ortho(struct sux *cpu, uint8_t opcode, uint8_t prefix, uint8_ } else if (is_2op(opcode)) { op2 = opr[1]; } - wprintw(scr, "%s%s%s %s%s %s", inst_name, postfix, os, opr[0], (op_count == 2) ? "," : "", op2); - wmove(scr, 29, 0); - wclrtoeol(scr); + wprintw(w, "%s%s%s %s%s %s", inst_name, postfix, os, opr[0], (op_count == 2) ? "," : "", op2); + wmove(w, getmaxy(w)-2, 0); + wclrtoeol(w); for (int i = 0; i < 2; i++) { if (op[i].type) { sprintf(address[i], "$%04"PRIX64, value[i]); @@ -290,11 +425,11 @@ static void disasm_ortho(struct sux *cpu, uint8_t opcode, uint8_t prefix, uint8_ sprintf(address[i], "none"); } } - wprintw(scr, "destination address: %s, source address: %s", address[0], address[1]); + wprintw(w, "destination address: %s, source address: %s", address[0], address[1]); } -void disasm(struct sux *cpu, uint8_t lines, uint8_t opcode, uint8_t prefix, uint8_t ext_prefix, uint8_t prefix2, uint8_t *op_type, uint8_t *op_id, uint8_t thread) { +void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t opcode, uint8_t prefix, uint8_t ext_prefix, uint8_t prefix2, uint8_t *op_type, uint8_t *op_id, uint8_t thread) { uint64_t value; uint64_t address = 0; operand ortho_op[2]; @@ -384,9 +519,9 @@ void disasm(struct sux *cpu, uint8_t lines, uint8_t opcode, uint8_t prefix, uint } switch (inst_type) { case BREG : - case IMPL : wprintw(scr, "%s%s" , inst_name, postfix); break; - case EIND : wprintw(scr, "%s%s (E)" , op, postfix); break; - case IMM : wprintw(scr, "%s%s #$%0*"PRIX64 , op, postfix, (addrsize+1) << 1, value); break; + case IMPL : wprintw(w, "%s%s" , inst_name, postfix); break; + case EIND : wprintw(w, "%s%s (E)" , op, postfix); break; + case IMM : wprintw(w, "%s%s #$%0*"PRIX64 , op, postfix, (addrsize+1) << 1, value); break; case AIND : case AINDX: case AINDY: @@ -398,145 +533,26 @@ void disasm(struct sux *cpu, uint8_t lines, uint8_t opcode, uint8_t prefix, uint case ABSX : case ABSY : case ZM : - case ABS : wprintw(scr, "%s%s %s%s%s$%0*" PRIX64"%s" , op, postfix, ind, of, sign, (addrsize+1) << 1, value, idx); break; - case REL : wprintw(scr, "%s%s %s$%0*"PRIX64 , op, postfix, sign, (addrsize+1) << 1, value); break; + case ABS : wprintw(w, "%s%s %s%s%s$%0*" PRIX64"%s" , op, postfix, ind, of, sign, (addrsize+1) << 1, value, idx); break; + case REL : wprintw(w, "%s%s %s$%0*"PRIX64 , op, postfix, sign, (addrsize+1) << 1, value); break; } } else { inst_name = ortho_opname[opcode]; memcpy(op, inst_name, 3); - disasm_ortho(cpu, opcode, prefix, prefix2, ortho_addr, op, postfix, ortho_op, (1 << rs), thread); - } - - if (address == TX_ADDR || address == RX_ADDR) { - wmove(scr, 27, 0); - wprintw(scr, "TX_ADDR: $%02X, RX_ADDR: $%02X", addr[TX_ADDR], addr[RX_ADDR]); + disasm_ortho(cpu, w, opcode, prefix, prefix2, ortho_addr, op, postfix, ortho_op, (1 << rs), thread); } + int y = getmaxy(w); if (ext_prefix != 0x1D) { - wmove(scr, 29, 0); - wclrtoeol(scr); - wprintw(scr, "address: $%04"PRIX64, address); + wmove(w, y-2, 0); + wclrtoeol(w); + wprintw(w, "address: $%04"PRIX64, address); + } + if (address == TX_ADDR || ortho_addr[0] == TX_ADDR || address == RX_ADDR || ortho_addr[1] == RX_ADDR) { + wmove(w, y-1, 0); + wprintw(w, "TX_ADDR: $%02X, RX_ADDR: $%02X", addr[TX_ADDR], addr[RX_ADDR]); } if (subdbg) { - uint8_t ln = 33; - uint16_t line_idx = 0; - uint32_t tmpad = 0x20247; - int row, col; - uint8_t iscursor = 0; - union reg ptr; - ptr.u64 = 0; - uint32_t adr; - if (address == CTRL_ADDR || addr[STEP_ADDR]) { - adr = read_value(cpu, 0, tmpad, 7, 0, 0); - tmpad += 8; - wprintw(scr, ", scr_row: %02u, scr_col: %02u, scr_str: %02u, scr_end: %02u", addr[0], addr[1], addr[2], addr[3]); - wmove(scr, 32, 0); - wprintw(scr, "bitabl: "); - for (uint8_t i = 0; i < 16; i++) { - wprintw(scr, "%s", showbits(addr[adr+i], 7, 0)); - } - mvwprintw(scr, ln++, 0, "buffer: "); - wmove(scr, ln++, 0); - uint8_t maxrow = 10; - int line_offset = (addr[0]-(maxrow-1) >= 0) ? addr[0]-(maxrow-1) : 0; - adr = read_value(cpu, 0, tmpad, 7, 0, 0); - for (uint8_t i = 0; i < maxrow; i++) { - line_idx = (i+addr[2]+line_offset << 6) + (i+addr[2]+line_offset << 4); - for (uint8_t j = 0; j < 0x50; j++) { - wprintw(scr, "%02X", addr[adr+j+line_idx]); - if ((addr[0] == i+line_offset) && addr[1] == j) { - iscursor=1; - getyx(scr,row, col); - wmove(scr, ln++, 0); - wclrtoeol(scr); - wmove(scr, row+1, col-2); - wprintw(scr, "/\\"); - wmove(scr, row, col); - } - } - wprintw(scr, ", i: %02X", i); - if (!iscursor) { - wmove(scr, ln, 0); - wclrtoeol(scr); - } - iscursor = 0; - wmove(scr, ln++, 0); - } - } - /*wclrtoeol(scr); - wprintw(scr, "rega: $%02X, ", addr[0x0A]); - wprintw(scr, "regb: $%02X, ", addr[0x0B]); - wprintw(scr, "regc: $%02X, ", addr[0x0C]); - wprintw(scr, "regd: $%02X, ", addr[0x0D]); - wprintw(scr, "rege: $%02X, ", addr[0x0E]); - wprintw(scr, "regf: $%02X, ", addr[0x0F]); - wprintw(scr, "regg: $%02X", addr[0x10]);*/ - - wmove(scr, 30, 0); - wclrtoeol(scr); - - adr = 0x25; - ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); - wprintw(scr, "ptr1: $%04"PRIX64, ptr.u64); - - adr = 0x2D; - ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); - wprintw(scr, ", ptr2: $%04"PRIX64, ptr.u64); - - adr = 0x35; - ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); - wprintw(scr, ", ptr3: $%04"PRIX64, ptr.u64); - - adr = 0x02049A; - ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); - wprintw(scr, ", idx0: $%04"PRIX64, ptr.u64); - - adr = 0x334BA; - ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); - wprintw(scr, ", valbuf: $%016"PRIX64, ptr.u64); - - - wmove(scr, 31, 0); - wclrtoeol(scr); - adr = 0x200CA; - ptr.u64 = read_value(cpu, 0, adr, 3, 0, 0); - wprintw(scr, "t_id: $%02X", ptr.u8[0]); - wprintw(scr, ", t_type: $%02X", ptr.u8[1]); - wprintw(scr, ", t_space: $%02X", ptr.u8[2]); - wprintw(scr, ", t_tab: $%02X", ptr.u8[3]); - adr += 4; - ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); - wprintw(scr, ", t_val: $%"PRIX64, ptr.u64); - adr += 8; - ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); - wprintw(scr, ", t_str: $%"PRIX64, ptr.u64); - adr += 8; - ptr.u64 = read_value(cpu, 0, adr, 7, 0, 0); - wprintw(scr, ", t_sym: $%"PRIX64, ptr.u64); - - - /* - wmove(scr, 47, 0); - wclrtoeol(scr); - wprintw(scr, "a: $%02X,", addr[0x0A]); - wprintw(scr, " b: $%02X,", addr[0x0B]); - wprintw(scr, " c: $%02X,", addr[0x0C]); - wprintw(scr, " d: $%02X,", addr[0x0D]); - wprintw(scr, " e: $%02X,", addr[0x0E]); - wprintw(scr, " f: $%02X", addr[0x0F]); - tmpad += 8; - adr = read_value(cpu, 0, tmpad, 7, 0, 0); - line_idx = 0; - wprintw(scr, "cmd_buf:"); - for (uint8_t i = 0; i < 1; i++) { - wmove(scr, ln++, 0); - wclrtoeol(scr); - line_idx = (i << 4)+(i << 6); - for (uint8_t j = 0; j < 0x50; j++) { - wprintw(scr, "%02X", addr[adr+j+line_idx]); - } - wprintw(scr, ", i: %02X", i); - }*/ - + sub_dbg(cpu, dbg_win, address, ortho_addr, thread); } } |