From c5537648e1378aed86b32488f83bd86e4a3f55ff Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Tue, 15 Mar 2011 09:29:33 +0800 Subject: misc bugfixes for gdb message parsing and error reporting Fixed gdb message parsing to access correct buffer address Fixed byte2ascii conversion routine --- Debugger/debug_comm.S | 7 +++++-- Debugger/debug_macros.h | 7 +++---- Debugger/debug_stub.S | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Debugger/debug_comm.S b/Debugger/debug_comm.S index aa1e36c..44a3a7a 100644 --- a/Debugger/debug_comm.S +++ b/Debugger/debug_comm.S @@ -159,8 +159,8 @@ byte2ascii_cont: lsl r2, r1, #24 /* Keep copy of input byte value R1[7:0], shifted to MSB R2[31:24] */ mov r4, #2 /* Loop counter */ _hex2char_lut r3 /* initialize LUT pointer */ -1: ror r1, r2, #28 /* Rotate MSNibble R2[31:28] into LSNibble position R1[3:0] */ - and r1, r1, #NIBBLE0 /* Mask out everything else */ +1: ror r2, r2, #28 /* Rotate MSNibble R2[31:28] into LSNibble position R2[3:0] */ + and r1, r2, #NIBBLE0 /* Mask out everything else, store Nibble in R1 */ _hex2char_cont r1, r3 /* Convert nibble to ASCII char */ strb r1, [r0], #1 subs r4, r4, #1 /* decrement loop counter */ @@ -577,9 +577,12 @@ _hasMsg2Copy: ldr r3, =debug_msgRxBufPtr ldr r3, [r3] /* Rx buffer Start Address */ +#ifdef CHECK_GDBSTARTCHAR + /* Checked in dbg__bkpt_waitCMD */ ldrb r0, [r3] teq r0, #MSGBUF_STARTCHAR /* Look for '$' */ bne exit_dbg__getMsgError /* No start char '$', exit with error */ +#endif sub r2, r4, #MSGBUF_CHKSUMOFFSET /* Look for '#': Message Length - 3 = '#' offset */ ldrb r0, [r3, r2] diff --git a/Debugger/debug_macros.h b/Debugger/debug_macros.h index 2c6c6e7..dc1efba 100644 --- a/Debugger/debug_macros.h +++ b/Debugger/debug_macros.h @@ -159,11 +159,10 @@ * R3: destroyed */ .macro _dbg_outputMsgStatusErr - mov r3, r0 + mov r1, r0 ldr r0, =debug_OutMsgBuf - ldr r1, =debug_ErrorResponsePrefix - _dbg_stpcpy r0, r1, r2 - mov r1, r3 + ldr r2, =debug_ErrorResponsePrefix + _dbg_stpcpy r0, r2, r3 bl byte2ascii /* R0 points to buffer position after byte value */ _asciiz r0, r1 .endm diff --git a/Debugger/debug_stub.S b/Debugger/debug_stub.S index 2f688c9..f40b6fb 100644 --- a/Debugger/debug_stub.S +++ b/Debugger/debug_stub.S @@ -533,13 +533,14 @@ dbg__bkpt_offset_outofrange: * ****************************************************************************/ dbg__bkpt_waitCMD: - bl dbg__getDebugMsg /* Read new message from Debugger, message buffer addr in R0, 0 if none, -1 if error */ + bl dbg__getDebugMsg /* Read new message from Debugger, message buffer length in R0, 0 if none, -1 if error */ cmp r0, #0 beq _dbg__housekeeping /* No message yet, do housekeeping tasks */ movlt r0, #MSG_ERRCHKSUM /* Message invalid, checksum error? */ blt _dbg__cmdError /* Send response to GDB server */ /* Message now has $\0 */ - mov r4, r0 /* Use R4 as Message Buffer pointer */ + ldr r4, =debug_msgRxBufPtr + ldr r4, [r4] /* Rx buffer Start Address */ ldrb r0, [r4], #1 /* Look for '$' */ teq r0, #MSGBUF_STARTCHAR movne r0, #MSG_ERRFORMAT /* Message Format invalid (not '$') */ -- cgit v1.2.3