aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/armdebug
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-30 10:10:46 +0800
committerTat-Chee Wan (USM)2011-03-30 10:10:46 +0800
commit5fdfaa83874590fcd9082659a55abd5dcca05c4f (patch)
tree321419a1b77cc53580ff44fdfd68d044e63df691 /AT91SAM7S256/armdebug
parent953c08633b8d04899c53bc4618c4d50279b27cbd (diff)
parent0451f85157573f18d9959098f83b67336966a0e1 (diff)
Merge branch 'master' of ssh://svc.cs.usm.my/~/gitrepo-bare/armdebug
Diffstat (limited to 'AT91SAM7S256/armdebug')
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_comm.S1
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_internals.h270
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_macros.h4
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.S210
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.h262
-rw-r--r--AT91SAM7S256/armdebug/Debugger/undef_handler.S1
6 files changed, 410 insertions, 338 deletions
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_comm.S b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
index 4d41e24..6635618 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_comm.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
@@ -19,6 +19,7 @@
#define __ASSEMBLY__
#include "debug_macros.h"
#include "debug_stub.h"
+#include "debug_internals.h"
#include "debug_comm.h"
.bss
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_internals.h b/AT91SAM7S256/armdebug/Debugger/debug_internals.h
new file mode 100644
index 0000000..a5121d7
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_internals.h
@@ -0,0 +1,270 @@
+/** @file debug_internals.h
+ * @brief Shared C/ASM header file for debugger internal constants
+ *
+ */
+
+/* Copyright (C) 2007-2011 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+#ifndef __DEBUG_INTERNALS_H__
+#define __DEBUG_INTERNALS_H__
+
+#include "_c_arm_macros.h"
+
+
+/** @addtogroup debugger */
+/*@{*/
+
+
+/* Declarations go here. */
+/** @name Debug Message Constants.
+ *
+ * Debug Message Values
+ */
+/*@{*/
+
+/*
+ * USB Buffer Sizes: Ctrl Intr Iso Bulk
+ * Full Speed Device 64 64 1023 64
+ * High Speed Device 64 1024 1024 512
+ */
+
+#define USB_BUFSIZE 64 /* USB Buffer size for AT91SAM7S */
+
+#define USB_NXT_TELEGRAMTYPE_OFFSET 0 /* NXT Direct Command/Response Header */
+#define USB_NXT_SEGNUM_OFFSET 1
+#define USB_NXT_TELEGRAMSIZE_OFFSET 2
+
+#define USB_NXT_TELEGRAMTYPE 0x8d /* GDB debugger specific, no Response required */
+
+#define USB_GDBMSG_START 3 /* Offset into USB Telegram buffer */
+
+#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_IN_OVERHEADLEN 5 /* For calculating max message data length (exclude ASCIIZ char) */
+#define MSGBUF_OUT_OVERHEADLEN 5 /* For calculating max message data length (exclude ASCIIZ char) */
+
+#define MSGBUF_CTRLC 0x03 /* For Out of Band Signaling: not implemented yet */
+#define MSGBUF_STARTCHAR '$'
+#define MSGBUF_ACKCHAR '+'
+#define MSGBUF_NAKCHAR '-'
+#define MSGBUF_ERRCHAR 'E'
+#define MSGBUF_SIGCHAR 'S'
+#define MSGBUF_SETCHAR '='
+#define MSGBUF_CHKSUMCHAR '#'
+#define MSGBUF_SEPCHAR ','
+#define MSGBUF_ARGCHAR ':'
+#define MSGBUF_MSGERROR -1
+/*@}*/
+
+/** @name Debug Command Lookup Constants.
+ *
+ * Debug Command Lookup
+ */
+/*@{*/
+
+#define CMDINDEX_OUTOFRANGE -1
+/*@}*/
+
+/** @name Debug Register Command Constants.
+ *
+ * Debug Register Command
+ */
+/*@{*/
+#define CMD_REG_NUMREGS 17
+#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_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)
+/*@}*/
+
+/** @name Debug Memory Command Constants.
+ *
+ * Debug Memory Command
+ * FIXME: These limits are not enforced by the GDB client, it truncates addresses and lengths to remove leading '0's
+ * The PARAMLEN constants would probably be removed
+ */
+/*@{*/
+#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_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_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 Continue and Step Command Constants.
+ *
+ * Debug Continue and Step Command
+ */
+/*@{*/
+#define CMD_CONTINUE_MINPARAMLEN 0
+#define CMD_STEP_MINPARAMLEN 0
+/*@}*/
+
+
+
+/** @name Debug Breakpoint Command Constants.
+ *
+ * Debug Breakpoint Command
+ */
+/*@{*/
+
+#define CMD_BKPT_INSERT_MINPARAMLEN 5
+#define CMD_BKPT_REMOVE_MINPARAMLEN 5
+
+
+#define CMD_BKPT_TYPE_BREAK_MEMORY 0
+#define CMD_BKPT_TYPE_BREAK_HARD 1 /* Not supported */
+#define CMD_BKPT_TYPE_WATCH_WRITE 2 /* Not supported (yet) */
+#define CMD_BKPT_TYPE_WATCH_READ 3 /* Not supported (yet) */
+#define CMD_BKPT_TYPE_WATCH_ACCESS 4 /* Not supported (yet) */
+
+#define CMD_BKPT_KIND_THUMB 2
+#define CMD_BKPT_KIND_THUMB2 3 /* Not supported */
+#define CMD_BKPT_KIND_ARM 4
+
+#define CMD_BKPT_NOTFOUND -1
+
+/*@}*/
+
+/** @name Debug Stack Constants.
+ *
+ * Debug Stack Manipulation Values
+ */
+/*@{*/
+#define DBGSTACK_NEXTINSTR_INDEX 0 /* Next Instruction Address is at index 0 from bottom of Debug Stack */
+#define DBGSTACK_USERCPSR_INDEX 1 /* User CPSR (SPSR_UNDEF) is at index 1 from bottom of Debug Stack */
+#define DBGSTACK_USERREG_INDEX 2 /* R0 starts at index 2 from bottom of Debug Stack */
+#define DBGSTACK_USERSP_INDEX (DBGSTACK_USERREG_INDEX + REG_SP) /* SP is R13 */
+#define DBGSTACK_USERLR_INDEX (DBGSTACK_USERREG_INDEX + REG_LR) /* LR is R14 */
+#define DBGSTACK_USERPC_INDEX (DBGSTACK_USERREG_INDEX + REG_PC) /* PC is R15 */
+/*@}*/
+
+/** @name Bitmask Definitions.
+ *
+ * Various Bitmasks used for data manipulation.
+ */
+/*@{*/
+#define BKPT_STATE_THUMB_FLAG 0x01 /* Flag Thumb Breakpoint */
+#define ASCII_LOWER2UPPER_MASK 0x20 /* ASCII Conversion bitmask */
+#define NIBBLE0 0x0000000F /* Nibble 0 word(3:0) */
+#define NIBBLE1 0x000000F0 /* Nibble 1 word(7:4) */
+#define NIBBLE2 0x00000F00 /* Nibble 2 word(11:8) */
+#define NIBBLE3 0x0000F000 /* Nibble 3 word(15:12) */
+#define NIBBLE4 0x000F0000 /* Nibble 4 word(19:16) */
+#define NIBBLE5 0x00F00000 /* Nibble 5 word(23:20) */
+#define NIBBLE6 0x0F000000 /* Nibble 6 word(27:24) */
+#define NIBBLE7 0xF0000000 /* Nibble 7 word(31:28) */
+#define BYTE0 0x000000FF /* Byte 0 word(7:0) */
+#define BYTE1 0x0000FF00 /* Byte 1 word(15:8) */
+#define BYTE2 0x00FF0000 /* Byte 2 word(23:16) */
+#define BYTE3 0xFF000000 /* Byte 3 word(31:24) */
+#define HLFWRD0 0x0000FFFF /* Halfword 0 word(15:0) */
+#define HLFWRD1 0xFFFF0000 /* Halfword 0 word(31:16) */
+/*@}*/
+
+/** @name CPSR Bit Definitions.
+ *
+ * Various Bit definitions for accessing the CPSR register.
+ */
+/*@{*/
+#define CPSR_THUMB 0x00000020
+#define CPSR_FIQ 0x00000040
+#define CPSR_IRQ 0x00000080
+#define CPSR_MODE 0x0000001F
+
+/* ARM Exception Modes */
+#define MODE_USR 0x10 /* User mode */
+#define MODE_FIQ 0x11 /* FIQ mode */
+#define MODE_IRQ 0x12 /* IRQ mode */
+#define MODE_SVC 0x13 /* Supervisor mode */
+#define MODE_ABT 0x17 /* Abort mode */
+#define MODE_UND 0x1B /* Undefined mode */
+#define MODE_SYS 0x1F /* System mode */
+
+/*@}*/
+
+/** Debugger State Enums
+ *
+ * Debugger State.
+ * The enums must be consecutive, starting from 0
+ */
+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_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.
+ * 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_ERROUTLENGTH) /**< Message Read Length Error. */
+ENUM_VAL(MSG_ERRFORMAT) /**< Message Format Error. */
+ENUM_VAL(MSG_UNKNOWNCMD) /**< Unrecognized Command Error. */
+ENUM_VAL(MSG_UNKNOWNPARAM) /**< Unrecognized Parameter Error. */
+ENUM_VAL(MSG_UNKNOWNBRKPT) /**< Unrecognized Breakpoint Error. */
+ENUM_END(dbg_msg_errno)
+
+/** Register Enums
+ *
+ * Register Enums.
+ * Refer to eCOS's arm_stub.h for enum values
+ */
+ENUM_BEGIN
+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 */
+ENUM_VAL(REG_R4) /**< User Reg R4 */
+ENUM_VAL(REG_R5) /**< User Reg R5 */
+ENUM_VAL(REG_R6) /**< User Reg R6 */
+ENUM_VAL(REG_R7) /**< User Reg R7 */
+ENUM_VAL(REG_R8) /**< User Reg R8 */
+ENUM_VAL(REG_R9) /**< User Reg R9 */
+ENUM_VAL(REG_R10) /**< User Reg R10 */
+ENUM_VAL(REG_R11) /**< User Reg R11 */
+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)
+
+
+#endif /* __DEBUG_INTERNALS_H__ */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_macros.h b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
index 0afa0a4..89c7035 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_macros.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
@@ -354,7 +354,7 @@
*/
.macro _dbg_getcurrbkpt_index reg
ldr \reg, =debug_curr_breakpoint
- ldr \reg, [\reg]
+ ldrb \reg, [\reg]
.endm
/* _dbg_setcurrbkpt_index
@@ -364,7 +364,7 @@
*/
.macro _dbg_setcurrbkpt_index reg
ldr r1, =debug_curr_breakpoint
- str \reg, [r1]
+ strb \reg, [r1]
.endm
/* _dbg_getabortedinstr_addr
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.S b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
index 1547882..4520c32 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
@@ -139,6 +139,7 @@
#define __ASSEMBLY__
#include "debug_stub.h"
+#include "debug_internals.h"
#include "debug_macros.h"
/* Macro definitions */
@@ -190,8 +191,6 @@
.bss
.align 4
-debug_curr_breakpoint:
- .word 0x0
debug_InMsgBuf:
.space MSGBUF_SIZE,0
debug_OutMsgBuf:
@@ -203,6 +202,8 @@ debug_mode:
.byte 0x0 /* Boolean variable */
debug_bkpt_type:
.byte 0x0 /* bkpt_type_t variable */
+debug_curr_breakpoint:
+ .byte 0x0
.data
.align 4
@@ -240,8 +241,8 @@ debug_cmdJumpTable:
.word _dbg__cmd_Continue /* 'c' */
.word _dbg__nop /* 's' */
.word _dbg__nop /* 'k' */
- .word _dbg__cmd_remove_breakpoint /* 'z' */
- .word _dbg__cmd_insert_breakpoint /* 'Z' */
+ .word _dbg__cmd_RemoveBreakpoint /* 'z' */
+ .word _dbg__cmd_InsertBreakpoint /* 'Z' */
.word _dbg__cmd_Status /* '?' */
.word _dbg__cmd_Query /* 'q' */
.word _dbg__nop /* 'Q' */
@@ -567,7 +568,17 @@ _process_auto_breakpoint:
bl _dbg__restore_singlestep
bl _dbg__clear_singlestep
_dbg_set_bkpt_type DBG_AUTO_BKPT
- b __dbg__resume_execution
+ /* b _dbg__switch2undefmode */
+
+/* _dbg__switch2undefmode
+ * Common internal routine to return execution to user program
+ */
+_dbg__switch2undefmode:
+ bl _dbg__flush_icache
+ msr cpsr_c, #(MODE_UND | CPSR_FIQ | CPSR_IRQ) /* Configure Undef Mode */
+ _dbg_setmode FALSE /* Debug Mode = False */
+ ldr lr, =resume_execution
+ mov pc, lr /* Exit via UNDEF mode */
_process_manual_breakpoint_thumb:
_dbg_set_bkpt_type DBG_MANUAL_BKPT_THUMB
@@ -1085,6 +1096,14 @@ _dbg__cmd_WriteMem:
/* _dbg__cmd_Continue
* Continue User Program Execution Command Handler
+ * Setup breakpoints before resuming execution of program.
+ *
+ * If Address is specified, update the next instruction address to specified address
+ *
+ * If this is a Normal Breakpoint, then we need to install an Autobreakpoint at next instruction address
+ * and resume from current (Breakpoint) exception address
+ * Else (it is a Manual Breakpoint or Address Specified)
+ * We need to resume from the next instruction address
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
* Optional: AA..AA
@@ -1094,25 +1113,43 @@ _dbg__cmd_WriteMem:
* operating mode to UNDEF and returns to previously active program
*/
_dbg__cmd_Continue:
+ /* Don't put anything on the stack, we won't return to the Debugger Run Loop */
bl __dbg__cmdParamLen
- cmp r1, #CMD_REG_CONTINUE_PARAMLEN /* Check for correct parameter length */
- beq _dbg__cmd_processContinue /* Continue from current PC */
-#if 0
- cmp r1, #CMD_REG_CONTINUEFROM_PARAMLEN /* Check for correct parameter length */
- bne __dbg__procCmdParamError /* Unexpected input, report error */
- bl ascii2word_be /* convert ASCII address location to Hex (in R0), R1 has address of next buffer char */
-#endif
+ cmp r1, #CMD_CONTINUE_MINPARAMLEN /* Check for correct parameter length */
+ beq _dbg__cont_check_breakpoint_type /* Continue from current PC */
+
+_dbg__cont_fromAddr:
bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
/* Continue from Specified Address */
mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
_setdbgregisterfromindex r2, r0, r1 /* Set Register contents in R0, using index in R2, and scratch register R1 */
+ b _dbg__cont_is_manual_bkpt_or_address_specified
+
+_dbg__cont_check_breakpoint_type:
+ _dbg_get_bkpt_type r0
+ teq r0, #DBG_MANUAL_BKPT_ARM
+ beq _dbg__cont_is_manual_bkpt_or_address_specified
+ teq r0, #DBG_MANUAL_BKPT_THUMB
+ bne _dbg__cont_is_normal_breakpoint
+
+_dbg__cont_is_manual_bkpt_or_address_specified:
+ bl _dbg__activate_breakpoints /* Restore exisiting breakpoints */
+ b _dbg__switch2undefmode
+
+_dbg__cont_is_normal_breakpoint:
+/* FIXME: _dbg_next_instruction_addr doesn't actually work currently.
+ This breaks normal breakpoints which need to determine the next instruction to execute
+ (for placing the autobreakpoint) prior to returning.
+*/
+ mov r2, #DBGSTACK_USERPC_INDEX /* Retrieve Aborted Instruction PC from the Debug Stack */
+ _getdbgregisterfromindex r2, r0 /* Retrieve Register contents into R0 */
+ mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
+ _setdbgregisterfromindex r2, r0, r1 /* Set Register contents in R0, using index in R2, and scratch register R1 */
+ bl _dbg_next_instruction_addr /* next instruction address returned in r1 */
+ bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
+ _dbg_getcurrbkpt_index r0 /* load current breakpoint index in memory */
+ bl _dbg__activate_autobreakpoint /* pass next instruction address in r1 */
-_dbg__cmd_processContinue:
-/* FIXME: Currently we assume that the trigger is a Manual Breakpoint, i.e., no need to
- restore instructions to memory, and handle auto-breakpoints (needed to reenable the memory
- breakpoint that was triggered) */
-
-@@@@@
#if 0
/* Not part of the GDB Remote Protocol spec. Messages are sent only when system halts, not when we resume */
__dbg__sendOkBeforeResume:
@@ -1124,11 +1161,68 @@ __dbg__sendOkBeforeResume:
b __dbg__sendOkBeforeResume /* Retry retransmission */
#endif
-_dbg__switch2undefmode:
- msr cpsr_c, #(MODE_UND | CPSR_FIQ | CPSR_IRQ) /* Configure Undef Mode */
- _dbg_setmode FALSE /* Debug Mode = False */
- ldr lr, =resume_execution
- mov pc, lr /* Exit via UNDEF mode */
+ b _dbg__switch2undefmode
+
+/* _dbg__cmd_Step
+ * Step User Program Execution Command Handler
+ * Setup breakpoints before resuming execution of program.
+ *
+ * If Address is specified, update the next instruction address to specified address
+ *
+ * If this is a Normal Breakpoint, then we need to install a Step Breakpoint at next instruction address
+ * and resume from current (Breakpoint) exception address
+ * Else (it is a Manual Breakpoint or Address specified)
+ * We need to install a Step Breakpoint at the following instruction address (after the next instruction address)
+ * and resume from the next instruction address
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * Optional: AA..AA
+ * On exit:
+ * r0, r1, r2: destroyed
+ * Note: This routine does not return to caller. Instead it switches
+ * operating mode to UNDEF and returns to previously active program
+ */
+_dbg__cmd_Step:
+ /* Don't put anything on the stack, we won't return to the Debugger Run Loop */
+ bl __dbg__cmdParamLen
+ cmp r1, #CMD_STEP_MINPARAMLEN /* Check for correct parameter length */
+ beq _dbg__step_check_breakpoint_type /* Step from current PC */
+
+_dbg__step_fromAddr:
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
+ /* Step from Specified Address */
+ mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
+ _setdbgregisterfromindex r2, r0, r1 /* Set Register contents in R0, using index in R2, and scratch register R1 */
+ b _dbg__step_is_manual_bkpt_or_address_specified
+
+_dbg__step_check_breakpoint_type:
+ _dbg_get_bkpt_type r0
+ teq r0, #DBG_MANUAL_BKPT_ARM
+ beq _dbg__step_is_manual_bkpt
+ teq r0, #DBG_MANUAL_BKPT_THUMB
+ bne _dbg__step_is_normal_breakpoint
+
+_dbg__step_is_manual_bkpt:
+ mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
+ _getdbgregisterfromindex r2, r1 /* Retrieve Register contents into R1 */
+ b _dbg__step_is_manual_bkpt_or_address_specified
+
+_dbg__step_is_normal_breakpoint:
+/* FIXME: _dbg_next_instruction_addr doesn't actually work currently.
+ This breaks normal breakpoints which need to determine the next instruction to execute
+ (for placing the autobreakpoint) prior to returning.
+*/
+ mov r2, #DBGSTACK_USERPC_INDEX /* Retrieve Aborted Instruction PC from the Debug Stack */
+ _getdbgregisterfromindex r2, r0 /* Retrieve Register contents into R0 */
+ mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
+ _setdbgregisterfromindex r2, r0, r1 /* Set Register contents in R0, using index in R2, and scratch register R1 */
+
+_dbg__step_is_manual_bkpt_or_address_specified:
+ /* R1 contains the instruction address to be executed upon return */
+ bl _dbg_next_instruction_addr /* following instruction address returned in r1 */
+ bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
+ bl _dbg__activate_singlestep
+ b _dbg__switch2undefmode
/* _dbg__proc_brkpt_params
@@ -1153,7 +1247,7 @@ _dbg__proc_brkpt_params:
_check_msgseparator r3
bne _dbg__proc_brkpt_params_error /* Something wrong with the parameters */
mov r0, r3 /* Check Address */
- bl ascii2word_be /* R0: value, R1: pointer to next char slot */
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
mov r3, r0 /* Keep breakpoint address in R3 */
_check_msgseparator r1
bne _dbg__proc_brkpt_params_error /* Something wrong with the parameters */
@@ -1171,7 +1265,7 @@ _exit_dbg__proc_brkpt_params:
mov r0, r3 /* return breakpoint address */
ldmfd sp!, {pc}
-/* _dbg__cmd_insert_breakpoint
+/* _dbg__cmd_InsertBreakpoint
* Add Breakpoint
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
@@ -1179,11 +1273,11 @@ _exit_dbg__proc_brkpt_params:
* On exit:
* r0, r1, r2, r3: destroyed
*/
-_dbg__cmd_insert_breakpoint:
+_dbg__cmd_InsertBreakpoint:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
- teq r1, #CMD_BKPT_INSERT_PARAMLEN /* Check for correct length */
- bne __dbg__procCmdParamError /* Unexpected input, report error */
+ teq r1, #CMD_BKPT_INSERT_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
bl _dbg__proc_brkpt_params /* R0: Breakpoint Address */
teq r0, #0
beq __dbg__procBreakpointAddrError /* Thumb2 instructions, or unknown kind */
@@ -1196,7 +1290,7 @@ _dbg__cmd_insert_breakpoint:
bl _dbg__install_one_breakpoint /* r0: index, r1: instruction address */
b __dbg__procCmdOk
-/* _dbg__cmd_remove_breakpoint
+/* _dbg__cmd_RemoveBreakpoint
* Remove Breakpoint
* On entry:
* r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
@@ -1204,11 +1298,11 @@ _dbg__cmd_insert_breakpoint:
* On exit:
* r0, r1, r2, r3: destroyed
*/
-_dbg__cmd_remove_breakpoint:
+_dbg__cmd_RemoveBreakpoint:
stmfd sp!, {lr}
bl __dbg__cmdParamLen
- teq r1, #CMD_BKPT_REMOVE_PARAMLEN /* Check for correct length */
- bne __dbg__procCmdParamError /* Unexpected input, report error */
+ teq r1, #CMD_BKPT_REMOVE_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
bl _dbg__proc_brkpt_params /* R0: Breakpoint Address */
teq r0, #0
beq __dbg__procBreakpointAddrError /* Thumb2 instructions, or unknown kind */
@@ -1221,46 +1315,7 @@ _dbg__cmd_remove_breakpoint:
b __dbg__procCmdOk
-/* _dbg__cmd_run
- * Continue execution of program
- */
-_dbg__cmd_run:
- bl _dbg__activate_breakpoints
- b __dbg__resume_execution
-
-/* _dbg__cmd_step
- * Single Step execution of program
- */
-_dbg__cmd_step:
- bl _dbg_next_instruction_addr /* next instruction address returned in r1 */
- bl _dbg__install_singlestep /* Setup Single Step */
- bl _dbg__activate_singlestep
- b __dbg__resume_execution
-/* _dbg__cmd_cont
- * Continue execution of program.
- * If this is a Normal Breakpoint, then we need to install an Autobreakpoint at next instruction address
- * and resume from current (Breakpoint) exception address
- * Else (it is a Manual Breakpoint)
- * We need to resume from the next instruction address
- */
-_dbg__cmd_cont:
-/* FIXME: What happens if we call this when we did not stop at a Breakpoint previously? */
- _dbg_getstate r0
- ldr r1, =DBG_MANUAL_BKPT_ARM
- teq r0, r1
- beq __dbg_is_manual_breakpoint
-
- bl _dbg_next_instruction_addr /* next instruction address returned in r1 */
- bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
- _dbg_getcurrbkpt_index r0 /* load current breakpoint index in memory */
- bl _dbg__activate_autobreakpoint /* pass next instruction address in r1 */
- b __dbg__resume_execution
-
-__dbg_is_manual_breakpoint:
- bl _dbg_next_instruction_addr /* Skip Manual Breakpoint Instruction(s) */
- bl _dbg__activate_breakpoints
- b __dbg__resume_execution
/****************************************************************************
// Selected Routines from the eCos arm_stub.c related to next instruction address
@@ -1720,7 +1775,6 @@ void __single_step (void)
****************************************************************************/
-
/* _dbg_next_instruction_addr
* Determine the address of the next instruction to execute.
* On exit:
@@ -1738,6 +1792,9 @@ void __single_step (void)
* the next instruction address (for inserting a Breakpoint).
*/
_dbg_next_instruction_addr:
+ /* FIXME: This needs a total rewrite */
+ mov r1, #0
+ bx lr
/* We assume that any BKPT instructions in the code will be Manual Breakpoints,
* i.e., the Debugger does not leave stray Single Step / Auto / Normal breakpoints in memory
*/
@@ -1778,15 +1835,6 @@ _next_instr_is_arm:
@@@@@@@@@
bx lr
-/* __dbg__resume_execution
- * cleanup, resume execution of program.
- * Restore User Mode Regsiters from Debugger Stack, and resume execution from aborted instruction
- */
-__dbg__resume_execution:
-@@@@@@
- bl _dbg__flush_icache
- b __dbg__resume_execution
-
/****************************************************************************
*
* Instruction Decode Routines
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.h b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
index a69efd3..931aa68 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
@@ -18,186 +18,6 @@
#include "_c_arm_macros.h"
-
-/** @addtogroup debugger */
-/*@{*/
-
-
-/* Declarations go here. */
-/** @name Debug Message Constants.
- *
- * Debug Message Values
- */
-/*@{*/
-
-/*
- * USB Buffer Sizes: Ctrl Intr Iso Bulk
- * Full Speed Device 64 64 1023 64
- * High Speed Device 64 1024 1024 512
- */
-
-#define USB_BUFSIZE 64 /* USB Buffer size for AT91SAM7S */
-
-#define USB_NXT_TELEGRAMTYPE_OFFSET 0 /* NXT Direct Command/Response Header */
-#define USB_NXT_SEGNUM_OFFSET 1
-#define USB_NXT_TELEGRAMSIZE_OFFSET 2
-
-#define USB_NXT_TELEGRAMTYPE 0x8d /* GDB debugger specific, no Response required */
-
-#define USB_GDBMSG_START 3 /* Offset into USB Telegram buffer */
-
-#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_IN_OVERHEADLEN 5 /* For calculating max message data length (exclude ASCIIZ char) */
-#define MSGBUF_OUT_OVERHEADLEN 5 /* For calculating max message data length (exclude ASCIIZ char) */
-
-#define MSGBUF_CTRLC 0x03 /* For Out of Band Signaling: not implemented yet */
-#define MSGBUF_STARTCHAR '$'
-#define MSGBUF_ACKCHAR '+'
-#define MSGBUF_NAKCHAR '-'
-#define MSGBUF_ERRCHAR 'E'
-#define MSGBUF_SIGCHAR 'S'
-#define MSGBUF_SETCHAR '='
-#define MSGBUF_CHKSUMCHAR '#'
-#define MSGBUF_SEPCHAR ','
-#define MSGBUF_ARGCHAR ':'
-#define MSGBUF_MSGERROR -1
-/*@}*/
-
-/** @name Debug Command Lookup Constants.
- *
- * Debug Command Lookup
- */
-/*@{*/
-
-#define CMDINDEX_OUTOFRANGE -1
-/*@}*/
-
-/** @name Debug Register Command Constants.
- *
- * Debug Register Command
- */
-/*@{*/
-#define CMD_REG_NUMREGS 17
-#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_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)
-/*@}*/
-
-/** @name Debug Memory Command Constants.
- *
- * Debug Memory Command
- * FIXME: These limits are not enforced by the GDB client, it truncates addresses and lengths to remove leading '0's
- * The PARAMLEN constants would probably be removed
- */
-/*@{*/
-#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_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_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 Continue Command Constants.
- *
- * Debug Continue Command
- */
-/*@{*/
-#define CMD_REG_CONTINUE_PARAMLEN 0
-/*@}*/
-
-
-
-/** @name Debug Breakpoint Command Constants.
- *
- * Debug Breakpoint Command
- */
-/*@{*/
-
-#define CMD_BKPT_INSERT_PARAMLEN 12
-#define CMD_BKPT_REMOVE_PARAMLEN 12
-
-
-#define CMD_BKPT_TYPE_BREAK_MEMORY 0
-#define CMD_BKPT_TYPE_BREAK_HARD 1 /* Not supported */
-#define CMD_BKPT_TYPE_WATCH_WRITE 2 /* Not supported (yet) */
-#define CMD_BKPT_TYPE_WATCH_READ 3 /* Not supported (yet) */
-#define CMD_BKPT_TYPE_WATCH_ACCESS 4 /* Not supported (yet) */
-
-#define CMD_BKPT_KIND_THUMB 2
-#define CMD_BKPT_KIND_THUMB2 3 /* Not supported */
-#define CMD_BKPT_KIND_ARM 4
-
-#define CMD_BKPT_NOTFOUND -1
-
-/*@}*/
-
-/** @name Debug Stack Constants.
- *
- * Debug Stack Manipulation Values
- */
-/*@{*/
-#define DBGSTACK_NEXTINSTR_INDEX 0 /* Next Instruction Address is at index 0 from bottom of Debug Stack */
-#define DBGSTACK_USERCPSR_INDEX 1 /* User CPSR (SPSR_UNDEF) is at index 1 from bottom of Debug Stack */
-#define DBGSTACK_USERREG_INDEX 2 /* R0 starts at index 2 from bottom of Debug Stack */
-#define DBGSTACK_USERSP_INDEX (DBGSTACK_USERREG_INDEX + REG_SP) /* SP is R13 */
-#define DBGSTACK_USERLR_INDEX (DBGSTACK_USERREG_INDEX + REG_LR) /* LR is R14 */
-#define DBGSTACK_USERPC_INDEX (DBGSTACK_USERREG_INDEX + REG_PC) /* PC is R15 */
-/*@}*/
-
-/** @name Bitmask Definitions.
- *
- * Various Bitmasks used for data manipulation.
- */
-/*@{*/
-#define BKPT_STATE_THUMB_FLAG 0x01 /* Flag Thumb Breakpoint */
-#define ASCII_LOWER2UPPER_MASK 0x20 /* ASCII Conversion bitmask */
-#define NIBBLE0 0x0000000F /* Nibble 0 word(3:0) */
-#define NIBBLE1 0x000000F0 /* Nibble 1 word(7:4) */
-#define NIBBLE2 0x00000F00 /* Nibble 2 word(11:8) */
-#define NIBBLE3 0x0000F000 /* Nibble 3 word(15:12) */
-#define NIBBLE4 0x000F0000 /* Nibble 4 word(19:16) */
-#define NIBBLE5 0x00F00000 /* Nibble 5 word(23:20) */
-#define NIBBLE6 0x0F000000 /* Nibble 6 word(27:24) */
-#define NIBBLE7 0xF0000000 /* Nibble 7 word(31:28) */
-#define BYTE0 0x000000FF /* Byte 0 word(7:0) */
-#define BYTE1 0x0000FF00 /* Byte 1 word(15:8) */
-#define BYTE2 0x00FF0000 /* Byte 2 word(23:16) */
-#define BYTE3 0xFF000000 /* Byte 3 word(31:24) */
-#define HLFWRD0 0x0000FFFF /* Halfword 0 word(15:0) */
-#define HLFWRD1 0xFFFF0000 /* Halfword 0 word(31:16) */
-/*@}*/
-
-/** @name CPSR Bit Definitions.
- *
- * Various Bit definitions for accessing the CPSR register.
- */
-/*@{*/
-#define CPSR_THUMB 0x00000020
-#define CPSR_FIQ 0x00000040
-#define CPSR_IRQ 0x00000080
-#define CPSR_MODE 0x0000001F
-
-/* ARM Exception Modes */
-#define MODE_USR 0x10 /* User mode */
-#define MODE_FIQ 0x11 /* FIQ mode */
-#define MODE_IRQ 0x12 /* IRQ mode */
-#define MODE_SVC 0x13 /* Supervisor mode */
-#define MODE_ABT 0x17 /* Abort mode */
-#define MODE_UND 0x1B /* Undefined mode */
-#define MODE_SYS 0x1F /* System mode */
-
-/*@}*/
-
/** @name BKPT suppport constants
*
* ARM and Thumb Breakpoint Instructions.
@@ -213,84 +33,16 @@
#define BKPT32_INSTR 0xE1200070 /* ARM BKPT instruction, will work in ARMv5T and above */
#endif
-#define BKPT32_ENUM_MASK 0x000FFF0F /* ARM BKPT Enum Mask */
-#define BKPT32_AUTO_BKPT 0x00080000 /* ARM BKPT Auto-Step Flag (for CONT support) */
-#define BKPT32_MANUAL_BKPT 0x0007FF0F /* Manually inserted ARM Breakpoint */
+#define BKPT32_ENUM_MASK 0x000FFF0F /* ARM BKPT Enum Mask */
+#define BKPT32_AUTO_BKPT 0x00080000 /* ARM BKPT Auto-Step Flag (for CONT support) */
+#define BKPT32_MANUAL_BKPT 0x0007FF0F /* Manually inserted ARM Breakpoint */
-#define BKPT16_INSTR 0xBE00 /* Thumb BKPT instruction */
-#define BKPT16_ENUM_MASK 0x00FF /* Thumb BKPT Enum Mask */
-#define BKPT16_AUTO_BKPT 0x0080 /* Thumb BKPT Auto-Step Flag (for CONT support) */
-#define BKPT16_MANUAL_BKPT 0x007F /* Manually inserted Thumb Breakpoint */
+#define BKPT16_INSTR 0xBE00 /* Thumb BKPT instruction */
+#define BKPT16_ENUM_MASK 0x00FF /* Thumb BKPT Enum Mask */
+#define BKPT16_AUTO_BKPT 0x0080 /* Thumb BKPT Auto-Step Flag (for CONT support) */
+#define BKPT16_MANUAL_BKPT 0x007F /* Manually inserted Thumb Breakpoint */
/*@}*/
-/** Debugger State Enums
- *
- * Debugger State.
- * The enums must be consecutive, starting from 0
- */
-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_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.
- * 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_ERROUTLENGTH) /**< Message Read Length Error. */
-ENUM_VAL(MSG_ERRFORMAT) /**< Message Format Error. */
-ENUM_VAL(MSG_UNKNOWNCMD) /**< Unrecognized Command Error. */
-ENUM_VAL(MSG_UNKNOWNPARAM) /**< Unrecognized Parameter Error. */
-ENUM_VAL(MSG_UNKNOWNBRKPT) /**< Unrecognized Breakpoint Error. */
-ENUM_END(dbg_msg_errno)
-
-/** Register Enums
- *
- * Register Enums.
- * Refer to eCOS's arm_stub.h for enum values
- */
-ENUM_BEGIN
-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 */
-ENUM_VAL(REG_R4) /**< User Reg R4 */
-ENUM_VAL(REG_R5) /**< User Reg R5 */
-ENUM_VAL(REG_R6) /**< User Reg R6 */
-ENUM_VAL(REG_R7) /**< User Reg R7 */
-ENUM_VAL(REG_R8) /**< User Reg R8 */
-ENUM_VAL(REG_R9) /**< User Reg R9 */
-ENUM_VAL(REG_R10) /**< User Reg R10 */
-ENUM_VAL(REG_R11) /**< User Reg R11 */
-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)
-
-
#ifndef __ASSEMBLY__
/* Define C stuff */
diff --git a/AT91SAM7S256/armdebug/Debugger/undef_handler.S b/AT91SAM7S256/armdebug/Debugger/undef_handler.S
index 5562738..b980a5d 100644
--- a/AT91SAM7S256/armdebug/Debugger/undef_handler.S
+++ b/AT91SAM7S256/armdebug/Debugger/undef_handler.S
@@ -10,6 +10,7 @@
*/
#define __ASSEMBLY__
#include "debug_stub.h"
+#include "debug_internals.h"
.text