1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include <efi/types.h>
#include <efi/error.h>
#include <efi/media.h>
#include <efi/tables.h>
#include "../kjarna.h"
#include "../config.h"
#include <libc/stdio.h>
#include "kjarna_efi.h"
struct efi_context const *efi_context;
EFI_STATUS efi_errno = EFI_SUCCESS;
EFI_STATUS _exit(EFI_STATUS status)
{
return gBS->Exit(efi_context->handle, status, 0, nullptr);
}
EFI_STATUS _start(EFI_HANDLE handle, EFI_SYSTEM_TABLE *system_table)
{
struct efi_context app_context = { handle, system_table };
efi_context = &app_context;
system_table->ConOut->ClearScreen(system_table->ConOut);
#ifdef DEBUG_WAIT
EFI_GUID lip_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
EFI_LOADED_IMAGE_PROTOCOL *lip = efi_get_protocol(efi_context->handle, &lip_guid);
uint64_t text_base;
uint64_t data_base;
printf("DEBUG: EFI_LOADED_IMAGE_PROTOCOL { .ImageBase = %p }\n", lip->ImageBase);
__asm__ volatile ("movq %0, %%rax" :: "r"(lip->ImageBase) : "rax");
__asm__ volatile (
"lea .text, %0\n"
"lea .data, %1\n"
: "=r"(text_base), "=r"(data_base)
:
);
printf("DEBUG: .text %p .data %p\n", text_base, data_base);
bool wait = true;
while(wait)
{
__asm__ ("hlt");
}
#endif
if (main(0, nullptr) != 0)
{
efi_errno = EFI_ABORTED;
}
return _exit(efi_errno);
}
|