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.

573 lines
13 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Copyright (c) 1998 Intel Corporation
  4. Module Name:
  5. exp.c
  6. Abstract:
  7. This file contains low level I/O functions that are implemented
  8. with BIOS calls.
  9. Author:
  10. Allen Kay (akay) 04-Aug-97
  11. --*/
  12. #include "bldr.h"
  13. #include "sudata.h"
  14. #if defined(_IA64_)
  15. #include "bootia64.h"
  16. #include "bldria64.h"
  17. #endif
  18. #include "efi.h"
  19. #include "extern.h"
  20. ARC_STATUS
  21. RebootProcessor(
  22. VOID
  23. )
  24. {
  25. #if DBG
  26. BlPrint(TEXT("About to call EfiRS->ResetSystem()"));
  27. #endif
  28. FlipToPhysical();
  29. return( (ARC_STATUS) EfiRS->ResetSystem(EfiResetCold, 0, 0, NULL) );
  30. }
  31. ARC_STATUS
  32. GetSector(
  33. ULONG Operation,
  34. ULONG Drive,
  35. ULONG Head,
  36. ULONG Cylinder,
  37. ULONG Sector,
  38. ULONG SectorCount,
  39. ULONG Buffer
  40. )
  41. {
  42. UNREFERENCED_PARAMETER( Operation );
  43. UNREFERENCED_PARAMETER( Drive );
  44. UNREFERENCED_PARAMETER( Head );
  45. UNREFERENCED_PARAMETER( Cylinder );
  46. UNREFERENCED_PARAMETER( Sector );
  47. UNREFERENCED_PARAMETER( SectorCount );
  48. UNREFERENCED_PARAMETER( Buffer );
  49. //
  50. // NOTE!: Need to remove this function
  51. //
  52. return (0);
  53. }
  54. ARC_STATUS
  55. GetEddsSector(
  56. EFI_HANDLE Handle,
  57. ULONG SectorNumberLow,
  58. ULONG SectorNumberHigh,
  59. ULONG SectorCount,
  60. PUCHAR Buffer,
  61. UCHAR Write
  62. )
  63. {
  64. EFI_BLOCK_IO *BlkDev;
  65. EFI_STATUS Status;
  66. ULONGLONG Lba;
  67. //
  68. // First go into physical mode since EFI calls can only be made in
  69. // physical mode.
  70. //
  71. FlipToPhysical();
  72. //
  73. // convert virtual address to physical if it is virtual.
  74. //
  75. if (((ULONGLONG)Buffer & KSEG0_BASE) == KSEG0_BASE) {
  76. Buffer = (PUCHAR) ((ULONGLONG)Buffer & ~KSEG0_BASE);
  77. }
  78. Lba = (SectorNumberHigh << 32) | SectorNumberLow;
  79. Status = EfiBS->HandleProtocol( Handle,
  80. &EfiBlockIoProtocol,
  81. &BlkDev);
  82. if (EFI_ERROR(Status)) {
  83. #if DBG
  84. EfiPrint( L"GetEddSector: HandleProtocol failed\n\r");
  85. #endif
  86. FlipToVirtual();
  87. return (EIO);
  88. }
  89. if (Write == 0x43) {
  90. Status = BlkDev->WriteBlocks( BlkDev,
  91. BlkDev->Media->MediaId,
  92. Lba,
  93. SectorCount * BlkDev->Media->BlockSize,
  94. Buffer);
  95. } else {
  96. Status = BlkDev->ReadBlocks( BlkDev,
  97. BlkDev->Media->MediaId,
  98. Lba,
  99. SectorCount * BlkDev->Media->BlockSize,
  100. Buffer);
  101. }
  102. if (EFI_ERROR(Status) && BlkDev->Media->RemovableMedia) {
  103. //
  104. // Failed operation to removable media.
  105. //
  106. #if DBG
  107. EfiPrint( L"GetEddSector: R/W operation to removable media failed\n\r");
  108. #endif
  109. FlipToVirtual();
  110. return (ENODEV);
  111. }
  112. if (EFI_ERROR(Status)) {
  113. //
  114. // Failed operation to fixed media.
  115. //
  116. #if DBG
  117. EfiPrint( L"\nGetEddsSector: R/W operation to fixed Media failed.\r\n");
  118. #endif
  119. FlipToVirtual();
  120. return (EIO);
  121. }
  122. //
  123. // Restore virtual mode before returning.
  124. //
  125. FlipToVirtual();
  126. return(ESUCCESS);
  127. }
  128. ULONG
  129. GetKey(
  130. VOID
  131. )
  132. {
  133. EFI_INPUT_KEY Key;
  134. EFI_STATUS Status;
  135. ULONG Code;
  136. BOOLEAN WasVirtual;
  137. //
  138. // default return value is 0
  139. //
  140. Code = 0;
  141. //
  142. // Remember if we started off in virtual mode
  143. //
  144. WasVirtual = IsPsrDtOn();
  145. //
  146. // First go into physical mode since EFI calls can only be made in
  147. // physical mode.
  148. //
  149. if (WasVirtual) {
  150. FlipToPhysical();
  151. }
  152. //
  153. // If set, wait for keystroke
  154. //
  155. Status = BlWaitForInput(&Key,
  156. BlGetInputTimeout()
  157. );
  158. if (EFI_ERROR(Status)) {
  159. goto GET_KEY_DONE;
  160. }
  161. if (Key.UnicodeChar) {
  162. // truncate unicode char to ascii
  163. if (Key.UnicodeChar > 0xFF) {
  164. Code = 0;
  165. goto GET_KEY_DONE;
  166. }
  167. // Convert back spaces
  168. if (Key.UnicodeChar == 0x08) {
  169. Key.UnicodeChar = 0x0E08;
  170. }
  171. Code = Key.UnicodeChar;
  172. goto GET_KEY_DONE;
  173. }
  174. //
  175. // Convert EFI keys to dos key codes
  176. //
  177. switch (Key.ScanCode) {
  178. #if 0
  179. case SCAN_UP: Code = 0x4800; break;
  180. case SCAN_DOWN: Code = 0x5000; break;
  181. case SCAN_RIGHT: Code = 0x4d00; break;
  182. case SCAN_LEFT: Code = 0x4b00; break;
  183. case SCAN_HOME: Code = 0x4700; break;
  184. case SCAN_INSERT: Code = 0x5200; break;
  185. case SCAN_DELETE: Code = 0x5300; break;
  186. case SCAN_PAGE_UP: Code = 0x4900; break;
  187. case SCAN_PAGE_DOWN: Code = 0x5100; break;
  188. case SCAN_F1: Code = 0x3b00; break;
  189. case SCAN_F2: Code = 0x3c00; break;
  190. case SCAN_F3: Code = 0x3d00; break;
  191. case SCAN_F4: Code = 0x3e00; break;
  192. case SCAN_F5: Code = 0x3f00; break;
  193. case SCAN_F6: Code = 0x4000; break;
  194. case SCAN_F7: Code = 0x4100; break;
  195. case SCAN_F8: Code = 0x4200; break;
  196. case SCAN_F9: Code = 0x4300; break;
  197. case SCAN_F10: Code = 0x4400; break;
  198. case SCAN_ESC: Code = 0x001d; break;
  199. #else
  200. case SCAN_UP: Code = UP_ARROW; break;
  201. case SCAN_DOWN: Code = DOWN_ARROW; break;
  202. case SCAN_RIGHT: Code = RIGHT_KEY; break;
  203. case SCAN_LEFT: Code = LEFT_KEY; break;
  204. case SCAN_HOME: Code = HOME_KEY; break;
  205. case SCAN_INSERT: Code = INS_KEY; break;
  206. case SCAN_DELETE: Code = DEL_KEY; break;
  207. // bugbug
  208. case SCAN_PAGE_UP: Code = 0x4900; break;
  209. // bugbug
  210. case SCAN_PAGE_DOWN: Code = 0x5100; break;
  211. case SCAN_F1: Code = F1_KEY; break;
  212. case SCAN_F2: Code = F2_KEY; break;
  213. case SCAN_F3: Code = F3_KEY; break;
  214. // bugbug
  215. case SCAN_F4: Code = 0x3e00; break;
  216. case SCAN_F5: Code = F5_KEY; break;
  217. case SCAN_F6: Code = F6_KEY; break;
  218. case SCAN_F7: Code = F7_KEY; break;
  219. case SCAN_F8: Code = F8_KEY; break;
  220. // bugbug
  221. case SCAN_F9: Code = 0x4300; break;
  222. case SCAN_F10: Code = F10_KEY; break;
  223. //bugbug different than 0x001d
  224. case SCAN_ESC: Code = ESCAPE_KEY; break;
  225. #endif
  226. }
  227. GET_KEY_DONE:
  228. //
  229. // Restore virtual mode before returning.
  230. //
  231. if (WasVirtual) {
  232. FlipToVirtual();
  233. }
  234. return Code;
  235. }
  236. ULONG Counter = 0;
  237. ULONG
  238. GetCounter(
  239. VOID
  240. )
  241. {
  242. EFI_TIME Time;
  243. UINTN ms;
  244. static UINTN BaseTick, LastMs;
  245. //
  246. // First go into physical mode since EFI calls can only be made in
  247. // physical mode.
  248. //
  249. FlipToPhysical();
  250. // NB. the NT loader only uses this to count seconds
  251. // this function only works if called at least every hour
  252. //
  253. // Get the current calendar time
  254. //
  255. EfiRS->GetTime (&Time, NULL);
  256. // Compute a millisecond value for the time
  257. ms = Time.Minute * 60 * 1000 + Time.Second * 1000 + Time.Nanosecond / 1000000;
  258. if (ms < LastMs) {
  259. BaseTick += 65520; // 60 * 60 * 18.2
  260. }
  261. LastMs = ms;
  262. //
  263. // Restore virtual mode before returning.
  264. //
  265. FlipToVirtual();
  266. return (ULONG) (( (ms * 182) / 10000) + BaseTick);
  267. }
  268. //
  269. // Transfer control to a loaded boot sector
  270. //
  271. VOID
  272. Reboot(
  273. ULONG BootType
  274. )
  275. {
  276. UNREFERENCED_PARAMETER( BootType );
  277. //
  278. // First go into physical mode since EFI calls can only be made in
  279. // physical mode.
  280. //
  281. FlipToPhysical();
  282. EfiBS->Exit(EfiImageHandle, 0, 0, 0);
  283. }
  284. VOID
  285. HardwareCursor(
  286. ULONG YCoord,
  287. ULONG XCoord
  288. )
  289. {
  290. UNREFERENCED_PARAMETER( YCoord );
  291. UNREFERENCED_PARAMETER( XCoord );
  292. //
  293. // NOTE!: Need to be implemented
  294. //
  295. }
  296. VOID
  297. GetDateTime(
  298. PULONG Date,
  299. PULONG Time
  300. )
  301. {
  302. UNREFERENCED_PARAMETER( Date );
  303. UNREFERENCED_PARAMETER( Time );
  304. //
  305. // NOTE!: Need to implement
  306. //
  307. }
  308. VOID
  309. DetectHardware(
  310. ULONG HeapStart,
  311. ULONG HeapSize,
  312. ULONG ConfigurationTree,
  313. ULONG HeapUsed,
  314. ULONG OptionString,
  315. ULONG OptionStringLength
  316. )
  317. {
  318. UNREFERENCED_PARAMETER( HeapStart );
  319. UNREFERENCED_PARAMETER( HeapSize );
  320. UNREFERENCED_PARAMETER( ConfigurationTree );
  321. UNREFERENCED_PARAMETER( HeapUsed );
  322. UNREFERENCED_PARAMETER( OptionString );
  323. UNREFERENCED_PARAMETER( OptionStringLength );
  324. //
  325. // NOTE!: needed to remove
  326. //
  327. }
  328. VOID
  329. ComPort(
  330. LONG Port,
  331. ULONG Function,
  332. UCHAR Arg
  333. )
  334. {
  335. //
  336. // NOTE!: needed to remove
  337. //
  338. UNREFERENCED_PARAMETER( Port );
  339. UNREFERENCED_PARAMETER( Function );
  340. UNREFERENCED_PARAMETER( Arg );
  341. }
  342. ULONG
  343. GetStallCount(
  344. VOID
  345. )
  346. {
  347. #if defined(VPC_PHASE2)
  348. ULONGLONG Frequency;
  349. //
  350. // First go into physical mode since EFI calls can only be made in
  351. // physical mode.
  352. //
  353. FlipToPhysical();
  354. IA32RegisterState.esp = SAL_PROC_SP;
  355. IA32RegisterState.ss = SAL_PROC_SS;
  356. IA32RegisterState.eflags = SAL_PROC_EFLAGS;
  357. SAL_PROC(SAL_FREQ_BASE,0,0,0,0,0,0,0,RetVals);
  358. Frequency = RetVals->RetVal1;
  359. //
  360. // Restore virtual mode before returning.
  361. //
  362. FlipToVirtual();
  363. return ((ULONG) Frequency / 1000); // Convert ticks/sec to ticks/usec
  364. #else
  365. return ((ULONG) 1000000); // Convert ticks/sec to ticks/usec
  366. #endif
  367. }
  368. VOID
  369. InitializeDisplayForNt(
  370. VOID
  371. )
  372. {
  373. //
  374. // NOTE!: Need to implement
  375. //
  376. }
  377. VOID
  378. GetMemoryDescriptor(
  379. )
  380. {
  381. //
  382. // NOTE!: need to remove
  383. //
  384. }
  385. BOOLEAN
  386. GetElToritoStatus(
  387. PUCHAR Buffer,
  388. UCHAR DriveNum
  389. )
  390. {
  391. UNREFERENCED_PARAMETER( Buffer );
  392. UNREFERENCED_PARAMETER( DriveNum );
  393. //
  394. // NOTE!: need to remove
  395. //
  396. return(0);
  397. }
  398. BOOLEAN
  399. GetExtendedInt13Params(
  400. PUCHAR Buffer,
  401. UCHAR Drive
  402. )
  403. {
  404. UNREFERENCED_PARAMETER( Buffer );
  405. UNREFERENCED_PARAMETER( Drive );
  406. return(1);
  407. }
  408. USHORT
  409. NetPcRomServices(
  410. ULONG FunctionNumber,
  411. PVOID CommandPacket
  412. )
  413. {
  414. UNREFERENCED_PARAMETER( FunctionNumber );
  415. UNREFERENCED_PARAMETER( CommandPacket );
  416. //
  417. // should never call this from EFI app.
  418. //
  419. ASSERT(FALSE);
  420. return (USHORT)0;
  421. }
  422. ULONG
  423. GetRedirectionData(
  424. ULONG Command
  425. )
  426. /* ++
  427. Routine Name:
  428. BiosRedirectService
  429. Description:
  430. Get parameters of bios redirection.
  431. Arguments:
  432. Command - 1: Get Com Port Number
  433. 2: Get Baud Rate
  434. 3: Get Parity
  435. 4: Get Stop Bits
  436. Returns:
  437. Value, or -1 if an error.
  438. --
  439. */
  440. {
  441. UNREFERENCED_PARAMETER( Command );
  442. //
  443. // should never call this from EFI app.
  444. //
  445. ASSERT(FALSE);
  446. return((ULONG)-1);
  447. }
  448. VOID
  449. APMAttemptReconect(
  450. VOID
  451. )
  452. {
  453. //
  454. // should never call this from EFI app.
  455. //
  456. ASSERT(FALSE);
  457. return;
  458. }
  459. VOID
  460. SuFillExportTable(
  461. )
  462. {
  463. PEXTERNAL_SERVICES_TABLE Est = (PEXTERNAL_SERVICES_TABLE)ExportEntryTable;
  464. Est->RebootProcessor = &RebootProcessor;
  465. Est->DiskIOSystem = &GetSector;
  466. Est->GetKey = &GetKey;
  467. Est->GetCounter = &GetCounter;
  468. Est->Reboot = &Reboot;
  469. Est->DetectHardware = &DetectHardware;
  470. Est->HardwareCursor = &HardwareCursor;
  471. Est->GetDateTime = &GetDateTime;
  472. Est->ComPort = &ComPort;
  473. Est->GetStallCount = &GetStallCount;
  474. Est->InitializeDisplayForNt = &InitializeDisplayForNt;
  475. Est->GetMemoryDescriptor = &GetMemoryDescriptor;
  476. Est->GetEddsSector = &GetEddsSector;
  477. Est->GetElToritoStatus = &GetElToritoStatus;
  478. Est->GetExtendedInt13Params = &GetExtendedInt13Params;
  479. Est->NetPcRomServices = &NetPcRomServices;
  480. Est->ApmAttemptReconnect = &APMAttemptReconect;
  481. Est->BiosRedirectService = &GetRedirectionData;
  482. }