Source code of Windows XP (NT5)
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.

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