bios.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. bios.h
  5. Abstract:
  6. This header contains definitions for PC/AT BIOS services.
  7. Author:
  8. Evan Green 18-Jul-2012
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. //
  17. // Define the physical address where the EBDA (Extended BIOS Data Area) address
  18. // is stored.
  19. //
  20. #define EBDA_POINTER_ADDRESS 0x40E
  21. //
  22. // Define the address and length of the space to search for the RSDP.
  23. //
  24. #define RSDP_SEARCH_ADDRESS (PVOID)0xE0000
  25. #define RSDP_SEARCH_LENGTH 0x20000
  26. //
  27. // Define INT 10 functions.
  28. //
  29. #define INT10_SET_CURSOR_POSITION 0x02
  30. //
  31. // Define INT 13 functions.
  32. //
  33. #define INT13_READ_SECTORS 0x02
  34. #define INT13_WRITE_SECTORS 0x03
  35. #define INT13_GET_DRIVE_PARAMETERS 0x08
  36. #define INT13_EXTENDED_READ 0x42
  37. #define INT13_EXTENDED_WRITE 0x43
  38. #define INT13_EXTENDED_GET_DRIVE_PARAMETERS 0x48
  39. //
  40. // Define BIOS text mode information.
  41. //
  42. #define BIOS_TEXT_VIDEO_BASE 0xB8000
  43. #define BIOS_TEXT_VIDEO_COLUMNS 80
  44. #define BIOS_TEXT_VIDEO_ROWS 25
  45. #define BIOS_TEXT_VIDEO_CELL_WIDTH 2
  46. //
  47. // --------------------------------------------------------------------- Macros
  48. //
  49. //
  50. // ------------------------------------------------------ Data Type Definitions
  51. //
  52. typedef enum _TEXT_COLOR {
  53. ColorBlack,
  54. ColorBlue,
  55. ColorGreen,
  56. ColorCyan,
  57. ColorRed,
  58. ColorMagenta,
  59. ColorBrown,
  60. ColorLightGray,
  61. ColorDarkGray,
  62. ColorBrightBlue,
  63. ColorBrightGreen,
  64. ColorBrightCyan,
  65. ColorBrightRed,
  66. ColorBrightMagenta,
  67. ColorYellow,
  68. ColorWhite
  69. } TEXT_COLOR, *PTEXT_COLOR;
  70. /*++
  71. Structure Description:
  72. This structure defines a disk access packet used in the INT 13 calls.
  73. Members:
  74. PacketSize - Stores the packet size of the packet, either 16 (this
  75. structure) or 24 if there is an additional quad word on the end
  76. containing the 64-bit transfer buffer.
  77. Reserved - Stores a reserved value. Set to zero.
  78. BlockCount - Stores the number of sectors to transfer.
  79. TransferBuffer - Stores a pointer to the data buffer, as a linear address.
  80. BlockAddress - Stores the absolute sector number to transfer. The first
  81. sector is zero.
  82. --*/
  83. typedef struct _INT13_DISK_ACCESS_PACKET {
  84. UCHAR PacketSize;
  85. UCHAR Reserved;
  86. USHORT BlockCount;
  87. ULONG TransferBuffer;
  88. ULONGLONG BlockAddress;
  89. } PACKED INT13_DISK_ACCESS_PACKET, *PINT13_DISK_ACCESS_PACKET;
  90. /*++
  91. Structure Description:
  92. This structure defines the structure of the drive parameters returned from
  93. int 0x13 function AH=0x48 (extended read drive parameters).
  94. Members:
  95. PacketSize - Stores the packet size of the packet, 0x1E bytes.
  96. InformationFlags - Stores various flags about the disk.
  97. Cylinders - Stores the number of cylinders on the disk (one beyond the last
  98. valid index).
  99. Heads - Stores the number of heads on the disk (one beyond the last valid
  100. index).
  101. SectorsPerTrack - Stores the number of sectors per track on the disk (the
  102. last valid index, since sector numbers start with one).
  103. TotalSectorCount - Stores the absolute number of sectors (one beyond the
  104. last valid index).
  105. SectorSize - Stores the number of bytes per sector.
  106. EnhancedDiskInformation - Stores an optional pointer to the enhanced drive
  107. information.
  108. --*/
  109. typedef struct _INT13_EXTENDED_DRIVE_PARAMETERS {
  110. USHORT PacketSize;
  111. USHORT InformationFlags;
  112. ULONG Cylinders;
  113. ULONG Heads;
  114. ULONG SectorsPerTrack;
  115. ULONGLONG TotalSectorCount;
  116. USHORT SectorSize;
  117. ULONG EnhancedDiskInformation;
  118. } PACKED INT13_EXTENDED_DRIVE_PARAMETERS, *PINT13_EXTENDED_DRIVE_PARAMETERS;
  119. //
  120. // -------------------------------------------------------------------- Globals
  121. //
  122. //
  123. // Store the frame buffer attributes.
  124. //
  125. extern ULONG FwFrameBufferMode;
  126. extern PHYSICAL_ADDRESS FwFrameBufferPhysical;
  127. extern ULONG FwFrameBufferWidth;
  128. extern ULONG FwFrameBufferHeight;
  129. extern ULONG FwFrameBufferBitsPerPixel;
  130. //
  131. // -------------------------------------------------------- Function Prototypes
  132. //
  133. KSTATUS
  134. FwPcatGetMemoryMap (
  135. PMEMORY_DESCRIPTOR_LIST MdlOut
  136. );
  137. /*++
  138. Routine Description:
  139. This routine gets the firmware memory map from the BIOS using int 15 E820
  140. calls.
  141. Arguments:
  142. MdlOut - Supplies a pointer where the memory map information will be
  143. stored. This buffer must be allocated by the caller.
  144. Return Value:
  145. STATUS_SUCCESS if one or more descriptors could be retrieved from the
  146. firmware.
  147. STATUS_UNSUCCESSFUL if no descriptors could be obtained from the firmware.
  148. --*/
  149. KSTATUS
  150. FwPcatAllocatePages (
  151. PULONGLONG Address,
  152. ULONGLONG Size,
  153. ULONG Alignment,
  154. MEMORY_TYPE MemoryType
  155. );
  156. /*++
  157. Routine Description:
  158. This routine allocates physical pages for use.
  159. Arguments:
  160. Address - Supplies a pointer to where the allocation will be returned.
  161. Size - Supplies the size of the required space.
  162. Alignment - Supplies the alignment requirement for the allocation, in bytes.
  163. Valid values are powers of 2. Set to 1 or 0 to specify no alignment
  164. requirement.
  165. MemoryType - Supplies the type of memory to mark the allocation as.
  166. Return Value:
  167. STATUS_SUCCESS if the allocation was successful.
  168. STATUS_INVALID_PARAMETER if a page count of 0 was passed or the address
  169. parameter was not filled out.
  170. STATUS_NO_MEMORY if the allocation request could not be filled.
  171. --*/
  172. KSTATUS
  173. FwpPcatOpenBootDisk (
  174. ULONG BootDriveNumber,
  175. ULONGLONG PartitionOffset,
  176. PHANDLE Handle
  177. );
  178. /*++
  179. Routine Description:
  180. This routine attempts to open the boot disk device.
  181. Arguments:
  182. BootDriveNumber - Supplies the drive number of the boot device.
  183. PartitionOffset - Supplies the offset in sectors of the active partition
  184. on this device, as discovered by earlier loader code.
  185. Handle - Supplies a pointer where a handle to the opened disk will be
  186. returned upon success.
  187. Return Value:
  188. Status code.
  189. --*/
  190. KSTATUS
  191. FwpPcatOpenPartition (
  192. UCHAR PartitionId[FIRMWARE_PARTITION_ID_SIZE],
  193. PHANDLE Handle
  194. );
  195. /*++
  196. Routine Description:
  197. This routine opens a handle to a disk and partition with the given IDs.
  198. Arguments:
  199. PartitionId - Supplies the partition identifier to match against.
  200. Handle - Supplies a pointer where a handle to the opened disk will be
  201. returned upon success.
  202. Return Value:
  203. Status code.
  204. --*/
  205. VOID
  206. FwpPcatCloseDisk (
  207. HANDLE DiskHandle
  208. );
  209. /*++
  210. Routine Description:
  211. This routine closes an open disk.
  212. Arguments:
  213. DiskHandle - Supplies a pointer to the open disk handle.
  214. Return Value:
  215. None.
  216. --*/
  217. KSTATUS
  218. FwpPcatReadSectors (
  219. HANDLE DiskHandle,
  220. ULONGLONG Sector,
  221. ULONG SectorCount,
  222. PVOID Buffer
  223. );
  224. /*++
  225. Routine Description:
  226. This routine uses the BIOS to read sectors off of a disk.
  227. Arguments:
  228. DiskHandle - Supplies a handle to the disk to read from.
  229. Sector - Supplies the zero-based sector number to read from.
  230. SectorCount - Supplies the number of sectors to read. The supplied buffer
  231. must be at least this large.
  232. Buffer - Supplies the buffer where the data read from the disk will be
  233. returned upon success.
  234. Return Value:
  235. STATUS_SUCCESS if the operation completed successfully.
  236. STATUS_FIRMWARE_ERROR if the BIOS returned an error.
  237. Other error codes.
  238. --*/
  239. KSTATUS
  240. FwpPcatWriteSectors (
  241. HANDLE DiskHandle,
  242. ULONGLONG Sector,
  243. ULONG SectorCount,
  244. PVOID Buffer
  245. );
  246. /*++
  247. Routine Description:
  248. This routine uses the BIOS to write sectors to a disk.
  249. Arguments:
  250. DiskHandle - Supplies a handle to the disk to write to.
  251. Sector - Supplies the zero-based sector number to write to.
  252. SectorCount - Supplies the number of sectors to write. The supplied buffer
  253. must be at least this large.
  254. Buffer - Supplies the buffer containing the data to write to the disk.
  255. Return Value:
  256. STATUS_SUCCESS if the operation completed successfully.
  257. STATUS_FIRMWARE_ERROR if the BIOS returned an error.
  258. Other error codes.
  259. --*/
  260. ULONG
  261. FwpPcatGetSectorSize (
  262. HANDLE DiskHandle
  263. );
  264. /*++
  265. Routine Description:
  266. This routine determines the number of bytes in a sector on the given disk.
  267. Arguments:
  268. DiskHandle - Supplies a handle to the disk to query.
  269. Return Value:
  270. Returns the number of bytes in a sector on success.
  271. 0 on error.
  272. --*/
  273. ULONGLONG
  274. FwpPcatGetSectorCount (
  275. HANDLE DiskHandle
  276. );
  277. /*++
  278. Routine Description:
  279. This routine determines the number of sectors on the disk.
  280. Arguments:
  281. DiskHandle - Supplies a handle to the disk to query.
  282. Return Value:
  283. Returns the number of sectors in the disk on success.
  284. 0 on error.
  285. --*/
  286. VOID
  287. FwpPcatGetDiskInformation (
  288. HANDLE DiskHandle,
  289. PULONG DriveNumber,
  290. PULONGLONG PartitionOffset
  291. );
  292. /*++
  293. Routine Description:
  294. This routine returns information about an open disk handle.
  295. Arguments:
  296. DiskHandle - Supplies a pointer to the open disk handle.
  297. DriveNumber - Supplies a pointer where the drive number of this disk
  298. handle will be returned.
  299. PartitionOffset - Supplies a pointer where the offset in sectors from the
  300. beginning of the disk to the partition this handle represents will be
  301. returned.
  302. Return Value:
  303. None.
  304. --*/
  305. KSTATUS
  306. FwpPcatInitializeVideo (
  307. );
  308. /*++
  309. Routine Description:
  310. This routine attempts to initialize the video subsystem on a PCAT machine.
  311. Arguments:
  312. None.
  313. Return Value:
  314. Status code.
  315. --*/
  316. PVOID
  317. FwPcatFindRsdp (
  318. VOID
  319. );
  320. /*++
  321. Routine Description:
  322. This routine attempts to find the ACPI RSDP table pointer on a PC-AT
  323. compatible system. It looks in the first 1k of the EBDA (Extended BIOS Data
  324. Area), as well as between the ranges 0xE0000 and 0xFFFFF. This routine
  325. must be run in physical mode.
  326. Arguments:
  327. None.
  328. Return Value:
  329. Returns a pointer to the RSDP table on success.
  330. NULL on failure.
  331. --*/
  332. PVOID
  333. FwPcatFindSmbiosTable (
  334. VOID
  335. );
  336. /*++
  337. Routine Description:
  338. This routine attempts to find the SMBIOS table entry point structure.
  339. Arguments:
  340. None.
  341. Return Value:
  342. Returns a pointer to the SMBIOS entry point structure on success.
  343. NULL on failure.
  344. --*/
  345. KSTATUS
  346. FwPcatGetCurrentTime (
  347. PSYSTEM_TIME Time
  348. );
  349. /*++
  350. Routine Description:
  351. This routine attempts to get the current system time.
  352. Arguments:
  353. Time - Supplies a pointer where the current time will be returned.
  354. Return Value:
  355. Status code.
  356. --*/
  357. KSTATUS
  358. FwPcatStall (
  359. ULONG Microseconds
  360. );
  361. /*++
  362. Routine Description:
  363. This routine performs a short busy stall using INT 0x1A function 0, which
  364. returns a counter that increments 18.6025 times per second. Callers are
  365. advised to perform a "warm-up" stall to align to tick boundaries for more
  366. accurate results.
  367. Arguments:
  368. Microseconds - Supplies the number of microseconds to stall for.
  369. Return Value:
  370. Status code.
  371. --*/
  372. KSTATUS
  373. FwPcatResetSystem (
  374. SYSTEM_RESET_TYPE ResetType
  375. );
  376. /*++
  377. Routine Description:
  378. This routine resets the system.
  379. Arguments:
  380. ResetType - Supplies the desired reset type. If the desired reset type is
  381. not supported, a cold reset will be attempted.
  382. Return Value:
  383. Does not return on success, the system is reset.
  384. STATUS_INVALID_PARAMETER if an invalid reset type was supplied.
  385. STATUS_NOT_SUPPORTED if the system cannot be reset.
  386. STATUS_UNSUCCESSFUL if the system did not reset.
  387. --*/