diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 338cd857..1804e175 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -304,57 +304,3 @@ static void setup_vbus_irq(void) exti15_10_isr(); } - -#ifdef ENABLE_DEBUG -enum { - RDI_SYS_OPEN = 0x01, - RDI_SYS_WRITE = 0x05, - RDI_SYS_ISTTY = 0x09, -}; - -int rdi_write(int fn, const char *buf, size_t len) -{ - (void)fn; - if (debug_bmp) - return len - usbuart_debug_write(buf, len); - - return 0; -} - -struct ex_frame { - union { - int syscall; - int retval; - }; - const int *params; - uint32_t r2, r3, r12, lr, pc; -}; - -void debug_monitor_handler_c(struct ex_frame *sp) -{ - /* Return to after breakpoint instruction */ - sp->pc += 2; - - switch (sp->syscall) { - case RDI_SYS_OPEN: - sp->retval = 1; - break; - case RDI_SYS_WRITE: - sp->retval = rdi_write(sp->params[0], (void*)sp->params[1], sp->params[2]); - break; - case RDI_SYS_ISTTY: - sp->retval = 1; - break; - default: - sp->retval = -1; - } - -} - -asm(".globl debug_monitor_handler\n" - ".thumb_func\n" - "debug_monitor_handler: \n" - " mov r0, sp\n" - " b debug_monitor_handler_c\n"); - -#endif diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index ed74d36c..a4a772e1 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -250,3 +250,57 @@ void USBUSART_TIM_ISR(void) /* process FIFO */ usbuart_run(); } + +#ifdef ENABLE_DEBUG +enum { + RDI_SYS_OPEN = 0x01, + RDI_SYS_WRITE = 0x05, + RDI_SYS_ISTTY = 0x09, +}; + +int rdi_write(int fn, const char *buf, size_t len) +{ + (void)fn; + if (debug_bmp) + return len - usbuart_debug_write(buf, len); + + return 0; +} + +struct ex_frame { + union { + int syscall; + int retval; + }; + const int *params; + uint32_t r2, r3, r12, lr, pc; +}; + +void debug_monitor_handler_c(struct ex_frame *sp) +{ + /* Return to after breakpoint instruction */ + sp->pc += 2; + + switch (sp->syscall) { + case RDI_SYS_OPEN: + sp->retval = 1; + break; + case RDI_SYS_WRITE: + sp->retval = rdi_write(sp->params[0], (void*)sp->params[1], sp->params[2]); + break; + case RDI_SYS_ISTTY: + sp->retval = 1; + break; + default: + sp->retval = -1; + } + +} + +asm(".globl debug_monitor_handler\n" + ".thumb_func\n" + "debug_monitor_handler: \n" + " mov r0, sp\n" + " b debug_monitor_handler_c\n"); + +#endif