summaryrefslogtreecommitdiff
path: root/lib/uefi.c3l/src/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'lib/uefi.c3l/src/protocol')
-rw-r--r--lib/uefi.c3l/src/protocol/console.c3225
-rw-r--r--lib/uefi.c3l/src/protocol/evt_timer_task.c3103
-rw-r--r--lib/uefi.c3l/src/protocol/handler.c386
-rw-r--r--lib/uefi.c3l/src/protocol/image.c327
-rw-r--r--lib/uefi.c3l/src/protocol/mem.c3105
-rw-r--r--lib/uefi.c3l/src/protocol/misc_boot_svcs.c325
-rw-r--r--lib/uefi.c3l/src/protocol/misc_runtime_svcs.c3124
-rw-r--r--lib/uefi.c3l/src/protocol/time.c323
-rw-r--r--lib/uefi.c3l/src/protocol/variable.c368
9 files changed, 786 insertions, 0 deletions
diff --git a/lib/uefi.c3l/src/protocol/console.c3 b/lib/uefi.c3l/src/protocol/console.c3
new file mode 100644
index 0000000..1e30f30
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/console.c3
@@ -0,0 +1,225 @@
+module uefi::proto::console;
+import uefi;
+
+
+/***/
+bitstruct ConsoleColor : char @bigendian
+{
+ TextColor background : 0..3;
+ TextColor foreground : 4..7; /* NOTE: bit '7' is technically not used per spec */
+}
+
+
+/* 12.1.) Console I/O Protocol (Scan Codes - see Appendix B, Table B.1) */
+enum ScanCode : ushort (ushort raw)
+{
+ NULL { 0x0000 },
+ UP_ARROW { 0x0001 },
+ DOWN_ARROW { 0x0002 },
+ RIGHT_ARROW { 0x0003 },
+ LEFT_ARROW { 0x0004 },
+ HOME { 0x0005 },
+ END { 0x0006 },
+ INSERT { 0x0007 },
+ DELETE { 0x0008 },
+ PAGE_UP { 0x0009 },
+ PAGE_DOWN { 0x000A },
+ F1 { 0x000B },
+ F2 { 0x000C },
+ F3 { 0x000D },
+ F4 { 0x000E },
+ F5 { 0x000F },
+ F6 { 0x0010 },
+ F7 { 0x0011 },
+ F8 { 0x0012 },
+ F9 { 0x0013 },
+ F10 { 0x0014 },
+ F11 { 0x0015 },
+ F12 { 0x0016 },
+ ESCAPE { 0x0017 },
+ PAUSE { 0x0048 },
+ F13 { 0x0068 },
+ F14 { 0x0069 },
+ F15 { 0x006A },
+ F16 { 0x006B },
+ F17 { 0x006C },
+ F18 { 0x006D },
+ F19 { 0x006E },
+ F20 { 0x006F },
+ F21 { 0x0070 },
+ F22 { 0x0071 },
+ F23 { 0x0072 },
+ F24 { 0x0073 },
+ MUTE { 0x007F },
+ VOLUME_UP { 0x0080 },
+ VOLUME_DOWN { 0x0081 },
+ BRIGHTNESS_UP { 0x0100 },
+ BRIGHTNESS_DOWN { 0x0101 },
+ SUSPEND { 0x0102 },
+ HIBERNATE { 0x0103 },
+ TOGGLE_DISPLAY { 0x0104 },
+ RECOVERY { 0x0105 },
+ EJECT { 0x0106 },
+}
+
+
+/* 12.3.) Simple Text Input Protocol */
+module uefi::guid;
+const EfiGuid SIMPLE_TEXT_INPUT_PROTOCOL = {
+ 0x387477c1,
+ 0x69c7,
+ 0x11d2,
+ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }
+};
+const EfiGuid SIMPLE_TEXT_INPUT_EX_PROTOCOL = {
+ 0xdd9e7534,
+ 0x7762,
+ 0x4698,
+ { 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa }
+};
+
+module uefi::proto::console;
+struct SimpleTextInputProtocol
+{
+ FnInputReset reset;
+ FnInputReadKey read_key;
+ EfiEvent event_wait_for_key;
+}
+
+struct EfiInputKey
+{
+ ushort scan_code;
+ ushort unicode_char;
+}
+
+alias FnInputReset = fn EfiStatus(SimpleTextInputProtocol*, bool);
+alias FnInputReadKey = fn EfiStatus(SimpleTextInputProtocol*, EfiInputKey*);
+
+
+/* 12.2.) Simple Text Input Ex Protocol */
+struct SimpleTextInputExProtocol
+{
+ FnInputResetEx reset;
+ FnInputReadKeyEx read_key;
+ EfiEvent event_wait_for_key;
+ FnInputSetState set_state;
+ FnInputRegisterKeystrokeNotify register_keystroke_notify;
+ FnInputUnregisterKeystrokeNotify unregister_keystroke_notify;
+}
+
+enum KeyShiftState : uint (uint raw)
+{
+ SHIFT_STATE_VALID { 0x8000_0000 },
+ RIGHT_SHIFT_PRESSED { 0x0000_0001 },
+ LEFT_SHIFT_PRESSED { 0x0000_0002 },
+ RIGHT_CONTROL_PRESSED { 0x0000_0004 },
+ LEFT_CONTROL_PRESSED { 0x0000_0008 },
+ RIGHT_ALT_PRESSED { 0x0000_0010 },
+ LEFT_ALT_PRESSED { 0x0000_0020 },
+ RIGHT_LOGO_PRESSED { 0x0000_0040 },
+ LEFT_LOGO_PRESSED { 0x0000_0080 },
+ MENU_KEY_PRESSED { 0x0000_0100 },
+ SYS_REQ_PRESSED { 0x0000_0200 },
+}
+
+enum KeyToggleState : char (char raw)
+{
+ TOGGLE_STATE_VALID { 0x80 },
+ KEY_STATE_EXPOSED { 0x40 },
+ SCROLL_LOCK_ACTIVE { 0x01 },
+ NUM_LOCK_ACTIVE { 0x02 },
+ CAPS_LOCK_ACTIVE { 0x04 },
+}
+
+struct EfiKeyState
+{
+ KeyShiftState key_shift_state;
+ KeyToggleState key_toggle_state;
+}
+
+struct EfiKeyData
+{
+ EfiInputKey key;
+ EfiKeyState key_state;
+}
+
+alias FnInputResetEx = fn EfiStatus(SimpleTextInputExProtocol*, bool);
+alias FnInputReadKeyEx = fn EfiStatus(SimpleTextInputExProtocol*, EfiKeyData*);
+alias FnInputSetState = fn EfiStatus(SimpleTextInputExProtocol*, KeyToggleState*);
+alias FnInputRegisterKeystrokeNotify = fn EfiStatus(
+ SimpleTextInputExProtocol*,
+ EfiKeyData*,
+ FnKeyNotificationFunction,
+ void**
+);
+alias FnInputUnregisterKeystrokeNotify = fn EfiStatus(EfiKeyData*);
+
+alias FnKeyNotificationFunction = fn EfiStatus(EfiKeyData*);
+
+
+/* 12.4.) Simple Text Output Protocol */
+module uefi::guid;
+const EfiGuid SIMPLE_TEXT_OUTPUT_PROTOCOL = {
+ 0x387477c2,
+ 0x69c7,
+ 0x11d2,
+ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }
+};
+
+module uefi::proto::console;
+struct SimpleTextOutputProtocol
+{
+ FnOutputReset reset;
+ FnOutputString output_string;
+ FnOutputTestString test_string;
+ FnOutputQueryMode query_mode;
+ FnOutputSetMode set_mode;
+ FnOutputSetAttribute set_attribute;
+ FnOutputClearScreen clear_screen;
+ FnOutputSetCursorPosition set_cursor_position;
+ FnOutputEnableCursor enable_cursor;
+ TextMode* mode;
+}
+
+struct TextMode
+{
+ int max_mode;
+ int current_mode;
+ int current_attribute;
+ int current_cursor_column;
+ int current_cursor_row;
+ bool is_cursor_visible;
+}
+
+alias FnOutputReset = fn EfiStatus(SimpleTextOutputProtocol*, bool);
+alias FnOutputString = fn EfiStatus(SimpleTextOutputProtocol*, EfiStringRaw);
+alias FnOutputTestString = fn EfiStatus(SimpleTextOutputProtocol*, EfiStringRaw);
+alias FnOutputQueryMode = fn EfiStatus(SimpleTextOutputProtocol*, usz, usz*, usz*);
+alias FnOutputSetMode = fn EfiStatus(SimpleTextOutputProtocol*, usz);
+alias FnOutputSetAttribute = fn EfiStatus(SimpleTextOutputProtocol*, usz);
+alias FnOutputClearScreen = fn EfiStatus(SimpleTextOutputProtocol*);
+alias FnOutputSetCursorPosition = fn EfiStatus(SimpleTextOutputProtocol*, usz, usz);
+alias FnOutputEnableCursor = fn EfiStatus(SimpleTextOutputProtocol*, bool);
+
+/* Standard terminal color constants. */
+enum TextColor : char (char raw)
+{
+ BLACK { 0x00 },
+ BLUE { 0x01 },
+ GREEN { 0x02 },
+ CYAN { 0x03 },
+ RED { 0x04 },
+ MAGENTA { 0x05 },
+ BROWN { 0x06 },
+ LIGHT_GRAY { 0x07 },
+ DARK_GRAY { 0x08 }, /* BRIGHT, or (BLACK|BRIGHT) */
+ LIGHT_BLUE { 0x09 },
+ LIGHT_GREEN { 0x0A },
+ LIGHT_CYAN { 0x0B },
+ LIGHT_RED { 0x0C },
+ LIGHT_MAGENTA { 0x0D },
+ YELLOW { 0x0E },
+ WHITE { 0x0F },
+}
+
+macro char @efi_color($fg, $bg) @builtin @public => ($fg | ((0x07 & $bg) << 4)); \ No newline at end of file
diff --git a/lib/uefi.c3l/src/protocol/evt_timer_task.c3 b/lib/uefi.c3l/src/protocol/evt_timer_task.c3
new file mode 100644
index 0000000..3d2929b
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/evt_timer_task.c3
@@ -0,0 +1,103 @@
+module uefi::proto::evt;
+import uefi;
+
+
+/* 7.1.) Event, Timer, and Task Priority Services */
+/* NOTE: EfiEvent is defined in ../def.c3, as it's more globally used. */
+enum EventType : uint (uint raw)
+{
+ TIMER { 0x8000_0000 },
+ RUNTIME { 0x4000_0000 },
+ NOTIFY_WAIT { 0x0000_0100 },
+ NOTIFY_SIGNAL { 0x0000_0200 },
+ SIGNAL_EXIT_BOOT_SERVICES { 0x0000_0201 },
+ SIGNAL_VIRTUAL_ADDRESS_CHANGE { 0x6000_0202 },
+}
+
+
+/* EFI_EVENT_NOTIFY (7.1.1) */
+alias FnEventNotify = fn void(EfiEvent, void*);
+
+/* EFI_CREATE_EVENT (7.1.1) */
+alias FnCreateEvent = fn EfiStatus(EventType, EventTpl, FnEventNotify, void*, EfiEvent*);
+
+/* EFI_CREATE_EVENT_EX (7.1.2) */
+alias FnCreateEventEx = fn EfiStatus(EventType, EventTpl, FnEventNotify, void*, EfiGuid*, EfiEvent*);
+
+/* EFI event group GUIDs (7.1.2) */
+const EfiGuid EVENT_GROUP_EXIT_BOOT_SERVICES = {
+ 0x27abf055,
+ 0xb1b8,
+ 0x4c26,
+ { 0x80, 0x48, 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf }
+};
+const EfiGuid EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES = {
+ 0x8be0e274,
+ 0x3970,
+ 0x4b44,
+ { 0x80, 0xc5, 0x1a, 0xb9, 0x50, 0x2f, 0x3b, 0xfc }
+};
+const EfiGuid EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE = {
+ 0x13fa7698,
+ 0xc831,
+ 0x49c7,
+ { 0x87, 0xea, 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96 }
+};
+const EfiGuid EVENT_GROUP_MEMORY_MAP_CHANGE = {
+ 0x78bee926,
+ 0x692f,
+ 0x48fd,
+ { 0x9e, 0xdb, 0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab }
+};
+const EfiGuid EVENT_GROUP_READY_TO_BOOT = {
+ 0x7ce88fb3,
+ 0x4bd7,
+ 0x4679,
+ { 0x87, 0xa8, 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b }
+};
+const EfiGuid EVENT_GROUP_AFTER_READY_TO_BOOT = {
+ 0x3a2a00ad,
+ 0x98b9,
+ 0x4cdf,
+ { 0xa4, 0x78, 0x70, 0x27, 0x77, 0xf1, 0xc1, 0x0b }
+};
+const EfiGuid EVENT_GROUP_RESET_SYSTEM = {
+ 0x62da6a56,
+ 0x13fb,
+ 0x485a,
+ { 0xa8, 0xda, 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b }
+};
+
+/* EFI_CLOSE_EVENT (7.1.3) */
+alias FnCloseEvent = fn EfiStatus(EfiEvent);
+
+/* EFI_SIGNAL_EVENT (7.1.4) */
+alias FnSignalEvent = fn EfiStatus(EfiEvent);
+
+/* EFI_WAIT_FOR_EVENT (7.1.5) */
+alias FnWaitForEvent = fn EfiStatus(usz, EfiEvent*, usz*);
+
+/* EFI_CHECK_EVENT (7.1.6) */
+alias FnCheckEvent = fn EfiStatus(EfiEvent);
+
+/* EFI_SET_TIMER (7.1.7) and EFI_TIMER_DELAY */
+alias FnSetTimer = fn EfiStatus(EfiEvent, TimerDelay, ulong);
+
+enum TimerDelay
+{
+ TIMER_CANCEL,
+ TIMER_PERIODIC,
+ TIMER_RELATIVE,
+}
+
+/* EFI_RAISE_TPL (7.1.8) and TPL */
+alias FnRaiseTpl = fn EventTpl(EventTpl);
+
+typedef EventTpl = usz;
+const EventTpl TPL_APPLICATION = (EventTpl)4;
+const EventTpl TPL_CALLBACK = (EventTpl)8;
+const EventTpl TPL_NOTIFY = (EventTpl)16;
+const EventTpl TPL_HIGH_LEVEL = (EventTpl)31;
+
+/* EFI_RESTORE_TPL (7.1.9) */
+alias FnRestoreTpl = fn void(EventTpl);
diff --git a/lib/uefi.c3l/src/protocol/handler.c3 b/lib/uefi.c3l/src/protocol/handler.c3
new file mode 100644
index 0000000..5bc9e86
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/handler.c3
@@ -0,0 +1,86 @@
+module uefi::proto::handle;
+import uefi;
+
+
+/* 7.3) Protocol Handler Services */
+/* EFI_INSTALL_PROTOCOL_INTERFACE (7.3.2) and related definitions */
+alias FnInstallProtocolInterface = fn EfiStatus(EfiHandle*, EfiGuid*, InterfaceType, void*);
+
+/* NOTE: EFI_HANDLE and EFI_GUID are defined in the def.c3 globals file. */
+enum InterfaceType
+{
+ NATIVE_INTERFACE,
+}
+
+/* EFI_UNINSTALL_PROTOCOL_INTERFACE (7.3.3) */
+alias FnUninstallProtocolInterface = fn EfiStatus(EfiHandle*, EfiGuid*, void*);
+
+/* EFI_REINSTALL_PROTOCOL_INTERFACE (7.3.4) */
+alias FnReinstallProtocolInterface = fn EfiStatus(EfiHandle*, EfiGuid*, void*, void*);
+
+/* EFI_REGISTER_PROTOCOL_NOTIFY (7.3.5) */
+alias FnRegisterProtocolNotify = fn EfiStatus(EfiGuid*, EfiEvent, void**);
+
+/* EFI_LOCATE_HANDLE (7.3.6) and related */
+alias FnLocateHandle = fn EfiStatus(HandleSearchType, EfiGuid*, void*, usz*, EfiHandle*);
+
+enum HandleSearchType
+{
+ ALL_HANDLES,
+ BY_REGISTER_NOTIFY,
+ BY_PROTOCOL,
+}
+
+/* EFI_HANDLE_PROTOCOL (7.3.7) */
+alias FnHandleProtocol = fn EfiStatus(EfiHandle, EfiGuid*, void**);
+
+/* EFI_LOCATE_DEVICE_PATH (7.3.8) */
+// alias FnLocateDevicePath = fn EfiStatus(EfiGuid*, device::DevicePathProtocol**, EfiHandle*);
+alias FnLocateDevicePath = fn EfiStatus(EfiGuid*, void**, EfiHandle*);
+
+/* EFI_OPEN_PROTOCOL (7.3.9) and related */
+alias FnOpenProtocol = fn EfiStatus(EfiHandle, EfiGuid*, void**, EfiHandle, EfiHandle, OpenProtocolAttribute);
+
+alias OpenProtocolAttribute = uint;
+const OpenProtocolAttribute BY_HANDLE_PROTOCOL = 0x0000_0001;
+const OpenProtocolAttribute GET_PROTOCOL = 0x0000_0002;
+const OpenProtocolAttribute TEST_PROTOCOL = 0x0000_0004;
+const OpenProtocolAttribute BY_CHILD_CONTROLLER = 0x0000_0008;
+const OpenProtocolAttribute BY_DRIVER = 0x0000_0010;
+const OpenProtocolAttribute EXCLUSIVE = 0x0000_0020;
+
+/* EFI_CLOSE_PROTOCOL (7.3.10) */
+alias FnCloseProtocol = fn EfiStatus(EfiHandle, EfiGuid*, EfiHandle, EfiHandle);
+
+/* EFI_OPEN_PROTOCOL_INFORMATION (7.3.11) and related */
+alias FnOpenProtocolInformation = fn EfiStatus(EfiHandle, EfiGuid*, OpenProtocolInformationEntry**, usz*);
+
+struct OpenProtocolInformationEntry
+{
+ EfiHandle agent_handle;
+ EfiHandle controller_handle;
+ OpenProtocolAttribute attributes;
+ uint open_count;
+}
+
+/* EFI_CONNECT_CONTROLLER (7.3.12) */
+// alias FnConnectController = fn EfiStatus(EfiHandle, EfiHandle*, device::DevicePathProtocol*, bool);
+alias FnConnectController = fn EfiStatus(EfiHandle, EfiHandle*, void*, bool);
+
+/* EFI_DISCONNECT_CONTROLLER (7.3.13) */
+alias FnDisconnectController = fn EfiStatus(EfiHandle, EfiHandle, EfiHandle);
+
+/* EFI_PROTOCOLS_PER_HANDLE (7.3.14) */
+alias FnProtocolsPerHandle = fn EfiStatus(EfiHandle, EfiGuid***, usz*);
+
+/* EFI_LOCATE_HANDLE_BUFFER (7.3.15) */
+alias FnLocateHandleBuffer = fn EfiStatus(HandleSearchType, EfiGuid*, void*, usz*, EfiHandle**);
+
+/* EFI_LOCATE_PROTOCOL (7.3.16) */
+alias FnLocateProtocol = fn EfiStatus(EfiGuid*, void*, void**);
+
+/* EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES (7.3.17) */
+alias FnInstallMultipleProtocolInterfaces = fn EfiStatus(EfiHandle*, ...);
+
+/* EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES (7.3.18) */
+alias FnUninstallMultipleProtocolInterfaces = fn EfiStatus(EfiHandle, ...); \ No newline at end of file
diff --git a/lib/uefi.c3l/src/protocol/image.c3 b/lib/uefi.c3l/src/protocol/image.c3
new file mode 100644
index 0000000..eb1a4b1
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/image.c3
@@ -0,0 +1,27 @@
+module uefi::proto::image;
+import uefi;
+
+
+/* 7.4) Image Services */
+/* EFI_IMAGE_LOAD (7.4.1) */
+// alias FnLoadImage = fn EfiStatus(bool, EfiHandle, device::DevicePathProtocol*, void*, usz, EfiHandle*);
+alias FnLoadImage = fn EfiStatus(bool, EfiHandle, void*, void*, usz, EfiHandle*);
+
+/* const EfiGuid HII_PACKAGE_LIST_PROTOCOL =
+ { 0x6a1ee763, 0xd47a, 0x43b4, {0xaa,0xbe,0xef,0x1d,0xe2,0xab,0x56,0xfc} };
+alias HiiPackageListHeader = hii::PackageListProtocol; */
+
+/* EFI_IMAGE_START (7.4.2) */
+alias FnStartImage = fn EfiStatus(EfiHandle, usz*, EfiStringRaw*);
+
+/* EFI_IMAGE_UNLOAD (7.4.3) */
+alias FnUnloadImage = fn EfiStatus(EfiHandle);
+
+/* EFI_IMAGE_ENTRY_POINT (7.4.4) */
+alias FnImageEntryPoint = fn EfiStatus(EfiHandle, SystemTable*);
+
+/* EFI_EXIT (7.4.5) */
+alias FnExitImage = fn EfiStatus(EfiHandle, EfiStatus, usz, EfiStringRaw);
+
+/* EFI_EXIT_BOOT_SERVICES (7.4.6) */
+alias FnExitBootServices = fn EfiStatus(EfiHandle, usz); \ No newline at end of file
diff --git a/lib/uefi.c3l/src/protocol/mem.c3 b/lib/uefi.c3l/src/protocol/mem.c3
new file mode 100644
index 0000000..8bb2cbb
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/mem.c3
@@ -0,0 +1,105 @@
+module uefi::proto::memory;
+import uefi;
+
+
+/* 7.2.) Memory Allocation Services */
+
+/* EFI_ALLOCATE_PAGES (7.2.1) and Allocation definitions */
+alias FnAllocatePages = fn EfiStatus(AllocateType, MemoryType, usz, PhysicalAddress*);
+
+alias PhysicalAddress = ulong;
+alias VirtualAddress = ulong;
+enum AllocateType
+{
+ ANY_PAGES,
+ MAX_ADDRESS,
+ ADDRESS,
+ LIMIT
+}
+enum MemoryType : uint
+{
+ RESERVED,
+ LOADER_CODE,
+ LOADER_DATA,
+ BOOT_SERVICES_CODE,
+ BOOT_SERVICES_DATA,
+ RUNTIME_SERVICES_CODE,
+ RUNTIME_SERVICES_DATA,
+ CONVENTIONAL,
+ UNUSABLE,
+ ACPI_RECLAIM,
+ ACPI_NVS,
+ MMIO,
+ MMIO_PORT_SPACE,
+ PAL_CODE,
+ PERSISTENT,
+ UNACCEPTED,
+ LIMIT
+}
+
+/* EFI_FREE_PAGES (7.2.2) */
+alias FnFreePages = fn EfiStatus(PhysicalAddress, usz);
+
+/* EFI_GET_MEMORY_MAP (7.2.3) and related definitions */
+alias FnGetMemoryMap = fn EfiStatus(usz*, void*, usz*, usz*, uint*);
+
+const uint MEMORY_DESCRIPTOR_VERSION = 1;
+struct MemoryDescriptor
+{
+ MemoryType type;
+ PhysicalAddress physical_start;
+ VirtualAddress virtual_start;
+ ulong num_pages;
+ MemoryAttribute attribute;
+}
+
+struct SystemMemoryMap
+{
+ usz map_key;
+ usz buffer_size;
+ usz descriptor_size;
+ uint descriptor_version;
+ void* descriptors;
+ usz descriptors_count;
+}
+
+typedef MemoryAttribute = ulong;
+const MemoryAttribute MEMORY_UC = (MemoryAttribute)0x0000_0000_0000_0001;
+const MemoryAttribute MEMORY_WC = (MemoryAttribute)0x0000_0000_0000_0002;
+const MemoryAttribute MEMORY_WT = (MemoryAttribute)0x0000_0000_0000_0004;
+const MemoryAttribute MEMORY_WB = (MemoryAttribute)0x0000_0000_0000_0008;
+const MemoryAttribute MEMORY_UCE = (MemoryAttribute)0x0000_0000_0000_0010;
+const MemoryAttribute MEMORY_WP = (MemoryAttribute)0x0000_0000_0000_1000;
+const MemoryAttribute MEMORY_RP = (MemoryAttribute)0x0000_0000_0000_2000;
+const MemoryAttribute MEMORY_XP = (MemoryAttribute)0x0000_0000_0000_4000;
+const MemoryAttribute MEMORY_NV = (MemoryAttribute)0x0000_0000_0000_8000;
+const MemoryAttribute MEMORY_MORE_RELIABLE = (MemoryAttribute)0x0000_0000_0001_0000;
+const MemoryAttribute MEMORY_RO = (MemoryAttribute)0x0000_0000_0002_0000;
+const MemoryAttribute MEMORY_SP = (MemoryAttribute)0x0000_0000_0004_0000;
+const MemoryAttribute MEMORY_CPU_CRYPTO = (MemoryAttribute)0x0000_0000_0008_0000;
+const MemoryAttribute MEMORY_HOT_PLUGGABLE = (MemoryAttribute)0x0000_0000_0010_0000;
+const MemoryAttribute MEMORY_RUNTIME = (MemoryAttribute)0x8000_0000_0000_0000;
+const MemoryAttribute MEMORY_ISA_VALID = (MemoryAttribute)0x4000_0000_0000_0000;
+const MemoryAttribute MEMORY_ISA_MASK = (MemoryAttribute)0x0FFF_F000_0000_0000;
+
+/* EFI_ALLOCATE_POOL (7.2.4) */
+alias FnAllocatePool = fn EfiStatus(MemoryType, usz, void**);
+
+/* EFI_FREE_POOL (7.2.5) */
+alias FnFreePool = fn EfiStatus(void*);
+
+
+/* 8.4.) Virtual Memory services */
+/* 8.4.1.) SetVirtualAddressMap() */
+alias FnSetVirtualAddressMap = fn EfiStatus(usz, usz, uint, MemoryDescriptor*);
+
+/* 8.4.2.) ConvertPointer() */
+alias FnConvertPointer = fn EfiStatus(usz, void**);
+const usz EFI_OPTIONAL_PTR = 0x1;
+
+/* 8.5.3.3.) Items related to capsules */
+struct MemoryRange
+{
+ PhysicalAddress address;
+ ulong length;
+}
diff --git a/lib/uefi.c3l/src/protocol/misc_boot_svcs.c3 b/lib/uefi.c3l/src/protocol/misc_boot_svcs.c3
new file mode 100644
index 0000000..8fc17af
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/misc_boot_svcs.c3
@@ -0,0 +1,25 @@
+module uefi::proto::misc_bs;
+import uefi;
+
+
+/* 7.5) Miscellaneous Boot Services */
+/* EFI_SET_WATCHDOG_TIMER (7.5.1) */
+alias FnSetWatchdogTimer = fn EfiStatus(usz, ulong, usz, EfiStringRaw);
+
+/* EFI_STALL (7.5.2) */
+alias FnStall = fn EfiStatus(usz);
+
+/* EFI_COPY_MEM (7.5.3) */
+alias FnCopyMem = fn void(void*, void*, usz);
+
+/* EFI_SET_MEM (7.5.4) */
+alias FnSetMem = fn void(void*, usz, char);
+
+/* EFI_GET_NEXT_MONOTONIC_COUNT (7.5.5) */
+alias FnGetNextMonotonicCount = fn EfiStatus(ulong*);
+
+/* EFI_INSTALL_CONFIGURATION_TABLE (7.5.6) */
+alias FnInstallConfigurationTable = fn EfiStatus(EfiGuid*, void*);
+
+/* EFI_CALCULATE_CRC32 (7.5.7) */
+alias FnCalculateCrc32 = fn EfiStatus(void*, usz, uint*); \ No newline at end of file
diff --git a/lib/uefi.c3l/src/protocol/misc_runtime_svcs.c3 b/lib/uefi.c3l/src/protocol/misc_runtime_svcs.c3
new file mode 100644
index 0000000..0ec0aba
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/misc_runtime_svcs.c3
@@ -0,0 +1,124 @@
+module uefi::proto::misc_rt;
+import uefi;
+
+
+/* 8.5.) Miscellaneous Runtime services */
+/* 8.5.1.1.) ResetSystem() */
+alias FnResetSystem = fn void(ResetType, EfiStatus, usz, void*);
+
+enum ResetType : uint
+{
+ COLD,
+ WARM,
+ SHUTDOWN,
+ PLATFORM_SPECIFIC,
+}
+
+/* 8.5.2.1.) GetNextHighMonotonicCount() */
+alias FnGetNextHighMonotonicCount = fn EfiStatus(uint*);
+
+/* 8.5.3.1.) UpdateCapsule() and related */
+alias FnUpdateCapsule = fn EfiStatus(CapsuleHeader**, usz, PhysicalAddress);
+
+struct CapsuleHeader
+{
+ EfiGuid capsule_guid;
+ uint header_size;
+ uint flags;
+ uint capsule_image_size;
+}
+
+enum CapsuleFlags : uint (uint raw)
+{
+ PERSIST_ACROSS_RESET { 0x0001_0000 },
+ POPULATE_SYSTEM_TABLE { 0x0002_0000 },
+ INITIATE_RESET { 0x0004_0000 },
+}
+
+struct CapsuleBlockDescriptor
+{
+ ulong length;
+ union
+ {
+ PhysicalAddress data_block;
+ PhysicalAddress continuation_pointer;
+ }
+}
+
+struct CapsuleTable
+{
+ uint capsule_array_number;
+ void* capsule_ptr;
+}
+
+const EfiGuid EFI_MEMORY_RANGE_CAPSULE_GUID = {
+ 0xde9f0ec,
+ 0x88b6,
+ 0x428f,
+ { 0x97, 0x7a, 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72 }
+};
+
+struct MemoryRangeCapsule
+{
+ CapsuleHeader header;
+ uint requested_memory_type;
+ ulong num_memory_ranges;
+ MemoryRange* memory_ranges;
+}
+
+struct MemoryRangeCapsuleResult
+{
+ ulong firmware_memory_requirement;
+ ulong num_memory_ranges;
+}
+
+/* 8.5.3.4.) QueryCapsuleCapabilities() */
+alias FnQueryCapsuleCapabilities = fn EfiStatus(CapsuleHeader**, usz, ulong*, ResetType*);
+
+/* OS Indications from a nearby section */
+enum OsIndications : ulong (ulong raw) // TODO: Change to inline ulong once supported
+{
+ BOOT_TO_FW_UI { 0x1 },
+ TIMESTAMP_REVOCATION { 0x2 },
+ FILE_CAPSULE_DELIVERY_SUPPORTED { 0x4 },
+ FMP_CAPSULE_SUPPORTED { 0x8 },
+ CAPSULE_RESULT_VAR_SUPPORTED { 0x10 },
+ START_OS_RECOVERY { 0x20 },
+ START_PLATFORM_RECOVERY { 0x40 },
+ JSON_CONFIG_DATA_REFRESH { 0x80 },
+}
+
+/* 8.5.6.1.) -- */
+const EfiGuid EFI_CAPSULE_REPORT_GUID = {
+ 0x39b68c46,
+ 0xf7fb,
+ 0x441b,
+ { 0xb6, 0xec, 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3 }
+};
+
+struct CapsuleResultVariableHeader
+{
+ uint variable_total_size;
+ uint reserved; /* spec says 'alignment' */
+ EfiGuid capsule_guid;
+ EfiTime capsule_processed_at;
+ EfiStatus capsule_status;
+}
+
+struct CapsuleResultVariableFMP
+{
+ ushort version;
+ char payload_index;
+ char update_image_index;
+ EfiGuid update_image_type_id;
+ /* implied: EfiStringRaw capsule_file_name */
+ /* implied: EfiStringRaw capsule_target */
+}
+
+struct CapsuleResultVariableJson
+{
+ uint version;
+ uint capsule_id;
+ uint response_length;
+ char* response_data;
+} \ No newline at end of file
diff --git a/lib/uefi.c3l/src/protocol/time.c3 b/lib/uefi.c3l/src/protocol/time.c3
new file mode 100644
index 0000000..261e4b1
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/time.c3
@@ -0,0 +1,23 @@
+module uefi::proto::time;
+import uefi;
+
+
+/* 8.3.) Time services */
+/* 8.3.1.) GetTime() */
+alias FnGetTime = fn EfiStatus(EfiTime*, EfiTimeCapabilities*);
+
+struct TimeCapabilities
+{
+ uint resolution;
+ uint accuracy;
+ bool sets_to_zero;
+}
+
+/* 8.3.2.) SetTime() */
+alias FnSetTime = fn EfiStatus(EfiTime*);
+
+/* 8.3.3.) GetWakeupTime() */
+alias FnGetWakeupTime = fn EfiStatus(bool*, bool*, EfiTime*);
+
+/* 8.3.4.) SetWakeupTime() */
+alias FnSetWakeupTime = fn EfiStatus(bool, EfiTime*); \ No newline at end of file
diff --git a/lib/uefi.c3l/src/protocol/variable.c3 b/lib/uefi.c3l/src/protocol/variable.c3
new file mode 100644
index 0000000..bf5175b
--- /dev/null
+++ b/lib/uefi.c3l/src/protocol/variable.c3
@@ -0,0 +1,68 @@
+module uefi::proto::variable;
+import uefi;
+
+
+/* 8.2.) Variable services */
+/* 8.2.1.) GetVariable() */
+alias FnGetVariable = fn EfiStatus(EfiStringRaw, EfiGuid*, uint*, usz*, void*);
+
+/* Variable Attributes */
+enum EfiVarAttr : uint (uint raw) // TODO: Add `inline` inside parens when supported
+{
+ NON_VOLATILE { 0x0000_0001 },
+ BOOTSERVICE_ACCESS { 0x0000_0002 },
+ RUNTIME_ACCESS { 0x0000_0004 },
+ HARDWARE_ERROR_RECORD { 0x0000_0008 },
+ HR { 0x0000_0008 }, /* spec notes aliasing of this to above */
+ RESERVED { 0x0000_0010 },
+ TIME_BASED_AUTHENTICATED_WRITE_ACCESS { 0x0000_0020 },
+ APPEND_WRITE { 0x0000_0040 },
+ ENHANCED_AUTHENTICATED_ACCESS { 0x0000_0080 },
+}
+
+struct VariableAuthentication3CertId
+{
+ char type;
+ uint id_size;
+ /* implied to follow: char id[id_size]; */
+}
+
+/* 8.2.2.) GetNextVariableName() */
+alias FnGetNextVariableName = fn EfiStatus(usz*, EfiStringRaw, EfiGuid*);
+
+/* 8.2.3.) SetVariable() */
+alias FnSetVariable = fn EfiStatus(EfiStringRaw, EfiGuid*, uint, usz, void*);
+
+/* TODO: Too much extra complexity to use right now. Add later. */
+/* struct VariableAuthentication2
+{
+ EfiTime timestamp;
+ WinCertificateUefiGuid auth_info;
+} */
+
+const char EFI_VARIABLE_AUTHENTICATION_3_TIMESTAMP_TYPE = 1;
+const char EFI_VARIABLE_AUTHENTICATION_3_NONCE_TYPE = 2;
+struct VariableAuthentication3
+{
+ char version;
+ char type;
+ uint metadata_size;
+ uint flags;
+}
+
+struct VariableAuthentication3Nonce
+{
+ uint nonce_size;
+ /* implied to follow: char nonce[nonce_size]; */
+}
+
+/* 8.2.4.) QueryVariableInfo() */
+alias FnQueryVariableInfo = fn EfiStatus(uint, ulong*, ulong*, ulong*);
+
+/* 8.2.7.2.) Hardware Error Record Variables */
+const EfiGuid EFI_HARDWARE_ERROR_VARIABLE = {
+ 0x414e6bdd,
+ 0xe47b,
+ 0x47cc,
+ { 0xb2, 0x44, 0xbb, 0x61, 0x02, 0x0c, 0xf5, 0x16 }
+}; \ No newline at end of file