aboutsummaryrefslogtreecommitdiff
path: root/Debugger
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-19 14:40:17 +0800
committerTat-Chee Wan (USM)2011-03-19 14:40:17 +0800
commit89b4bf567db9eeda1b9b4e5e7e3049ee8f62c988 (patch)
treef1f4a63acce3b145e2d9969217731ab5da613ee7 /Debugger
parent1fa36d1d6cbbf8e469618462f2078d27684e9669 (diff)
implemented memory write command, renumbered error messages
Preliminary Memory Write command implementation. Error Message Enum renumbered based on ecos error message values (not validated).
Diffstat (limited to 'Debugger')
-rw-r--r--Debugger/debug_stub.S88
-rw-r--r--Debugger/debug_stub.h16
2 files changed, 84 insertions, 20 deletions
diff --git a/Debugger/debug_stub.S b/Debugger/debug_stub.S
index 8bc4f96..ba6bf28 100644
--- a/Debugger/debug_stub.S
+++ b/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
@@ -122,8 +123,6 @@
* Additional commands from GDB Reference Appendix D.2
*/
-/* FIXME: Format for Write bytes 'M' is incomplete */
-
#define __ASSEMBLY__
#include "debug_stub.h"
#include "debug_macros.h"
@@ -145,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:
@@ -636,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
@@ -646,19 +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__procCmdReturnLengthError
- * Common subroutine exit stub to handle Command Return Length Error for Command Handlers
+/* __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__procCmdReturnLengthError:
- _dbg_outputMsgStatusErrCode MSG_ERRLENGTH
- bl dbg__putDebugMsg /* Send error response to the GDB server */
- ldmfd sp!, {pc}
+__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
@@ -667,6 +687,8 @@ __dbg__procCmdReturnLengthError:
*/
__dbg__procBreakpointAddrError:
_dbg_outputMsgStatusErrCode MSG_UNKNOWNBRKPT
+
+__dbg__sendDebugMsgExit:
bl dbg__putDebugMsg /* Send error response to the GDB server */
ldmfd sp!, {pc}
@@ -843,8 +865,8 @@ _dbg__cmd_ReadMem:
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_MAXNUMBYTES
- bhi __dbg__procCmdReturnLengthError /* Requested Length greater than buffer size, return error */
+ 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? */
@@ -859,6 +881,42 @@ _dbg__cmd_ReadMem:
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
* On entry:
diff --git a/Debugger/debug_stub.h b/Debugger/debug_stub.h
index dce47fc..09750be 100644
--- a/Debugger/debug_stub.h
+++ b/Debugger/debug_stub.h
@@ -50,7 +50,8 @@
#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_OVERHEADLEN 6 /* For calculating max message data length (include ASCIIZ char) */
+#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 '$'
@@ -62,6 +63,7 @@
#define MSGBUF_SETCHAR '='
#define MSGBUF_CHKSUMCHAR '#'
#define MSGBUF_SEPCHAR ','
+#define MSGBUF_ARGCHAR ':'
#define MSGBUF_MSGERROR -1
/*@}*/
@@ -87,10 +89,12 @@
#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_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_MAXBUFLEN (MSGBUF_SIZE - MSGBUF_OVERHEADLEN)
-#define CMD_MEM_MAXNUMBYTES (CMD_MEM_MAXBUFLEN/2)
+#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.
@@ -215,11 +219,13 @@ 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_ERRLENGTH) /**< Message Output Length Error. */
ENUM_VAL(MSG_UNKNOWNCMD) /**< Unrecognized Command Error. */
ENUM_VAL(MSG_UNKNOWNPARAM) /**< Unrecognized Parameter Error. */
ENUM_VAL(MSG_UNKNOWNBRKPT) /**< Unrecognized Breakpoint Error. */