DebugAgentDxe.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /** @file
  2. Initialize Debug Agent in DXE by invoking Debug Agent Library.
  3. Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiDxe.h>
  7. #include <Guid/EventGroup.h>
  8. #include <Library/UefiBootServicesTableLib.h>
  9. #include <Library/DebugAgentLib.h>
  10. #include <Library/UefiLib.h>
  11. EFI_EVENT mExitBootServiceEvent;
  12. /**
  13. One notified function to disable Debug Timer interrupt when gBS->ExitBootServices() called.
  14. @param[in] Event Pointer to this event
  15. @param[in] Context Event handler private data
  16. **/
  17. VOID
  18. EFIAPI
  19. DisableDebugTimerExitBootService (
  20. EFI_EVENT Event,
  21. VOID *Context
  22. )
  23. {
  24. SaveAndSetDebugTimerInterrupt (FALSE);
  25. }
  26. /**
  27. The Entry Point for Debug Agent Dxe driver.
  28. It will invoke Debug Agent Library to enable source debugging feature in DXE phase.
  29. @param[in] ImageHandle The firmware allocated handle for the EFI image.
  30. @param[in] SystemTable A pointer to the EFI System Table.
  31. @retval EFI_SUCCESS The entry point is executed successfully.
  32. @retval other Some error occurs when initialized Debug Agent.
  33. **/
  34. EFI_STATUS
  35. EFIAPI
  36. DebugAgentDxeInitialize (
  37. IN EFI_HANDLE ImageHandle,
  38. IN EFI_SYSTEM_TABLE *SystemTable
  39. )
  40. {
  41. EFI_STATUS Status;
  42. if (gST->ConOut != NULL) {
  43. Print (L"If the Debug Port is serial port, please make sure this serial port isn't connected by");
  44. Print (L" ISA Serial driver\r\n");
  45. Print (L"You could do the following steps to disconnect the serial port:\r\n");
  46. Print (L"1: Shell> drivers\r\n");
  47. Print (L" ...\r\n");
  48. Print (L" V VERSION E G G #D #C DRIVER NAME IMAGE NAME\r\n");
  49. Print (L" == ======== = = = == == =================================== ===================\r\n");
  50. Print (L" 8F 0000000A B - - 1 14 PCI Bus Driver PciBusDxe\r\n");
  51. Print (L" 91 00000010 ? - - - - ATA Bus Driver AtaBusDxe\r\n");
  52. Print (L" ...\r\n");
  53. Print (L" A7 0000000A B - - 1 1 ISA Serial Driver IsaSerialDxe\r\n");
  54. Print (L" ...\r\n");
  55. Print (L"2: Shell> dh -d A7\r\n");
  56. Print (L" A7: Image(IsaSerialDxe) ImageDevPath (..9FB3-11D4-9A3A-0090273FC14D))DriverBinding");
  57. Print (L" ComponentName ComponentName2\r\n");
  58. Print (L" Driver Name : ISA Serial Driver\r\n");
  59. Print (L" Image Name : FvFile(93B80003-9FB3-11D4-9A3A-0090273FC14D)\r\n");
  60. Print (L" Driver Version : 0000000A\r\n");
  61. Print (L" Driver Type : BUS\r\n");
  62. Print (L" Configuration : NO\r\n");
  63. Print (L" Diagnostics : NO\r\n");
  64. Print (L" Managing :\r\n");
  65. Print (L" Ctrl[EA] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)\r\n");
  66. Print (L" Child[EB] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)/Uart(115200,8,N,1)\r\n");
  67. Print (L"3: Shell> disconnect EA\r\n");
  68. Print (L"4: Shell> load -nc DebugAgentDxe.efi\r\n\r\n");
  69. }
  70. Status = EFI_UNSUPPORTED;
  71. InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_LOAD, &Status, NULL);
  72. if (EFI_ERROR (Status)) {
  73. return Status;
  74. }
  75. if (gST->ConOut != NULL) {
  76. Print (L"Debug Agent: Initialized successfully!\r\n\r\n");
  77. }
  78. //
  79. // Create event to disable Debug Timer interrupt when exit boot service.
  80. //
  81. Status = gBS->CreateEventEx (
  82. EVT_NOTIFY_SIGNAL,
  83. TPL_NOTIFY,
  84. DisableDebugTimerExitBootService,
  85. NULL,
  86. &gEfiEventExitBootServicesGuid,
  87. &mExitBootServiceEvent
  88. );
  89. return Status;
  90. }
  91. /**
  92. This is the unload handle for Debug Agent Dxe driver.
  93. It will invoke Debug Agent Library to disable source debugging feature.
  94. @param[in] ImageHandle The drivers' driver image.
  95. @retval EFI_SUCCESS The image is unloaded.
  96. @retval Others Failed to unload the image.
  97. **/
  98. EFI_STATUS
  99. EFIAPI
  100. DebugAgentDxeUnload (
  101. IN EFI_HANDLE ImageHandle
  102. )
  103. {
  104. EFI_STATUS Status;
  105. Status = EFI_UNSUPPORTED;
  106. InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_UNLOAD, &Status, NULL);
  107. switch (Status) {
  108. case EFI_ACCESS_DENIED:
  109. Print (L"Debug Agent: Host is still connected, please de-attach TARGET firstly!\r\n");
  110. break;
  111. case EFI_NOT_STARTED:
  112. Print (L"Debug Agent: It hasn't been initialized, cannot unload it!\r\n");
  113. break;
  114. }
  115. return Status;
  116. }