Rev 7130 | Rev 8150 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7130 | dunkaist | 1 | ;********************************************************************* |
2 | ;* * |
||
3 | ;* UEFI library for fasm by bzt, Public Domain * |
||
4 | ;* * |
||
5 | ;********************************************************************* |
||
8092 | dunkaist | 6 | |
7130 | dunkaist | 7 | ; EFI_MEMORY_TYPE |
8 | EFI_RESERVED_MEMORY_TYPE = 0 |
||
9 | EFI_LOADER_CODE = 1 |
||
10 | EFI_LOADER_DATA = 2 |
||
11 | EFI_BOOT_SERVICES_CODE = 3 |
||
12 | EFI_BOOT_SERVICES_DATA = 4 |
||
13 | EFI_RUNTIME_SERVICES_CODE = 5 |
||
14 | EFI_RUNTIME_SERVICES_DATA = 6 |
||
15 | EFI_CONVENTIONAL_MEMORY = 7 |
||
16 | EFI_UNUSABLE_MEMORY = 8 |
||
17 | EFI_ACPI_RECLAIM_MEMORY = 9 |
||
18 | EFI_ACPI_MEMORY_NVS = 10 |
||
19 | EFI_MEMORY_MAPPED_IO = 11 |
||
20 | EFI_MEMORY_MAPPED_IO_PORT_SPACE = 12 |
||
21 | EFI_PAL_CODE = 13 |
||
22 | EFI_PERSISTENT_MEMORY = 14 |
||
23 | EFI_MAX_MEMORY_TYPE = 15 |
||
24 | |||
8092 | dunkaist | 25 | ; EFI_ALLOCATE_TYPE |
26 | EFI_ALLOCATE_ANY_PAGES = 0 |
||
27 | EFI_ALLOCATE_MAX_ADDRESS = 1 |
||
28 | EFI_ALLOCATE_ADDRESS = 2 |
||
29 | |||
7130 | dunkaist | 30 | EFI_MEMORY_UC = 0x0000000000000001 |
31 | EFI_MEMORY_WC = 0x0000000000000002 |
||
32 | EFI_MEMORY_WT = 0x0000000000000004 |
||
33 | EFI_MEMORY_WB = 0x0000000000000008 |
||
34 | EFI_MEMORY_UCE = 0x0000000000000010 |
||
35 | EFI_MEMORY_WP = 0x0000000000001000 |
||
36 | EFI_MEMORY_RP = 0x0000000000002000 |
||
37 | EFI_MEMORY_XP = 0x0000000000004000 |
||
38 | EFI_MEMORY_NV = 0x0000000000008000 |
||
39 | EFI_MEMORY_MORE_RELIABLE = 0x0000000000010000 |
||
40 | EFI_MEMORY_RO = 0x0000000000020000 |
||
41 | EFI_MEMORY_RUNTIME = 0x8000000000000000 |
||
42 | |||
43 | EFIERR = 0x8000000000000000 |
||
44 | EFI_SUCCESS = 0 |
||
45 | EFI_LOAD_ERROR = EFIERR or 1 |
||
46 | EFI_INVALID_PARAMETER = EFIERR or 2 |
||
47 | EFI_UNSUPPORTED = EFIERR or 3 |
||
48 | EFI_BAD_BUFFER_SIZE = EFIERR or 4 |
||
49 | EFI_BUFFER_TOO_SMALL = EFIERR or 5 |
||
50 | EFI_NOT_READY = EFIERR or 6 |
||
51 | EFI_DEVICE_ERROR = EFIERR or 7 |
||
52 | EFI_WRITE_PROTECTED = EFIERR or 8 |
||
53 | EFI_OUT_OF_RESOURCES = EFIERR or 9 |
||
54 | EFI_VOLUME_CORRUPTED = EFIERR or 10 |
||
55 | EFI_VOLUME_FULL = EFIERR or 11 |
||
56 | EFI_NO_MEDIA = EFIERR or 12 |
||
57 | EFI_MEDIA_CHANGED = EFIERR or 13 |
||
58 | EFI_NOT_FOUND = EFIERR or 14 |
||
59 | EFI_ACCESS_DENIED = EFIERR or 15 |
||
60 | EFI_NO_RESPONSE = EFIERR or 16 |
||
61 | EFI_NO_MAPPING = EFIERR or 17 |
||
62 | EFI_TIMEOUT = EFIERR or 18 |
||
63 | EFI_NOT_STARTED = EFIERR or 19 |
||
64 | EFI_ALREADY_STARTED = EFIERR or 20 |
||
65 | EFI_ABORTED = EFIERR or 21 |
||
66 | EFI_ICMP_ERROR = EFIERR or 22 |
||
67 | EFI_TFTP_ERROR = EFIERR or 23 |
||
68 | EFI_PROTOCOL_ERROR = EFIERR or 24 |
||
8092 | dunkaist | 69 | |
70 | struct EFI_FILE_SYSTEM_INFO |
||
71 | Size dq ? |
||
72 | ReadOnly db ? |
||
73 | rb 7 |
||
74 | VolumeSize dq ? |
||
75 | FreeSpace dq ? |
||
76 | BlockSize dd ? |
||
77 | VolumeLabel rw 32 |
||
78 | ends |
||
79 | |||
80 | EFI_FILE_SYSTEM_INFO_ID equ 0x93,0x6e,0x57,0x09,0x3f,0x6d,0xd2,0x11, \ |
||
81 | 0x39,0x8e,0x00,0xa0,0xc9,0x69,0x72,0x3b |
||
82 | |||
7130 | dunkaist | 83 | EFI_SYSTEM_TABLE_SIGNATURE equ 0x49,0x42,0x49,0x20,0x53,0x59,0x53,0x54 |
84 | struct EFI_TABLE_HEADER |
||
85 | Signature dq ? |
||
86 | Revision dd ? |
||
87 | HeaderSize dd ? |
||
88 | CRC32 dd ? |
||
89 | Reserved dd ? |
||
90 | ends |
||
8092 | dunkaist | 91 | |
7130 | dunkaist | 92 | struct EFI_SYSTEM_TABLE |
93 | Hdr EFI_TABLE_HEADER |
||
94 | FirmwareVendor dq ? |
||
95 | FirmwareRevision dd ? |
||
96 | dd ? |
||
97 | ConsoleInHandle dq ? |
||
98 | ConIn dq ? |
||
99 | ConsoleOutHandle dq ? |
||
100 | ConOut dq ? |
||
101 | StandardErrorHandle dq ? |
||
102 | StdErr dq ? |
||
103 | RuntimeServices dq ? |
||
104 | BootServices dq ? |
||
105 | NumberOfTableEntries dq ? |
||
106 | ConfigurationTable dq ? |
||
107 | ends |
||
8092 | dunkaist | 108 | |
7130 | dunkaist | 109 | struct SIMPLE_TEXT_OUTPUT_INTERFACE |
110 | Reset dq ? |
||
111 | OutputString dq ? |
||
112 | TestString dq ? |
||
113 | QueryMode dq ? |
||
114 | SetMode dq ? |
||
115 | SetAttribute dq ? |
||
116 | ClearScreen dq ? |
||
117 | SetCursorPosition dq ? |
||
118 | EnableCursor dq ? |
||
119 | Mode dq ? |
||
120 | ends |
||
8092 | dunkaist | 121 | |
122 | |||
7130 | dunkaist | 123 | struct SIMPLE_INPUT_INTERFACE |
124 | Reset dq ? |
||
125 | ReadKeyStroke dq ? |
||
126 | WaitForKey dq ? |
||
127 | ends |
||
8092 | dunkaist | 128 | |
7130 | dunkaist | 129 | struct EFI_BOOT_SERVICES_TABLE |
130 | Hdr EFI_TABLE_HEADER |
||
131 | RaisePriority dq ? |
||
132 | RestorePriority dq ? |
||
133 | AllocatePages dq ? |
||
134 | FreePages dq ? |
||
135 | GetMemoryMap dq ? |
||
136 | AllocatePool dq ? |
||
137 | FreePool dq ? |
||
138 | CreateEvent dq ? |
||
139 | SetTimer dq ? |
||
140 | WaitForEvent dq ? |
||
141 | SignalEvent dq ? |
||
142 | CloseEvent dq ? |
||
143 | CheckEvent dq ? |
||
144 | InstallProtocolInterface dq ? |
||
145 | ReInstallProtocolInterface dq ? |
||
146 | UnInstallProtocolInterface dq ? |
||
147 | HandleProtocol dq ? |
||
148 | Void dq ? |
||
149 | RegisterProtocolNotify dq ? |
||
150 | LocateHandle dq ? |
||
151 | LocateDevicePath dq ? |
||
152 | InstallConfigurationTable dq ? |
||
153 | ImageLoad dq ? |
||
154 | ImageStart dq ? |
||
155 | Exit dq ? |
||
156 | ImageUnLoad dq ? |
||
157 | ExitBootServices dq ? |
||
158 | GetNextMonotonicCount dq ? |
||
159 | Stall dq ? |
||
160 | SetWatchdogTimer dq ? |
||
161 | ConnectController dq ? |
||
162 | DisConnectController dq ? |
||
163 | OpenProtocol dq ? |
||
164 | CloseProtocol dq ? |
||
165 | OpenProtocolInformation dq ? |
||
166 | ProtocolsPerHandle dq ? |
||
167 | LocateHandleBuffer dq ? |
||
168 | LocateProtocol dq ? |
||
169 | InstallMultipleProtocolInterfaces dq ? |
||
170 | UnInstallMultipleProtocolInterfaces dq ? |
||
171 | CalculateCrc32 dq ? |
||
172 | CopyMem dq ? |
||
173 | SetMem dq ? |
||
174 | ends |
||
8092 | dunkaist | 175 | |
7130 | dunkaist | 176 | struct EFI_RUNTIME_SERVICES_TABLE |
177 | Hdr EFI_TABLE_HEADER |
||
178 | GetTime dq ? |
||
179 | SetTime dq ? |
||
180 | GetWakeUpTime dq ? |
||
181 | SetWakeUpTime dq ? |
||
182 | SetVirtualAddressMap dq ? |
||
183 | ConvertPointer dq ? |
||
184 | GetVariable dq ? |
||
185 | GetNextVariableName dq ? |
||
186 | SetVariable dq ? |
||
187 | GetNextHighMonoCount dq ? |
||
188 | ResetSystem dq ? |
||
189 | ends |
||
8092 | dunkaist | 190 | |
7130 | dunkaist | 191 | struct EFI_TIME |
192 | Year dw ? |
||
193 | Month db ? |
||
194 | Day db ? |
||
195 | Hour db ? |
||
196 | Minute db ? |
||
197 | Second db ? |
||
198 | Pad1 db ? |
||
199 | Nanosecond dd ? |
||
200 | TimeZone dw ? |
||
201 | Daylight db ? |
||
202 | Pad2 db ? |
||
203 | sizeof db ? |
||
204 | ends |
||
8092 | dunkaist | 205 | |
206 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID equ 0x22,0x5b,0x4e,0x96,0x59,0x64,0xd2,0x11, \ |
||
207 | 0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b |
||
208 | |||
209 | struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL |
||
210 | Revision dq ? |
||
211 | OpenVolume dq ? |
||
212 | ends |
||
213 | |||
214 | EFI_FILE_MODE_READ = 1 |
||
215 | EFI_FILE_MODE_WRITE = 2 |
||
216 | EFI_FILE_MODE_CREATE = 0x8000000000000000 |
||
217 | |||
218 | struct EFI_FILE_PROTOCOL |
||
219 | Revision dq ? |
||
220 | Open dq ? |
||
221 | Close dq ? |
||
222 | Delete dq ? |
||
223 | Read dq ? |
||
224 | Write dq ? |
||
225 | GetPosition dq ? |
||
226 | SetPosition dq ? |
||
227 | GetInfo dq ? |
||
228 | SetInfo dq ? |
||
229 | Flush dq ? |
||
230 | OpenEx dq ? |
||
231 | ReadEx dq ? |
||
232 | WriteEx dq ? |
||
233 | FlushEx dq ? |
||
234 | ends |
||
235 | |||
236 | EFI_LOADED_IMAGE_PROTOCOL_GUID equ 0xA1,0x31,0x1b,0x5b,0x62,0x95,0xd2,0x11, \ |
||
237 | 0x8E,0x3F,0x00,0xA0,0xC9,0x69,0x72,0x3B |
||
7130 | dunkaist | 238 | struct EFI_LOADED_IMAGE_PROTOCOL |
239 | Revision dd ? |
||
240 | dd ? |
||
241 | ParentHandle dq ? |
||
242 | SystemTable dq ? |
||
243 | DeviceHandle dq ? |
||
244 | FilePath dq ? |
||
245 | Reserved dq ? |
||
246 | LoadOptionsSize dd ? |
||
247 | dd ? |
||
248 | ImageBase dq ? |
||
249 | ImageSize dq ? |
||
250 | ImageCodeType dd ? |
||
251 | ImageDataType dd ? |
||
252 | UnLoad dq ? |
||
253 | ends |
||
8092 | dunkaist | 254 | |
255 | EFI_BLOCK_IO_PROTOCOL_GUID equ 0x21,0x5b,0x4e,0x96,0x59,0x64,0xd2,0x11, \ |
||
256 | 0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b |
||
7130 | dunkaist | 257 | struct EFI_BLOCK_IO_PROTOCOL |
258 | Revision dq ? |
||
259 | Media dq ? |
||
260 | Reset dq ? |
||
261 | ReadBlocks dq ? |
||
262 | WriteBlocks dq ? |
||
263 | FlushBlocks dq ? |
||
264 | ends |
||
8092 | dunkaist | 265 | |
7130 | dunkaist | 266 | struct EFI_BLOCK_IO_MEDIA |
267 | MediaId dd ? |
||
268 | RemovableMedia db ? |
||
269 | MediaPresent db ? |
||
270 | LogicalPartition db ? |
||
271 | ReadOnly db ? |
||
272 | WriteCaching db ? |
||
273 | rb 3 |
||
274 | BlockSize dd ? |
||
275 | IoAlign dd ? |
||
276 | LastBlock dq ? |
||
277 | ends |
||
8092 | dunkaist | 278 | |
279 | EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID equ 0xde,0xa9,0x42,0x90,0xdc,0x23,0x38,0x4a, \ |
||
280 | 0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a |
||
7130 | dunkaist | 281 | struct EFI_GRAPHICS_OUTPUT_PROTOCOL |
282 | QueryMode dq ? |
||
283 | SetMode dq ? |
||
284 | Blt dq ? |
||
285 | Mode dq ? |
||
286 | ends |
||
8092 | dunkaist | 287 | |
7130 | dunkaist | 288 | struct EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE |
289 | MaxMode dd ? |
||
290 | Mode dd ? |
||
291 | nfo dq ? |
||
292 | SizeOfInfo dq ? |
||
293 | FrameBufferBase dq ? |
||
294 | FrameBufferSize dq ? |
||
295 | ends |
||
8092 | dunkaist | 296 | |
7130 | dunkaist | 297 | struct EFI_GRAPHICS_OUTPUT_MODE_INFORMATION |
298 | Version dd ? |
||
299 | HorizontalResolution dd ? |
||
300 | VerticalResolution dd ? |
||
301 | PixelFormat dd ? |
||
302 | RedMask dd ? |
||
303 | GreenMask dd ? |
||
304 | BlueMask dd ? |
||
305 | Reserved dd ? |
||
306 | PixelsPerScanLine dd ? |
||
307 | ends |
||
308 | |||
309 | ;---macros to make life easier--- |
||
310 | ;call it early, after entry point is the best |
||
311 | macro InitializeLib |
||
312 | { |
||
313 | clc |
||
314 | test rdx, rdx |
||
315 | jz .badout |
||
316 | cmp dword[rdx], 'IBI ' ; 20494249h |
||
317 | jz @f |
||
318 | .badout: |
||
319 | xor ecx, ecx |
||
320 | xor edx, edx |
||
321 | stc |
||
322 | @@: |
||
323 | mov [efi_handler], rcx ; ImageHandle |
||
324 | mov [efi_ptr], rdx ; pointer to SystemTable |
||
325 | } |
||
8092 | dunkaist | 326 | |
7130 | dunkaist | 327 | ;invoke an UEFI function |
8092 | dunkaist | 328 | macro eficall interface,function,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11 |
7130 | dunkaist | 329 | { |
330 | numarg = 0 |
||
331 | |||
332 | if ~ arg11 eq |
||
333 | numarg = numarg + 1 |
||
334 | if ~ arg11 eq rdi |
||
335 | mov rdi, arg11 |
||
336 | end if |
||
337 | end if |
||
338 | |||
339 | if ~ arg10 eq |
||
340 | numarg = numarg + 1 |
||
341 | if ~ arg10 eq rsi |
||
342 | mov rsi, arg10 |
||
343 | end if |
||
344 | end if |
||
345 | |||
346 | if ~ arg9 eq |
||
347 | numarg = numarg + 1 |
||
348 | if ~ arg9 eq r14 |
||
349 | mov r14, arg9 |
||
350 | end if |
||
351 | end if |
||
352 | |||
353 | if ~ arg8 eq |
||
354 | numarg = numarg + 1 |
||
355 | if ~ arg8 eq r13 |
||
356 | mov r13, arg8 |
||
357 | end if |
||
358 | end if |
||
359 | |||
360 | if ~ arg7 eq |
||
361 | numarg = numarg + 1 |
||
362 | if ~ arg7 eq r12 |
||
363 | mov r12, arg7 |
||
364 | end if |
||
365 | end if |
||
366 | |||
367 | if ~ arg6 eq |
||
368 | numarg = numarg + 1 |
||
369 | if ~ arg6 eq r11 |
||
370 | mov r11, arg6 |
||
371 | end if |
||
372 | end if |
||
373 | |||
374 | if ~ arg5 eq |
||
375 | numarg = numarg + 1 |
||
376 | if ~ arg5 eq r10 |
||
377 | mov r10, arg5 |
||
378 | end if |
||
379 | end if |
||
380 | |||
381 | if ~ arg4 eq |
||
382 | numarg = numarg + 1 |
||
383 | if ~ arg4 eq r9 |
||
384 | mov r9, arg4 |
||
385 | end if |
||
386 | end if |
||
387 | |||
388 | if ~ arg3 eq |
||
389 | numarg = numarg + 1 |
||
390 | if ~ arg3 eq r8 |
||
391 | mov r8, arg3 |
||
392 | end if |
||
393 | end if |
||
394 | |||
395 | if ~ arg2 eq |
||
396 | numarg = numarg + 1 |
||
397 | if ~ arg2 eq rdx |
||
398 | mov rdx, arg2 |
||
399 | end if |
||
400 | end if |
||
401 | |||
402 | if ~ arg1 eq |
||
403 | numarg = numarg + 1 |
||
404 | if ~ arg1 eq rcx |
||
405 | if ~ arg1 in |
||
406 | mov rcx, arg1 |
||
407 | end if |
||
408 | end if |
||
409 | end if |
||
410 | |||
411 | xor rax, rax |
||
412 | mov al, numarg |
||
413 | |||
414 | if interface in |
||
415 | mov rbx, [efi_ptr] |
||
416 | mov rbx, [rbx + EFI_SYSTEM_TABLE.#interface] |
||
417 | else |
||
418 | if ~ interface eq rbx |
||
419 | mov rbx, interface |
||
420 | end if |
||
421 | end if |
||
422 | |||
423 | if arg1 in |
||
424 | mov rcx, rbx |
||
425 | end if |
||
426 | |||
427 | if defined SIMPLE_INPUT_INTERFACE.#function |
||
428 | mov rbx, [rbx + SIMPLE_INPUT_INTERFACE.#function] |
||
429 | else |
||
430 | if defined SIMPLE_TEXT_OUTPUT_INTERFACE.#function |
||
431 | mov rbx, [rbx + SIMPLE_TEXT_OUTPUT_INTERFACE.#function] |
||
432 | else |
||
433 | if defined EFI_BOOT_SERVICES_TABLE.#function |
||
434 | mov rbx, [rbx + EFI_BOOT_SERVICES_TABLE.#function] |
||
435 | else |
||
436 | if defined EFI_RUNTIME_SERVICES_TABLE.#function |
||
437 | mov rbx, [rbx + EFI_RUNTIME_SERVICES_TABLE.#function] |
||
438 | else |
||
439 | if defined EFI_GRAPHICS_OUTPUT_PROTOCOL.#function |
||
440 | mov rbx, [rbx + EFI_GRAPHICS_OUTPUT_PROTOCOL.#function] |
||
441 | else |
||
442 | if defined EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.#function |
||
443 | mov rbx, [rbx + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.#function] |
||
444 | else |
||
445 | mov rbx, [rbx + function] |
||
446 | end if |
||
447 | end if |
||
448 | end if |
||
449 | end if |
||
450 | end if |
||
451 | end if |
||
452 | call uefifunc |
||
453 | } |
||
8092 | dunkaist | 454 | |
7130 | dunkaist | 455 | ;********************************************************************* |
456 | ;* Library functions * |
||
457 | ;********************************************************************* |
||
8092 | dunkaist | 458 | |
7130 | dunkaist | 459 | section '.text' code executable readable |
8092 | dunkaist | 460 | |
7130 | dunkaist | 461 | uefifunc: |
462 | ;save stack pointer |
||
463 | mov qword [uefi_rsptmp], rsp |
||
464 | ;set up new aligned stack |
||
465 | and esp, 0xFFFFFFF0 |
||
466 | ;alignment check on arguments |
||
467 | bt eax, 0 |
||
468 | jnc @f |
||
469 | push rax |
||
470 | ;arguments |
||
471 | @@: |
||
472 | cmp al, 11 |
||
473 | jb @f |
||
474 | push rdi |
||
475 | @@: |
||
476 | cmp al, 10 |
||
477 | jb @f |
||
478 | push rsi |
||
479 | @@: |
||
480 | cmp al, 9 |
||
481 | jb @f |
||
482 | push r14 |
||
483 | @@: |
||
484 | cmp al, 8 |
||
485 | jb @f |
||
486 | push r13 |
||
487 | @@: |
||
488 | cmp al, 7 |
||
489 | jb @f |
||
490 | push r12 |
||
491 | @@: |
||
492 | cmp al, 6 |
||
493 | jb @f |
||
494 | push r11 |
||
495 | @@: |
||
496 | cmp al, 5 |
||
497 | jb @f |
||
498 | push r10 |
||
499 | @@: |
||
500 | ;space for |
||
501 | ;r9 |
||
502 | ;r8 |
||
503 | ;rdx |
||
504 | ;rcx |
||
505 | sub rsp, 4*8 |
||
506 | ;call function |
||
507 | call rbx |
||
508 | ;restore old stack |
||
509 | mov rsp, qword [uefi_rsptmp] |
||
510 | ret |
||
8092 | dunkaist | 511 | |
7130 | dunkaist | 512 | section '.data' data readable writeable |
513 | efi_handler dq 0 |
||
514 | efi_ptr dq 0 |
||
515 | uefi_rsptmp dq 0 |