summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/FirmwareKit/EFI/API.h
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-12-21 21:59:13 +0100
committerAmlal <amlalelmahrouss@icloud.com>2024-12-21 21:59:45 +0100
commit610f91d87152cbe48d3054fcf437d8239da6ef35 (patch)
treea386f7047ab73d088169ab2371ddc6ffe8020f1c /dev/Kernel/FirmwareKit/EFI/API.h
parent509fcca5986651c8ba712fb395f8498f2dea4109 (diff)
IMP: :boom: Breaking changes some checks are needed to be done.
Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/FirmwareKit/EFI/API.h')
-rw-r--r--dev/Kernel/FirmwareKit/EFI/API.h114
1 files changed, 114 insertions, 0 deletions
diff --git a/dev/Kernel/FirmwareKit/EFI/API.h b/dev/Kernel/FirmwareKit/EFI/API.h
new file mode 100644
index 00000000..096a3157
--- /dev/null
+++ b/dev/Kernel/FirmwareKit/EFI/API.h
@@ -0,0 +1,114 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024, TQ B.V, all rights reserved.
+
+------------------------------------------- */
+
+#ifndef __EFI_API__
+#define __EFI_API__
+
+#include <FirmwareKit/EFI/EFI.h>
+#include <FirmwareKit/Handover.h>
+#include <KernelKit/MSDOS.h>
+#include <KernelKit/PE.h>
+
+#define kZKASubsystem 17
+
+#ifdef __ZBAOSLDR__
+// forward decl.
+class BTextWriter;
+
+#define __BOOTKIT_NO_INCLUDE__ 1
+
+#include <BootKit/BootKit.h>
+#include <Modules/FB/FB.h>
+#endif // ifdef __ZBAOSLDR__
+
+inline EfiSystemTable* ST = nullptr;
+inline EfiBootServices* BS = nullptr;
+
+EXTERN_C void rt_cli();
+EXTERN_C void rt_hlt();
+
+namespace EFI
+{
+ /// @brief Halt and clear interrupts.
+ /// @return
+ inline Void Stop() noexcept
+ {
+ while (1)
+ {
+ rt_hlt();
+ rt_cli();
+ }
+ }
+
+ /**
+@brief Exit EFI API to let the OS load correctly.
+Bascially frees everything we have in the EFI side.
+*/
+ inline void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept
+ {
+ if (!ST)
+ return;
+
+ ST->BootServices->ExitBootServices(ImageHandle, MapKey);
+ }
+
+ enum
+ {
+ kPartEPM,
+ kPartGPT,
+ kPartMBR,
+ kPartCnt,
+ };
+
+ inline UInt32 Platform() noexcept
+ {
+ return kPeMachineAMD64;
+ }
+
+ /***
+ * @brief Throw an error, stop execution as well.
+ * @param ErrorCode error code to be print.
+ * @param Reason reason to be print.
+ */
+ inline void ThrowError(const EfiCharType* ErrorCode,
+ const EfiCharType* Reason) noexcept
+ {
+ ST->ConOut->OutputString(ST->ConOut, L"\r*** STOP ***\r");
+
+ ST->ConOut->OutputString(ST->ConOut, L"*** Error: ");
+ ST->ConOut->OutputString(ST->ConOut, ErrorCode);
+
+ ST->ConOut->OutputString(ST->ConOut, L", Reason: ");
+ ST->ConOut->OutputString(ST->ConOut, Reason);
+
+ ST->ConOut->OutputString(ST->ConOut, L" ***\r");
+
+ EFI::Stop();
+ }
+} // namespace EFI
+
+inline void InitEFI(EfiSystemTable* SystemTable) noexcept
+{
+ if (!SystemTable)
+ return;
+
+ ST = SystemTable;
+ BS = ST->BootServices;
+
+ ST->ConOut->ClearScreen(SystemTable->ConOut);
+ ST->ConOut->SetAttribute(SystemTable->ConOut, kEFIYellow);
+
+ ST->BootServices->SetWatchdogTimer(0, 0, 0, nullptr);
+ ST->ConOut->EnableCursor(ST->ConOut, false);
+}
+
+#ifdef __ZBAOSLDR__
+
+#include <BootKit/Platform.h>
+
+#endif // ifdef __ZBAOSLDR__
+
+#endif /* ifndef __EFI_API__ */