aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/armdebug/Debugger/debug_stub.S
diff options
context:
space:
mode:
Diffstat (limited to 'AT91SAM7S256/armdebug/Debugger/debug_stub.S')
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.S199
1 files changed, 90 insertions, 109 deletions
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.S b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
index 4e26da3..b987d7c 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
@@ -79,6 +79,8 @@
* MAA..AA,LLLL:bb..bb
* Write LLLL bytes at address AA.AA OK or ENN
*
+ * D Detach (equivalent to continue Ack Only
+ * at current address)
* c Resume at current address SNN ( signal NN)
* cAA..AA Continue at address AA..AA SNN
*
@@ -142,6 +144,21 @@
#include "debug_internals.h"
#include "debug_macros.h"
+ /* Hexutils function references */
+ .extern hex2char
+ .extern char2hex
+ .extern byte2ascii
+ .extern halfword2ascii_be
+ .extern halfword2ascii_le
+ .extern word2ascii_be
+ .extern word2ascii_le
+ .extern ascii2hex_varlen_be
+ .extern ascii2byte
+ .extern ascii2halfword_be
+ .extern ascii2halfword_le
+ .extern ascii2word_be
+ .extern ascii2word_le
+
/* Macro definitions */
/* _check_msgseparator
@@ -196,6 +213,12 @@ debug_InMsgBuf:
debug_OutMsgBuf:
.space MSGBUF_SIZE,0
+ /* Make Debugger State accessible from other modules */
+ .global debug_state
+ .global debug_mode
+ .global debug_bkpt_type
+ .global debug_curr_breakpoint
+
debug_state:
.byte 0x0 /* dbg_state_t variable */
debug_mode:
@@ -227,7 +250,7 @@ debug_OkResponse:
/* The CmdIndexTable and CmdJumpTable must be kept in sync */
debug_cmdIndexTable:
- .byte 'g','G','p','P','m','M','c','s','k','z','Z','?','q','Q',0
+ .byte 'g','G','p','P','m','M','D','c','s','k','z','Z','?','q','Q',0
/* Command Handlers
* On entry:
@@ -241,9 +264,15 @@ debug_cmdJumpTable:
.word _dbg__cmd_SetOneReg /* 'P' */
.word _dbg__cmd_ReadMem /* 'm' */
.word _dbg__cmd_WriteMem /* 'M' */
+ .word _dbg__cmd_Detach /* 'D' */
.word _dbg__cmd_Continue /* 'c' */
+#ifdef __NXOS__
+ .word _dbg__cmd_Step /* 's' */
+#else
+ /* NXT Firmware does not support Stepping */
.word _dbg__nop /* 's' */
- .word _dbg__nop /* 'k' */
+#endif
+ .word _dbg__cmd_Kill /* 'k' */
.word _dbg__cmd_RemoveBreakpoint /* 'z' */
.word _dbg__cmd_InsertBreakpoint /* 'Z' */
.word _dbg__cmd_Status /* '?' */
@@ -469,99 +498,6 @@ debug_armComplexCCTable:
/* FIXME: The Debugger Stack Frame is probably not 100% consistent with the order that
GDB expects in the g/G messages. CSPR is probably located above R15 */
-#ifdef __NXOS__
-/****************************************************************************
- *
- * GDB Debugger Invocation Routine for NxOS
- *
- ****************************************************************************/
- .code 32
- .align 4
- .global nxos__handleDebug
-/* nxos__handleDebug
- * Prepare to switch to Debug Mode
- * int nxos__handleDebug(unsigned char *msg, comm_chan_t channel, long len, void *isrRetAddr);
- *
- * This routine is called from NxOS Fantom library to setup
- * Single Step Breakpoint and copy Incoming Message to
- * Debugger Message Buffers in preparation for Debugger invocation.
- *
- * If we're operating in normal NxOS mode, return True (!0)
- * If we're already in Debugger Mode, return False (0)
- */
-nxos__handleDebug:
- push {r4, lr}
- /* When called, NxOS is in ISR servicing mode (MODE_IRQ) */
- /* R0-R3 has received message related parameters */
- mov r4, r3 /* Keep isrRetAddr in R4 */
- mrs r3, spsr /* Copy SPSR to r3 */
- and r3, r3, #CPSR_MODE /* Get previous mode */
- teq r3, #MODE_ABT /* Are we in Abort (Debug) mode? */
- moveq r0, #FALSE
- beq exit_nxos__handleDebug /* Yes, return False */
-
-_nxos_switch2debug:
- bl dbg__copyNxtDebugMsg /* setup Debugger Message Buffers, validate input, CPSR returned in R0 */
-
- /* Retrieve ISR Return Address */
- mrs r3, spsr /* Copy SPSR to r3 */
- tst r3, #CPSR_THUMB /* Check for Thumb Mode */
- sub r1, r4, #4 /* R3 (isrRetAddr) has PC + 4, need to setup Single Step Breakpoint at PC */
- orrne r1, r1, #1 /* Configure for Thumb Single Step Breakpoint */
- bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
- bl _dbg__activate_singlestep
- mov r0, #TRUE /* We're going to switch to Debug Mode */
-exit_nxos__handleDebug:
- pop {r4, lr}
- mov r1, lr /* Safe code: Thumb mode can't access lr */
- bx r1 /* In case we have Interworking from different caller mode */
-#endif
-
-#ifndef __NXOS__
-/****************************************************************************
- *
- * GDB Debugger Invocation Routine for NXT Firmware
- *
- ****************************************************************************/
- .code 16
- .align 2
- .global cCommHandleDebug
- .thumb_func
-/* cCommHandleDebug
- * Switch Mode to Debugger.
- * Used by NXT Firmware only
- *
- * UWORD cCommHandleDebug(UBYTE *pInBuf, UBYTE CmdBit, UWORD MsgLength);
- *
- * This routine is called from cCommInterprete either in normal operation mode (SVC)
- * or else when we're in debug mode (ABORT) which uses the cCommCtrl() routine to handle
- * I/O with the Host.
- *
- * On entry, the message is copied from the NXT buffer into our own buffers.
- *
- * If this is accessed from normal operation mode, we need to switch mode to
- * ABORT mode to handle the incoming message using a Manual Breakpoint instruction.
- * When DEBUG is exited, the execution resumes from the instruction following the Breakpoint.
- */
-cCommHandleDebug:
-/* Arg Registers are not preserved since this is invoked explicitly */
- push {lr} /* store arg registers */
- bl dbg__copyNxtDebugMsg /* setup Debugger Message Buffers, validate input, CPSR returned in R0 */
- _dbg_getmode r0 /* Get Debug Mode */
- cmp r0, #(TRUE & BYTE0) /* Confine it to Byte size */
-
- /* If Debug Mode is TRUE, this means that we're already running the Debugger */
- beq _cCommHandleDebug_cont
- /* Else, we're in normal operation mode (SVC), or other mode (??!) and need to force a switch to Debug mode */
- dbg__bkpt_thumb
-_cCommHandleDebug_cont:
- mov r0, #0 /* FIXME: Return Status */
- pop {r1} /* Can't Pop LR directly */
- bx r1 /* Safe code: actually we should be able to Pop PC since the caller is Thumb Mode */
-
- .ltorg
-#endif
-
/****************************************************************************
*
* GDB Debugger Init and Breakpoint Handler Routines
@@ -607,7 +543,7 @@ _dbg__flush_icache:
*/
dbg__thumb_bkpt_handler:
/* On entry, r0 contains breakpoint index value */
- mov r4, #BKPT16_AUTO_BKPT
+ /* mov r4, #BKPT16_AUTO_BKPT Redundant?! */
and r4, r0, #BKPT16_AUTO_BKPT /* keep AUTO flag value in r4 */
bic r0, r0, #BKPT16_AUTO_BKPT /* mask out AUTO flag */
_dbg_setcurrbkpt_index r0 /* keep current breakpoint index in memory */
@@ -630,7 +566,7 @@ dbg__thumb_bkpt_handler:
*/
dbg__arm_bkpt_handler:
/* On entry, r0 contains breakpoint index value */
- mov r4, #BKPT32_AUTO_BKPT
+ /* mov r4, #BKPT32_AUTO_BKPT Redundant?! */
and r4, r0, #BKPT32_AUTO_BKPT /* keep AUTO flag value in r4 */
bic r0, r0, #BKPT32_AUTO_BKPT /* mask out AUTO flag */
_dbg_setcurrbkpt_index r0 /* keep current breakpoint index in memory */
@@ -648,8 +584,8 @@ dbg__arm_bkpt_handler:
/* b _process_normal_breakpoint */
_process_normal_breakpoint:
- bl _dbg__restore_breakpoints
- bl _dbg__restore_singlestep
+ bl _dbg__restore_breakpoints /* includes restoring single step */
+/* bl _dbg__restore_singlestep */
bl _dbg__clear_singlestep
bl _dbg__flush_icache
b dbg__bkpt_waitCMD
@@ -706,6 +642,8 @@ dbg__bkpt_offset_outofrange:
dbg__bkpt_waitCMD:
/* We enter this code section when a Breakpoint Triggers */
_dbg_setmode TRUE /* Debug Mode = True */
+ msr cpsr_c, #(MODE_ABT) /* Re-enable Interrupts */
+
_dbg_getstate r0
cmp r0, #DBG_CONFIGURED
blo dbg__bkpt_waitCMD_cont /* Not configured yet, don't send Breakpoint Signal Response */
@@ -1233,6 +1171,27 @@ _dbg__cmd_WriteMem:
bne 1b
b __dbg__procCmdOk
+/* _dbg__cmd_Detach
+ * Detach User Program Execution Command Handler
+ * Treat this as being equivalent to 'Continue' without any arguments
+ *
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * <NULL> (No Parameters)
+ * On exit:
+ * r0-r7: destroyed
+ * Note: This routine does not return to caller. Instead it switches
+ * operating mode to UNDEF and returns to previously active program
+ */
+_dbg__cmd_Detach:
+ stmfd sp!, {lr} /* In case unexpected parameters were received */
+ bl __dbg__cmdParamLen
+ teq r1, #CMD_DETACH_PARAMLEN /* Check for correct length */
+ 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__cmd_Continue
* Continue User Program Execution Command Handler
* Setup breakpoints before resuming execution of program.
@@ -1281,7 +1240,7 @@ _dbg__cont_is_normal_breakpoint:
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_following_instruction_addr /* following instruction address returned in r1 */
- bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
+ 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
@@ -1294,7 +1253,7 @@ _dbg__cont_is_manual_bkpt_or_address_specified:
* Step User Program Execution Command Handler
* Setup breakpoints before resuming execution of program.
*
- * If Address is specified, update the next instruction address to specified address
+ * If Address is specified, update the next instruction address to specified address
*
* If this is a Normal Breakpoint, then we need to install a Step Breakpoint at next instruction address
* and resume from current (Breakpoint) exception address
@@ -1347,10 +1306,30 @@ _dbg__step_is_manual_bkpt:
_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
+ bl dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
+ bl dbg__activate_singlestep
b _dbg__switch2undefmode_withAck
+/* _dbg__cmd_Kill
+ * Kill User Program Execution Command Handler
+ * Kill Program, this is accomplished by rebooting the Brick
+ *
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * <NULL> (No Parameters)
+ * On exit:
+ * r0-r7: destroyed
+ * Note: This routine does not return to caller. Instead it calls
+ * the relevant system routine to reboot the Brick
+ */
+_dbg__cmd_Kill:
+ stmfd sp!, {lr} /* In case unexpected parameters were received */
+ bl __dbg__cmdParamLen
+ teq r1, #CMD_KILL_PARAMLEN /* Check for correct length */
+ bne __dbg__procCmdParamError /* Unexpected input, report error */
+
+ bl __dbg__procAckOnly /* send Ack to keep GDB server happy */
+ b dbg__reboot /* Goodbye.... */
/* _dbg__proc_brkpt_params
* Process Breakpoint Parameters
@@ -2800,12 +2779,13 @@ _dbg__clear_breakpoints:
blo 3b
ldmfd sp!, {pc}
-/* _dbg__install_singlestep
+ .global dbg__install_singlestep
+/* dbg__install_singlestep
* Install the Single Step Breakpoint
* On entry:
* R1: Instruction Address (31 bits, b0 = THUMB flag)
*/
-_dbg__install_singlestep:
+dbg__install_singlestep:
mov r0, #0
/* b _dbg__install_one_breakpoint */
@@ -2866,10 +2846,11 @@ _dbg__restore_breakpoints:
ldr r5, =_dbg__restore_one_breakpoint
b __dbg__iterate_breakpoint_array
-/* _dbg__activate_singlestep
+ .global dbg__activate_singlestep
+/* dbg__activate_singlestep
* Activate the single step breakpoint to memory
*/
-_dbg__activate_singlestep:
+dbg__activate_singlestep:
mov r0, #0 /* single step breakpoint index */
_index2bkptindex_addr r0, r1 /* Calculate Single Step Breakpoint Entry Address */
ldm r1, {r1, r2} /* r1: Breakpoint Address, r2: Breakpoint Instruction */
@@ -2894,7 +2875,7 @@ _nx_is_arm_bp:
teq r2, r3 /* check that the two instructions are identical */
bne _dbg__breakpoint_invalid_arm
ldr r2, =BKPT32_INSTR /* ARM BKPT instruction */
- and r2, r2, r0 /* Merge Breakpoint index */
+ orr r2, r2, r0 /* Merge Breakpoint index */
str r2, [r1] /* Store it into memory location */
_dbg__breakpoint_invalid_arm:
bx lr
@@ -2904,7 +2885,7 @@ _nx_is_thumb_bp:
teq r2, r3 /* check that the two instructions are identical */
bne _dbg__breakpoint_invalid_thumb
ldr r2, =BKPT16_INSTR /* Thumb BKPT instruction */
- and r2, r2, r0 /* Merge Breakpoint index */
+ orr r2, r2, r0 /* Merge Breakpoint index */
strh r2, [r1] /* Store it into memory location */
_dbg__breakpoint_invalid_thumb:
bx lr