PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
main.c File Reference
#include <boot/boot_info.h>
#include <efi.h>
#include <efilib.h>
#include <kernel/mem/paging.h>
#include <kernel/mem/paging_types.h>
#include <kernel/version.h>
#include <stddef.h>
#include <sys/defs.h>
#include <sys/elf.h>
#include <sys/list.h>
#include <sys/math.h>
#include <sys/proc.h>
#include <functions/assert/assert.c>
#include <functions/elf/elf64_get_loadable_bounds.c>
#include <functions/elf/elf64_load_segments.c>
#include <functions/elf/elf64_validate.c>
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define GOP_WIDTH   1920
 Ignored if GOP_USE_DEFAULT_RES is set to 1.
 
#define GOP_HEIGHT   1080
 Ignored if GOP_USE_DEFAULT_RES is set to 1.
 
#define GOP_USE_DEFAULT_RES   1
 
#define MEM_BASIC_ALLOCATOR_RESERVE_PERCENTAGE   10
 
#define MEM_BASIC_ALLOCATOR_MIN_PAGES   8192
 
#define EXIT_BOOT_SERVICES_MAX_RETRIES   5
 

Enumerations

enum  panic_code_t {
  PANIC_ALLOCATOR_EXHAUSTED = 0 , PANIC_PAGE_TABLE_INIT = 1 , PANIC_IDENTITY_MAP = 2 , PANIC_HIGHER_HALF_INVALID = 3 ,
  PANIC_HIGHER_HALF_MAP = 4 , PANIC_KERNEL_MAP = 5 , PANIC_GOP_MAP = 6
}
 Panic error codes for debugging when boot services are unavailable. More...
 

Functions

static void * rsdp_locate (EFI_SYSTEM_TABLE *systemTable)
 Locates the ACPI RSDP from the EFI configuration table.
 
static UINT32 gop_find_best_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, int64_t requestedWidth, int64_t requestedHeight)
 Finds the best matching graphics mode for the requested resolution.
 
static EFI_STATUS gop_set_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, int64_t requestedWidth, int64_t requestedHeight)
 Sets the graphics mode to best match the requested resolution.
 
static EFI_STATUS gop_init (boot_gop_t *buffer)
 Initializes the GOP buffer structure with framebuffer information.
 
static _NORETURN void panic_halt (panic_code_t code)
 Halts the system with a colored screen indicating the error.
 
static EFI_STATUS mem_map_init (boot_memory_map_t *map)
 Initializes the EFI memory map structure.
 
static void mem_map_cleanup (boot_memory_map_t *map)
 Free the memory map structure.
 
static size_t mem_count_available_pages (boot_memory_map_t *map)
 Calculates the total available conventional memory.
 
static EFI_STATUS mem_allocator_init (void)
 Initializes the basic page allocator.
 
static uint64_t basic_allocator_alloc_pages (pfn_t *pfns, size_t amount)
 Allocate pages from the basic allocator.
 
static void mem_page_table_init (page_table_t *table, boot_memory_map_t *map, boot_gop_t *gop, boot_kernel_t *kernel)
 Initializes the kernel page table with all required mappings.
 
static bool wstr_to_str (char *dest, size_t destSize, const CHAR16 *src)
 Copies a wide character string to a narrow character buffer.
 
static void boot_file_free (boot_file_t *file)
 Frees a boot file structure and its data.
 
static void boot_dir_free (boot_dir_t *dir)
 Recursively frees a directory tree.
 
static boot_file_tdisk_load_file (EFI_FILE *parentDir, const CHAR16 *fileName)
 Loads a single file from an EFI file handle.
 
static boot_dir_tdisk_load_dir (EFI_FILE *dirHandle, const CHAR16 *dirName)
 Recursively loads a directory and its contents.
 
static EFI_STATUS disk_init (boot_disk_t *disk, EFI_FILE *rootHandle)
 Loads the initial RAM disk from the boot volume.
 
static EFI_STATUS kernel_load (boot_kernel_t *kernel, EFI_FILE *rootHandle)
 Loads and validates the kernel ELF file.
 
static void splash_screen_display (void)
 Displays the bootloader splash screen.
 
static EFI_STATUS volume_open_root (EFI_FILE **rootFile, EFI_HANDLE imageHandle)
 Opens the root volume of the boot device.
 
static EFI_STATUS boot_info_populate (EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE *systemTable, boot_info_t *bootInfo)
 Populates the boot information structure.
 
static EFI_STATUS boot_services_exit (EFI_HANDLE imageHandle, boot_info_t *bootInfo)
 Exits UEFI boot services and prepares for kernel handoff.
 
EFI_STATUS efi_main (EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE *systemTable)
 UEFI entry point.
 

Variables

struct { 
 
   EFI_PHYSICAL_ADDRESS   buffer 
 
   size_t   maxPages 
 
   size_t   pagesAllocated 
 
   boot_gop_t *   gop 
 
   boot_memory_map_t *   map 
 
basicAllocator 
 Basic page allocator state.
 
static const uint32_t PANIC_COLORS []
 Color values for panic display.
 

Variable Documentation

◆ buffer

EFI_PHYSICAL_ADDRESS buffer

Definition at line 237 of file main.c.

◆ maxPages

size_t maxPages

Definition at line 238 of file main.c.

◆ pagesAllocated

size_t pagesAllocated

Definition at line 239 of file main.c.

◆ gop

boot_gop_t* gop

Definition at line 240 of file main.c.

◆ map

Definition at line 241 of file main.c.