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.

336 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. blmisc.c
  5. Abstract:
  6. This module contains miscellaneous routines for use by
  7. the boot loader and setupldr.
  8. Author:
  9. David N. Cutler (davec) 10-May-1991
  10. Revision History:
  11. --*/
  12. #include "bootlib.h"
  13. #if defined(EFI)
  14. #include "smbios.h"
  15. extern PVOID SMBiosTable;
  16. #endif
  17. #if defined(_X86AMD64_)
  18. #include "amd64\amd64prv.h"
  19. #endif
  20. //
  21. // Value indicating whether a dbcs locale is active.
  22. // If this value is non-0 we use alternate display routines, etc,
  23. // and fetch messages in this language.
  24. //
  25. ULONG DbcsLangId;
  26. PCHAR
  27. BlGetArgumentValue (
  28. IN ULONG Argc,
  29. IN CHAR * FIRMWARE_PTR * FIRMWARE_PTR Argv,
  30. IN PCHAR ArgumentName
  31. )
  32. /*++
  33. Routine Description:
  34. This routine scans the specified argument list for the named argument
  35. and returns the address of the argument value. Argument strings are
  36. specified as:
  37. ArgumentName=ArgumentValue
  38. Argument names are specified as:
  39. ArgumentName=
  40. The argument name match is case insensitive.
  41. Arguments:
  42. Argc - Supplies the number of argument strings that are to be scanned.
  43. Argv - Supplies a pointer to a vector of pointers to null terminated
  44. argument strings.
  45. ArgumentName - Supplies a pointer to a null terminated argument name.
  46. Return Value:
  47. If the specified argument name is located, then a pointer to the argument
  48. value is returned as the function value. Otherwise, a value of NULL is
  49. returned.
  50. --*/
  51. {
  52. PCHAR Name;
  53. PCHAR String;
  54. //
  55. // Scan the argument strings until either a match is found or all of
  56. // the strings have been scanned.
  57. //
  58. while (Argc > 0) {
  59. String = Argv[Argc - 1];
  60. if (String != NULL) {
  61. Name = ArgumentName;
  62. while ((*Name != 0) && (*String != 0)) {
  63. if (toupper(*Name) != toupper(*String)) {
  64. break;
  65. }
  66. Name += 1;
  67. String += 1;
  68. }
  69. if ((*Name == 0) && (*String == '=')) {
  70. return String + 1;
  71. }
  72. Argc -= 1;
  73. }
  74. }
  75. return NULL;
  76. }
  77. PCHAR
  78. BlSetArgumentValue (
  79. IN ULONG Argc,
  80. IN CHAR * FIRMWARE_PTR * FIRMWARE_PTR Argv,
  81. IN PCHAR ArgumentName,
  82. IN PCHAR NewValue
  83. )
  84. /*++
  85. Routine Description:
  86. This routine scans the specified argument list for the named argument
  87. and returns the address of the argument value. The value associated
  88. with the arg is changed to the value passed in. Argument strings are
  89. specified as:
  90. ArgumentName=ArgumentValue
  91. Argument names are specified as:
  92. ArgumentName=
  93. The argument name match is case insensitive.
  94. Arguments:
  95. Argc - Supplies the number of argument strings that are to be scanned.
  96. Argv - Supplies a pointer to a vector of pointers to null terminated
  97. argument strings.
  98. ArgumentName - Supplies a pointer to a null terminated argument name.
  99. Return Value:
  100. If the specified argument name is located, then a pointer to the argument
  101. value is returned as the function value. Otherwise, a value of NULL is
  102. returned.
  103. --*/
  104. {
  105. PCHAR Name;
  106. PCHAR String;
  107. //
  108. // Scan the argument strings until either a match is found or all of
  109. // the strings have been scanned.
  110. //
  111. while (Argc > 0) {
  112. String = Argv[Argc - 1];
  113. if (String != NULL) {
  114. Name = ArgumentName;
  115. while ((*Name != 0) && (*String != 0)) {
  116. if (toupper(*Name) != toupper(*String)) {
  117. break;
  118. }
  119. Name += 1;
  120. String += 1;
  121. }
  122. if ((*Name == 0) && (*String == '=')) {
  123. Name = (PCHAR)BlAllocateHeap((ULONG)strlen(ArgumentName)+2+(ULONG)strlen(NewValue));
  124. if (Name) {
  125. strcpy( Name, ArgumentName );
  126. strcat( Name, "=" );
  127. strcat( Name, NewValue );
  128. return Name+strlen(ArgumentName)+1;
  129. }
  130. return String + 1;
  131. }
  132. Argc -= 1;
  133. }
  134. }
  135. return NULL;
  136. }
  137. //
  138. // Line draw chars -- different scheme in Far East vs. SBCS
  139. //
  140. _TUCHAR
  141. GetGraphicsChar(
  142. IN GraphicsChar WhichOne
  143. )
  144. {
  145. #ifdef EFI
  146. return(TextGetGraphicsCharacter(WhichOne));
  147. #else
  148. #if defined(_X86_) && !defined(ARCI386)
  149. return(TextGetGraphicsCharacter(WhichOne));
  150. #else
  151. //
  152. // ARC machines don't support dbcs for now
  153. //
  154. static _TUCHAR ArcGraphicsChars[GraphicsCharMax] = { (UCHAR)'\311', // right-down
  155. (UCHAR)'\273', // left-down
  156. (UCHAR)'\310', // right-up
  157. (UCHAR)'\274', // left-up
  158. (UCHAR)'\272', // vertical
  159. (UCHAR)'\315' // horizontal
  160. };
  161. return(((unsigned)WhichOne < (unsigned)GraphicsCharMax)
  162. ? ArcGraphicsChars[WhichOne]
  163. : TEXT(' '));
  164. #endif
  165. #endif
  166. }
  167. LOGICAL
  168. BdPollBreakIn(
  169. VOID
  170. );
  171. #if defined(_X86_)
  172. #include <bldrx86.h>
  173. #endif
  174. VOID
  175. BlWaitForReboot (
  176. VOID
  177. )
  178. {
  179. #if defined(_X86)
  180. BlPrint( TEXT("Press any key to reboot\n") );
  181. #endif
  182. while (TRUE) {
  183. #if defined(_X86_)
  184. if ( BdPollBreakIn() ) {
  185. DbgBreakPoint();
  186. }
  187. if ( ArcGetReadStatus(BlConsoleInDeviceId) ) {
  188. BlPrint( TEXT("Rebooting...\n") );
  189. ArcReboot();
  190. }
  191. #endif
  192. ;
  193. }
  194. }
  195. #ifdef EFI
  196. VOID
  197. SetupSMBiosInLoaderBlock(
  198. VOID
  199. )
  200. {
  201. PSMBIOS_EPS_HEADER SMBiosEPSHeader;
  202. if (SMBiosTable != NULL)
  203. {
  204. SMBiosEPSHeader = BlAllocateHeap(sizeof(SMBIOS_EPS_HEADER));
  205. RtlCopyMemory(SMBiosEPSHeader, SMBiosTable, sizeof(SMBIOS_EPS_HEADER));
  206. } else {
  207. SMBiosEPSHeader = NULL;
  208. }
  209. BlLoaderBlock->Extension->SMBiosEPSHeader = SMBiosEPSHeader;
  210. }
  211. #endif
  212. VOID
  213. BlTransferToKernel(
  214. IN PTRANSFER_ROUTINE SystemEntry,
  215. IN PLOADER_PARAMETER_BLOCK BlLoaderBlock
  216. )
  217. {
  218. //
  219. // Turn off the debugging system
  220. //
  221. BlLogTerminate();
  222. //
  223. // Inform the boot debugger that the boot phase is complete.
  224. //
  225. #if defined(ENABLE_LOADER_DEBUG) || DBG
  226. #if (defined(_X86_) || defined(_ALPHA_)) && !defined(ARCI386)
  227. if (BdDebuggerEnabled == TRUE) {
  228. DbgUnLoadImageSymbols(NULL, (PVOID)-1, 0);
  229. }
  230. #endif
  231. #endif
  232. #if defined(_X86AMD64_)
  233. if (BlAmd64UseLongMode != FALSE) {
  234. //
  235. // Do the work to switch to AMD64 long mode, then branch to the
  236. // kernel image.
  237. //
  238. BlAmd64TransferToKernel(SystemEntry, BlLoaderBlock);
  239. return;
  240. }
  241. #endif
  242. //
  243. // Transfer control to loaded image.
  244. //
  245. (SystemEntry)(BlLoaderBlock);
  246. }