XenevaOS

The Boot Process

Current versions of Xeneva follows simple boot steps to load the ‘Kernel’. From beginning itself, Xeneva boots under UEFI environment, where Xeneva has it’s own bootloader, which prepares all the required steps for the kernel to boot properly. The required steps includes the Memory Map, The Allocated Physical Memory Stack and Boot Information struct.

The Memory Map

The Memory Map is a pointer to a buffer allocated by XNLDR which includes all information related to ‘EFI_MEMORY_DESCRIPTOR’. Xeneva depends on EFI provided Memory Descriptor to get all the usable ‘Physical Memory Blocks’ excluding Non Usable Memory blocks.

Non Usable Memory Blocks: Non Usable Memory Blocks are regions of memory that the Operating System do not use for its regular operations. These regions are typically reserved for firmware, hardware, or other special purposes. Key types of non-usable memory blocks in EFI memory descriptors includes:

The ‘Allocated Physical Memory for Kernel Code and Data’ is passed to the Kernel through dereferenced pointer operation along with number of allocated block count variable.

uint64_t allocated_blk_count = bootinfo->reserved_mem_count; 
uint64_t* allocated_blk_stack = (uint64_t*)bootinfo->allocated_stack;
while(allocated_blk_count){
    uint64_t address = *allocated_blk_stack--;
	AuPmmngrLockPage(address);
	allocated_blk_count--;
}

The ‘AuPmmngrLockPage’ function is a kernel Physical Memory Manager function that marks a memory block as unusable.

Boot Information Struct

Xeneva has its own format of Boot Information that it expects to be passed as argument to the main entry of Kernel. The ‘Boot Information Struct contains all the information for Memory Management, UEFI GOP’s framebuffer, Pointer to ACPI tables, formatted print function implemented by XNLDR and pointer to loaded runtime drivers memory area.

/**
* Kernel Boot information structure passed by XNLDR
*/
#pragma pack (push,1)
typedef struct _KERNEL_BOOT_INFO_ {
	/* Boot type either UEFI_BOOT or BIOS_BOOT */
	int boot_type;

	void* allocated_stack;

	uint64_t reserved_mem_count;

	/* map -- UEFI memory map */
	void *map;

	/* descriptor_size -- UEFI memory map descriptor size */
	uint64_t descriptor_size;

	/* mem_map_size -- UEFI memory map size */
	uint64_t mem_map_size;

	/* graphics_framebuffer -- framebuffer address passed by XNLDR */
	uint32_t* graphics_framebuffer;

	/* fb_size -- framebuffer total size */
	size_t   fb_size;

	/* X_Resolution -- Total width of the entire display */
	uint16_t  X_Resolution;

	/* Y_Resolution -- Total height of the entire display */
	uint16_t   Y_Resolution;

	/* pixels_per_line -- scanline of the current display */
	uint16_t   pixels_per_line;

	/* redmask, greenmask, bluemask, resvmask -- color mask */
	uint32_t redmask;
	uint32_t greenmask;
	uint32_t bluemask;
	uint32_t resvmask;

	/* acpi_table_pointer -- acpi base memory map */
	void*    acpi_table_pointer;

	/* kernel_size -- total kernel image size */
	size_t   kernel_size;

	/* psf_font_data -- screen font address loaded
	by XNLDR to use for debugging purpose */
	uint8_t* psf_font_data;

	/* printf_gui -- formatted printing function pointer to use
	for debugging purpose provided by XNLDR */
	void(*printf_gui) (const char* text, ...);

	/* unused pointer entries, reserved for runtime drivers */
	uint8_t* driver_entry1;   
	uint8_t *driver_entry2;   
	uint8_t *driver_entry3;   
	uint8_t* driver_entry4;   
	uint8_t* driver_entry5;   
	uint8_t* driver_entry6;  

    /* multiprocessor initialisation code */
	void*    apcode;

    /* boot storage related informations */s  
	uint32_t hid;
	uint32_t uid;
	uint32_t cid;
}KERNEL_BOOT_INFO, *PKERNEL_BOOT_INFO;
#pragma pack(pop)

File from ‘BaseHdr/aurora.h’
Overall, the boot information passed by the bootloader to the kernel is crucial for the successful initialization and operation of the operating system. This information includes various parameters and settings that help the kernel understand the system’s hardware and environment. The boot information ensures a smooth transition from the firmare/bootloader to a fully operational operating system. More information can be find here.