From b23ccf5a8c9b7a1a83efc5c42be2b8063b427104 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 16 Jan 2017 19:25:08 +0000 Subject: [PATCH] - added and use gdb-stub git-svn-id: http://moon:8086/svn/mips@87 a8ebac50-d88d-4704-bea3-6648445a41b3 --- src/libsys/Makefile | 2 +- src/libsys/boards/denano/board.c | 78 ++++++++++++++++++-------------- src/libsys/kernel.S | 4 +- src/libsys/mips_dbg.c | 27 ++++------- 4 files changed, 56 insertions(+), 55 deletions(-) diff --git a/src/libsys/Makefile b/src/libsys/Makefile index 64dcfab..8afb344 100644 --- a/src/libsys/Makefile +++ b/src/libsys/Makefile @@ -32,7 +32,7 @@ OBJCOPY=mipsel-elf-objcopy FLASHGEN=flashgen OBJS-ml402=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o mips_dbg.o mips_dis.o mips_ps2.o mips_gfx.o console.o screen.o uart.o board.o gpio.o) -OBJS-denano=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o mips_dbg.o mips_dis.o console.o uart.o board.o) +OBJS-denano=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o mips_dbg.o mips_dis.o console.o uart.o board.o gdb_stub.o) all: $(BUILD_DIR) $(BUILD_DIR)/libsys.a diff --git a/src/libsys/boards/denano/board.c b/src/libsys/boards/denano/board.c index c2f4700..1e0df4f 100644 --- a/src/libsys/boards/denano/board.c +++ b/src/libsys/boards/denano/board.c @@ -31,41 +31,13 @@ static volatile uint32_t *pGpioData = (uint32_t*)SYS_GPIO_0_DATA; static volatile uint32_t *pGpioDir = (uint32_t*)SYS_GPIO_0_DIR; static uint32_t led_count = 0; -void dbg_uart_setup(); +extern int dbg_handler(struct xcptcontext * xcp); +extern void handle_exception (unsigned long *registers); -void board_init(void) +int gdb_stub(struct xcptcontext * xcp) { - uint32_t volatile *pITIM_ctrl = (uint32_t*)SYS_ITIM_CTRL; - - // Disable timers - *pITIM_ctrl = 0; - - // Setup syscall support - syscalls_init(); - - // Setup Uart ISR - dbg_uart_setup(); - - // Setup debugger - dbg_init(); - - // Setup interrupt support - interrupt_init(); - - // Do some initializations here - *pGpioDir = 0xFF; -} - -extern void dbg_handler(struct xcptcontext * xcp); -void dbg_uart_isr(struct xcptcontext *xcp); -void dbg_uart_setup() -{ - const int UART_INT = SYS_INT_UART1; - dbg_uart = (uart_if_t*)con_getInterfaceByName("UART-1")->pInst; - - *dbg_uart->pCTRL = SYS_UART_BIT_RX_INTEN; - interrupt_register(UART_INT, dbg_uart_isr); - interrupt_enable(UART_INT); + handle_exception((unsigned long *)xcp); + return 0; } void dbg_uart_isr(struct xcptcontext *xcp) @@ -75,11 +47,21 @@ void dbg_uart_isr(struct xcptcontext *xcp) char c = *dbg_uart->pDATA; if (c == 3) { - dbg_handler(xcp); + gdb_stub(xcp); } } } +void dbg_uart_setup() +{ + const int UART_INT = SYS_INT_UART1; + dbg_uart = (uart_if_t*)con_getInterfaceByName("UART-1")->pInst; + + *dbg_uart->pCTRL = SYS_UART_BIT_RX_INTEN; + interrupt_register(UART_INT, dbg_uart_isr); + interrupt_enable(UART_INT); +} + inline void _dbg_writechar(uart_if_t const *pUart, char c) { while((SYS_UART_BIT_TX_HALFFULL & *pUart->pCTRL) != 0); @@ -113,3 +95,31 @@ char dbg_getchar() { return (char)_dbg_readchar(dbg_uart); } + +void dbg_init() +{ + xcpt_register(EXC_BP, gdb_stub); +} + +void board_init(void) +{ + uint32_t volatile *pITIM_ctrl = (uint32_t*)SYS_ITIM_CTRL; + + // Disable timers + *pITIM_ctrl = 0; + + // Setup syscall support + syscalls_init(); + + // Setup Uart ISR + dbg_uart_setup(); + + // Setup debugger + dbg_init(); + + // Setup interrupt support + interrupt_init(); + + // Do some initializations here + *pGpioDir = 0xFF; +} diff --git a/src/libsys/kernel.S b/src/libsys/kernel.S index de78847..8cb9299 100644 --- a/src/libsys/kernel.S +++ b/src/libsys/kernel.S @@ -16,8 +16,8 @@ LEAF(_xcpt_handler) /* allocate exception stack frame (on 8-byte boundary) */ li k1, XCP_SIZE - subu k1, sp, k1 - srl k1, 3 /* shift right/left -> alligned on boundary */ + subu k1, sp, k1 + srl k1, 3 /* shift right/left -> alligned on boundary */ sll k1, 3 /* save enough registers to get by */ diff --git a/src/libsys/mips_dbg.c b/src/libsys/mips_dbg.c index 2b317a9..115ded6 100644 --- a/src/libsys/mips_dbg.c +++ b/src/libsys/mips_dbg.c @@ -42,10 +42,9 @@ enum STATE_NUM_ENTRIES }; -static int g_state; +static int g_state = STATE_INIT; static char *g_state_names[STATE_NUM_ENTRIES] = {"Init", "Run", "Single step", "Precedure step"}; - typedef struct _sbp_t { uint32_t *pAddr; @@ -285,7 +284,7 @@ void singlestep(struct xcptcontext * xcp, uint32_t *pAddr_curr, uint32_t is_bran } -void dbg_handler(struct xcptcontext * xcp) +int dbg_handler(struct xcptcontext * xcp) { uint32_t bp_addr, bp_index = 0, branch_addr, reg, result, bp_type; @@ -302,8 +301,13 @@ void dbg_handler(struct xcptcontext * xcp) pAddr_prev = pAddr_curr - 1; pAddr_next = pAddr_curr + 1; + if (g_state = STATE_INIT) + { + memset(&xcp_last, 0, sizeof(EXCEPTION_CONTEXT)); + } + dbg_puts_d("\n");dbg_puts_d(g_state_names[g_state]);dbg_puts_d("\n"); - + if (IsBreak(*pAddr_curr)) { bp_type = BreakGetType(*pAddr_curr); @@ -582,19 +586,6 @@ void dbg_handler(struct xcptcontext * xcp) } while (!leave_isr); memcpy(&xcp_last, xcp, sizeof(EXCEPTION_CONTEXT)); -} - -int debug_break(struct xcptcontext * xcp) -{ - dbg_handler(xcp); + return 0; - } - -void dbg_init(void) -{ - memset(&xcp_last, 0, sizeof(EXCEPTION_CONTEXT)); - g_state = STATE_INIT; - xcpt_register(EXC_BP, debug_break); -} -