- fixed file descriptor table

- abstract I/O to mips_dbg



git-svn-id: http://moon:8086/svn/mips@73 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2017-01-11 22:23:45 +00:00
parent f9eb889616
commit 06f7be107b
7 changed files with 230 additions and 103 deletions
+16 -3
View File
@@ -8,6 +8,7 @@
#include "board.h"
#include "../../irq.h"
#include "../../uart.h"
#include "../../console.h"
@@ -17,8 +18,10 @@ extern uart_if_t uart_if[];
const con_if_entry_t con_if_entry[] =
{
{"UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar},
{"UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar}
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
{2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar},
{3, "UART1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar}
};
con_if_t con_if =
@@ -43,4 +46,14 @@ void board_init(void)
dbg_init();
// Do some initializations here
}
}
void dbg_putchar(char c)
{
writechar(3, c);
}
char dbg_getchar()
{
return (char)readchar(3);
}
+3 -3
View File
@@ -89,9 +89,9 @@
#define SYS_UART0_DATA (SYS_IO_BASE + 0x10000)
#define SYS_UART0_STAT (SYS_IO_BASE + 0x10004)
#define SYS_UART0_BAUD (SYS_IO_BASE + 0x10008)
#define SYS_UART1_DATA (SYS_IO_BASE + 0x10100)
#define SYS_UART1_STAT (SYS_IO_BASE + 0x10104)
#define SYS_UART1_BAUD (SYS_IO_BASE + 0x10108)
#define SYS_UART1_DATA (SYS_IO_BASE + 0x30000)
#define SYS_UART1_STAT (SYS_IO_BASE + 0x30004)
#define SYS_UART1_BAUD (SYS_IO_BASE + 0x30008)
// SPI
#define SYS_SPI_STAT (SYS_IO_BASE + 0x20000)
+20 -6
View File
@@ -7,7 +7,7 @@
#include <stddef.h>
#include "board.h"
#include "../../irq.h"
#include "../../mips_ps2.h"
#include "../../screen.h"
#include "../../uart.h"
@@ -21,11 +21,13 @@ extern vga_if_t vga_if;
static const con_if_entry_t con_if_entry[] =
{
{"UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar},
{"UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar},
{"PS2-0", &ps2_if[0], PS2_open, PS2_close, PS2_readchar, NULL},
{"PS2-1", &ps2_if[1], PS2_open, PS2_close, PS2_readchar, NULL},
{"VGA-0", &vga_if, cg_open, cg_close, NULL, cg_writechar}
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
{2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar},
{3, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar},
{4, "PS2-0", &ps2_if[0], PS2_open, PS2_close, PS2_readchar, NULL},
{5, "PS2-1", &ps2_if[1], PS2_open, PS2_close, PS2_readchar, NULL},
{6, "VGA-0", &vga_if, cg_open, cg_close, NULL, cg_writechar}
};
con_if_t con_if =
@@ -53,6 +55,8 @@ void board_init(void)
// Initalize debugger
dbg_init();
interrupt_register(2, debug_int);
interrupt_enable(2);
// flush stdin
// flush(con_getPort(0));
@@ -60,3 +64,13 @@ void board_init(void)
// Do some initializations here
}
void dbg_putchar(char c)
{
writechar(1, c);
}
char dbg_getchar()
{
return (char)readchar(0);
}
+11 -3
View File
@@ -13,9 +13,17 @@ extern con_if_t con_if;
// Funcs
con_if_entry_t const* con_getPort(int file)
{
assert(file < con_if.length);
return &con_if.con_if_entry[file];
con_if_entry_t const *result = NULL;
int i;
for (i=0; i < con_if.length; i++)
{
if (file == con_if.con_if_entry[i].fd)
{
result = &con_if.con_if_entry[i];
break;
}
}
return result;
}
int con_open(char const *pName)
+1
View File
@@ -23,6 +23,7 @@ typedef void (*close_func_t)(void const *pInst);
typedef struct _scon_if_entry_t
{
int fd;
char const *pName;
void const *pInst;
open_func_t openFunc;
+10 -6
View File
@@ -331,10 +331,14 @@ int read(int file, char *ptr, int len)
{
int i;
char c;
// sputs("read (file="); print_word(file); sputs(", len ="); print_word(len); sputs(")\n");
i = 0;
int fd_out = file;
if (file == 0)
{
fd_out = 1;
}
i = 0;
while (i < len)
{
c = readchar(file);
@@ -344,14 +348,14 @@ int read(int file, char *ptr, int len)
if ((c == 0x0D) || (c == 0x0A))
{
writechar(file, 0x0D);
writechar(fd_out, 0x0D);
ptr[i++] = 0x0D;
writechar(file, 0x0A);
writechar(fd_out, 0x0A);
ptr[i++] = 0x0A;
break;
}
writechar(file, c);
writechar(fd_out, c);
ptr[i++] = c;
}
+169 -82
View File
@@ -1,10 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "irq.h"
#include "xcpt.h"
#include "libsys.h"
#include "mips_dis.h"
#define DBG_PRINT_REG(tag_str, reg) \
dbg_puts(tag_str); \
dbg_print_word(reg); \
dbg_puts(" ");
#define DBG_PRINT_REG_CHG(tag_str, reg, chg_tag) \
dbg_puts(tag_str); \
dbg_print_word(reg); \
dbg_puts(chg_tag); \
dbg_puts(" ");
#define MAX_USER_BP 16
#define BP_MASK_ID 0x00FFF
#define BP_MASK_TYPE 0xFF000
@@ -48,6 +61,81 @@ static bp_t mgmt_bp_ru[2];
static int g_is_ss;
static int g_bp_count;
#if 1
extern void dbg_putchar(char c);
extern char dbg_getchar();
void dbg_puts(const char *buffer)
{
while(*buffer)
{
dbg_putchar(*buffer);
buffer++;
}
}
void dbg_print_byte(char byte)
{
int i;
unsigned char c, nibble;
for (i=0; i < 2; i++)
{
nibble = (char)((byte >> 4) & 0xF);
byte <<= 4;
if (nibble < 10)
c = nibble + '0';
else
c = nibble + 'A' - 10;
dbg_putchar(c);
}
}
void dbg_print_word(int word)
{
int i;
unsigned char c;
for (i=0; i < 4; i++)
{
c = (char) (word >> 24);
dbg_print_byte(c);
word <<= 8;
}
}
int dbg_gets(char *buffer, size_t size)
{
size_t len = 0;
while(size)
{
char c = dbg_getchar();
if (c == 0x0A || c == 0x0D)
{
if (len)
{
break;
}
}
else
{
buffer[len++] = c;
dbg_putchar(c);
if (len == size)
{
break;
}
}
}
buffer[len] = 0;
dbg_putchar(0x0D);
dbg_putchar(0x0A);
return len;
}
#endif
int IsBreak(uint32_t instr)
{
return ((instr & 0xFC00003F) == 0x0000000D);
@@ -78,7 +166,7 @@ void set_mgmt_break(uint32_t *pAddr_break)
// Don't overwrite user breaks
if (IsBreak(*pAddr_break) && (BreakGetType(*pAddr_break) == BP_USER_BASE))
{
// sputs("Instruction at address ");print_word((long)pAddr_break);sputs(" is user break\n");
// dbg_puts("Instruction at address ");dbg_print_word((long)pAddr_break);dbg_puts(" is user break\n");
}
else
{
@@ -119,7 +207,7 @@ void singlestep(struct xcptcontext * xcp, uint32_t *pAddr_curr, uint32_t is_bran
// Don't overwrite user breaks
if (IsBreak(branch_addr) && (BreakGetType(branch_addr) == BP_USER_BASE))
{
// sputs("Instruction at branch address ");print_word((long)branch_addr);sputs(" is user break\n");
// dbg_puts("Instruction at branch address ");dbg_print_word((long)branch_addr);dbg_puts(" is user break\n");
}
else
{
@@ -159,12 +247,12 @@ void dbg_handler(struct xcptcontext * xcp)
case BP_MGMT_BASE_SS:
// Restore original instructions after single-step
// sputs("1. Restore after single-step at ");print_word((long)mgmt_bp_ss[0].pAddr);sputs("\n");
// dbg_puts("1. Restore after single-step at ");dbg_print_word((long)mgmt_bp_ss[0].pAddr);dbg_puts("\n\r");
*(mgmt_bp_ss[0].pAddr) = mgmt_bp_ss[0].instr;
ICACHE_invalidate_at(mgmt_bp_ss[0].pAddr);
if (mgmt_bp_ss[1].pAddr)
{
// sputs("2. Restore after single-step at ");print_word((long)mgmt_bp_ss[1].pAddr);sputs("\n");
// dbg_puts("2. Restore after single-step at ");dbg_print_word((long)mgmt_bp_ss[1].pAddr);dbg_puts("\n\r");
*(mgmt_bp_ss[1].pAddr) = mgmt_bp_ss[1].instr;
ICACHE_invalidate_at(mgmt_bp_ss[1].pAddr);
}
@@ -174,19 +262,19 @@ void dbg_handler(struct xcptcontext * xcp)
case BP_MGMT_BASE_RU:
bp_index = BP_GET_ID(*pAddr_curr);
// sputs("Restore user break at ");print_word((long)user_bp[bp_index].pAddr);sputs("\n");
// dbg_puts("Restore user break at ");dbg_print_word((long)user_bp[bp_index].pAddr);dbg_puts("\n\r");
*(user_bp[bp_index].pAddr) = BP_USER(bp_index);
ICACHE_invalidate_at(user_bp[bp_index].pAddr);
*(mgmt_bp_ru[0].pAddr) = mgmt_bp_ru[0].instr;
ICACHE_invalidate_at(mgmt_bp_ru[0].pAddr);
// sputs("1. Restore after RU at ");print_word((long)mgmt_bp_ru[0].pAddr);sputs("\n");
// dbg_puts("1. Restore after RU at ");dbg_print_word((long)mgmt_bp_ru[0].pAddr);dbg_puts("\n\r");
if (mgmt_bp_ru[1].pAddr)
{
*(mgmt_bp_ru[1].pAddr) = mgmt_bp_ru[1].instr;
ICACHE_invalidate_at(mgmt_bp_ru[1].pAddr);
// sputs("2. Restore after RU at ");print_word((long)mgmt_bp_ru[1].pAddr);sputs("\n");
// dbg_puts("2. Restore after RU at ");dbg_print_word((long)mgmt_bp_ru[1].pAddr);dbg_puts("\n\r");
}
if (!g_is_ss)
return;
@@ -197,91 +285,91 @@ void dbg_handler(struct xcptcontext * xcp)
is_user_bp = 1;
bp_index = BP_GET_ID(*pAddr_curr);
// sputs("Restore instruction at ");print_word((long)user_bp[bp_index].pAddr);sputs("\n");
// dbg_puts("Restore instruction at ");dbg_print_word((long)user_bp[bp_index].pAddr);dbg_puts("\n\r");
*(user_bp[bp_index].pAddr) = user_bp[bp_index].instr;
ICACHE_invalidate_at(user_bp[bp_index].pAddr);
break;
default:
// sputs("Found ordinary break at ");print_word((long)pAddr_curr);sputs("\n");
// dbg_puts("Found ordinary break at ");dbg_print_word((long)pAddr_curr);dbg_puts("\n\r");
break;
}
}
sputs("\n");
PRINT_REG_CHG(" Status : ", xcp->sr, reg_changed(xcp->sr, xcp_last.sr));
PRINT_REG_CHG(" Cause : ", xcp->cr, reg_changed(xcp->cr, xcp_last.cr));
PRINT_REG_CHG(" EPC : ", xcp->epc, reg_changed(xcp->epc, xcp_last.epc));
PRINT_REG_CHG("BadAddr : ", xcp->baddr, reg_changed(xcp->baddr, xcp_last.baddr));
sputs("\n");
PRINT_REG_CHG(" MDLO : ", xcp->mdlo, reg_changed(xcp->mdlo, xcp_last.mdlo));
PRINT_REG_CHG(" MDHI : ", xcp->mdhi, reg_changed(xcp->mdhi, xcp_last.mdhi));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG(" Status : ", xcp->sr, reg_changed(xcp->sr, xcp_last.sr));
DBG_PRINT_REG_CHG(" Cause : ", xcp->cr, reg_changed(xcp->cr, xcp_last.cr));
DBG_PRINT_REG_CHG(" EPC : ", xcp->epc, reg_changed(xcp->epc, xcp_last.epc));
DBG_PRINT_REG_CHG("BadAddr : ", xcp->baddr, reg_changed(xcp->baddr, xcp_last.baddr));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG(" MDLO : ", xcp->mdlo, reg_changed(xcp->mdlo, xcp_last.mdlo));
DBG_PRINT_REG_CHG(" MDHI : ", xcp->mdhi, reg_changed(xcp->mdhi, xcp_last.mdhi));
sputs("\n");
dbg_puts("\n\r");
sputs("Registers:\n");
PRINT_REG_CHG(" 0 (ze) : ", xcp->regs[0], reg_changed(xcp->regs[0], xcp_last.regs[0]));
PRINT_REG_CHG(" 1 (at) : ", xcp->regs[1], reg_changed(xcp->regs[1], xcp_last.regs[1]));
PRINT_REG_CHG(" 2 (v0) : ", xcp->regs[2], reg_changed(xcp->regs[2], xcp_last.regs[2]));
PRINT_REG_CHG(" 3 (v1) : ", xcp->regs[3], reg_changed(xcp->regs[3], xcp_last.regs[3]));
sputs("\n");
PRINT_REG_CHG(" 4 (a0) : ", xcp->regs[4], reg_changed(xcp->regs[4], xcp_last.regs[4]));
PRINT_REG_CHG(" 5 (a1) : ", xcp->regs[5], reg_changed(xcp->regs[5], xcp_last.regs[5]));
PRINT_REG_CHG(" 6 (a2) : ", xcp->regs[6], reg_changed(xcp->regs[6], xcp_last.regs[6]));
PRINT_REG_CHG(" 7 (a3) : ", xcp->regs[7], reg_changed(xcp->regs[7], xcp_last.regs[7]));
sputs("\n");
PRINT_REG_CHG(" 8 (t0) : ", xcp->regs[8], reg_changed(xcp->regs[8], xcp_last.regs[8]));
PRINT_REG_CHG(" 9 (t1) : ", xcp->regs[9], reg_changed(xcp->regs[9], xcp_last.regs[9]));
PRINT_REG_CHG("10 (t2) : ", xcp->regs[10], reg_changed(xcp->regs[10], xcp_last.regs[10]));
PRINT_REG_CHG("11 (t3) : ", xcp->regs[11], reg_changed(xcp->regs[11], xcp_last.regs[11]));
sputs("\n");
PRINT_REG_CHG("12 (t4) : ", xcp->regs[12], reg_changed(xcp->regs[12], xcp_last.regs[12]));
PRINT_REG_CHG("13 (t5) : ", xcp->regs[13], reg_changed(xcp->regs[13], xcp_last.regs[13]));
PRINT_REG_CHG("14 (t6) : ", xcp->regs[14], reg_changed(xcp->regs[14], xcp_last.regs[14]));
PRINT_REG_CHG("15 (t7) : ", xcp->regs[15], reg_changed(xcp->regs[15], xcp_last.regs[15]));
sputs("\n");
PRINT_REG_CHG("16 (s0) : ", xcp->regs[16], reg_changed(xcp->regs[16], xcp_last.regs[16]));
PRINT_REG_CHG("17 (s1) : ", xcp->regs[17], reg_changed(xcp->regs[17], xcp_last.regs[17]));
PRINT_REG_CHG("18 (s2) : ", xcp->regs[18], reg_changed(xcp->regs[18], xcp_last.regs[18]));
PRINT_REG_CHG("19 (s3) : ", xcp->regs[19], reg_changed(xcp->regs[19], xcp_last.regs[19]));
sputs("\n");
PRINT_REG_CHG("20 (s4) : ", xcp->regs[20], reg_changed(xcp->regs[20], xcp_last.regs[20]));
PRINT_REG_CHG("21 (s5) : ", xcp->regs[21], reg_changed(xcp->regs[21], xcp_last.regs[21]));
PRINT_REG_CHG("22 (s6) : ", xcp->regs[22], reg_changed(xcp->regs[22], xcp_last.regs[22]));
PRINT_REG_CHG("23 (s7) : ", xcp->regs[23], reg_changed(xcp->regs[23], xcp_last.regs[23]));
sputs("\n");
PRINT_REG_CHG("24 (s8) : ", xcp->regs[24], reg_changed(xcp->regs[24], xcp_last.regs[24]));
PRINT_REG_CHG("25 (s9) : ", xcp->regs[25], reg_changed(xcp->regs[25], xcp_last.regs[25]));
PRINT_REG_CHG("26 (k0) : ", xcp->regs[26], reg_changed(xcp->regs[26], xcp_last.regs[26]));
PRINT_REG_CHG("27 (k1) : ", xcp->regs[27], reg_changed(xcp->regs[27], xcp_last.regs[27]));
sputs("\n");
PRINT_REG_CHG("28 (gp) : ", xcp->regs[28], reg_changed(xcp->regs[28], xcp_last.regs[28]));
PRINT_REG_CHG("29 (sp) : ", xcp->regs[29], reg_changed(xcp->regs[29], xcp_last.regs[29]));
PRINT_REG_CHG("30 (fp) : ", xcp->regs[30], reg_changed(xcp->regs[30], xcp_last.regs[30]));
PRINT_REG_CHG("31 (ra) : ", xcp->regs[31], reg_changed(xcp->regs[31], xcp_last.regs[31]));
sputs("\n");
sputs("\n");
dbg_puts("Registers:\n\r");
DBG_PRINT_REG_CHG(" 0 (ze) : ", xcp->regs[0], reg_changed(xcp->regs[0], xcp_last.regs[0]));
DBG_PRINT_REG_CHG(" 1 (at) : ", xcp->regs[1], reg_changed(xcp->regs[1], xcp_last.regs[1]));
DBG_PRINT_REG_CHG(" 2 (v0) : ", xcp->regs[2], reg_changed(xcp->regs[2], xcp_last.regs[2]));
DBG_PRINT_REG_CHG(" 3 (v1) : ", xcp->regs[3], reg_changed(xcp->regs[3], xcp_last.regs[3]));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG(" 4 (a0) : ", xcp->regs[4], reg_changed(xcp->regs[4], xcp_last.regs[4]));
DBG_PRINT_REG_CHG(" 5 (a1) : ", xcp->regs[5], reg_changed(xcp->regs[5], xcp_last.regs[5]));
DBG_PRINT_REG_CHG(" 6 (a2) : ", xcp->regs[6], reg_changed(xcp->regs[6], xcp_last.regs[6]));
DBG_PRINT_REG_CHG(" 7 (a3) : ", xcp->regs[7], reg_changed(xcp->regs[7], xcp_last.regs[7]));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG(" 8 (t0) : ", xcp->regs[8], reg_changed(xcp->regs[8], xcp_last.regs[8]));
DBG_PRINT_REG_CHG(" 9 (t1) : ", xcp->regs[9], reg_changed(xcp->regs[9], xcp_last.regs[9]));
DBG_PRINT_REG_CHG("10 (t2) : ", xcp->regs[10], reg_changed(xcp->regs[10], xcp_last.regs[10]));
DBG_PRINT_REG_CHG("11 (t3) : ", xcp->regs[11], reg_changed(xcp->regs[11], xcp_last.regs[11]));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG("12 (t4) : ", xcp->regs[12], reg_changed(xcp->regs[12], xcp_last.regs[12]));
DBG_PRINT_REG_CHG("13 (t5) : ", xcp->regs[13], reg_changed(xcp->regs[13], xcp_last.regs[13]));
DBG_PRINT_REG_CHG("14 (t6) : ", xcp->regs[14], reg_changed(xcp->regs[14], xcp_last.regs[14]));
DBG_PRINT_REG_CHG("15 (t7) : ", xcp->regs[15], reg_changed(xcp->regs[15], xcp_last.regs[15]));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG("16 (s0) : ", xcp->regs[16], reg_changed(xcp->regs[16], xcp_last.regs[16]));
DBG_PRINT_REG_CHG("17 (s1) : ", xcp->regs[17], reg_changed(xcp->regs[17], xcp_last.regs[17]));
DBG_PRINT_REG_CHG("18 (s2) : ", xcp->regs[18], reg_changed(xcp->regs[18], xcp_last.regs[18]));
DBG_PRINT_REG_CHG("19 (s3) : ", xcp->regs[19], reg_changed(xcp->regs[19], xcp_last.regs[19]));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG("20 (s4) : ", xcp->regs[20], reg_changed(xcp->regs[20], xcp_last.regs[20]));
DBG_PRINT_REG_CHG("21 (s5) : ", xcp->regs[21], reg_changed(xcp->regs[21], xcp_last.regs[21]));
DBG_PRINT_REG_CHG("22 (s6) : ", xcp->regs[22], reg_changed(xcp->regs[22], xcp_last.regs[22]));
DBG_PRINT_REG_CHG("23 (s7) : ", xcp->regs[23], reg_changed(xcp->regs[23], xcp_last.regs[23]));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG("24 (s8) : ", xcp->regs[24], reg_changed(xcp->regs[24], xcp_last.regs[24]));
DBG_PRINT_REG_CHG("25 (s9) : ", xcp->regs[25], reg_changed(xcp->regs[25], xcp_last.regs[25]));
DBG_PRINT_REG_CHG("26 (k0) : ", xcp->regs[26], reg_changed(xcp->regs[26], xcp_last.regs[26]));
DBG_PRINT_REG_CHG("27 (k1) : ", xcp->regs[27], reg_changed(xcp->regs[27], xcp_last.regs[27]));
dbg_puts("\n\r");
DBG_PRINT_REG_CHG("28 (gp) : ", xcp->regs[28], reg_changed(xcp->regs[28], xcp_last.regs[28]));
DBG_PRINT_REG_CHG("29 (sp) : ", xcp->regs[29], reg_changed(xcp->regs[29], xcp_last.regs[29]));
DBG_PRINT_REG_CHG("30 (fp) : ", xcp->regs[30], reg_changed(xcp->regs[30], xcp_last.regs[30]));
DBG_PRINT_REG_CHG("31 (ra) : ", xcp->regs[31], reg_changed(xcp->regs[31], xcp_last.regs[31]));
dbg_puts("\n\r");
dbg_puts("\n\r");
// sputs(g_state_names[g_state]);sputs("\n");
// sputs("\n");
// dbg_puts(g_state_names[g_state]);dbg_puts("\n\r");
// dbg_puts("\n\r");
pInstr = pAddr_prev;
// Disassemble instructions
for (i=0; i < 3; i++)
{
print_word((long)pInstr);
dbg_print_word((long)pInstr);
if (pInstr != pAddr_curr)
{
if (IsBreak(*pInstr) && (BreakGetType(*pInstr) == BP_USER_BASE))
{
tdisasm(g_buf, (long)user_bp[BP_GET_ID(*pInstr)].pAddr, user_bp[BP_GET_ID(*pInstr)].instr, 0, &junk, &junk, &junk);
sputs(": b("); print_byte((char)BP_GET_ID(*pInstr)); sputs(") ");
dbg_puts(": b("); dbg_print_byte((char)BP_GET_ID(*pInstr)); dbg_puts(") ");
}
else
{
tdisasm(g_buf, (long)pInstr, *pInstr, 0, &junk, &junk, &junk);
sputs(": ");
dbg_puts(": ");
}
}
else
@@ -289,15 +377,15 @@ void dbg_handler(struct xcptcontext * xcp)
tdisasm(g_buf, (long)pInstr, *pInstr, 0, &junk, &junk, &junk);
if (is_user_bp)
{
sputs(": b("); print_byte((char)bp_index); sputs(")-> ");
dbg_puts(": b("); dbg_print_byte((char)bp_index); dbg_puts(")-> ");
}
else
{
sputs(": -> ");
dbg_puts(": -> ");
}
}
sputs(g_buf);
sputs("\n");
dbg_puts(g_buf);
dbg_puts("\n\r");
pInstr++;
}
@@ -311,7 +399,7 @@ void dbg_handler(struct xcptcontext * xcp)
ICACHE_invalidate_at(mgmt_bp_ru[0].pAddr);
mgmt_bp_ru[1].pAddr = NULL;
mgmt_bp_ru[1].pAddr = 0;
// sputs("1. Insert RU-break at ");print_word((long)mgmt_bp_ru[0].pAddr);sputs("\n");
// dbg_puts("1. Insert RU-break at ");dbg_print_word((long)mgmt_bp_ru[0].pAddr);dbg_puts("\n\r");
// We have two possible management breaks, if previous instruction was branch or jump
if (is_branch_shadow)
@@ -328,14 +416,15 @@ void dbg_handler(struct xcptcontext * xcp)
// Replace instruction with managment breakpoint
*(mgmt_bp_ru[1].pAddr) = BP_MGMT_RU(bp_index);
ICACHE_invalidate_at(mgmt_bp_ru[1].pAddr);
// sputs("2. Insert RU-break at ");print_word((long)mgmt_bp_ru[1].pAddr);sputs("\n");
// dbg_puts("2. Insert RU-break at ");dbg_print_word((long)mgmt_bp_ru[1].pAddr);dbg_puts("\n\r");
}
}
do
{
char buffer[33];
leave_isr = 0;
switch(_getchar())
switch(dbg_getchar())
{
case 'g':
g_state = STATE_RUN;
@@ -351,16 +440,17 @@ void dbg_handler(struct xcptcontext * xcp)
break;
case 'b':
printf("Enter breakpoint: ");
scanf("%x", &bp_addr);
printf("Insert breakpoint at %.8X\n", bp_addr);
dbg_puts("Enter breakpoint: ");
dbg_gets(buffer, sizeof(buffer));
bp_addr = strtol(buffer, NULL, 16);
dbg_puts("Insert breakpoint at "); dbg_print_word(bp_addr); dbg_puts("\n\r");
user_bp[g_bp_count].pAddr = (uint32_t*)bp_addr;
user_bp[g_bp_count].instr = *(user_bp[g_bp_count].pAddr);
*(user_bp[g_bp_count].pAddr) = BP_USER(g_bp_count);
tdisasm(g_buf, (long)user_bp[g_bp_count].pAddr, user_bp[g_bp_count].instr, 0, &junk, &junk, &junk);
print_word((long)user_bp[g_bp_count].pAddr);sputs(": b ");sputs(g_buf);sputs("\n");
dbg_print_word((long)user_bp[g_bp_count].pAddr);dbg_puts(": b ");dbg_puts(g_buf);dbg_puts("\n\r");
ICACHE_invalidate_at(user_bp[g_bp_count].pAddr);
g_bp_count++;
break;
@@ -426,7 +516,7 @@ void dbg_handler(struct xcptcontext * xcp)
pInstr++;
} while(1);
// sputs("Return found at "); print_word((long)pInstr);sputs("\n");
// dbg_puts("Return found at "); dbg_print_word((long)pInstr);dbg_puts("\n\r");
set_mgmt_break(pInstr);
break;
@@ -454,7 +544,7 @@ void dbg_handler(struct xcptcontext * xcp)
if ((result == INSTR_TYPE_JUMP) && (info.flags & INSTR_FLAGS_JUMP_LINK))
{
singlestep(xcp, pAddr_next, 0);
// sputs("Skip sub-routine\n");
// printf("Skip sub-routine\n");
}
else
{
@@ -486,10 +576,7 @@ int debug_break(struct xcptcontext * xcp)
void dbg_init(void)
{
memset(&xcp_last, 0, sizeof(EXCEPTION_CONTEXT));
interrupt_register(2, debug_int);
interrupt_enable(2);
g_state = STATE_INIT;
xcpt_register(EXC_BP, debug_break);
}