From 1fa36d1d6cbbf8e469618462f2078d27684e9669 Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Sat, 19 Mar 2011 09:01:24 +0800 Subject: added read memory command WIP. Added prelim read memory command --- Debugger/debug_stub.S | 52 ++++++++++++++++++++++++++++++++++++++++++++++++--- Debugger/debug_stub.h | 12 +++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/Debugger/debug_stub.S b/Debugger/debug_stub.S index f8e58ec..8bc4f96 100644 --- a/Debugger/debug_stub.S +++ b/Debugger/debug_stub.S @@ -122,6 +122,8 @@ * 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" @@ -200,8 +202,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' */ @@ -648,6 +650,16 @@ __dbg__procCmdParamError: ldmfd sp!, {pc} +/* __dbg__procCmdReturnLengthError + * Common subroutine exit stub to handle Command Return 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__procBreakpointAddrError * Common subroutine exit stub to handle Breakpoint Address Error for Breakpoint Insert/Remove Handlers * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack. @@ -725,7 +737,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 */ @@ -811,6 +823,40 @@ _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 '') + * 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_MAXNUMBYTES + bhi __dbg__procCmdReturnLengthError /* 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__proc_brkpt_params diff --git a/Debugger/debug_stub.h b/Debugger/debug_stub.h index 63e3c26..dce47fc 100644 --- a/Debugger/debug_stub.h +++ b/Debugger/debug_stub.h @@ -46,10 +46,11 @@ #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_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 '$' @@ -84,8 +85,12 @@ #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_PARAMLEN (CMD_REG_REGPARAMLEN + CMD_NUMITEMS_PARAMLEN + 1) /* 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) /*@}*/ /** @name Debug Breakpoint Command Constants. @@ -214,6 +219,7 @@ ENUM_BEGIN ENUM_VALASSIGN(MSG_ERRIMPL, 0) /**< Stub (not implemented) Error. */ ENUM_VAL(MSG_ERRCHKSUM) /**< Checksum 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. */ -- cgit v1.2.3