aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-24 12:14:16 +0800
committerTat-Chee Wan (USM)2011-03-24 12:14:16 +0800
commit5b15d51e06cd552142081dea28b17a822f3e39a7 (patch)
treed85905f0a6a1d36ea679bcafc5297308695f3274 /AT91SAM7S256
parentdb6cb8ae6a27149af9abf87ebc9da223211a373c (diff)
parent110b7562fef3ef9efe37c04dd9d86a34d4bdf53b (diff)
Merge branch 'master' of ssh://svc.cs.usm.my/~/gitrepo-bare/armdebugGDB_ALPHA_0.1
Diffstat (limited to 'AT91SAM7S256')
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_comm.S56
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.S99
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.h35
-rw-r--r--AT91SAM7S256/armdebug/Host/gdb-commands.txt6
4 files changed, 133 insertions, 63 deletions
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_comm.S b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
index db9ac16..4d41e24 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_comm.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
@@ -133,29 +133,34 @@ hex2char:
* equivalent byte sized hex value in R0(7:0).
* It accepts lowercase and uppercase ASCII Hex char inputs.
* Invalid inputs return -1 as the value
+* On entry:
+ * R0: ASCII character
+ * On exit:
+ * R0: Hex value
*/
.global char2hex
char2hex:
- and r1, r0, #BYTE0 /* make sure that input is sane */
- mov r0, #-1 /* Initialize Return value to Error value */
- cmp r1, #'0'
- blo exit_char2hex
- cmp r1, #'9'
+ and r0, r0, #BYTE0 /* make sure that input is sane */
+ cmp r0, #'0'
+ blo char2hex_error
+ cmp r0, #'9'
bls perform_char2hex
- cmp r1, #'A'
- blo exit_char2hex
- cmp r1, #'F'
+ cmp r0, #'A'
+ blo char2hex_error
+ cmp r0, #'F'
bls perform_char2hex
- cmp r1, #'a'
- blo exit_char2hex
- cmp r1, #'f'
- bhi exit_char2hex
+ cmp r0, #'a'
+ blo char2hex_error
+ cmp r0, #'f'
+ bhi char2hex_error
/* Validated Hex Char */
perform_char2hex:
- mov r0, r1 /* restore hex char */
- _char2hex r0
-exit_char2hex:
+ _char2hex r0 /* Return hex value in R0 */
+ bx lr
+
+char2hex_error:
+ mov r0, #-1 /* Set Return value to Error value */
bx lr
/* byte2ascii_cont
@@ -326,12 +331,13 @@ ascii2hex_varlen_be:
mov r3, #CMD_REG_REGPARAMLEN /* Set max count to 8 (Max Register size) */
mov r1, r0 /* Use R1 as ASCII buffer pointer */
mov r2, #0 /* Initialize Cummulative Results */
-2: ldrb r0, [r1], #1 /* Load ASCII char for Hex Value */
+2: ldrb r0, [r1] /* Load ASCII char for Hex Value */
bl char2hex /* on return, hex value in R0, -1 for error */
cmp r0, #-1
beq _exit_ascii2hex_varlen
orr r2, r0, r2, lsl #4 /* combined byte value */
subs r3, r3, #1 /* Decrement Counter */
+ add r1, r1, #1 /* Go to next char slot */
bne 2b
_exit_ascii2hex_varlen:
mov r0, r2 /* Return results in R0 */
@@ -756,6 +762,15 @@ _hasMsg2Copy:
ldr r5, =debug_msgRxBufPtr
ldr r5, [r5] /* Rx buffer Start Address */
+/* Need to account for Packet Acknowledgement */
+1: ldrb r0, [r5]
+ teq r0, #MSGBUF_NAKCHAR /* Look for '-' */
+ beq exit_dbg__getMsgError /* FIXME: We can't handle retransmission, flag message error */
+ teq r0, #MSGBUF_ACKCHAR /* Look for '+' */
+ addeq r5, r5, #1 /* Adjust Buffer Start Pointer (excl '+') */
+ subeq r4, r4, #1 /* Adjust Message Length */
+ beq 1b /* Skip all Packet Acknowledgements */
+
/* Note: Here we assume that we won't get a single ACK '+' or NAK '-' character message.
* If we do, it'll be flagged as an error
*/
@@ -768,15 +783,6 @@ _hasMsg2Copy:
mov r1, #0
strb r1, [r5, r2] /* Zero out '#' char for checksum calc later */
-/* Need to account for Packet Acknowledgement */
-1: ldrb r0, [r5]
- teq r0, #MSGBUF_NAKCHAR /* Look for '-' */
- beq exit_dbg__getMsgError /* FIXME: We can't handle retransmission, flag message error */
- teq r0, #MSGBUF_ACKCHAR /* Look for '+' */
- addeq r5, r5, #1 /* Adjust Buffer Start Pointer (excl '+') */
- subeq r4, r4, #1 /* Adjust Message Length */
- beq 1b /* Skip all Packet Acknowledgements */
-
#ifdef CHECK_GDBSTARTCHAR
/* Checked in dbg__bkpt_waitCMD */
ldrb r0, [r5]
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.S b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
index 9943ba2..55b2183 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
@@ -792,7 +792,7 @@ _dbg__cmd_GetOneReg:
bne __dbg__procCmdParamError /* Unexpected input, report error */
ldrb r0, [r0] /* Load Register index parameter */
teq r0, #MSGBUF_CPSRREG /* Check for CPSR register indicator */
- moveq r0, #DBGSTACK_USERCPSR_OFFSET /* Put offset from User Registers (-1) into index, so that after adjustment it points to CPSR slot */
+ moveq r0, #REG_CPSR /* Use CPSR Enum (-1) */
beq _dbg__proc_getRegister /* Handle User CPSR */
bl char2hex /* Convert to Hex value (assume input is valid) */
cmp r0, #NIBBLE0 /* sanity check, (though it is not foolproof as input char in 0x0-0xF (ctrl-chars) will pass through) */
@@ -808,10 +808,10 @@ _dbg__proc_getRegister:
ldmfd sp!, {pc}
/* _dbg_outputOneRegValue
- * Given Register Index (-1: CPSR, 0-F: R0-R15), output hex char to buffer
+ * Given Register Enum (-1: CPSR, 0-F: R0-R15), output hex char to buffer
* On entry:
* r0: output message buffer pointer
- * r1: register index (-1, 0-F)
+ * r1: register enum (-1, 0-F)
* On exit:
* r0: updated (points to next character slot at end of Output Buffer)
* r1: original output message buffer pointer
@@ -819,7 +819,7 @@ _dbg__proc_getRegister:
*/
_dbg_outputOneRegValue:
stmfd sp!, {lr}
- add r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register index to Debug Stack index */
+ add r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register enum to Debug Stack index */
_getdbgregisterfromindex r2, r1 /* Retrieve Register contents into R1 */
#ifdef __BIG_ENDIAN__
bl word2ascii_be /* Convert and put hex chars into Output Message Buffer */
@@ -830,7 +830,7 @@ _dbg_outputOneRegValue:
/* _dbg__cmd_GetAllRegs
* Get All Register Values Command Handler
- * Output Buffer returns register values in the order: User R0, R1, R2, ..., R15, CPSR
+ * Output Buffer returns register values in the order: User R0, R1, R2, ..., R15, FPSCR (dummy), CPSR
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
* <NULL> (no parameters)
@@ -846,30 +846,42 @@ _dbg__cmd_GetAllRegs:
_dbg_outputMsgValidResponse /* R0: address of output message buffer data pointer (after response prefix) */
/* We must return R0-R15, then CPSR */
- mov r3, #DBGSTACK_USERREG_INDEX /* Output User Register Values first */
+ mov r3, #REG_R0 /* Output User Register Values first */
1: mov r1, r3
bl _dbg_outputOneRegValue /* update output buffer */
add r3, r3, #1 /* increment index */
- cmp r3, #0xF
- ble 1b /* process all the registers */
-
- mov r1, #DBGSTACK_USERCPSR_OFFSET /* Output User CPSR Value lasat */
+ cmp r3, #REG_PC
+ bls 1b /* process all the registers */
+_get_cpsr:
+#if 0
+ /* GDB was not happy when this was added */
+ /* Output Dummy FPSCR value */
+ mov r1, #0
+#ifdef __BIG_ENDIAN__
+ bl word2ascii_be /* Convert and put hex chars into Output Message Buffer */
+#else
+ bl word2ascii_le /* Convert and put hex chars into Output Message Buffer */
+#endif
+#endif
+ mov r1, #REG_CPSR /* Output User CPSR Value last */
bl _dbg_outputOneRegValue /* update output buffer */
_asciiz r0, r1
bl dbg__putDebugMsg /* Send response to the GDB server */
ldmfd sp!, {pc}
-/* Internal Routine: Do not call directly
- * Shared by _dbg__cmd_SetOneReg and _dbg__cmd_SetAllRegs
- * On entry:
+/* _dbg_setOneRegValue
+ * Given Register Enum (-1: CPSR, 0-F: R0-R15), set register to buffer contents
+ * On entry:
* r0: parameter buffer pointer
- * r2: Register Index in Debug Stack (NOT Register Enum)
- * On exit:
- * r0, r2, r3: destroyed
+ * r1: register enum (-1, 0-F)
+ * On exit:
+ * r0: (Updated) Address of parameter in buffer
+ * r1, r2, r3: destroyed
*/
-__dbg_setRegister_fromIndex_withBufferVal:
+_dbg_setOneRegValue:
stmfd sp!, {lr}
+ add r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register enum to Debug Stack index */
#ifdef __BIG_ENDIAN__
bl ascii2word_be
#else
@@ -877,6 +889,7 @@ __dbg_setRegister_fromIndex_withBufferVal:
#endif
/* R0: value, R1: pointer to next char in buffer */
_setdbgregisterfromindex r2, r0, r3 /* Set Register contents in R0, using index in R2, and scratch register R3 */
+ mov r0, r1 /* Copy buffer pointer to next parameter to R0 for return value */
ldmfd sp!, {pc}
@@ -891,28 +904,27 @@ __dbg_setRegister_fromIndex_withBufferVal:
* r0, r1, r2, r3: destroyed
*
*/
-
_dbg__cmd_SetOneReg:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
teq r1, #CMD_REG_SETONE_PARAMLEN /* Check for correct length */
bne __dbg__procCmdParamError /* Unexpected input, report error */
mov r3, r0 /* Keep parameter buffer address in R3 */
- ldrb r1, [r3], #1 /* Load Register index parameter */
+ ldrb r1, [r3], #1 /* Load Register enum parameter */
_check_msgassignment r3
bne __dbg__procCmdParamError /* Can't find '=' */
- mov r0, r1 /* Move register index to R0 for subsequent processing */
- teq r0, #MSGBUF_CPSRREG /* Check for CPSR register indicator */
- moveq r0, #DBGSTACK_USERCPSR_OFFSET /* Put offset from User Registers (-1) into index, so that after adjustment it points to CPSR slot */
+ teq r1, #MSGBUF_CPSRREG /* Check for CPSR register indicator */
+ moveq r1, #REG_CPSR /* Use CPSR enum (-1) */
beq _dbg__proc_setRegister /* Handle User CPSR */
+ mov r0, r1 /* Move register enum to R0 for subsequent processing */
bl char2hex /* Convert to Hex value (assume input is valid) */
cmp r0, #NIBBLE0 /* sanity check, (though it is not foolproof as input char in 0x0-0xF (ctrl-chars) will pass through) */
bhi __dbg__procCmdParamError /* Non-hex char, report error */
+ mov r1, r0 /* move register enum to R1 to call _dbg_setOneRegValue */
_dbg__proc_setRegister:
- add r2, r0, #DBGSTACK_USERREG_INDEX /* Convert register index to Debug Stack index, keep in R2 */
mov r0, r3 /* Retrieve parameter buffer pointer */
- bl __dbg_setRegister_fromIndex_withBufferVal
+ bl _dbg_setOneRegValue
b __dbg__procCmdOk
/* _dbg__cmd_SetAllReg
@@ -925,22 +937,32 @@ _dbg__proc_setRegister:
*
*/
_dbg__cmd_SetAllRegs:
-/* FIXME: Assumes that the registers are in the sequence R0, R1, ... R15, CPSR -- May not be GDB ordering */
+ /* Assumes that the registers are in the sequence R0, R1, ... R15, CPSR */
stmfd sp!, {lr}
bl __dbg__cmdParamLen /* R0: pointer to parameters in buffer */
teq r1, #CMD_REG_SETALL_PARAMLEN /* Check for correct length */
bne __dbg__procCmdParamError /* Unexpected input, report error */
- mov r2, #DBGSTACK_USERREG_INDEX /* R2: register index, starting with R0 */
-1: bl __dbg_setRegister_fromIndex_withBufferVal
- mov r0, r1 /* setup R0 for next ascii2word call */
- add r2, r2, #1 /* increment index */
- cmp r2, #DBGSTACK_USERPC_INDEX
+ mov r4, #REG_R0 /* R4: register enum, starting with enum for R0 */
+1: mov r1, r4 /* Copy enum to R1; R0 already points to current parameter */
+ bl _dbg_setOneRegValue /* R0: next parameter address pointer */
+ add r4, r4, #1 /* increment index */
+ cmp r4, #REG_PC
bls 1b
_set_cpsr:
- mov r2, #DBGSTACK_USERCPSR_INDEX /* R2: CPSR Index */
- bl __dbg_setRegister_fromIndex_withBufferVal
- ldrb r0, [r1]
+#if 0
+ /* GDB was not happy when this was added */
+ /* Read dummy FPSCR value (ignored) */
+#ifdef __BIG_ENDIAN__
+ bl ascii2word_be
+#else
+ bl ascii2word_le
+#endif
+ mov r0, r1 /* Copy buffer pointer to next parameter to R0 for return value */
+#endif
+ mov r1, #REG_CPSR /* Use CPSR enum (-1) */
+ bl _dbg_setOneRegValue /* R0: next parameter address pointer */
+ ldrb r0, [r0]
teq r0, #0 /* Look for ASCIIZ character to terminate loop */
beq __dbg__procCmdOk
bne __dbg__procCmdParamError /* Unexpected input, report error */
@@ -968,9 +990,12 @@ _dbg__nop:
_dbg__cmd_ReadMem:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
+#if 0
teq r1, #CMD_MEM_READ_PARAMLEN /* Check for correct 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
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
mov r3, r0 /* Keep Address location in R3 */
_check_msgseparator r1
bne __dbg__procCmdParamError /* Can't find ',' */
@@ -1003,10 +1028,13 @@ _dbg__cmd_ReadMem:
_dbg__cmd_WriteMem:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
+#if 0
cmp r1, #CMD_MEM_WRITE_MINPARAMLEN /* Check for correct (minimum) length */
blo __dbg__procCmdParamError /* Unexpected input, report error */
sub r4, r1, #CMD_MEM_WRITE_MINPARAMLEN /* R4: Number of ASCII Hex chars for byte writes */
bl ascii2word_be /* convert ASCII address location to Hex (in R0), R1 has address of next buffer char */
+#endif
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
mov r3, r0 /* Keep Address location in R3 */
_check_msgseparator r1
bne __dbg__procCmdParamError /* Can't find ',' */
@@ -1042,10 +1070,13 @@ _dbg__cmd_Continue:
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 */
- /* Continue from Specified Address */
bl ascii2word_be /* convert ASCII address location to Hex (in R0), R1 has address of next buffer char */
+#endif
+ 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 */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.h b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
index 7dc9aa8..9d97705 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
@@ -92,6 +92,8 @@
/** @name Debug Memory Command Constants.
*
* Debug Memory Command
+ * FIXME: These limits are not enforced by the GDB client, it truncates addresses and lengths to remove leading '0's
+ * The PARAMLEN constants would probably be removed
*/
/*@{*/
#define CMD_NUMITEMS_PARAMLEN 4 /* 16-bit ASCII Hex Value */
@@ -110,7 +112,6 @@
*/
/*@{*/
#define CMD_REG_CONTINUE_PARAMLEN 0
-#define CMD_REG_CONTINUEFROM_PARAMLEN CMD_REG_REGPARAMLEN /* Address length is equivalent to reg param len */
/*@}*/
@@ -147,9 +148,9 @@
#define DBGSTACK_NEXTINSTR_INDEX 0 /* Next Instruction Address is at index 0 from bottom of Debug Stack */
#define DBGSTACK_USERCPSR_INDEX 1 /* User CPSR (SPSR_UNDEF) is at index 1 from bottom of Debug Stack */
#define DBGSTACK_USERREG_INDEX 2 /* R0 starts at index 2 from bottom of Debug Stack */
-#define DBGSTACK_USERSP_INDEX (DBGSTACK_USERREG_INDEX + 13) /* SP is R13 */
-#define DBGSTACK_USERPC_INDEX (DBGSTACK_USERREG_INDEX + 15) /* PC is R15 */
-#define DBGSTACK_USERCPSR_OFFSET (DBGSTACK_USERCPSR_INDEX-DBGSTACK_USERREG_INDEX) /* = -1, offset for calculating Debug Stack index */
+#define DBGSTACK_USERSP_INDEX (DBGSTACK_USERREG_INDEX + REG_SP) /* SP is R13 */
+#define DBGSTACK_USERLR_INDEX (DBGSTACK_USERREG_INDEX + REG_LR) /* LR is R14 */
+#define DBGSTACK_USERPC_INDEX (DBGSTACK_USERREG_INDEX + REG_PC) /* PC is R15 */
/*@}*/
/** @name Bitmask Definitions.
@@ -252,6 +253,32 @@ ENUM_VAL(MSG_UNKNOWNPARAM) /**< Unrecognized Parameter Error. */
ENUM_VAL(MSG_UNKNOWNBRKPT) /**< Unrecognized Breakpoint Error. */
ENUM_END(dbg_msg_errno)
+/** Register Enums
+ *
+ * Register Enums.
+ * The enums must be consecutive, starting from -1
+ */
+ENUM_BEGIN
+ENUM_VALASSIGN(REG_CPSR, -1) /**< Previous Mode CPSR */
+ENUM_VAL(REG_R0) /**< User Reg R0 */
+ENUM_VAL(REG_R1) /**< User Reg R1 */
+ENUM_VAL(REG_R2) /**< User Reg R2 */
+ENUM_VAL(REG_R3) /**< User Reg R3 */
+ENUM_VAL(REG_R4) /**< User Reg R4 */
+ENUM_VAL(REG_R5) /**< User Reg R5 */
+ENUM_VAL(REG_R6) /**< User Reg R6 */
+ENUM_VAL(REG_R7) /**< User Reg R7 */
+ENUM_VAL(REG_R8) /**< User Reg R8 */
+ENUM_VAL(REG_R9) /**< User Reg R9 */
+ENUM_VAL(REG_R10) /**< User Reg R10 */
+ENUM_VAL(REG_R11) /**< User Reg R11 */
+ENUM_VAL(REG_R12) /**< User Reg R12 */
+ENUM_VAL(REG_SP) /**< Previous Mode SP (R13) */
+ENUM_VAL(REG_LR) /**< Previous Mode LR (R14) */
+ENUM_VAL(REG_PC) /**< Program Counter (R15) */
+
+ENUM_END(register_enum_t)
+
#ifndef __ASSEMBLY__
diff --git a/AT91SAM7S256/armdebug/Host/gdb-commands.txt b/AT91SAM7S256/armdebug/Host/gdb-commands.txt
index 8e6f156..fd7ffd6 100644
--- a/AT91SAM7S256/armdebug/Host/gdb-commands.txt
+++ b/AT91SAM7S256/armdebug/Host/gdb-commands.txt
@@ -32,3 +32,9 @@ $M00201D74,0002:AA55#03
# Write 2 bytes of memory to 0x00201d74 (padding bytes after debug_mode)
$M00201D74,0002:9966#F5
+
+# GDB Read Instruction at Address (PC)
++$m1001de,4#58
+
+# Continue Execution
+$c#87