diff options
Diffstat (limited to 'efi/hello.c')
| -rw-r--r-- | efi/hello.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/efi/hello.c b/efi/hello.c new file mode 100644 index 0000000..35cd86d --- /dev/null +++ b/efi/hello.c @@ -0,0 +1,52 @@ +/* + * Болваночный EFI-апп для amd64 (bootx64.efi), PE32+. + * Собирается ПОРТИРОВАННЫМ тулчейном Plan9 (6c/6a/6l) на Linux/musl: + * PE-заголовок и entry -> pe64.s (ассемблер 6a), из 9legacy nboot/efi. + * Печать -> UEFI SIMPLE_TEXT_OUTPUT_PROTOCOL (efi.h из 9legacy). + * Контракт входа задаёт pe64.s: reloc кладёт SystemTable, прыгает на efimain(ih, st). + */ +#include <u.h> +#include "efi.h" + +/* глобалы, которых ждёт контракт (как в референсном efi.c) */ +EFI_HANDLE IH; +EFI_SYSTEM_TABLE *ST; + +/* вызов EFI-функции по MS-x64 ABI — реализован в pe64.s */ +extern uintptr eficall(void *fn, ...); + +/* печать ASCII-строки через ConOut (конверт в UTF-16, \n -> \r\n) */ +static void +eputs(char *s) +{ + CHAR16 w[2]; + + w[1] = 0; + for(; *s; s++){ + if(*s == '\n'){ + w[0] = '\r'; + eficall(ST->ConOut->OutputString, ST->ConOut, w); + } + w[0] = (uchar)*s; + eficall(ST->ConOut->OutputString, ST->ConOut, w); + } +} + +void +efimain(EFI_HANDLE ih, EFI_SYSTEM_TABLE *st) +{ + IH = ih; + ST = st; + + eputs("\n"); + eputs("+--------------------------------------------------+\n"); + eputs("| Hello from a Plan 9 kencc EFI application |\n"); + eputs("| compiler/assembler/linker: 6c / 6a / 6l |\n"); + eputs("| cross-built on Linux/musl, wrapped as PE32+ |\n"); + eputs("+--------------------------------------------------+\n"); + eputs("\nefimain reached OK. Idling via BootServices->Stall.\n"); + + /* болванка: просто крутимся, чтобы прошивка не считала нас упавшими */ + for(;;) + eficall(ST->BootServices->Stall, (UINTN)1000000); +} |
