EFI.Mod 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. MODULE EFI; (** AUTHOR "Matthias Frei"; PURPOSE "Provides (low-level) API to the (Unified) Extensible Firmware Interface"; *)
  2. IMPORT SYSTEM;
  3. CONST
  4. (* Status Codes *)
  5. (* Success *)
  6. Success* = 0;
  7. (* Warnings *)
  8. WarnUnknownGlyph *= 1;
  9. WarnDeleteFailure *= 2;
  10. WarnWriteFailure *= 3;
  11. WarnBufferTooSmall *= 4;
  12. (* Errors*)
  13. Error* = LONGINT(80000000H); (* == 80000000H *)
  14. ErrLoadError* = Error + 1;
  15. ErrInvalidParameter* = Error + 2;
  16. ErrUnsupported* = Error + 3;
  17. ErrBadBufferSize* = Error + 4;
  18. ErrBufferTooSmall* = Error + 5;
  19. (* ... TODO ... *)
  20. ErrNotFound* = Error + 14;
  21. (* ... TODO ... *)
  22. ErrEndOfFile* = Error + 31;
  23. ErrInvalidLanguage* = Error + 32;
  24. (* BSAllocatePages allocation types *)
  25. AllocateAnyPage* = 0;
  26. AllocateMaxAddress* = 1;
  27. AllocateAddress* = 2;
  28. MaxAllocateType* = 3;
  29. (* Memory Types (for BSAllocatePages and MemoryDescriptor.Type)*)
  30. MTReserved* = 0;
  31. MTLoaderCode* = 1;
  32. MTLoaderData* = 2;
  33. MTBootServicesCode* = 3;
  34. MTBootServicesData* = 4;
  35. MTRuntimeServicesCode* = 5;
  36. MTRuntimeServicesData* = 6;
  37. MTConventionalMemory*= 7;
  38. MTUnusableMemory* = 8;
  39. MTACPIReclaimMemory* = 9;
  40. MTACPIMemoryNVSM* = 10;
  41. MTMemoryMappedIO* = 11;
  42. MTMemoryMappedIOPortSpace* = 12;
  43. MTPalCode* = 13;
  44. MTMaxMemoryType* = 14;
  45. (* Page Size in bytes *)
  46. PageSize* = 1000H; (* = 4KB *)
  47. (* BSLocateHandle search types *)
  48. AllHandles* = 0; (* the 'Protocol' and 'SearchLey' argument are ignored and all handles in the system are returned *)
  49. ByRegistryNotify* = 1; (* 'SearchKey' supplies the Registration value returned by RegisterProtocolNotify(). 'Protocol' is ignored *)
  50. ByProtocol* =2; (* return all handles that support 'Protocol' the 'SearchKey' argument is ignored *)
  51. (* Task Priority Levels *)
  52. ApplicationTPL* = 4;
  53. CallbackTPL* = 8;
  54. NotifiyTPL* = 16;
  55. HighLevelTPL* = 31;
  56. (* various type definitions *)
  57. TYPE Char8* = SHORTINT;
  58. TYPE Char16* = INTEGER;
  59. TYPE Boolean* = BOOLEAN;
  60. TYPE Int* = SIZE; (* size of Int architecture dependant (e.g. 32bit on i386, 64bit on ia64) *)
  61. TYPE Int8* = SHORTINT; (* Int8, Int16, Int32, Int64 NOT architecture dependant *)
  62. TYPE Int16* = INTEGER;
  63. TYPE Int32* = LONGINT;
  64. TYPE Int64* = HUGEINT;
  65. TYPE Address*= ADDRESS;
  66. TYPE Status* = Int;
  67. TYPE TPL* = Int;
  68. TYPE LBA* = Int64;
  69. TYPE Pointer* = Address;
  70. TYPE VirtualAddress* = Int64; (* sic! *)
  71. TYPE PhysicalAddress* = Int64; (* sic! *)
  72. TYPE Handle* = Pointer;
  73. TYPE Event* = Pointer;
  74. TYPE Protocol* = POINTER TO ProtocolDescription;
  75. TYPE ProtocolDescription* = RECORD END;
  76. TYPE GUID* = RECORD
  77. Data1*: Int32;
  78. Data2*: Int16;
  79. Data3*: Int16;
  80. Data4*: ARRAY 8 OF Int8;
  81. END;
  82. TYPE
  83. MemoryDescriptorPointer*= POINTER TO MemoryDescriptor;
  84. MemoryDescriptor* = RECORD
  85. Type- : Int32;
  86. pad-: Int32;
  87. PhysicalStart-: PhysicalAddress;
  88. VirtualStart-: VirtualAddress;
  89. (* PhysicalStart-: Int64;
  90. VirtualStart-: Int64; *)
  91. NumberOfPages-: Int64;
  92. Attribute-: Int64;
  93. END;
  94. TYPE Time* = RECORD
  95. Year-: Int16; (* 1998 - 20XX *)
  96. Month-: Int8; (* 1 - 12 *)
  97. Day-: Int8; (* 1 - 31 *)
  98. Hour-: Int8; (* 0-23 *)
  99. Minute-: Int8; (* 0 - 59 *)
  100. Second-: Int8; (* 0 - 59 *)
  101. Pad1 : Int8;
  102. Nanosecond-: Int32; (* 0 - 999,999,999 *)
  103. TimeZone- : Int8; (* -1440 - 1440 or 2047 (= unspecified) *)
  104. Daylight-: Int8; (* 1 : EFITimeAdjustDaylight, 2 : EFITimeInDaylight *)
  105. Pad2 : Int8;
  106. END;
  107. (* efi generic table header *)
  108. TYPE TableHeader* = RECORD
  109. Signature-: Int64;
  110. Revision-: Int32;
  111. HeaderSize-: Int32;
  112. CRC32-: Int32;
  113. Reserved-: Int32;
  114. END;
  115. (* main EFI tables *)
  116. TYPE
  117. SystemTable* = RECORD
  118. Hdr-: TableHeader;
  119. FirmwareVendor-{UNTRACED}: POINTER TO ARRAY OF Char16;
  120. FirmwareRevision-: Int32;
  121. ConsoleInHandle* : Handle;
  122. ConIn* {UNTRACED}: POINTER TO SimpleInputInterface;
  123. ConsoleOutHandle*: Handle;
  124. ConOut* {UNTRACED}: POINTER TO SimpleTextOutputInterface;
  125. StandardErrorHandle*: Handle;
  126. StdErr* {UNTRACED}: POINTER TO SimpleTextOutputInterface;
  127. RS- {UNTRACED}: POINTER TO RuntimeServices;
  128. BS* {UNTRACED}: POINTER TO BootServices;
  129. NumberOfTableEntries-: Int;
  130. ConfigurationTable-{UNTRACED}: POINTER TO ARRAY 2048 OF ConfigurationTableEntry; (* access to ACPI, SMBIOS, ... *)
  131. END;
  132. (* BootServices function type declarations *)
  133. TYPE DevicePath* = RECORD
  134. Type-: Int8;
  135. SubType-: Int8;
  136. Length-: ARRAY 2 OF Int8;
  137. END;
  138. TYPE BSDummyType* = PROCEDURE{C};
  139. (* task priority functions *)
  140. TYPE BSTPLRaise* = PROCEDURE{C}(NewTpl : TPL) : TPL;
  141. TYPE BSTPLRestore* = PROCEDURE{C}(oldTpl : TPL);
  142. (* Memory functions *)
  143. TYPE BSAllocatePages* = PROCEDURE{C}(Type : Int; MemoryType : Int; Pages : Int; VAR Memory : PhysicalAddress) : Status;
  144. TYPE BSFreePages* = PROCEDURE{C}(Memory : PhysicalAddress; Pages : Int) : Status;
  145. TYPE BSGetMemoryMap* = PROCEDURE{C}(VAR MemoryMapSize : Int; VAR MemoryMap : ARRAY OF MemoryDescriptor; VAR MapKey, DescriptorSize : Int; VAR DescriptorVersion : Int32) : Status;
  146. (* protocol handler functions *)
  147. TYPE BSProtocolInstall* = PROCEDURE{C}(VAR Handle : Handle; CONST Protocol : GUID; InterfaceType : Int; Interface : Protocol) : Status;
  148. TYPE BSProtocolReinstall* = PROCEDURE{C}(Handle : Handle; CONST Protocol : GUID; OldInterface, NewInterface : Protocol) : Status;
  149. TYPE BSProtocolUninstall* = PROCEDURE{C}(Handle : Handle; CONST Protocol : GUID; Interface : Protocol) : Status;
  150. TYPE BSProtocolHandle* = PROCEDURE{C}(Handle : Handle; CONST Protocol : GUID; VAR Interface : Protocol) : Status;
  151. TYPE BSProtocolRegisterNotify* = PROCEDURE{C}(CONST Protocol : GUID; Event : Event; VAR Registration : Pointer) : Status;
  152. TYPE BSLocateHandle* = PROCEDURE{C}(SearchType : Int; CONST Protocol : GUID; SearchKey : Pointer; VAR BufferSize : Int; VAR Buffer : ARRAY OF Handle): Status;
  153. TYPE BSLocateDevicePath* = PROCEDURE{C}(CONST Protocol : GUID; VAR DevicePath : DevicePath; VAR Device : Handle) : Status;
  154. TYPE BSInstallConfigurationTable* = PROCEDURE{C}(CONST Protocol : GUID; Table : Pointer) : Status;
  155. (* image functions *)
  156. TYPE BSImageLoad* = PROCEDURE{C}(BootPolicy : Boolean; ParentImageHandle : Handle; CONST FilePath : DevicePath; SourceSize : Int; SourceBuffer : Pointer; VAR ImageHandle : Handle) : Status;
  157. TYPE BSImageStart* = PROCEDURE{C}(ImageHandle : Handle; VAR ExitDataSize : Int; VAR ExitData : ARRAY OF Char16) : Status;
  158. TYPE BSImageExit* = PROCEDURE{C}(ImageHandle : Handle; ExitStatus : Status; ExitDataSize : Int; VAR ExitData : ARRAY OF Char16) : Status;
  159. TYPE BSImageUnload* = PROCEDURE{C}(ImageHandle : Handle) : Status;
  160. TYPE BSExitBootServices* = PROCEDURE{C}(ImageHandle : Handle; MapKey : Int) : Status;
  161. (* misc. functions *)
  162. TYPE BSGetNextMonotonicCount* = PROCEDURE{C}(VAR Count : Int64);
  163. TYPE BSStall* = PROCEDURE{C}(Microseconds : Int);
  164. TYPE BootServices* = RECORD
  165. Hdr- : TableHeader;
  166. RaiseTPL-: BSTPLRaise;
  167. RestoreTPL-: BSTPLRestore;
  168. (* memory functions *)
  169. AllocatePages-: BSAllocatePages;
  170. FreePages-: BSFreePages;
  171. GetMemoryMap-: BSGetMemoryMap;
  172. AllocatePool-: BSDummyType;
  173. FreePool-: BSDummyType;
  174. (* event & timer functions *)
  175. CreateEvent-: BSDummyType;
  176. SetTimer-: BSDummyType;
  177. WaitForEvent-: BSDummyType;
  178. SignaleEvent-: BSDummyType;
  179. CloseEvent-: BSDummyType;
  180. CheckEvent-: BSDummyType;
  181. (* protocol handler functions *)
  182. InstallProtocolInterface-: BSProtocolInstall;
  183. ReinstallProtocolInterface-: BSProtocolReinstall;
  184. UninstallProtocolInterface-: BSProtocolUninstall;
  185. HandleProtocol-: BSProtocolHandle;
  186. PCHandleProtocol-: BSProtocolHandle;
  187. RegisterProtocolNotify-: BSProtocolRegisterNotify;
  188. LocateHandle-: BSLocateHandle;
  189. LocateDevicePath-: BSLocateDevicePath;
  190. InstallConfigurationTable-: BSDummyType;
  191. (* image functions *)
  192. LoadImage-: BSImageLoad;
  193. StartImage-: BSImageStart;
  194. Exit-: BSImageExit;
  195. UnloadImage-: BSImageUnload;
  196. ExitBootServices-: BSExitBootServices;
  197. (* misc *)
  198. GetNextMonotinicCount-: BSGetNextMonotonicCount;
  199. Stall-: BSStall;
  200. SetWatchdogTimer-: BSDummyType;
  201. END;
  202. (* RuntimeService function type declarations *)
  203. TYPE RSDummyType* = PROCEDURE{C};
  204. TYPE RuntimeServices* = RECORD
  205. Hdr- : TableHeader;
  206. (* time services *)
  207. GetTime-: RSDummyType;
  208. SetTime-: RSDummyType;
  209. GetWakeupTime-: RSDummyType;
  210. SetWakeupTime-: RSDummyType;
  211. (* virtual memory services *)
  212. SetVirtualAddressMap-: RSDummyType;
  213. ConvertPointer-: RSDummyType;
  214. (* varible services *)
  215. GetVariable-: RSDummyType;
  216. GetNextVariable-: RSDummyType;
  217. SetVariable-: RSDummyType;
  218. (* misc *)
  219. GetNextHighMonotonicCount-: RSDummyType;
  220. ResetSystem -: RSDummyType;
  221. END;
  222. TYPE ConfigurationTableEntry* = RECORD
  223. VendorGuid-: GUID;
  224. VendorTable-: ADDRESS; (* virtual OR physical address - see EFI spec. Chapter 4.6 *)
  225. END;
  226. (* basic EFI protocols ( = function tables to communicate with EFI services ) *)
  227. (* Simple Input Interface Protocol *)
  228. TYPE InputKey* = RECORD
  229. ScanCode-: Int16;
  230. UnicodeChar-: Char16;
  231. END;
  232. TYPE InputReset* = PROCEDURE {C} (This: POINTER TO SimpleInputInterface; ExtendedVerification: Boolean): Status;
  233. TYPE InputReadKey* = PROCEDURE {C} (This: POINTER TO SimpleInputInterface; VAR key: InputKey): Status;
  234. TYPE SimpleInputInterface* = RECORD(ProtocolDescription)
  235. Reset-: InputReset;
  236. ReadKey-: InputReadKey;
  237. WaitForEvent- : Event;
  238. END;
  239. (* Simple Text Output Interface Protocol *)
  240. TYPE SimpleTextOutputInterfaceMode* = RECORD
  241. MaxMode-: Int32;
  242. (* current settings: *)
  243. Mode-: Int32;
  244. Attribute-: Int32;
  245. CursorColumn-: Int32;
  246. CursorRow-: Int32;
  247. CursorVisible-: Boolean;
  248. END;
  249. TYPE TextReset* = PROCEDURE {C} (This: POINTER TO SimpleTextOutputInterface; ExtendedVerification: Boolean): Status;
  250. TYPE TextString* = PROCEDURE {C} (This: POINTER TO SimpleTextOutputInterface; CONST String: ARRAY OF Char16): Status;
  251. TYPE TextTestString* = PROCEDURE {C} (This: POINTER TO SimpleTextOutputInterface; CONST String: ARRAY OF Char16): Status;
  252. TYPE TextQueryMode* = PROCEDURE {C} (This: POINTER TO SimpleTextOutputInterface; ModeNumber: Int; VAR Columns, Rows: Int): Status;
  253. TYPE TextSetMode* = PROCEDURE {C} (This: POINTER TO SimpleTextOutputInterface; ModeNumber: Int): Status;
  254. TYPE TextSetAttribute* = PROCEDURE {C} (This: POINTER TO SimpleTextOutputInterface; Attribute: Int): Status;
  255. TYPE TextClearScreen* = PROCEDURE {C} (This: POINTER TO SimpleTextOutputInterface): Status;
  256. TYPE TextSetCursorPos* = PROCEDURE {C} (This: POINTER TO SimpleTextOutputInterface; Column, Row : Int): Status;
  257. TYPE TextEnableCursor* = PROCEDURE {C} (This : POINTER TO SimpleTextOutputInterface; Visible : Boolean): Status;
  258. TYPE SimpleTextOutputInterface* = RECORD(ProtocolDescription)
  259. Reset-: TextReset;
  260. OutputString-: TextString;
  261. TestString-: TextTestString;
  262. QueryMode-: TextQueryMode;
  263. SetMode-: TextSetMode;
  264. SetAttribute-: TextSetAttribute;
  265. ClearScreen-: TextClearScreen;
  266. SetCursorPosition-: TextSetAttribute;
  267. EnableCursor-: TextEnableCursor;
  268. Mode-{UNTRACED}: POINTER TO SimpleTextOutputInterfaceMode;
  269. END;
  270. VAR
  271. imageHandle-: Handle;
  272. table- {UNTRACED}: POINTER TO SystemTable;
  273. END EFI.