NeKernel dev
Loading...
Searching...
No Matches
API.h
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5======================================== */
6
7#ifndef __EFI_API__
8#define __EFI_API__
9
10#include <FirmwareKit/EFI/EFI.h>
12#include <KernelKit/MSDOS.h>
13#include <KernelKit/PE.h>
14
15#ifdef __BOOTZ__
16// forward decl.
17class BootTextWriter;
18
19#define __BOOTKIT_NO_INCLUDE__ 1
20
21#include <BootKit/BootKit.h>
23#endif // ifdef __BOOTZ__
24
25inline EfiSystemTable* ST = nullptr;
26inline EfiBootServices* BS = nullptr;
27
30
31namespace Boot {
34inline Void Stop() {
35 while (YES) {
36 rt_cli();
37 rt_halt();
38 }
39}
40
45inline Void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) {
46 if (!ST) return;
47
48 ST->BootServices->ExitBootServices(ImageHandle, MapKey);
49}
50
51inline UInt32 Platform() {
52 return kPeMachineAMD64;
53}
54
55/***
56 * @brief Throw an error, stop execution as well.
57 * @param ErrorCode error code to be print.
58 * @param Reason reason to be print.
59 */
60inline void ThrowError(const EfiCharType* ErrorCode, const EfiCharType* Reason) {
61 ST->ConOut->OutputString(ST->ConOut, L"\r*** STOP ***\r");
62
63 ST->ConOut->OutputString(ST->ConOut, L"*** ERROR: ");
64 ST->ConOut->OutputString(ST->ConOut, ErrorCode);
65
66 ST->ConOut->OutputString(ST->ConOut, L" ***\r *** REASON: ");
67 ST->ConOut->OutputString(ST->ConOut, Reason);
68
69 ST->ConOut->OutputString(ST->ConOut, L" ***\r");
70
71 Boot::Stop();
72}
73} // namespace Boot
74
75inline void fw_init_efi(EfiSystemTable* SystemTable) {
76 if (!SystemTable) return;
77
78 ST = SystemTable;
79 BS = ST->BootServices;
80}
81
82#ifdef __BOOTZ__
83
84#include <BootKit/Platform.h>
85
86#endif // ifdef __BOOTZ__
87
88#endif /* ifndef __EFI_API__ */
EXTERN_C void rt_cli()
EfiSystemTable * ST
Definition API.h:25
void fw_init_efi(EfiSystemTable *SystemTable)
Definition API.h:75
EXTERN_C void rt_halt()
Bootloader Application Programming Interface.
EXTERN EfiBootServices * BS
External boot services symbol.
Definition BootThread.cc:21
WideChar EfiCharType
Definition EFI.h:63
struct EfiHandle * EfiHandlePtr
Core Handle Kind Self is like NT's Win32 HANDLE type.
#define YES
#define EXTERN_C
The handover boot protocol.
#define kPeMachineAMD64
Definition PE.h:24
Platform specific code.
Framebuffer helpers.
Definition BootKit.h:42
void ThrowError(const WideChar *errorCode, const WideChar *reason)
Definition API.h:60
UInt32 Platform()
Definition API.h:51
Void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle)
Exit EFI API to let the OS load correctly. Bascially frees everything we have in the EFI side.
Definition API.h:45
Void Stop()
Halt and clear interrut flag on x86.
Definition API.h:34
void Void
Definition Config.h:87
__UINT32_TYPE__ UInt32
Definition Config.h:44
__UINT64_TYPE__ UInt64
Definition Config.h:48
Definition EFI.h:512
The Structure that they give you when booting.
Definition EFI.h:627