aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/armdebug/Debugger/debug_stub.S
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-30 10:10:46 +0800
committerTat-Chee Wan (USM)2011-03-30 10:10:46 +0800
commit5fdfaa83874590fcd9082659a55abd5dcca05c4f (patch)
tree321419a1b77cc53580ff44fdfd68d044e63df691 /AT91SAM7S256/armdebug/Debugger/debug_stub.S
parent953c08633b8d04899c53bc4618c4d50279b27cbd (diff)
parent0451f85157573f18d9959098f83b67336966a0e1 (diff)
Merge branch 'master' of ssh://svc.cs.usm.my/~/gitrepo-bare/armdebug
Diffstat (limited to 'AT91SAM7S256/armdebug/Debugger/debug_stub.S')
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.S210
1 files changed, 129 insertions, 81 deletions
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.S b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
index 1547882..4520c32 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
@@ -139,6 +139,7 @@
#define __ASSEMBLY__
#include "debug_stub.h"
+#include "debug_internals.h"
#include "debug_macros.h"
/* Macro definitions */
@@ -190,8 +191,6 @@
.bss
.align 4
-debug_curr_breakpoint:
- .word 0x0
debug_InMsgBuf:
.space MSGBUF_SIZE,0
debug_OutMsgBuf:
@@ -203,6 +202,8 @@ debug_mode:
.byte 0x0 /* Boolean variable */
debug_bkpt_type:
.byte 0x0 /* bkpt_type_t variable */
+debug_curr_breakpoint:
+ .byte 0x0
.data
.align 4
@@ -240,8 +241,8 @@ debug_cmdJumpTable:
.word _dbg__cmd_Continue /* 'c' */
.word _dbg__nop /* 's' */
.word _dbg__nop /* 'k' */
- .word _dbg__cmd_remove_breakpoint /* 'z' */
- .word _dbg__cmd_insert_breakpoint /* 'Z' */
+ .word _dbg__cmd_RemoveBreakpoint /* 'z' */
+ .word _dbg__cmd_InsertBreakpoint /* 'Z' */
.word _dbg__cmd_Status /* '?' */
.word _dbg__cmd_Query /* 'q' */
.word _dbg__nop /* 'Q' */
@@ -567,7 +568,17 @@ _process_auto_breakpoint:
bl _dbg__restore_singlestep
bl _dbg__clear_singlestep
_dbg_set_bkpt_type DBG_AUTO_BKPT
- b __dbg__resume_execution
+ /* b _dbg__switch2undefmode */
+
+/* _dbg__switch2undefmode
+ * Common internal routine to return execution to user program
+ */
+_dbg__switch2undefmode:
+ bl _dbg__flush_icache
+ msr cpsr_c, #(MODE_UND | CPSR_FIQ | CPSR_IRQ) /* Configure Undef Mode */
+ _dbg_setmode FALSE /* Debug Mode = False */
+ ldr lr, =resume_execution
+ mov pc, lr /* Exit via UNDEF mode */
_process_manual_breakpoint_thumb:
_dbg_set_bkpt_type DBG_MANUAL_BKPT_THUMB
@@ -1085,6 +1096,14 @@ _dbg__cmd_WriteMem:
/* _dbg__cmd_Continue
* Continue 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 this is a Normal Breakpoint, then we need to install an Autobreakpoint at next instruction address
+ * and resume from current (Breakpoint) exception address
+ * Else (it is a Manual Breakpoint or Address Specified)
+ * We need to resume from the next instruction address
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
* Optional: AA..AA
@@ -1094,25 +1113,43 @@ _dbg__cmd_WriteMem:
* operating mode to UNDEF and returns to previously active program
*/
_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_REG_CONTINUE_PARAMLEN /* Check for correct parameter length */
- beq _dbg__cmd_processContinue /* Continue from current PC */
-#if 0
- cmp r1, #CMD_REG_CONTINUEFROM_PARAMLEN /* Check for correct parameter length */
- bne __dbg__procCmdParamError /* Unexpected input, report error */
- bl ascii2word_be /* convert ASCII address location to Hex (in R0), R1 has address of next buffer char */
-#endif
+ cmp r1, #CMD_CONTINUE_MINPARAMLEN /* Check for correct parameter length */
+ beq _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 */
+ b _dbg__cont_is_manual_bkpt_or_address_specified
+
+_dbg__cont_check_breakpoint_type:
+ _dbg_get_bkpt_type r0
+ teq r0, #DBG_MANUAL_BKPT_ARM
+ beq _dbg__cont_is_manual_bkpt_or_address_specified
+ teq r0, #DBG_MANUAL_BKPT_THUMB
+ bne _dbg__cont_is_normal_breakpoint
+
+_dbg__cont_is_manual_bkpt_or_address_specified:
+ bl _dbg__activate_breakpoints /* Restore exisiting breakpoints */
+ b _dbg__switch2undefmode
+
+_dbg__cont_is_normal_breakpoint:
+/* FIXME: _dbg_next_instruction_addr doesn't actually work currently.
+ This breaks normal breakpoints which need to determine the next instruction to execute
+ (for placing the autobreakpoint) prior to returning.
+*/
+ mov r2, #DBGSTACK_USERPC_INDEX /* Retrieve Aborted Instruction PC from the Debug Stack */
+ _getdbgregisterfromindex r2, r0 /* Retrieve Register contents into R0 */
+ 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_next_instruction_addr /* 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 */
-_dbg__cmd_processContinue:
-/* FIXME: Currently we assume that the trigger is a Manual Breakpoint, i.e., no need to
- restore instructions to memory, and handle auto-breakpoints (needed to reenable the memory
- breakpoint that was triggered) */
-
-@@@@@
#if 0
/* Not part of the GDB Remote Protocol spec. Messages are sent only when system halts, not when we resume */
__dbg__sendOkBeforeResume:
@@ -1124,11 +1161,68 @@ __dbg__sendOkBeforeResume:
b __dbg__sendOkBeforeResume /* Retry retransmission */
#endif
-_dbg__switch2undefmode:
- msr cpsr_c, #(MODE_UND | CPSR_FIQ | CPSR_IRQ) /* Configure Undef Mode */
- _dbg_setmode FALSE /* Debug Mode = False */
- ldr lr, =resume_execution
- mov pc, lr /* Exit via UNDEF mode */
+ b _dbg__switch2undefmode
+
+/* _dbg__cmd_Step
+ * 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 this is a Normal Breakpoint, then we need to install a Step Breakpoint at next instruction address
+ * and resume from current (Breakpoint) exception address
+ * Else (it is a Manual Breakpoint or Address specified)
+ * We need to install a Step Breakpoint at the following instruction address (after the next instruction address)
+ * and resume from the next instruction address
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * Optional: AA..AA
+ * On exit:
+ * r0, r1, r2: destroyed
+ * Note: This routine does not return to caller. Instead it switches
+ * operating mode to UNDEF and returns to previously active program
+ */
+_dbg__cmd_Step:
+ /* Don't put anything on the stack, we won't return to the Debugger Run Loop */
+ bl __dbg__cmdParamLen
+ cmp r1, #CMD_STEP_MINPARAMLEN /* Check for correct parameter length */
+ beq _dbg__step_check_breakpoint_type /* Step from current PC */
+
+_dbg__step_fromAddr:
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
+ /* Step 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 */
+ b _dbg__step_is_manual_bkpt_or_address_specified
+
+_dbg__step_check_breakpoint_type:
+ _dbg_get_bkpt_type r0
+ teq r0, #DBG_MANUAL_BKPT_ARM
+ beq _dbg__step_is_manual_bkpt
+ teq r0, #DBG_MANUAL_BKPT_THUMB
+ bne _dbg__step_is_normal_breakpoint
+
+_dbg__step_is_manual_bkpt:
+ mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
+ _getdbgregisterfromindex r2, r1 /* Retrieve Register contents into R1 */
+ b _dbg__step_is_manual_bkpt_or_address_specified
+
+_dbg__step_is_normal_breakpoint:
+/* FIXME: _dbg_next_instruction_addr doesn't actually work currently.
+ This breaks normal breakpoints which need to determine the next instruction to execute
+ (for placing the autobreakpoint) prior to returning.
+*/
+ mov r2, #DBGSTACK_USERPC_INDEX /* Retrieve Aborted Instruction PC from the Debug Stack */
+ _getdbgregisterfromindex r2, r0 /* Retrieve Register contents into R0 */
+ 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 */
+
+_dbg__step_is_manual_bkpt_or_address_specified:
+ /* R1 contains the instruction address to be executed upon return */
+ bl _dbg_next_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
/* _dbg__proc_brkpt_params
@@ -1153,7 +1247,7 @@ _dbg__proc_brkpt_params:
_check_msgseparator r3
bne _dbg__proc_brkpt_params_error /* Something wrong with the parameters */
mov r0, r3 /* Check Address */
- bl ascii2word_be /* R0: value, R1: pointer to next char slot */
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
mov r3, r0 /* Keep breakpoint address in R3 */
_check_msgseparator r1
bne _dbg__proc_brkpt_params_error /* Something wrong with the parameters */
@@ -1171,7 +1265,7 @@ _exit_dbg__proc_brkpt_params:
mov r0, r3 /* return breakpoint address */
ldmfd sp!, {pc}
-/* _dbg__cmd_insert_breakpoint
+/* _dbg__cmd_InsertBreakpoint
* Add Breakpoint
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
@@ -1179,11 +1273,11 @@ _exit_dbg__proc_brkpt_params:
* On exit:
* r0, r1, r2, r3: destroyed
*/
-_dbg__cmd_insert_breakpoint:
+_dbg__cmd_InsertBreakpoint:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
- teq r1, #CMD_BKPT_INSERT_PARAMLEN /* Check for correct length */
- bne __dbg__procCmdParamError /* Unexpected input, report error */
+ teq r1, #CMD_BKPT_INSERT_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
bl _dbg__proc_brkpt_params /* R0: Breakpoint Address */
teq r0, #0
beq __dbg__procBreakpointAddrError /* Thumb2 instructions, or unknown kind */
@@ -1196,7 +1290,7 @@ _dbg__cmd_insert_breakpoint:
bl _dbg__install_one_breakpoint /* r0: index, r1: instruction address */
b __dbg__procCmdOk
-/* _dbg__cmd_remove_breakpoint
+/* _dbg__cmd_RemoveBreakpoint
* Remove Breakpoint
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
@@ -1204,11 +1298,11 @@ _dbg__cmd_insert_breakpoint:
* On exit:
* r0, r1, r2, r3: destroyed
*/
-_dbg__cmd_remove_breakpoint:
+_dbg__cmd_RemoveBreakpoint:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
- teq r1, #CMD_BKPT_REMOVE_PARAMLEN /* Check for correct length */
- bne __dbg__procCmdParamError /* Unexpected input, report error */
+ teq r1, #CMD_BKPT_REMOVE_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
bl _dbg__proc_brkpt_params /* R0: Breakpoint Address */
teq r0, #0
beq __dbg__procBreakpointAddrError /* Thumb2 instructions, or unknown kind */
@@ -1221,46 +1315,7 @@ _dbg__cmd_remove_breakpoint:
b __dbg__procCmdOk
-/* _dbg__cmd_run
- * Continue execution of program
- */
-_dbg__cmd_run:
- bl _dbg__activate_breakpoints
- b __dbg__resume_execution
-
-/* _dbg__cmd_step
- * Single Step execution of program
- */
-_dbg__cmd_step:
- bl _dbg_next_instruction_addr /* next instruction address returned in r1 */
- bl _dbg__install_singlestep /* Setup Single Step */
- bl _dbg__activate_singlestep
- b __dbg__resume_execution
-/* _dbg__cmd_cont
- * Continue execution of program.
- * If this is a Normal Breakpoint, then we need to install an Autobreakpoint at next instruction address
- * and resume from current (Breakpoint) exception address
- * Else (it is a Manual Breakpoint)
- * We need to resume from the next instruction address
- */
-_dbg__cmd_cont:
-/* FIXME: What happens if we call this when we did not stop at a Breakpoint previously? */
- _dbg_getstate r0
- ldr r1, =DBG_MANUAL_BKPT_ARM
- teq r0, r1
- beq __dbg_is_manual_breakpoint
-
- bl _dbg_next_instruction_addr /* 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__resume_execution
-
-__dbg_is_manual_breakpoint:
- bl _dbg_next_instruction_addr /* Skip Manual Breakpoint Instruction(s) */
- bl _dbg__activate_breakpoints
- b __dbg__resume_execution
/****************************************************************************
// Selected Routines from the eCos arm_stub.c related to next instruction address
@@ -1720,7 +1775,6 @@ void __single_step (void)
****************************************************************************/
-
/* _dbg_next_instruction_addr
* Determine the address of the next instruction to execute.
* On exit:
@@ -1738,6 +1792,9 @@ void __single_step (void)
* the next instruction address (for inserting a Breakpoint).
*/
_dbg_next_instruction_addr:
+ /* FIXME: This needs a total rewrite */
+ mov r1, #0
+ bx lr
/* We assume that any BKPT instructions in the code will be Manual Breakpoints,
* i.e., the Debugger does not leave stray Single Step / Auto / Normal breakpoints in memory
*/
@@ -1778,15 +1835,6 @@ _next_instr_is_arm:
@@@@@@@@@
bx lr
-/* __dbg__resume_execution
- * cleanup, resume execution of program.
- * Restore User Mode Regsiters from Debugger Stack, and resume execution from aborted instruction
- */
-__dbg__resume_execution:
-@@@@@@
- bl _dbg__flush_icache
- b __dbg__resume_execution
-
/****************************************************************************
*
* Instruction Decode Routines