Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. init.c
  5. Abstract:
  6. This module implements the initialization for the boot debgger.
  7. Author:
  8. David N. Cutler (davec) 27-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "bd.h"
  12. #if defined(EFI)
  13. #include "bootefi.h"
  14. #endif
  15. //
  16. // Define local data.
  17. //
  18. #define BAUD_OPTION "BAUDRATE"
  19. #define PORT_OPTION "DEBUGPORT"
  20. ULONG BdFileId;
  21. VOID
  22. BdInitDebugger (
  23. IN PCHAR LoaderName,
  24. IN PVOID LoaderBase,
  25. IN PCHAR Options
  26. )
  27. /*++
  28. Routine Description:
  29. This routine initializes the boot kernel debugger.
  30. Arguments:
  31. Options - Supplies a pointer to the the boot options.
  32. Stop - Supplies a logical value that determines whether a debug message
  33. and breakpoint are generated.
  34. Return Value:
  35. None.
  36. --*/
  37. {
  38. PCHAR BaudOption;
  39. ULONG BaudRate;
  40. ULONG Index;
  41. ULONG PortNumber;
  42. PCHAR PortOption;
  43. STRING String;
  44. //
  45. // If the boot debugger is not already initialized, then attempt to
  46. // initialize the debugger.
  47. //
  48. if (BdDebuggerEnabled == FALSE) {
  49. //
  50. // Set the address of the debug routine to the stub function and parse
  51. // any options if specified.
  52. //
  53. BdDebugRoutine = BdStub;
  54. if (Options != NULL) {
  55. _strupr(Options);
  56. //
  57. // If nodebug is not explicitly specified, then check if the baud
  58. // rate, com port, or debug is explicitly specified.
  59. //
  60. if (strstr(Options, "NODEBUG") == NULL) {
  61. PortNumber = 0;
  62. PortOption = strstr(Options, PORT_OPTION);
  63. BaudOption = strstr(Options, BAUD_OPTION);
  64. BaudRate = 0;
  65. if ((PortOption == NULL) && (BaudOption == NULL)) {
  66. if (strstr(Options, "DEBUG") == NULL) {
  67. return;
  68. }
  69. } else {
  70. if (PortOption != NULL) {
  71. PortOption = strstr(PortOption, "COM");
  72. if (PortOption != NULL) {
  73. PortNumber = atol(PortOption + 3);
  74. }
  75. }
  76. if (BaudOption != NULL) {
  77. BaudOption += strlen(BAUD_OPTION);
  78. while (*BaudOption == ' ') {
  79. BaudOption++;
  80. }
  81. if (*BaudOption != '\0') {
  82. BaudRate = atol(BaudOption + 1);
  83. }
  84. }
  85. }
  86. //
  87. // Attempt to initialize the debug port.
  88. //
  89. if (BdPortInitialize(BaudRate, PortNumber, &BdFileId) == FALSE) {
  90. return;
  91. }
  92. //
  93. // Set the value of a break point instruction, set the address
  94. // of the debug routine to the trap function, set the debugger
  95. // enabled and initialize the breakpoint table.
  96. //
  97. BdBreakpointInstruction = BD_BREAKPOINT_VALUE;
  98. BdDebugRoutine = BdTrap;
  99. BdDebuggerEnabled = TRUE;
  100. for (Index = 0; Index < BREAKPOINT_TABLE_SIZE; Index += 1) {
  101. BdBreakpointTable[Index].Flags = 0;
  102. BdBreakpointTable[Index].Address = 0;
  103. }
  104. //
  105. // Initialize the ID for the NEXT packet to send and the Expect
  106. // ID of next incoming packet.
  107. //
  108. BdNextPacketIdToSend = INITIAL_PACKET_ID | SYNC_PACKET_ID;
  109. BdPacketIdExpected = INITIAL_PACKET_ID;
  110. //
  111. // Announce debugger initialized.
  112. //
  113. DbgPrint("BD: Boot Debugger Initialized\n");
  114. //
  115. // Notify the kernel debugger to load symbols for the loader.
  116. //
  117. String.Buffer = LoaderName;
  118. String.Length = (USHORT) strlen(LoaderName);
  119. DbgPrint("BD: %s base address %p\n", LoaderName, LoaderBase);
  120. DbgLoadImageSymbols(&String, LoaderBase, (ULONG_PTR)-1);
  121. if (strstr(Options, "DEBUGSTOP") != NULL) {
  122. //
  123. // Treat this like a request for initial breakpoint.
  124. //
  125. DbgBreakPoint();
  126. }
  127. #if defined(EFI)
  128. //
  129. // if running under the debugger disable the watchdog so we
  130. // don't get reset
  131. //
  132. DisableEFIWatchDog();
  133. #endif
  134. }
  135. }
  136. }
  137. return;
  138. }