From e2fc5ed4ef73ea42d1d13e20d5e09260722d23a9 Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Mon, 20 Jun 2011 16:24:36 +0800 Subject: implement detach and kill command support --- Debugger/debug_runlooptasks.S | 44 ++++++++++++++++++++++++++++++++++++++++++- Debugger/debug_stub.S | 42 +++++++++++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 11 deletions(-) diff --git a/Debugger/debug_runlooptasks.S b/Debugger/debug_runlooptasks.S index 48b7e5a..ceab2e9 100644 --- a/Debugger/debug_runlooptasks.S +++ b/Debugger/debug_runlooptasks.S @@ -115,13 +115,55 @@ dbg__runloopTasks: b nx_core_reset /* Reboot Brick, won't return */ #else + .extern dIOCtrlSetPower + .extern dIOCtrlSetPwm + .extern dIOCtrlTransfer + .equ BOOT, 0xA55A + .equ POWERDOWN, 0x5A00 /**************************************************************************** * * NXT Firmware Reboot Routine * ****************************************************************************/ dbg__reboot: - bx lr + /* Powerdown Sequence + dIOCtrlSetPower((POWERDOWN>>8)); + dIOCtrlTransfer(); + + Reboot Sequence + dIOCtrlSetPower((UBYTE)(BOOT>>8)); + dIOCtrlSetPwm((UBYTE)BOOT); + dIOCtrlTransfer(); + */ + + /* We implement the powerdown sequence for now */ + +#if 1 + /* Powerdown sequence */ + ldr r0, =((POWERDOWN >> 8) & 0xFF) + ldr r1, =dIOCtrlSetPower + mov lr,pc + bx r1 +#endif + +#if 0 + /* Reboot sequence: this forces SAMBA mode??!! */ + ldr r0, =((BOOT >> 8) & 0xFF) + ldr r1, =dIOCtrlSetPower + mov lr,pc + bx r1 + + ldr r0, =(BOOT & 0xFF) + ldr r1, =dIOCtrlSetPwm + mov lr,pc + bx r1 +#endif + + ldr r1, =dIOCtrlTransfer + mov lr,pc + bx r1 + + b . /* Wait for AVR... */ #endif diff --git a/Debugger/debug_stub.S b/Debugger/debug_stub.S index b987d7c..e32c2dc 100644 --- a/Debugger/debug_stub.S +++ b/Debugger/debug_stub.S @@ -436,7 +436,6 @@ debug_armComplexCCTable: .text .align 4 .extern __breakpoints_num__ - .extern dbg__hasDebugMsg /* Check for message from the communications link */ .extern dbg__getDebugMsg /* Read a message from the communications link */ .extern dbg__putDebugMsg /* Write a message to the communications link */ .extern dbg__sendAckOrNak /* Send Ack or Nak to indicate success/failure of message receipt */ @@ -605,9 +604,6 @@ _process_auto_breakpoint: /* _dbg__switch2undefmode * Common internal routine to return execution to user program */ -_dbg__switch2undefmode_withAck: - bl __dbg__procAckOnly /* send Ack to keep GDB server happy */ - bl dbg__runloopTasks /* Service run loop tasks */ _dbg__switch2undefmode: bl _dbg__flush_icache msr cpsr_c, #(MODE_UND | CPSR_FIQ | CPSR_IRQ) /* Configure Undef Mode */ @@ -701,6 +697,26 @@ _dbg__cmdError: b dbg__bkpt_waitCMD_cont +/* __dbg__procOkOnly + * Send OK to GDB due to Detach + * On entry: + * None + * On exit: + * r0-r3: destroyed + */ +__dbg__procOkOnly: + stmfd sp!, {lr} + _dbg_outputMsgStatusOk /* Acknowledge Detach command from GDB server */ +_cont_procOkOnly: + bl dbg__putDebugMsg /* Send OK response to the GDB server */ + cmp r0, #0 + beq _cont_procOkOnly_exit /* Sending of OK succeeded */ + bl dbg__runloopTasks /* Service run loop tasks */ + b _cont_procOkOnly /* Retry OK transmission */ +_cont_procOkOnly_exit: + ldmfd sp!, {pc} + + /* __dbg__procAckOnly * Send Ack to GDB due to Continue or Step * On entry: @@ -1190,7 +1206,9 @@ _dbg__cmd_Detach: bne __dbg__procCmdParamError /* Unexpected input, report error */ ldmfd sp!, {lr} /* Cleanup stack, since we won't return to the Debugger Run Loop */ - b _dbg__cont_check_breakpoint_type /* Continue from current PC */ + _dbg_setstate DBG_INIT /* Reset the Debug State */ + bl __dbg__procOkOnly /* send OK to keep GDB server happy */ + b _dbg__cont_check_breakpoint_type /* Continue from current PC */ /* _dbg__cmd_Continue * Continue User Program Execution Command Handler @@ -1213,14 +1231,17 @@ _dbg__cmd_Detach: _dbg__cmd_Continue: /* Don't put anything on the stack, we won't return to the Debugger Run Loop */ bl __dbg__cmdParamLen - cmp r1, #CMD_CONTINUE_MINPARAMLEN /* Check for correct parameter length */ - beq _dbg__cont_check_breakpoint_type /* Continue from current PC */ + cmp r1, #CMD_CONTINUE_MINPARAMLEN /* Check for correct parameter length */ + bne _dbg__cont_fromAddr /* Address is specified */ + bl __dbg__procAckOnly /* send Ack to keep GDB server happy */ + b _dbg__cont_check_breakpoint_type /* Continue from current PC */ _dbg__cont_fromAddr: bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */ /* Continue from Specified Address */ mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */ _setdbgregisterfromindex r2, r0, r1 /* Set Register contents in R0, using index in R2, and scratch register R1 */ + bl __dbg__procAckOnly /* send Ack to keep GDB server happy */ b _dbg__cont_is_manual_bkpt_or_address_specified _dbg__cont_check_breakpoint_type: @@ -1243,11 +1264,11 @@ _dbg__cont_is_normal_breakpoint: bl dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */ _dbg_getcurrbkpt_index r0 /* load current breakpoint index in memory */ bl _dbg__activate_autobreakpoint /* pass next instruction address in r1 */ - b _dbg__switch2undefmode_withAck + b _dbg__switch2undefmode _dbg__cont_is_manual_bkpt_or_address_specified: bl _dbg__activate_breakpoints /* Restore exisiting breakpoints */ - b _dbg__switch2undefmode_withAck + b _dbg__switch2undefmode /* _dbg__cmd_Step * Step User Program Execution Command Handler @@ -1308,7 +1329,8 @@ _dbg__step_is_manual_bkpt_or_address_specified: bl _dbg_following_instruction_addr /* following instruction address returned in r1 */ bl dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */ bl dbg__activate_singlestep - b _dbg__switch2undefmode_withAck + bl __dbg__procAckOnly /* send Ack to keep GDB server happy */ + b _dbg__switch2undefmode /* _dbg__cmd_Kill * Kill User Program Execution Command Handler -- cgit v1.2.3