From fa8394892071007624e8eab04152eba477cdf706 Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Wed, 15 Jun 2011 08:24:44 +0800 Subject: split platform specific code from generic debug code Move platform specific routines from debug_stub.S into debug_runlooptasks.S --- Debugger/debug_runlooptasks.S | 125 +++++++++++++++++++++++++++++++++++++++++- Debugger/debug_stub.S | 107 ------------------------------------ 2 files changed, 124 insertions(+), 108 deletions(-) diff --git a/Debugger/debug_runlooptasks.S b/Debugger/debug_runlooptasks.S index fd17412..bf636f7 100644 --- a/Debugger/debug_runlooptasks.S +++ b/Debugger/debug_runlooptasks.S @@ -1,4 +1,4 @@ -/** @file debug_runloop.S +/** @file debug_runlooptasks.S * @brief GDB Server platform Run Loop * */ @@ -13,6 +13,11 @@ * */ +/* + * This file contains platform specific code. + * This include ABORT Run Loop operation, as well as + * Debugger Interfacing code to the platform code. + */ /* * The Debugger has to implement a Run Loop in ABORT mode @@ -65,6 +70,11 @@ */ #define __ASSEMBLY__ +#include "debug_internals.h" +#include "debug_macros.h" + + .code 32 + .align 4 .global dbg__runloopTasks @@ -85,3 +95,116 @@ dbg__runloopTasks: /* OSWatchdogWrite is a NULL function in the NXT Firmware?! */ pop {pc} #endif + + +#ifdef __NXOS__ +/**************************************************************************** + * + * GDB Debugger Invocation Routine for NxOS + * + ****************************************************************************/ + .code 32 + .align 4 + + .extern _dbg__install_singlestep + .extern _dbg__activate_singlestep + .global nxos__handleDebug +/* nxos__handleDebug + * Prepare to switch to Debug Mode + * int nxos__handleDebug(unsigned char *msg, comm_chan_t channel, long len); + * + * This routine is called from NxOS Fantom library to setup + * Single Step Breakpoint in preparation for Debugger invocation if we're in + * normal execution mode. + * + * It returns to complete the IRQ handling normally, after which the single + * step breakpoint will be triggered, and the incoming GDB message will then + * be processed in the dbg__bkpt_waitCMD() loop. + * + * If we're in Debugger Mode already, then just return and let the + * dbg__bkpt_waitCMD() loop handle it normally. + * + * If we're operating in normal NxOS mode, return True (!0) + * If we're already in Debugger Mode, return False (0) + */ +nxos__handleDebug: + push {r4, r5, lr} + /* When called, NxOS is in Supervisor mode (MODE_SVC), called from nx__irq_handler() + * via fantom_filter_packet(). + * + * The IRQ Stack contains the LR and SPSR from the topmost interrupted task + * (NxOS supports nested IRQs) + */ + /* R0-R2 has received message related parameters */ + + /* Switch to IRQ mode get SPSR to find out how we were called */ + msr cpsr_c, #(MODE_IRQ | CPSR_FIQ | CPSR_IRQ) + mrs r3, spsr /* Copy SPSR to r3 */ + msr cpsr_c, #(MODE_SVC) /* Return to SVC mode, restore interrupts */ + and r3, r3, #CPSR_MODE /* Get previous mode */ + teq r3, #MODE_ABT /* Are we in Abort (Debug) mode? */ + moveq r0, #FALSE + beq exit_nxos__handleDebug /* Yes, return False */ + +_nxos_switch2debug: + /* Retrieve ISR Return Address */ + ldr r3, =__irq_stack__ + ldmdb r3, {r4,r5} /* R4: SPSR, R5: LR */ + tst r4, #CPSR_THUMB /* Check for Thumb Mode */ + mov r1, r5 /* R5 has interrupted instruction address, setup Single Step Breakpoint for it */ + orrne r1, r1, #1 /* Configure for Thumb Single Step Breakpoint */ + bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */ + bl _dbg__activate_singlestep + mov r0, #TRUE /* We're going to switch to Debug Mode (via Single Step Breakpoint) */ +exit_nxos__handleDebug: + pop {r4, r5, lr} + mov r1, lr /* Safe code: Thumb mode can't access lr */ + bx r1 /* In case we have Interworking from different caller mode */ + +#else + +/**************************************************************************** + * + * GDB Debugger Invocation Routine for NXT Firmware + * + ****************************************************************************/ + .code 16 + .align 2 + + .extern dbg__copyNxtDebugMsg + .global cCommHandleDebug + .thumb_func +/* cCommHandleDebug + * Switch Mode to Debugger. + * Used by NXT Firmware only + * + * UWORD cCommHandleDebug(UBYTE *pInBuf, UBYTE CmdBit, UWORD MsgLength); + * + * 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: +/* 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 */ + _dbg_getmode r0 /* Get Debug Mode */ + cmp r0, #(TRUE & BYTE0) /* Confine it to Byte size */ + + /* 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 */ + dbg__bkpt_thumb +_cCommHandleDebug_cont: + mov r0, #0 /* FIXME: Return Status */ + pop {r1} /* Can't Pop LR directly */ + bx r1 /* Safe code: actually we should be able to Pop PC since the caller is Thumb Mode */ + + .ltorg +#endif diff --git a/Debugger/debug_stub.S b/Debugger/debug_stub.S index b7c1253..119b939 100644 --- a/Debugger/debug_stub.S +++ b/Debugger/debug_stub.S @@ -469,113 +469,6 @@ debug_armComplexCCTable: /* FIXME: The Debugger Stack Frame is probably not 100% consistent with the order that GDB expects in the g/G messages. CSPR is probably located above R15 */ -#ifdef __NXOS__ -/**************************************************************************** - * - * GDB Debugger Invocation Routine for NxOS - * - ****************************************************************************/ - .code 32 - .align 4 - .global nxos__handleDebug -/* nxos__handleDebug - * Prepare to switch to Debug Mode - * int nxos__handleDebug(unsigned char *msg, comm_chan_t channel, long len); - * - * This routine is called from NxOS Fantom library to setup - * Single Step Breakpoint in preparation for Debugger invocation if we're in - * normal execution mode. - * - * It returns to complete the IRQ handling normally, after which the single - * step breakpoint will be triggered, and the incoming GDB message will then - * be processed in the dbg__bkpt_waitCMD() loop. - * - * If we're in Debugger Mode already, then just return and let the - * dbg__bkpt_waitCMD() loop handle it normally. - * - * If we're operating in normal NxOS mode, return True (!0) - * If we're already in Debugger Mode, return False (0) - */ -nxos__handleDebug: - push {r4, r5, lr} - /* When called, NxOS is in Supervisor mode (MODE_SVC), called from nx__irq_handler() - * via fantom_filter_packet(). - * - * The IRQ Stack contains the LR and SPSR from the topmost interrupted task - * (NxOS supports nested IRQs) - */ - /* R0-R2 has received message related parameters */ - - /* Switch to IRQ mode get SPSR to find out how we were called */ - msr cpsr_c, #(MODE_IRQ | CPSR_FIQ | CPSR_IRQ) - mrs r3, spsr /* Copy SPSR to r3 */ - msr cpsr_c, #(MODE_SVC) /* Return to SVC mode, restore interrupts */ - and r3, r3, #CPSR_MODE /* Get previous mode */ - teq r3, #MODE_ABT /* Are we in Abort (Debug) mode? */ - moveq r0, #FALSE - beq exit_nxos__handleDebug /* Yes, return False */ - -_nxos_switch2debug: - /* Retrieve ISR Return Address */ - ldr r3, =__irq_stack__ - ldmdb r3, {r4,r5} /* R4: SPSR, R5: LR */ - tst r4, #CPSR_THUMB /* Check for Thumb Mode */ - mov r1, r5 /* R5 has interrupted instruction address, setup Single Step Breakpoint for it */ - orrne r1, r1, #1 /* Configure for Thumb Single Step Breakpoint */ - bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */ - bl _dbg__activate_singlestep - mov r0, #TRUE /* We're going to switch to Debug Mode (via Single Step Breakpoint) */ -exit_nxos__handleDebug: - pop {r4, r5, lr} - mov r1, lr /* Safe code: Thumb mode can't access lr */ - bx r1 /* In case we have Interworking from different caller mode */ - -#else - -/**************************************************************************** - * - * GDB Debugger Invocation Routine for NXT Firmware - * - ****************************************************************************/ - .code 16 - .align 2 - .global cCommHandleDebug - .thumb_func -/* cCommHandleDebug - * Switch Mode to Debugger. - * Used by NXT Firmware only - * - * UWORD cCommHandleDebug(UBYTE *pInBuf, UBYTE CmdBit, UWORD MsgLength); - * - * 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: -/* 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 */ - _dbg_getmode r0 /* Get Debug Mode */ - cmp r0, #(TRUE & BYTE0) /* Confine it to Byte size */ - - /* 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 */ - dbg__bkpt_thumb -_cCommHandleDebug_cont: - mov r0, #0 /* FIXME: Return Status */ - pop {r1} /* Can't Pop LR directly */ - bx r1 /* Safe code: actually we should be able to Pop PC since the caller is Thumb Mode */ - - .ltorg -#endif - /**************************************************************************** * * GDB Debugger Init and Breakpoint Handler Routines -- cgit v1.2.3