summaryrefslogtreecommitdiff
path: root/Debugger
diff options
context:
space:
mode:
Diffstat (limited to 'Debugger')
-rw-r--r--Debugger/debug_comm.S4
-rw-r--r--Debugger/debug_macros.h27
-rw-r--r--Debugger/debug_stub.S41
3 files changed, 50 insertions, 22 deletions
diff --git a/Debugger/debug_comm.S b/Debugger/debug_comm.S
index efe44a9..6a7aa11 100644
--- a/Debugger/debug_comm.S
+++ b/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/Debugger/debug_macros.h b/Debugger/debug_macros.h
index dc1efba..5af75fd 100644
--- a/Debugger/debug_macros.h
+++ b/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/Debugger/debug_stub.S b/Debugger/debug_stub.S
index ec6b149..f8e58ec 100644
--- a/Debugger/debug_stub.S
+++ b/Debugger/debug_stub.S
@@ -160,8 +160,6 @@
.bss
.align 4
-debug_state:
- .word 0x0
debug_curr_breakpoint:
.word 0x0
debug_InMsgBuf:
@@ -169,6 +167,11 @@ debug_InMsgBuf:
debug_OutMsgBuf:
.space MSGBUF_SIZE,0
+debug_state:
+ .byte 0x0
+debug_mode:
+ .byte 0x0 /* Boolean variable */
+
.data
.align 4
debug_ValidResponsePrefix:
@@ -394,26 +397,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 +449,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 +552,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 +576,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