/** Initialize debug agent. 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. 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 DEBUG_AGENT_CONTINUE Function OPTIONAL ) { UINTN Offset; UINTN Length; BOOLEAN IrqEnabled; UINT64 *VectorBase; // // Disable interrupts // IrqEnabled = ArmGetInterruptState (); ArmDisableInterrupts (); ArmDisableFiq (); // // Copy an implementation of the ARM exception vectors to PcdCpuVectorBaseAddress. // Length = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart; // // Reserve space for the exception handlers // VectorBase = (UINT64 *)(UINTN)PcdGet64 (PcdCpuVectorBaseAddress); // Copy our assembly code into the page that contains the exception vectors. CopyMem ((VOID *)VectorBase, (VOID *)ExceptionHandlersStart, Length); // // Patch in the common Assembly exception handler // Offset = (UINTN)CommonExceptionEntry - (UINTN)ExceptionHandlersStart; *(UINTN *) (((UINT8 *)VectorBase) + Offset) = (UINTN)AsmCommonExceptionEntry; // Flush Caches since we updated executable stuff InvalidateInstructionCacheRange ((VOID *)PcdGet64(PcdCpuVectorBaseAddress), Length); // setup a timer so gdb can break in via ctrl-c DebugAgentTimerIntialize (); if (IrqEnabled) { ArmEnableInterrupts (); } if (Function != NULL) { Function (Context); } return; }
EFI_STATUS InitializeExceptions ( IN EFI_CPU_ARCH_PROTOCOL *Cpu ) { EFI_STATUS Status; BOOLEAN IrqEnabled; BOOLEAN FiqEnabled; Status = EFI_SUCCESS; ZeroMem (gExceptionHandlers,sizeof(*gExceptionHandlers)); // // Disable interrupts // Cpu->GetInterruptState (Cpu, &IrqEnabled); Cpu->DisableInterrupt (Cpu); // // EFI does not use the FIQ, but a debugger might so we must disable // as we take over the exception vectors. // FiqEnabled = ArmGetFiqState (); ArmDisableFiq (); // AArch64 alignment? The Vector table must be 2k-byte aligned (bottom 11 bits zero)? //DEBUG ((EFI_D_ERROR, "vbar set addr: 0x%016lx\n",(UINTN)ExceptionHandlersStart)); //ASSERT(((UINTN)ExceptionHandlersStart & ((1 << 11)-1)) == 0); // We do not copy the Exception Table at PcdGet32(PcdCpuVectorBaseAddress). We just set Vector Base Address to point into CpuDxe code. ArmWriteVBar ((UINTN)ExceptionHandlersStart); if (FiqEnabled) { ArmEnableFiq (); } if (IrqEnabled) { // // Restore interrupt state // Status = Cpu->EnableInterrupt (Cpu); } return Status; }
/** Enable/Disable the interrupt of debug timer and return the interrupt state prior to the operation. If EnableStatus is TRUE, enable the interrupt of debug timer. If EnableStatus is FALSE, disable the interrupt of debug timer. @param[in] EnableStatus Enable/Disable. @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 EFIAPI SaveAndSetDebugTimerInterrupt ( IN BOOLEAN EnableStatus ) { BOOLEAN FiqEnabled; FiqEnabled = ArmGetFiqState (); if (EnableStatus) { DebugAgentTimerSetPeriod (PcdGet32 (PcdGdbTimerPeriodMilliseconds)); ArmEnableFiq (); } else { DebugAgentTimerSetPeriod (0); ArmDisableFiq (); } return FiqEnabled; }