X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EmbeddedPkg%2FLibrary%2FGdbDebugAgent%2FArm%2FProcessor.c;h=d3c050499a302fb2f9155649bc8f669ab4429122;hp=e09e18d6c1c8eafa72a2c81f7e5797d4a8c30444;hb=685f8c760077cb2fb11b74c5758a6d54aebf539f;hpb=969eba7b0df70c9aa261eaf005085568b88de87c diff --git a/EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c b/EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c index e09e18d6c1..d3c050499a 100755 --- a/EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c +++ b/EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c @@ -1,9 +1,9 @@ /** @file Processor specific parts of the GDB stub - Copyright (c) 2008-2010, Apple Inc. All rights reserved. + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
- All rights reserved. This program and the accompanying materials + This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -15,7 +15,6 @@ #include -#include #include #include @@ -466,6 +465,33 @@ ProcessorSendTSignal ( *TSignalPtr = '\0'; } +/** + FIQ state is only changed by FIQ exception. We don't want to take FIQ + ticks in the GDB stub. The stub disables FIQ on entry, but this is the + third instruction that executes in the execption handler. Thus we have + a crack we need to test for. + + @param PC PC of execption + + @return TRUE We are in the GDB stub exception preamble + @return FALSE We are not in GDB stub code + **/ +BOOLEAN +InFiqCrack ( + IN UINT32 PC + ) +{ + UINT32 VectorBase = PcdGet32 (PcdCpuVectorBaseAddress); + UINT32 Length = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart; + + if ((PC >= VectorBase) && (PC <= (VectorBase + Length))) { + return TRUE; + } + + return FALSE; +} + + /** Check to see if this exception is related to ctrl-c handling. @@ -486,6 +512,7 @@ ProcessorControlC ( IN OUT EFI_SYSTEM_CONTEXT SystemContext ) { + CHAR8 Char; BOOLEAN Return = TRUE; if (ExceptionType != EXCEPT_ARM_FIQ) { @@ -493,6 +520,12 @@ ProcessorControlC ( return FALSE; } + if (InFiqCrack (SystemContext.SystemContextArm->PC)) { + // We are in our own interrupt preable, so skip this tick. + // We never want to let gdb see the debug stub running if we can help it + return FALSE; + } + while (TRUE) { if (!GdbIsCharAvailable ()) { // @@ -502,7 +535,8 @@ ProcessorControlC ( break; } - if (GdbGetChar () == 0x03) { + Char = GdbGetChar (); + if (Char == 0x03) { // // We have a ctrl-c so exit and process exception for ctrl-c // @@ -527,7 +561,8 @@ ProcessorControlC ( @param[in] EnableStatus Enable/Disable. - @return FALSE always. + @retval TRUE Debug timer interrupt were enabled on entry to this call. + @retval FALSE Debug timer interrupt were disabled on entry to this call. **/ BOOLEAN @@ -541,7 +576,7 @@ SaveAndSetDebugTimerInterrupt ( FiqEnabled = ArmGetFiqState (); if (EnableStatus) { - DebugAgentTimerSetPeriod (100); + DebugAgentTimerSetPeriod (PcdGet32 (PcdGdbTimerPeriodMilliseconds)); ArmEnableFiq (); } else { DebugAgentTimerSetPeriod (0); @@ -551,6 +586,8 @@ SaveAndSetDebugTimerInterrupt ( return FiqEnabled; } + + VOID GdbFPutString ( IN CHAR8 *String @@ -559,37 +596,44 @@ GdbFPutString ( /** Initialize debug agent. - This function is used to set up debug enviroment. It may enable interrupts. + This function is used to set up debug environment to support source level debugging. + If certain Debug Agent Library instance has to save some private data in the stack, + this function must work on the mode that doesn't return to the caller, then + the caller needs to wrap up all rest of logic after InitializeDebugAgent() into one + function and pass it into InitializeDebugAgent(). InitializeDebugAgent() is + responsible to invoke the passing-in function at the end of InitializeDebugAgent(). + + If the parameter Function is not NULL, Debug Agent Libary instance will invoke it by + passing in the Context to be its parameter. - @param[in] InitFlag Init flag is used to decide initialize process. - @param[in] Context Context needed according to InitFlag, it was optional. + If Function() is NULL, Debug Agent Library instance will return after setup debug + environment. + + @param[in] InitFlag Init flag is used to decide the initialize process. + @param[in] Context Context needed according to InitFlag; it was optional. + @param[in] Function Continue function called by debug agent library; it was + optional. **/ VOID EFIAPI InitializeDebugAgent ( IN UINT32 InitFlag, - IN VOID *Context OPTIONAL + IN VOID *Context, OPTIONAL + IN DEBUG_AGENT_CONTINUE Function OPTIONAL ) { UINTN Offset; UINTN Length; BOOLEAN IrqEnabled; - BOOLEAN FiqEnabled; UINT32 *VectorBase; - + // // Disable interrupts // IrqEnabled = ArmGetInterruptState (); ArmDisableInterrupts (); - - // - // EFI does not use the FIQ, but a debugger might so we must disable - // as we take over the exception vectors. - // - FiqEnabled = ArmGetFiqState (); ArmDisableFiq (); // @@ -615,16 +659,17 @@ InitializeDebugAgent ( // Flush Caches since we updated executable stuff InvalidateInstructionCacheRange ((VOID *)PcdGet32(PcdCpuVectorBaseAddress), Length); + // setup a timer so gdb can break in via ctrl-c DebugAgentTimerIntialize (); - if (FiqEnabled) { - ArmEnableFiq (); - } - if (IrqEnabled) { ArmEnableInterrupts (); } + if (Function != NULL) { + Function (Context); + } + return; }