aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / boot / efi_entry_x86_64.S
| 1 | /* efi_entry_x86_64.S -- UEFI entry of an AIENOS x86_64 image (AIENOS-IMAC-BOOT-0). |
| 2 | * Firmware calls _start(ImageHandle, SystemTable) in long mode with the |
| 3 | * Microsoft x64 convention (RCX, RDX; UEFI 2.10 section 2.3.4). The image is |
| 4 | * linked at 0 and loaded anywhere: apply our R_X86_64_RELATIVE relocations |
| 5 | * against the load address, zero .bss, then call efi_main (built -mabi=ms). |
| 6 | * Only volatile registers (RAX, RCX, RDX, R8-R11) are touched before the call. |
| 7 | * This runs exactly once per load. */ |
| 8 | .section .text.entry, "ax" |
| 9 | .global _start |
| 10 | .type _start, @function |
| 11 | _start: |
| 12 | push %rbp |
| 13 | mov %rsp, %rbp |
| 14 | push %rcx |
| 15 | push %rdx |
| 16 | lea __image_base(%rip), %r8 /* load address == link offset 0 */ |
| 17 | lea __rela_start(%rip), %r9 |
| 18 | lea __rela_end(%rip), %r10 |
| 19 | 1: cmp %r10, %r9 |
| 20 | jae 3f |
| 21 | mov 8(%r9), %rax /* r_info */ |
| 22 | mov %eax, %eax /* type: low 32 bits */ |
| 23 | add $24, %r9 |
| 24 | cmp $8, %rax /* R_X86_64_RELATIVE */ |
| 25 | jne 2f |
| 26 | mov -8(%r9), %r11 /* r_addend */ |
| 27 | add %r8, %r11 |
| 28 | mov -24(%r9), %rcx /* r_offset */ |
| 29 | mov %r11, (%r8,%rcx) |
| 30 | jmp 1b |
| 31 | 2: test %rax, %rax /* R_X86_64_NONE */ |
| 32 | jz 1b |
| 33 | movabs $0x8000000000000001, %rax /* unexpected relocation type: EFI_LOAD_ERROR */ |
| 34 | mov %rbp, %rsp |
| 35 | pop %rbp |
| 36 | ret |
| 37 | 3: lea __bss_start(%rip), %r9 |
| 38 | lea __bss_end(%rip), %r10 |
| 39 | 4: cmp %r10, %r9 |
| 40 | jae 5f |
| 41 | movq $0, (%r9) |
| 42 | add $8, %r9 |
| 43 | jmp 4b |
| 44 | 5: pop %rdx |
| 45 | pop %rcx |
| 46 | sub $32, %rsp /* shadow space; RSP stays 16-byte aligned */ |
| 47 | call efi_main |
| 48 | mov %rbp, %rsp |
| 49 | pop %rbp |
| 50 | ret |
| 51 | .size _start, . - _start |
| 52 | .section .note.GNU-stack, "", @progbits |