Refactor boot_info.h and related files for improved abstraction and consistency. Updated function signatures to use generic types, replaced UEFI-specific types with kernel types, and enhanced documentation for clarity. Adjusted kernel entry point and service wrappers to align with new structure.
This commit is contained in:
60
boot_info.h
60
boot_info.h
@@ -1,45 +1,67 @@
|
||||
/*
|
||||
* boot_info.h – Shared interface between the UEFI loader and the kernel.
|
||||
* boot_info.h – Shared interface between the firmware loader and kernel.
|
||||
*
|
||||
* The BootInfo struct is populated by the loader (main.c) and passed to
|
||||
* the kernel entry point (kmain). It provides function pointers that
|
||||
* abstract UEFI Boot/Runtime Services so the kernel can use console I/O,
|
||||
* memory allocation, and system control without linking against GNU-EFI.
|
||||
* The BootInfo struct is populated by the platform-specific loader
|
||||
* (currently the UEFI loader in main.c) and passed to the kernel entry
|
||||
* point (kmain). It exposes only generic types and function pointers so
|
||||
* that the kernel remains independent of any particular firmware API.
|
||||
*/
|
||||
|
||||
#ifndef BOOT_INFO_H
|
||||
#define BOOT_INFO_H
|
||||
|
||||
#include <efi.h>
|
||||
/*
|
||||
* Status code returned by loader-provided services (0 = success).
|
||||
* The underlying integer type (UINT64) must be provided by including
|
||||
* either the firmware headers (e.g. <efi.h>) or the kernel type
|
||||
* header before including this file.
|
||||
*/
|
||||
typedef UINT64 KSTATUS;
|
||||
|
||||
/* Printf-style print function (backed by UEFI ConOut). */
|
||||
/* Simple key event used by the kernel's input path. */
|
||||
typedef struct {
|
||||
UINT16 scan_code;
|
||||
CHAR16 unicode_char;
|
||||
} KeyEvent;
|
||||
|
||||
/* Printf-style print function (typically backed by firmware console). */
|
||||
typedef UINTN (*KernelPrintFn)(const CHAR16 *Format, ...);
|
||||
|
||||
/* Console output helpers. */
|
||||
typedef KSTATUS (*ConsoleClearFn)(void);
|
||||
typedef KSTATUS (*ConsoleSetAttrFn)(UINTN Attribute);
|
||||
|
||||
/* Keyboard input helpers. */
|
||||
typedef KSTATUS (*KeyReadFn)(KeyEvent *Key);
|
||||
|
||||
/*
|
||||
* BootInfo – everything the kernel needs from the UEFI environment.
|
||||
* BootInfo – everything the kernel needs from the loader at boot time.
|
||||
*
|
||||
* All function pointers are optional: the kernel must NULL-check before
|
||||
* calling. If a service is unavailable the corresponding field is NULL.
|
||||
*/
|
||||
typedef struct {
|
||||
EFI_SYSTEM_TABLE *SystemTable; /* UEFI System Table */
|
||||
|
||||
/* Console I/O */
|
||||
KernelPrintFn print; /* formatted text output */
|
||||
EFI_STATUS (*clear_screen)(void); /* clear the console */
|
||||
EFI_STATUS (*set_attribute)(UINTN Attribute); /* set text colour/attr */
|
||||
EFI_STATUS (*read_key)(EFI_INPUT_KEY *Key); /* blocking key read */
|
||||
EFI_STATUS (*try_read_key)(EFI_INPUT_KEY *Key); /* non-blocking key read */
|
||||
KernelPrintFn print; /* formatted text output */
|
||||
ConsoleClearFn clear_screen; /* clear the console */
|
||||
ConsoleSetAttrFn set_attribute; /* set text colour/attr */
|
||||
KeyReadFn read_key; /* blocking key read */
|
||||
KeyReadFn try_read_key; /* non-blocking key read */
|
||||
|
||||
/* System control */
|
||||
void (*shutdown)(void); /* power-off the machine */
|
||||
void (*shutdown)(void); /* power-off the machine */
|
||||
|
||||
/* Physical memory */
|
||||
EFI_STATUS (*alloc_pages)(UINTN pages, EFI_PHYSICAL_ADDRESS *addr);
|
||||
EFI_STATUS (*free_pages)(EFI_PHYSICAL_ADDRESS addr, UINTN pages);
|
||||
KSTATUS (*alloc_pages)(UINTN pages, UINT64 *addr);
|
||||
KSTATUS (*free_pages)(UINT64 addr, UINTN pages);
|
||||
|
||||
/* Firmware metadata (for informational commands only). */
|
||||
const CHAR16 *firmware_vendor;
|
||||
UINT32 firmware_major;
|
||||
UINT32 firmware_minor;
|
||||
} BootInfo;
|
||||
|
||||
/* Kernel entry point signature (called by the UEFI loader). */
|
||||
/* Kernel entry point signature (called by the loader). */
|
||||
typedef void (*KernelEntryFn)(BootInfo *Boot);
|
||||
|
||||
#endif /* BOOT_INFO_H */
|
||||
|
||||
Reference in New Issue
Block a user