aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/armdebug
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-06-22 07:48:39 +0800
committerTat-Chee Wan (USM)2011-06-22 07:48:39 +0800
commit08d838f59595978fced9b3fa25a7bb8255898f29 (patch)
tree35561ecf16623b5050bea7c7b43ddfa8bd670817 /AT91SAM7S256/armdebug
parent44dcbdc61981f8d2ebc24d125ce786b9595e7969 (diff)
parentabedf371a610485c3de77af2a05e2699627ff358 (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.S131
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S130
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.h (renamed from AT91SAM7S256/armdebug/Debugger/debug_comm.h)17
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.h8
4 files changed, 151 insertions, 135 deletions
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_comm.S b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
index 570fedc..e237999 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_comm.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
@@ -13,14 +13,12 @@
*
*/
-
-/* #define __NXOS__ */ /* Defined externally in SConstruct */
-
#define __ASSEMBLY__
#include "debug_macros.h"
#include "debug_stub.h"
#include "debug_internals.h"
-#include "debug_comm.h"
+
+ .extern dbg__sendCommMsg
/* Hexutils function references */
.extern hex2char
@@ -41,6 +39,8 @@
.bss
.align 4
+ .global debug_InCommBuf
+ .global debug_OutCommBuf
debug_InCommBuf:
.space USB_BUFSIZE,0
debug_OutCommBuf:
@@ -62,15 +62,20 @@ debug_msgTxBuf_AppendPtr:
debug_segmentRxNum: /* Current Rx Segment Number */
.word 0x0
-debug_nxtMsgLength: /* NXT Firmware Received Message Length */
+/* Comm Channel and NXT Received Message Length is now common to both NxOS and NXT Firmware */
+debug_nxtMsgLength:
.word 0x0
-/* Comm Channel is now common to both NxOS and NXT Firmware */
.global debug_nxtCommChannel
debug_nxtCommChannel:
.word 0x0
+ .global debug_nxtCommOverrun
+debug_nxtCommOverrun:
+ .word 0x0
+
.equ NXTCOMMCHANNEL_OFFSET, (debug_nxtCommChannel - debug_nxtMsgLength)
+ .equ NXTCOMMOVERRUN_OFFSET, (debug_nxtCommOverrun - debug_nxtMsgLength)
.data
.align 4
@@ -160,30 +165,17 @@ dbg__comm_init:
str r0, [r1, #NXTCOMMCHANNEL_OFFSET] /* Clear NXT Channel on INIT */
ldmfd sp!, {pc}
-#ifdef __NXOS__
-_dbg__comm_readbuf_reset:
- stmfd sp!, {lr}
- ldr r0, =debug_InCommBuf
- mov r1, #USB_BUFSIZE
- ldr r2, =fantom_init
- mov lr, pc
- bx r2
-#if 0
- ldr r1, =debug_nxtMsgLength
- mov r0, #0
- str r0, [r1] /* Clear NxOS Received Message Length */
-#endif
- ldmfd sp!, {pc}
-#else
+
_dbg__comm_readbuf_reset:
ldr r1, =debug_nxtMsgLength
mov r0, #0
- str r0, [r1] /* Clear NXT Received Message Length */
+ str r0, [r1] /* Clear Received Comm Message Length */
bx lr
.global dbg__copyNxtDebugMsg
/* dbg__copyNxtDebugMsg
- * Copy NXT Firmware Debug Message to our own Buffers, indicate Msg Received status.
+ * Copy NXT Debug Message to our own Buffers, indicate Msg Received status.
+ * Note: This routine is now used by both NXT Firmware and NxOS
* On Entry:
* R0: NXT Input Buf Pointer
* R1: NXT Communications Channel Enum (CmdBit)
@@ -193,15 +185,21 @@ _dbg__comm_readbuf_reset:
*/
dbg__copyNxtDebugMsg:
ldr r3, =debug_nxtMsgLength
- str r1, [r3, #NXTCOMMCHANNEL_OFFSET]
+ str r1, [r3, #NXTCOMMCHANNEL_OFFSET] /* save Communications Channel first */
+ ldr r1, [r3] /* Check if there's an unread message in the buffer */
+ cmp r1, #0
+ beq cont_dbg__copyNxtDebugMsg /* No unread message, so continue */
+exit_dbg__NxtDebugMsgOverrun:
+ ldr r1, [r3, #NXTCOMMOVERRUN_OFFSET]
+ add r1, r1, #1
+ str r1, [r3, #NXTCOMMOVERRUN_OFFSET] /* update message overrun stats */
+ b exit_dbg__copyNxtDebugMsg
+cont_dbg__copyNxtDebugMsg:
str r2, [r3]
ldr r1, =debug_InCommBuf
-/* FIXME: We can probably save some cycles and buffer space by using the
- * NXT comms buffer specified in R0 directly without copying to internal buffers
- */
_dbg_memcpy r1, r0, r2, r3 /* r3: scratch register */
+exit_dbg__copyNxtDebugMsg:
bx lr
-#endif
/* _dbg_reset_msgTxBuf_AppendPtr
* Internal variable to reset pointers.
@@ -223,15 +221,8 @@ _dbg_reset_msgTxBuf_AppendPtr:
*/
_dbg__commHasMsg:
stmfd sp!, {lr}
-#ifdef __NXOS__
- ldr r2, =nx_usb_fantom_data_read
- mov lr,pc
- bx r2 /* Number of bytes read in R0 */
- /* Note: The return value in R0 is the Comm Buffer Size, includes NXT Direct Command Header */
-#else
ldr r0, =debug_nxtMsgLength
ldr r0, [r0] /* R0 contains the Comm Buffer Size, including the NXT Direct Command Header */
-#endif
ldr r2, =debug_InCommBuf
ldrb r1, [r2, #NXT_MSG_TELEGRAMTYPE_OFFSET]
@@ -412,74 +403,6 @@ exit_dbg__getDebugMsg:
mov r1, r5 /* Return GDB Message Buffer Pointer in R1 */
ldmfd sp!, {r4,r5,pc}
-/* _dbg__sendCommMsg
- * Internal send routine (interfaces with drivers).
- * On entry:
- * R0: Total Message Buffer length
- * On exit:
- R0: Tx Status (TRUE if data sent)
- */
-_dbg__sendCommMsg:
- stmfd sp!, {r4, lr}
- mov r4, r0 /* Keep Comm Buffer length in R4 */
-#ifdef __NXOS__
- /* Check USB bus status, transmit message if possible */
- bl nx_usb_is_connected /* R0 = TRUE (#1) if USB is ready */
- teq r0, #0 /* FALSE == #0;
- We can't check for True condition since values
- used by C-Compiler & ARMDEBUG are different */
- beq _dbg__sendCommMsgFailed
-
- /* Actual transmission (blocking) */
- ldr r0, =debug_OutCommBuf /* data pointer parameter */
- mov r1, r4 /* Comm buffer length */
- bl nx_usb_write
-
-1: bl nx_usb_data_written /* R0 = True if data has been sent */
- teq r0, #0 /* FALSE == #0;
- We can't check for True condition since values
- used by C-Compiler & ARMDEBUG are different */
- /* FIXME: implement timeout */
- beq 1b /* Busy Wait Loop */
-#else
- ldr r0, =debug_nxtCommChannel
- ldr r0, [r0] /* Get Channel Enum */
- teq r0, #BT_CMD_READY
- beq _dbg__sendBTMsg
- teq r0, #USB_CMD_READY
- beq _dbg__sendUSBMsg
- b _dbg__sendCommMsgFailed /* Channel Enum Doesn't Match, shouldn't happen? */
-
-_dbg__sendBTMsg:
- /* NXT BT routines do not have any configuration checks */
- ldr r0, =debug_OutCommBuf /* data pointer parameter */
- mov r1, r4 /* BT Bytes to Send */
- mov r2, r4 /* BT Message Size */
- bl dBtSendMsg /* Send it via Bluetooth (complete message) */
- mov r0, #TRUE /* Always flag Success */
- b _exit_dbg__sendCommMsg
-
-_dbg__sendUSBMsg:
- /* Check USB bus status, transmit message if possible */
- bl dUsbIsConfigured /* R0: UByte status, TRUE / FALSE */
- teq r0, #nxt_UBYTE_TRUE
- bne _dbg__sendCommMsgFailed
-
- /* Actual transmission (blocking) */
- ldr r0, =debug_OutCommBuf /* data pointer parameter */
- mov r1, r4 /* Comm buffer length */
- bl dUsbWrite /* call NXT Firmware USB driver, return 0: done, !0: remaining chars */
- teq r0, #0 /* Tx done if returned length is 0 */
- moveq r0, #TRUE /* Convert NXT firmware return value to our Status (TRUE/FALSE) */
- beq _exit_dbg__sendCommMsg
-#endif
-
-_dbg__sendCommMsgFailed:
- mov r0, #FALSE
-
-_exit_dbg__sendCommMsg:
- ldmfd sp!, {r4, pc}
-
/* _copy_msg_to_commbuf
* Internal Comm buffer copy routine, handles segment fragmentation.
@@ -518,7 +441,7 @@ _copy_msg_to_commbuf:
mov r5, r2 /* Updated Tx Append Pointer, keep in R5 for now */
add r0, r4, #NXT_GDBMSG_START /* Total Comm Buffer Size for Tx (NXT_GDBMSG_START offset = header size) */
- bl _dbg__sendCommMsg /* Common interface routine to commnuncations drivers */
+ bl dbg__sendCommMsg /* Common interface routine to commnuncations drivers */
cmp r0, #TRUE
ldrne r5, [r6, #TXAPPENDPTR_OFFSET] /* Tx failed, Retrieve Original Tx Append Pointer */
streq r5, [r6, #TXAPPENDPTR_OFFSET] /* Tx succeeded, Update Tx Append Pointer to new position */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S b/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S
index f00e99d..75c477c 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S
@@ -69,6 +69,9 @@
*/
#define __ASSEMBLY__
+#define REBOOT_POWERDOWN
+#include "debug_runlooptasks.h"
+
#include "debug_internals.h"
#include "debug_macros.h"
#include "debug_stub.h"
@@ -77,6 +80,7 @@
.align 4
.global dbg__runloopTasks
.global dbg__reboot
+ .global dbg__sendCommMsg
#ifdef __NXOS__
/****************************************************************************
@@ -94,8 +98,6 @@ dbg__runloopTasks:
* NXT Firmware Run Loop
*
****************************************************************************/
- .extern cCommCtrl
-
dbg__runloopTasks:
push {lr}
/* FIXME: Add necessary cXXXCtrl calls here */
@@ -105,7 +107,6 @@ dbg__runloopTasks:
#endif
#ifdef __NXOS__
- .extern nx_core_reset
/****************************************************************************
*
* NxOS Reboot Routine
@@ -115,11 +116,6 @@ dbg__runloopTasks:
b nx_core_reset /* Reboot Brick, won't return */
#else
- .extern dIOCtrlSetPower
- .extern dIOCtrlSetPwm
- .extern dIOCtrlTransfer
- .equ BOOT, 0xA55A
- .equ POWERDOWN, 0x5A00
/****************************************************************************
*
* NXT Firmware Reboot Routine
@@ -138,15 +134,13 @@ dbg__reboot:
/* We implement the powerdown sequence for now */
-#if 1
+#ifdef REBOOT_POWERDOWN
/* Powerdown sequence */
ldr r0, =((POWERDOWN >> 8) & 0xFF)
ldr r1, =dIOCtrlSetPower
mov lr,pc
bx r1
-#endif
-
-#if 0
+#else
/* Reboot sequence: this forces SAMBA mode??!! */
ldr r0, =((BOOT >> 8) & 0xFF)
ldr r1, =dIOCtrlSetPower
@@ -169,6 +163,102 @@ _dbg__reboot_wait:
#ifdef __NXOS__
+ .extern debug_OutCommBuf
+/****************************************************************************
+ *
+ * NxOS Communications Driver Interface Routine
+ *
+ ****************************************************************************/
+/* dbg__sendCommMsg
+ * Internal send routine (interfaces with drivers).
+ * On entry:
+ * R0: Total Message Buffer length
+ * On exit:
+ R0: Tx Status (TRUE if data sent)
+ */
+dbg__sendCommMsg:
+ stmfd sp!, {r4, lr}
+ mov r4, r0 /* Keep Comm Buffer length in R4 */
+ /* Check USB bus status, transmit message if possible */
+ bl nx_usb_is_connected /* R0 = TRUE (#1) if USB is ready */
+ teq r0, #0 /* FALSE == #0;
+ We can't check for True condition since values
+ used by C-Compiler & ARMDEBUG are different */
+ beq dbg__sendCommMsgFailed
+
+ /* Actual transmission (blocking) */
+ ldr r0, =debug_OutCommBuf /* data pointer parameter */
+ mov r1, r4 /* Comm buffer length */
+ bl nx_usb_write
+
+1: bl nx_usb_data_written /* R0 = True if data has been sent */
+ teq r0, #0 /* FALSE == #0;
+ We can't check for True condition since values
+ used by C-Compiler & ARMDEBUG are different */
+ /* FIXME: implement timeout */
+ beq 1b /* Busy Wait Loop */
+dbg__sendCommMsgFailed:
+ mov r0, #FALSE
+
+exit_dbg__sendCommMsg:
+ ldmfd sp!, {r4, pc}
+
+
+#else
+/****************************************************************************
+ *
+ * NXT Firmware Communications Driver Interface Routine
+ *
+ ****************************************************************************/
+/* dbg__sendCommMsg
+ * Internal send routine (interfaces with drivers).
+ * On entry:
+ * R0: Total Message Buffer length
+ * On exit:
+ R0: Tx Status (TRUE if data sent)
+ */
+dbg__sendCommMsg:
+ stmfd sp!, {r4, lr}
+ mov r4, r0 /* Keep Comm Buffer length in R4 */
+ ldr r0, =debug_nxtCommChannel
+ ldr r0, [r0] /* Get Channel Enum */
+ teq r0, #BT_CMD_READY
+ beq dbg__sendBTMsg
+ teq r0, #USB_CMD_READY
+ beq dbg__sendUSBMsg
+ b dbg__sendCommMsgFailed /* Channel Enum Doesn't Match, shouldn't happen? */
+
+dbg__sendBTMsg:
+ /* NXT BT routines do not have any configuration checks */
+ ldr r0, =debug_OutCommBuf /* data pointer parameter */
+ mov r1, r4 /* BT Bytes to Send */
+ mov r2, r4 /* BT Message Size */
+ bl dBtSendMsg /* Send it via Bluetooth (complete message) */
+ mov r0, #TRUE /* Always flag Success */
+ b exit_dbg__sendCommMsg
+
+dbg__sendUSBMsg:
+ /* Check USB bus status, transmit message if possible */
+ bl dUsbIsConfigured /* R0: UByte status, TRUE / FALSE */
+ teq r0, #nxt_UBYTE_TRUE
+ bne dbg__sendCommMsgFailed
+
+ /* Actual transmission (blocking) */
+ ldr r0, =debug_OutCommBuf /* data pointer parameter */
+ mov r1, r4 /* Comm buffer length */
+ bl dUsbWrite /* call NXT Firmware USB driver, return 0: done, !0: remaining chars */
+ teq r0, #0 /* Tx done if returned length is 0 */
+ moveq r0, #TRUE /* Convert NXT firmware return value to our Status (TRUE/FALSE) */
+ beq exit_dbg__sendCommMsg
+dbg__sendCommMsgFailed:
+ mov r0, #FALSE
+
+exit_dbg__sendCommMsg:
+ ldmfd sp!, {r4, pc}
+#endif
+
+
+#ifdef __NXOS__
/****************************************************************************
*
* GDB Debugger Invocation Routine for NxOS
@@ -183,7 +273,7 @@ _dbg__reboot_wait:
.global nxos__handleDebug
/* nxos__handleDebug
* Prepare to switch to Debug Mode
- * int nxos__handleDebug(comm_chan_t channel);
+ * int nxos__handleDebug(U8 *buffer, comm_chan_t channel, U32 length);
*
* This routine is called from NxOS Fantom library to setup
* Single Step Breakpoint in preparation for Debugger invocation if we're in
@@ -207,15 +297,11 @@ nxos__handleDebug:
* The IRQ Stack Frame Pointer will contains the LR and SPSR from the topmost interrupted task
* if it is non-zero (NxOS supports nested IRQs)
*/
-
- ldr r3, =debug_nxtCommChannel
- str r0, [r3] /* Keep track of which communications link was used (USB/Bluetooth) */
-
- /* Check our current operating mode */
+ bl dbg__copyNxtDebugMsg /* Copy to Debugger Message Buffer, Remember Comm Channel */
mov r0, #FALSE /* Setup Default Return value (False) */
- mrs r3, cpsr /* Copy CPSR to r3 */
- and r3, r3, #CPSR_MODE /* Get current mode */
- teq r3, #MODE_ABT /* Are we in Abort (Debug) mode? */
+ _dbg_getmode r1 /* Get Debug Mode */
+ cmp r1, #(TRUE & BYTE0) /* Confine it to Byte size */
+ /* If Debug Mode is TRUE, this means that we're already running the Debugger */
beq exit_nxos__handleDebug /* Yes, return False */
/* Retrieve ISR Return Address */
@@ -271,7 +357,7 @@ exit_nxos__handleDebug:
cCommHandleDebug:
/* Arg Registers are not preserved since this is invoked explicitly */
push {lr} /* store arg registers */
- bl dbg__copyNxtDebugMsg /* setup Debugger Message Buffers, validate input, CPSR returned in R0 */
+ bl dbg__copyNxtDebugMsg /* Copy to Debugger Message Buffer, Remember Comm Channel */
_dbg_getmode r0 /* Get Debug Mode */
cmp r0, #(TRUE & BYTE0) /* Confine it to Byte size */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_comm.h b/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.h
index 7553240..360e0d1 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_comm.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.h
@@ -1,9 +1,9 @@
-/** @file debug_comm.h
+/** @file debug_runlooptasks.h
* @brief Shared C/ASM header file for debugger communications
*
*/
-/* Copyright (C) 2007-2010 the NxOS developers
+/* Copyright (C) 2007-2011 the NxOS developers
*
* Module Developed by: TC Wan <tcwan@cs.usm.my>
*
@@ -13,8 +13,8 @@
*
*/
-#ifndef __DEBUG_COMM_H__
-#define __DEBUG_COMM_H__
+#ifndef __DEBUG_RUNLOOPTASKS_H__
+#define __DEBUG_RUNLOOPTASKS_H__
#include "_c_arm_macros.h"
@@ -27,12 +27,13 @@
#ifdef __NXOS__
- .extern nx_usb_is_connected
+ .extern nx_usb_is_connected
.extern nx_usb_can_write
.extern nx_usb_write
.extern nx_usb_data_written
.extern nx_usb_read
.extern nx_usb_data_read
+ .extern nx_core_reset
#else /* NXT Firmware */
@@ -48,6 +49,12 @@
.equ USB_CMD_READY, 0x01 /* From c_comm.iom */
.equ BT_CMD_READY, 0x02 /* From c_comm.iom */
+ .extern dIOCtrlSetPower
+ .extern dIOCtrlSetPwm
+ .extern dIOCtrlTransfer
+ .equ BOOT, 0xA55A /* from c_ioctrl.iom */
+ .equ POWERDOWN, 0x5A00 /* from c_ioctrl.iom */
+
#endif
#endif
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.h b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
index a4cbdda..11b348e 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
@@ -71,13 +71,13 @@ ENUM_END(comm_chan_t)
* !0 if mode switch will happen
* Used by NxOS only
*/
-FUNCDEF int nxos__handleDebug(comm_chan_t channel);
-#endif
-
-#ifndef __NXOS__
+/* Note: This platform specific routine is found in debug_runlooptasks.S */
+FUNCDEF int nxos__handleDebug(U8 *buffer, comm_chan_t channel, U32 length);
+#else
/** Switch Mode to Debugger.
* Used by NXT Firmware only
*/
+/* Note: This platform specific routine is found in debug_runlooptasks.S */
FUNCDEF UWORD cCommHandleDebug(UBYTE *pInBuf, UBYTE CmdBit, UWORD MsgLength);
#endif