aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-21 07:16:29 +0800
committerTat-Chee Wan (USM)2011-03-21 07:16:29 +0800
commitdc8b6097f61bc2b3ddd76846e1260c06688d49ee (patch)
tree049a034632a636dca02cc6aaef3b97e7ad48b680
parent00bb26bd744271dabf17582062a7d1a275a5ecd2 (diff)
parent89b4bf567db9eeda1b9b4e5e7e3049ee8f62c988 (diff)
Merge branch 'master' of ssh://svc.cs.usm.my/~/gitrepo-bare/armdebug
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_comm.S4
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_macros.h27
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.S161
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.h18
-rw-r--r--AT91SAM7S256/armdebug/Host/gdb-commands.txt3
5 files changed, 180 insertions, 33 deletions
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_comm.S b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
index efe44a9..6a7aa11 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_comm.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
@@ -408,8 +408,7 @@ _dbg__usb_readbuf_reset:
* R1: USB Command Bit
* R2: USB Raw Message Length
* On Exit:
- * R0: CPSR
- * R1-R3: Destroyed
+ * R0-R3: Destroyed
*/
dbg__copyNxtDebugMsg:
@@ -417,7 +416,6 @@ dbg__copyNxtDebugMsg:
str r2, [r1]
ldr r1, =debug_InUSBBuf
_dbg_memcpy r1, r0, r2, r3 /* r3: scratch register */
- mrs r0, cpsr
bx lr
#endif
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_macros.h b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
index dc1efba..5af75fd 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_macros.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
@@ -251,7 +251,7 @@
*/
.macro _dbg_getstate reg
ldr \reg, =debug_state
- ldr \reg, [\reg]
+ ldrb \reg, [\reg]
.endm
/* _dbg_setstate
@@ -260,9 +260,30 @@
* r0, r1: destroyed
*/
.macro _dbg_setstate state
- ldr r0, =\state
+ mov r0, #\state
ldr r1, =debug_state
- str r0, [r1]
+ strb r0, [r1]
+ .endm
+
+/* _dbg_getmode
+ * Get Debugger Mode
+ * On exit:
+ * reg: Debugger Mode (Boolean)
+ */
+ .macro _dbg_getmode reg
+ ldr \reg, =debug_mode
+ ldrb \reg, [\reg]
+ .endm
+
+/* _dbg_setmode
+ * Set Debugger Mode to given value
+ * On exit:
+ * r0, r1: destroyed
+ */
+ .macro _dbg_setmode mode
+ mov r0, #\mode
+ ldr r1, =debug_mode
+ strb r0, [r1]
.endm
/* _dbg_getcurrbkpt_index
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.S b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
index ec6b149..ba6bf28 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
@@ -75,7 +75,8 @@
* x = ['0','F'] for R0-R15, '!' for User CPSR
*
* mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
- * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN
+ * MAA..AA,LLLL:bb..bb
+ * Write LLLL bytes at address AA.AA OK or ENN
*
* c Resume at current address SNN ( signal NN)
* cAA..AA Continue at address AA..AA SNN
@@ -143,6 +144,21 @@
cmp r0, #MSGBUF_SEPCHAR
.endm
+/* _check_msgargument
+ * Look for argument ':'
+ * On entry:
+ * bufferptr: points to the parameter buffer [can't be R0]
+ * On exit:
+ * R0: destroyed
+ * bufferptr: points to the next character location in the parameter buffer
+ * Flags: Updated
+ */
+
+ .macro _check_msgargument bufferptr
+ ldrb r0, [\bufferptr], #1 /* get separator */
+ cmp r0, #MSGBUF_ARGCHAR
+ .endm
+
/* _check_msgassignment
* Look for assignment '='
* On entry:
@@ -160,8 +176,6 @@
.bss
.align 4
-debug_state:
- .word 0x0
debug_curr_breakpoint:
.word 0x0
debug_InMsgBuf:
@@ -169,6 +183,11 @@ debug_InMsgBuf:
debug_OutMsgBuf:
.space MSGBUF_SIZE,0
+debug_state:
+ .byte 0x0
+debug_mode:
+ .byte 0x0 /* Boolean variable */
+
.data
.align 4
debug_ValidResponsePrefix:
@@ -197,8 +216,8 @@ debug_cmdJumpTable:
.word _dbg__cmd_SetAllRegs /* 'G' */
.word _dbg__cmd_GetOneReg /* 'p' */
.word _dbg__cmd_SetOneReg /* 'P' */
- .word _dbg__nop /* 'm' */
- .word _dbg__nop /* 'M' */
+ .word _dbg__cmd_ReadMem /* 'm' */
+ .word _dbg__cmd_WriteMem /* 'M' */
.word _dbg__nop /* 'c' */
.word _dbg__nop /* 's' */
.word _dbg__nop /* 'k' */
@@ -394,26 +413,29 @@ debug_armComplexCCTable:
*
* UWORD cCommHandleDebug(UBYTE *pInBuf, UBYTE CmdBit, UWORD MsgLength);
*
- * On Entry, we're in SVC mode. We need to setup the USB Buffers, and switch mode to
+ * 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:
- push {r0-r3} /* store all argX registers */
+/* Arg Registers are not preserved since this is invoked explicitly */
+ /* push {r1-r3} */ /* store arg registers */
bl dbg__copyNxtDebugMsg /* setup Debugger Message Buffers, validate input, CPSR returned in R0 */
- mov r1, #CPSR_MODE /* Thumb mode can't handle immediate Operands for AND */
- and r0, r1 /* Check Current Mode */
- cmp r0, #MODE_ABT /* Debug Mode Check (Flags set) */
+ /* pop {r1-r3} */ /* restore values */
+ _dbg_getmode r0 /* Get Debug Mode */
+ cmp r0, #TRUE
- /* If we're in ABT (Abort) mode, this means that we're already running the Debugger */
- beq _in_debug
+ /* 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 */
- pop {r0-r3} /* restore all values */
dbg__bkpt_thumb
- b _cont_cCommHandleDebug
-_in_debug:
- pop {r0-r3} /* restore all values */
-_cont_cCommHandleDebug:
+_cCommHandleDebug_cont:
mov r0, #0 /* FIXME: Return Status */
bx lr
#endif
@@ -443,6 +465,7 @@ dbg__bkpt_init:
/* FIXME: Initialize other stuff here */
_dbg_setstate DBG_INIT
+ _dbg_setmode FALSE /* Debug Mode = False */
pop {lr}
bx lr /* Must return via BX; may have been called from Thumb mode (NXT Firmware) */
@@ -545,6 +568,8 @@ dbg__bkpt_offset_outofrange:
*
****************************************************************************/
dbg__bkpt_waitCMD:
+ _dbg_setmode TRUE /* Debug Mode = True */
+dbg__bkpt_waitCMD_cont:
bl dbg__getDebugMsg /* Read new message from Debugger, buflen in R0, 0 if none, -1 if error, msgbuf pointer in R1 */
cmp r0, #0
beq _dbg__housekeeping /* No message yet, do housekeeping tasks */
@@ -567,14 +592,14 @@ _dbg__cmdExists:
mov r3, r0 /* put Command Handler Index in R3 */
mov r0, r4 /* R0 now contains Input Message Buffer Parameter Pointer (previously in R4) */
_dbg_jumpTableHandler debug_cmdJumpTable, r2, r3 /* Call Command Handler Routine, use R2 as jump address pointer */
- b dbg__bkpt_waitCMD
+ b dbg__bkpt_waitCMD_cont
_dbg__cmdError:
_dbg_outputMsgStatusErr
bl dbg__putDebugMsg /* Send error response to the GDB server */
_dbg__housekeeping:
bl dbg__runloopTasks /* Execute platform run loop tasks while in ABRT mode */
- b dbg__bkpt_waitCMD
+ b dbg__bkpt_waitCMD_cont
/* _dbg__cmdChar2Index
@@ -625,8 +650,7 @@ __dbg__cmdParamLen:
*/
__dbg__procCmdOk:
_dbg_outputMsgStatusOk
- bl dbg__putDebugMsg /* Send error response to the GDB server */
- ldmfd sp!, {pc}
+ b __dbg__sendDebugMsgExit
/* __dbg__procCmdParamError
* Common subroutine exit stub to handle Command Parameter Error for Command Handlers
@@ -635,9 +659,26 @@ __dbg__procCmdOk:
*/
__dbg__procCmdParamError:
_dbg_outputMsgStatusErrCode MSG_UNKNOWNPARAM
- bl dbg__putDebugMsg /* Send error response to the GDB server */
- ldmfd sp!, {pc}
+ b __dbg__sendDebugMsgExit
+
+
+/* __dbg__procCmdReturnInputLengthError
+ * Common subroutine exit stub to handle Command Input Length Error for Command Handlers
+ * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack.
+ *
+ */
+__dbg__procCmdReturnInputLengthError:
+ _dbg_outputMsgStatusErrCode MSG_ERRINLENGTH
+ b __dbg__sendDebugMsgExit
+/* __dbg__procCmdReturnOutputLengthError
+ * Common subroutine exit stub to handle Command Return Output Error for Command Handlers
+ * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack.
+ *
+ */
+__dbg__procCmdReturnOutputLengthError:
+ _dbg_outputMsgStatusErrCode MSG_ERROUTLENGTH
+ b __dbg__sendDebugMsgExit
/* __dbg__procBreakpointAddrError
* Common subroutine exit stub to handle Breakpoint Address Error for Breakpoint Insert/Remove Handlers
@@ -646,6 +687,8 @@ __dbg__procCmdParamError:
*/
__dbg__procBreakpointAddrError:
_dbg_outputMsgStatusErrCode MSG_UNKNOWNBRKPT
+
+__dbg__sendDebugMsgExit:
bl dbg__putDebugMsg /* Send error response to the GDB server */
ldmfd sp!, {pc}
@@ -716,7 +759,7 @@ _dbg__cmd_GetAllRegs:
teq r1, #CMD_REG_GETALL_PARAMLEN /* Check for correct length */
bne __dbg__procCmdParamError /* Unexpected input, report error */
- _dbg_outputMsgValidResponse /* Setup R1 with address of output message buffer data pointer (after response prefix) */
+ _dbg_outputMsgValidResponse /* R0: address of output message buffer data pointer (after response prefix) */
mov r3, #DBGSTACK_USERCPSR_OFFSET /* Output User CPSR Value first */
1: mov r1, r3
bl _dbg_outputOneRegValue /* update output buffer */
@@ -802,7 +845,77 @@ _dbg__nop:
bl dbg__putDebugMsg /* Send error response to the GDB server */
ldmfd sp!, {pc}
+/* _dbg__cmd_ReadMem
+ * Read Memory Contents Command Handler
+ * Output Buffer returns memory contents
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * AA..AA,LLLL
+ * On exit:
+ * r0, r1, r2, r3, r4: destroyed
+ */
+_dbg__cmd_ReadMem:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+ teq r1, #CMD_MEM_READ_PARAMLEN /* Check for correct length */
+ bne __dbg__procCmdParamError /* Unexpected input, report error */
+ bl ascii2word /* convert ASCII address location 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 ',' */
+ mov r0, r1 /* move buffer pointer to R0 for subsequent processing */
+ bl ascii2halfword /* convert ASCII length to Hex (in R0), R1 has address of next buffer char */
+ cmp r0, #CMD_MEM_MAXREADBYTES /* Don't overflow our buffer (2 x CMD_MEM_MAXREADBYTES) */
+ bhi __dbg__procCmdReturnOutLengthError /* Requested Length greater than buffer size, return error */
+ mov r4, r0 /* Keep numbytes in R4 */
+ /* FIXME: Should validate the address? */
+
+ _dbg_outputMsgValidResponse /* R0: address of output message buffer data pointer (after response prefix) */
+1: ldrb r1, [r3], #1
+ bl byte2ascii /* update output buffer */
+ subs r4, r4, #1
+ bne 1b
+
+ _asciiz r0, r1
+ bl dbg__putDebugMsg /* Send response to the GDB server */
+ ldmfd sp!, {pc}
+
+/* _dbg__cmd_WriteMem
+ * Write Memory Contents Command Handler
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * AA..AA,LLLL::bb..bb
+ * On exit:
+ * r0, r1, r2, r3, r4: destroyed
+ */
+_dbg__cmd_WriteMem:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+ 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 /* convert ASCII address location 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 ',' */
+ mov r0, r1 /* move buffer pointer to R0 for subsequent processing */
+ bl ascii2halfword /* convert ASCII length to Hex (in R0), R1 has address of next buffer char */
+ cmp r0, r4, asr #1 /* is Number of bytes to write == (number of ASCII Hex Chars / 2)? */
+ bne __dbg__procCmdParamError /* Number of bytes does not match argument length */
+ cmp r0, #CMD_MEM_MAXWRITEBYTES /* Don't overflow our buffer (2 x CMD_MEM_MAXWRITEBYTES) */
+ bhi __dbg__procCmdReturnInLengthError /* Requested Length greater than buffer size, return error */
+ moveq r4, r0 /* Keep numbytes in R4 */
+ /* FIXME: Should validate the address? */
+ _check_msgargument r1
+ bne __dbg__procCmdParamError /* Can't find ':' */
+
+1: mov r0, r1
+ bl ascii2byte /* convert ASCII Hex value into byte value */
+ strb r0, [r3], #1 /* Store into memory location */
+ subs r4, r4, #1
+ bne 1b
+ b __dbg__procCmdOk
/* _dbg__proc_brkpt_params
* Process Breakpoint Parameters
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.h b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
index 63e3c26..09750be 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
@@ -46,10 +46,12 @@
#define USB_GDBMSG_START 3 /* Offset into USB Telegram buffer */
-#define MSG_NUMSEGMENTS 3 /* For packet transfers */
+#define MSG_NUMSEGMENTS 3 /* For packet transfers */
#define MSG_SEGMENTSIZE (USB_BUFSIZE - USB_GDBMSG_START) /* 61 bytes per segment */
#define MSGBUF_SIZE (MSG_SEGMENTSIZE*MSG_NUMSEGMENTS) /* Debug Message Buffer Size, 61 x 3 = 183 chars = ~80 bytes of actual data */
#define MSGBUF_CHKSUMOFFSET 3 /* to be subtracted from message length */
+#define MSGBUF_IN_OVERHEADLEN 5 /* For calculating max message data length (include ASCIIZ char) */
+#define MSGBUF_OUT_OVERHEADLEN 6 /* For calculating max message data length (include ASCIIZ char) */
#define MSGBUF_CTRLC 0x03 /* For Out of Band Signaling: not implemented yet */
#define MSGBUF_STARTCHAR '$'
@@ -61,6 +63,7 @@
#define MSGBUF_SETCHAR '='
#define MSGBUF_CHKSUMCHAR '#'
#define MSGBUF_SEPCHAR ','
+#define MSGBUF_ARGCHAR ':'
#define MSGBUF_MSGERROR -1
/*@}*/
@@ -84,8 +87,14 @@
#define CMD_REG_REGPARAMLEN 8 /* 32-bit ASCII Hex Value */
#define CMD_REG_SETONE_PARAMLEN (2 + CMD_REG_REGPARAMLEN)
#define CMD_REG_SETALL_PARAMLEN (CMD_REG_NUMREGS*CMD_REG_REGPARAMLEN)
-
-
+#define CMD_NUMITEMS_PARAMLEN 4 /* 16-bit ASCII Hex Value */
+#define CMD_MEM_READ_PARAMLEN (CMD_REG_REGPARAMLEN + CMD_NUMITEMS_PARAMLEN + 1) /* Address length is equivalent to reg param len */
+#define CMD_MEM_WRITE_MINPARAMLEN (CMD_REG_REGPARAMLEN + CMD_NUMITEMS_PARAMLEN + 2) /* Address length is equivalent to reg param len */
+#define CMD_MEM_SEPCHAR_OFFSET CMD_REG_REGPARAMLEN /* Address length is equivalent to reg param len */
+#define CMD_MEM_MAXOUTBUFLEN (MSGBUF_SIZE - MSGBUF_OUT_OVERHEADLEN)
+#define CMD_MEM_MAXREADBYTES (CMD_MEM_MAXOUTBUFLEN/2)
+#define CMD_MEM_MAXINBUFLEN (MSGBUF_SIZE - MSGBUF_IN_OVERHEADLEN)
+#define CMD_MEM_MAXWRITEBYTES ((CMD_MEM_MAXINBUFLEN - CMD_MEM_WRITE_MINPARAMLEN)/2)
/*@}*/
/** @name Debug Breakpoint Command Constants.
@@ -210,9 +219,12 @@ ENUM_END(dbg_state_t)
* Debugger Error Message Enums.
* The enums must be consecutive, starting from 1
*/
+/* FIXME: Need to validate against the ecos-generic-stub.c Error enums */
ENUM_BEGIN
ENUM_VALASSIGN(MSG_ERRIMPL, 0) /**< Stub (not implemented) Error. */
+ENUM_VAL(MSG_ERRINLENGTH) /**< Message Write Length Error. */
ENUM_VAL(MSG_ERRCHKSUM) /**< Checksum Error. */
+ENUM_VAL(MSG_ERROUTLENGTH) /**< Message Read Length Error. */
ENUM_VAL(MSG_ERRFORMAT) /**< Message Format Error. */
ENUM_VAL(MSG_UNKNOWNCMD) /**< Unrecognized Command Error. */
ENUM_VAL(MSG_UNKNOWNPARAM) /**< Unrecognized Parameter Error. */
diff --git a/AT91SAM7S256/armdebug/Host/gdb-commands.txt b/AT91SAM7S256/armdebug/Host/gdb-commands.txt
index ef412d1..37b84d5 100644
--- a/AT91SAM7S256/armdebug/Host/gdb-commands.txt
+++ b/AT91SAM7S256/armdebug/Host/gdb-commands.txt
@@ -6,6 +6,9 @@ $g#67
# Display R0
$p0#A0
+# Display R1
+$p1#A1
+
# Display PC
$pF#B6