aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-25 12:45:50 +0800
committerTat-Chee Wan (USM)2011-03-25 12:45:50 +0800
commit953c08633b8d04899c53bc4618c4d50279b27cbd (patch)
tree2f8c19f7a94de68b566707c8ca0cf4a7aab96f9b
parent5b15d51e06cd552142081dea28b17a822f3e39a7 (diff)
parent41d30e96debfa7fb4a787ec6b298b8d3e6b76045 (diff)
Merge branch 'master' of ssh://svc.cs.usm.my/~/gitrepo-bare/armdebug
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_macros.h31
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.S133
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.h31
-rw-r--r--AT91SAM7S256/armdebug/Host/gdb-commands.txt7
-rwxr-xr-xAT91SAM7S256/armdebug/Host/nxt-gdb-server.py7
5 files changed, 139 insertions, 70 deletions
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_macros.h b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
index d6786d5..0afa0a4 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_macros.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
@@ -289,7 +289,7 @@
*/
.macro _dbg_getstate reg
ldr \reg, =debug_state
- ldrb \reg, [\reg]
+ ldrb \reg, [\reg]
.endm
/* _dbg_setstate
@@ -300,7 +300,7 @@
.macro _dbg_setstate state
mov r0, #\state
ldr r1, =debug_state
- strb r0, [r1]
+ strb r0, [r1]
.endm
/* _dbg_getmode
@@ -310,7 +310,7 @@
*/
.macro _dbg_getmode reg
ldr \reg, =debug_mode
- ldrb \reg, [\reg]
+ ldrb \reg, [\reg]
.endm
/* _dbg_setmode
@@ -321,9 +321,32 @@
.macro _dbg_setmode mode
mov r0, #\mode
ldr r1, =debug_mode
- strb r0, [r1]
+ strb r0, [r1]
.endm
+/* _dbg_get_bkpt_type
+ * Get Breakpoint Type
+ * On exit:
+ * reg: Breakpoint Type
+ */
+ .macro _dbg_get_bkpt_type reg
+ ldr \reg, =debug_bkpt_type
+ ldrb \reg, [\reg]
+ .endm
+
+/* _dbg_set_bkpt_type
+ * Set Breakpoint Type to given value
+ * On exit:
+ * r0, r1: destroyed
+ */
+ .macro _dbg_set_bkpt_type bkpt_type
+ mov r0, #\bkpt_type
+ ldr r1, =debug_bkpt_type
+ strb r0, [r1]
+ .endm
+
+
+
/* _dbg_getcurrbkpt_index
* Get current breakpoint index
* On exit:
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.S b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
index 55b2183..1547882 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
@@ -72,7 +72,8 @@
* px get the value of one register (x) hex data or ENN
* Px=rrrr set the value of one register (x) to OK or ENN
* 32-bit hex value rrrr.
- * x = ['0','F'] for R0-R15, '!' for User CPSR
+ * x = ['0','F'] for R0-R15,
+ * '18' for FPSCR (dummy), '19' for User CPSR
*
* mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
* MAA..AA,LLLL:bb..bb
@@ -197,9 +198,11 @@ debug_OutMsgBuf:
.space MSGBUF_SIZE,0
debug_state:
- .byte 0x0
+ .byte 0x0 /* dbg_state_t variable */
debug_mode:
.byte 0x0 /* Boolean variable */
+debug_bkpt_type:
+ .byte 0x0 /* bkpt_type_t variable */
.data
.align 4
@@ -521,7 +524,7 @@ dbg__thumb_bkpt_handler:
teq r4, #0 /* Check if AUTO flag set */
bne _process_auto_breakpoint
/* else */
- _dbg_setstate DBG_NORMAL_BKPT_THUMB
+ _dbg_set_bkpt_type DBG_NORMAL_BKPT_THUMB
b _process_normal_breakpoint
.global dbg__arm_bkpt_handler
@@ -544,7 +547,7 @@ dbg__arm_bkpt_handler:
teq r4, #0 /* Check if AUTO flag set */
bne _process_auto_breakpoint
/* else */
- _dbg_setstate DBG_NORMAL_BKPT_ARM
+ _dbg_set_bkpt_type DBG_NORMAL_BKPT_ARM
/* b _process_normal_breakpoint */
_process_normal_breakpoint:
@@ -563,14 +566,15 @@ _process_auto_breakpoint:
bl _dbg__activate_one_breakpoint
bl _dbg__restore_singlestep
bl _dbg__clear_singlestep
+ _dbg_set_bkpt_type DBG_AUTO_BKPT
b __dbg__resume_execution
_process_manual_breakpoint_thumb:
- _dbg_setstate DBG_MANUAL_BKPT_THUMB
+ _dbg_set_bkpt_type DBG_MANUAL_BKPT_THUMB
b dbg__bkpt_waitCMD
_process_manual_breakpoint_arm:
- _dbg_setstate DBG_MANUAL_BKPT_ARM
+ _dbg_set_bkpt_type DBG_MANUAL_BKPT_ARM
/* b dbg__bkpt_waitCMD */
dbg__bkpt_inactive:
@@ -776,8 +780,8 @@ _dbg__cmd_Query:
/* _dbg__cmd_GetOneReg
* Get One Register Value Command Handler
- * Valid command parameter x is from '0' to 'F' for User Mode Registers R0-R15
- * CPSR register is '!'
+ * Valid command parameter x is from '0' to 'F' for User Mode Registers R0-R15,
+ * '18' for FPSCR (dummy), and '19' for CPSR
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
* x
@@ -788,15 +792,11 @@ _dbg__cmd_Query:
_dbg__cmd_GetOneReg:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
- teq r1, #CMD_REG_GETONE_PARAMLEN /* Check for correct length */
- bne __dbg__procCmdParamError /* Unexpected input, report error */
- ldrb r0, [r0] /* Load Register index parameter */
- teq r0, #MSGBUF_CPSRREG /* Check for CPSR register indicator */
- moveq r0, #REG_CPSR /* Use CPSR Enum (-1) */
- beq _dbg__proc_getRegister /* Handle User CPSR */
- bl char2hex /* Convert to Hex value (assume input is valid) */
- cmp r0, #NIBBLE0 /* sanity check, (though it is not foolproof as input char in 0x0-0xF (ctrl-chars) will pass through) */
- bhi __dbg__procCmdParamError /* Non-hex char, report error */
+ cmp r1, #CMD_REG_GETONE_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
+ cmp r1, #CMD_REG_GETONE_MAXPARAMLEN /* Check for correct length */
+ bhi __dbg__procCmdParamError /* Unexpected input, report error */
+ bl ascii2hex_varlen_be /* convert ASCII reg enum to Hex (in R0), R1 has address of next buffer char */
_dbg__proc_getRegister:
mov r3, r0 /* Keep register index safe */
@@ -808,10 +808,10 @@ _dbg__proc_getRegister:
ldmfd sp!, {pc}
/* _dbg_outputOneRegValue
- * Given Register Enum (-1: CPSR, 0-F: R0-R15), output hex char to buffer
+ * Given Register Enum (0-F: R0-R15, 0x19: CPSR, OtherVal: dummy), output hex char to buffer
* On entry:
* r0: output message buffer pointer
- * r1: register enum (-1, 0-F)
+ * r1: register enum (0-F, 0x19)
* On exit:
* r0: updated (points to next character slot at end of Output Buffer)
* r1: original output message buffer pointer
@@ -819,18 +819,39 @@ _dbg__proc_getRegister:
*/
_dbg_outputOneRegValue:
stmfd sp!, {lr}
- add r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register enum to Debug Stack index */
+ cmp r1, #REG_PC
+ addls r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register enum to Debug Stack index */
+ bls _retrieve_RegVal
+
+ cmp r1, #REG_CPSR
+ moveq r2, #DBGSTACK_USERCPSR_INDEX /* convert register enum to Debug Stack index */
+ beq _retrieve_RegVal
+
+ cmp r1, #REG_FPSCR
+ bne _exit_dbg_outputOneRegValue /* No match, skip */
+
+_output_dummy_fpscr:
+ /* Output Dummy FPSCR value */
+ mov r1, #0
+ b _output2buffer /* Output all zeros for FPSCR */
+
+_retrieve_RegVal:
_getdbgregisterfromindex r2, r1 /* Retrieve Register contents into R1 */
+
+_output2buffer:
+
#ifdef __BIG_ENDIAN__
bl word2ascii_be /* Convert and put hex chars into Output Message Buffer */
#else
bl word2ascii_le /* Convert and put hex chars into Output Message Buffer */
#endif
+
+_exit_dbg_outputOneRegValue:
ldmfd sp!, {pc}
/* _dbg__cmd_GetAllRegs
* Get All Register Values Command Handler
- * Output Buffer returns register values in the order: User R0, R1, R2, ..., R15, FPSCR (dummy), CPSR
+ * Output Buffer returns register values in the order: User R0, R1, R2, ..., R15, CPSR
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
* <NULL> (no parameters)
@@ -853,16 +874,6 @@ _dbg__cmd_GetAllRegs:
cmp r3, #REG_PC
bls 1b /* process all the registers */
_get_cpsr:
-#if 0
- /* GDB was not happy when this was added */
- /* Output Dummy FPSCR value */
- mov r1, #0
-#ifdef __BIG_ENDIAN__
- bl word2ascii_be /* Convert and put hex chars into Output Message Buffer */
-#else
- bl word2ascii_le /* Convert and put hex chars into Output Message Buffer */
-#endif
-#endif
mov r1, #REG_CPSR /* Output User CPSR Value last */
bl _dbg_outputOneRegValue /* update output buffer */
@@ -871,17 +882,34 @@ _get_cpsr:
ldmfd sp!, {pc}
/* _dbg_setOneRegValue
- * Given Register Enum (-1: CPSR, 0-F: R0-R15), set register to buffer contents
+ * Given Register Enum (0-F: R0-R15, 0x19: CPSR, OtherVal: dummy), output hex char to buffer
* On entry:
* r0: parameter buffer pointer
- * r1: register enum (-1, 0-F)
+ * r1: register enum (0-F, 0x19)
* On exit:
* r0: (Updated) Address of parameter in buffer
* r1, r2, r3: destroyed
*/
_dbg_setOneRegValue:
stmfd sp!, {lr}
- add r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register enum to Debug Stack index */
+ cmp r1, #REG_PC
+ addls r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register enum to Debug Stack index */
+ bls _store_RegVal
+
+ cmp r1, #REG_CPSR
+ moveq r2, #DBGSTACK_USERCPSR_INDEX /* convert register enum to Debug Stack index */
+ beq _store_RegVal
+
+ cmp r1, #REG_FPSCR
+ bne _exit_dbg_setOneRegValue /* No match, skip */
+ /* FIXME: If we get SetAllRegs with FP reg values, this will not skip pass the FP regs! */
+
+_set_dummy_fpscr:
+ /* Set dummy FPSCR value (ignored) */
+ add r1, r0, #CMD_REG_REGPARAMLEN /* Just increment the pointer */
+ b _done_store_RegVal
+
+_store_RegVal:
#ifdef __BIG_ENDIAN__
bl ascii2word_be
#else
@@ -889,41 +917,39 @@ _dbg_setOneRegValue:
#endif
/* R0: value, R1: pointer to next char in buffer */
_setdbgregisterfromindex r2, r0, r3 /* Set Register contents in R0, using index in R2, and scratch register R3 */
+_done_store_RegVal:
mov r0, r1 /* Copy buffer pointer to next parameter to R0 for return value */
+_exit_dbg_setOneRegValue:
ldmfd sp!, {pc}
/* _dbg__cmd_SetOneReg
* Set One Register Value Command Handler
- * Valid command parameter x is from '0' to 'F' for User Mode Registers R0-R15
- * CPSR register is '!'
+ * Valid command parameter x is from '0' to 'F' for User Mode Registers R0-R15,
+ * '18' for FPSCR (dummy), and '19' for CPSR
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
* x=rrrr
* On exit:
- * r0, r1, r2, r3: destroyed
+ * r0, r1, r2, r3, r4: destroyed
*
*/
_dbg__cmd_SetOneReg:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
- teq r1, #CMD_REG_SETONE_PARAMLEN /* Check for correct length */
- bne __dbg__procCmdParamError /* Unexpected input, report error */
- mov r3, r0 /* Keep parameter buffer address in R3 */
- ldrb r1, [r3], #1 /* Load Register enum parameter */
- _check_msgassignment r3
+ cmp r1, #CMD_REG_SETONE_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
+ cmp r1, #CMD_REG_SETONE_MAXPARAMLEN /* Check for correct length */
+ bhi __dbg__procCmdParamError /* Unexpected input, report error */
+
+ bl ascii2hex_varlen_be /* convert ASCII reg enum to Hex (in R0), R1 has address of next buffer char */
+ mov r4, r0 /* Keep enum in R4 */
+ _check_msgassignment r1 /* R1 points to next char in buffer */
bne __dbg__procCmdParamError /* Can't find '=' */
- teq r1, #MSGBUF_CPSRREG /* Check for CPSR register indicator */
- moveq r1, #REG_CPSR /* Use CPSR enum (-1) */
- beq _dbg__proc_setRegister /* Handle User CPSR */
- mov r0, r1 /* Move register enum to R0 for subsequent processing */
- bl char2hex /* Convert to Hex value (assume input is valid) */
- cmp r0, #NIBBLE0 /* sanity check, (though it is not foolproof as input char in 0x0-0xF (ctrl-chars) will pass through) */
- bhi __dbg__procCmdParamError /* Non-hex char, report error */
- mov r1, r0 /* move register enum to R1 to call _dbg_setOneRegValue */
_dbg__proc_setRegister:
- mov r0, r3 /* Retrieve parameter buffer pointer */
+ mov r0, r1 /* move parameter buffer pointer to R0 */
+ mov r1, r4 /* and retrieve enum to R1 to call _dbg_setOneRegValue */
bl _dbg_setOneRegValue
b __dbg__procCmdOk
@@ -933,7 +959,7 @@ _dbg__proc_setRegister:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
* rrrrRRRRrrrr... (17 registers)
* On exit:
- * r0, r1, r2, r3: destroyed
+ * r0, r1, r2, r3, r4: destroyed
*
*/
_dbg__cmd_SetAllRegs:
@@ -960,7 +986,8 @@ _set_cpsr:
#endif
mov r0, r1 /* Copy buffer pointer to next parameter to R0 for return value */
#endif
- mov r1, #REG_CPSR /* Use CPSR enum (-1) */
+
+ mov r1, #REG_CPSR /* Use CPSR enum */
bl _dbg_setOneRegValue /* R0: next parameter address pointer */
ldrb r0, [r0]
teq r0, #0 /* Look for ASCIIZ character to terminate loop */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.h b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
index 9d97705..a69efd3 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
@@ -59,7 +59,6 @@
#define MSGBUF_NAKCHAR '-'
#define MSGBUF_ERRCHAR 'E'
#define MSGBUF_SIGCHAR 'S'
-#define MSGBUF_CPSRREG '!'
#define MSGBUF_SETCHAR '='
#define MSGBUF_CHKSUMCHAR '#'
#define MSGBUF_SEPCHAR ','
@@ -82,10 +81,12 @@
*/
/*@{*/
#define CMD_REG_NUMREGS 17
-#define CMD_REG_GETONE_PARAMLEN 1
+#define CMD_REG_GETONE_MINPARAMLEN 1
+#define CMD_REG_GETONE_MAXPARAMLEN 2
#define CMD_REG_GETALL_PARAMLEN 0
#define CMD_REG_REGPARAMLEN 8 /* 32-bit ASCII Hex Value */
-#define CMD_REG_SETONE_PARAMLEN (2 + CMD_REG_REGPARAMLEN)
+#define CMD_REG_SETONE_MINPARAMLEN (2 + CMD_REG_REGPARAMLEN)
+#define CMD_REG_SETONE_MAXPARAMLEN (3 + CMD_REG_REGPARAMLEN)
#define CMD_REG_SETALL_PARAMLEN (CMD_REG_NUMREGS*CMD_REG_REGPARAMLEN)
/*@}*/
@@ -231,12 +232,21 @@ ENUM_BEGIN
ENUM_VALASSIGN(DBG_RESET, 0) /**< Initial State. */
ENUM_VAL(DBG_INIT) /**< Debugger Initialized. */
ENUM_VAL(DBG_CONFIGURED) /**< Debugger has been configured by GDB Server */
-ENUM_VAL(DBG_MANUAL_BKPT_ARM) /**< Manual ARM Breakpoint. */
-ENUM_VAL(DBG_NORMAL_BKPT_ARM) /**< Normal ARM Breakpoint (Single Step, Normal). */
-ENUM_VAL(DBG_MANUAL_BKPT_THUMB) /**< Manual Thumb Breakpoint. */
-ENUM_VAL(DBG_NORMAL_BKPT_THUMB) /**< Normal Thumb Breakpoint (Single Step, Normal). */
ENUM_END(dbg_state_t)
+/** Breakpoint Type Enums
+ *
+ * Breakpoint Type.
+ * The enums must be consecutive, starting from 0
+ */
+ENUM_BEGIN
+ENUM_VALASSIGN(DBG_AUTO_BKPT,0) /**< Auto Thumb Breakpoint (Instruction resume after breakpoint). */
+ENUM_VAL(DBG_MANUAL_BKPT_ARM) /**< Manual ARM Breakpoint. */
+ENUM_VAL(DBG_NORMAL_BKPT_ARM) /**< Normal ARM Breakpoint (Single Step, Normal). */
+ENUM_VAL(DBG_MANUAL_BKPT_THUMB) /**< Manual Thumb Breakpoint. */
+ENUM_VAL(DBG_NORMAL_BKPT_THUMB) /**< Normal Thumb Breakpoint (Single Step, Normal). */
+ENUM_END(bkpt_type_t)
+
/** Debugger Message Error Enums
*
* Debugger Error Message Enums.
@@ -256,11 +266,10 @@ ENUM_END(dbg_msg_errno)
/** Register Enums
*
* Register Enums.
- * The enums must be consecutive, starting from -1
+ * Refer to eCOS's arm_stub.h for enum values
*/
ENUM_BEGIN
-ENUM_VALASSIGN(REG_CPSR, -1) /**< Previous Mode CPSR */
-ENUM_VAL(REG_R0) /**< User Reg R0 */
+ENUM_VALASSIGN(REG_R0, 0) /**< User Reg R0 */
ENUM_VAL(REG_R1) /**< User Reg R1 */
ENUM_VAL(REG_R2) /**< User Reg R2 */
ENUM_VAL(REG_R3) /**< User Reg R3 */
@@ -276,6 +285,8 @@ ENUM_VAL(REG_R12) /**< User Reg R12 */
ENUM_VAL(REG_SP) /**< Previous Mode SP (R13) */
ENUM_VAL(REG_LR) /**< Previous Mode LR (R14) */
ENUM_VAL(REG_PC) /**< Program Counter (R15) */
+ENUM_VALASSIGN(REG_FPSCR, 24) /**< Previous Mode FPSCR (dummy) */
+ENUM_VAL(REG_CPSR) /**< Previous Mode CPSR */
ENUM_END(register_enum_t)
diff --git a/AT91SAM7S256/armdebug/Host/gdb-commands.txt b/AT91SAM7S256/armdebug/Host/gdb-commands.txt
index fd7ffd6..3135a1e 100644
--- a/AT91SAM7S256/armdebug/Host/gdb-commands.txt
+++ b/AT91SAM7S256/armdebug/Host/gdb-commands.txt
@@ -12,8 +12,11 @@ $p1#A1
# Display PC
$pF#B6
+# Display FPSCR (dummy)
+$p18#D9
+
# Display User CPSR
-$p!#91
+$p19#DA
# Query Status
$?#3F
@@ -37,4 +40,4 @@ $M00201D74,0002:9966#F5
+$m1001de,4#58
# Continue Execution
-$c#87
+$c#63
diff --git a/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py b/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py
index 4babdb9..ee03899 100755
--- a/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py
+++ b/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py
@@ -25,6 +25,7 @@ import struct
DEFAULT_PORT = 2828
SELECT_TIMEOUT = 0.1
DEBUG = True
+DEBUG2 = False
NXT_RECV_ERR = -1
# Libusb 0.12.x blocks on USB reads
@@ -152,12 +153,16 @@ class NXTGDBServer:
# Some pyusb are buggy, ignore some "errors".
if e.args != ('No error', ):
raise e
- if s and LIBUSB_RECEIVE_BLOCKING:
+ if segments != [] and LIBUSB_RECEIVE_BLOCKING:
+ if DEBUG2:
+ print "Accessing Blocking sock.recv()"
data = self.reassemble (brick.sock)
else:
client.close ()
client = None
if not LIBUSB_RECEIVE_BLOCKING:
+ if DEBUG2:
+ print "Accessing Non-Blocking sock.recv()"
data = self.reassemble (brick.sock)
# Is there something from NXT brick?