diff --git a/kaleid/include/kernel/base.h b/kaleid/include/kernel/base.h index cb1d2db..199385e 100644 --- a/kaleid/include/kernel/base.h +++ b/kaleid/include/kernel/base.h @@ -42,7 +42,7 @@ typedef struct Terminal_t Terminal_t; typedef struct ListHead_t ListHead_t; typedef struct ListNode_t ListNode_t; typedef struct Processor_t Processor_t; -typedef struct MemoryMap_t MemoryMap_t; +typedef struct BootInfo_t BootInfo_t; typedef enum ProcState_t ProcState_t; typedef enum TermColor_t TermColor_t; @@ -63,6 +63,8 @@ typedef enum TermColor_t TermColor_t; #define GetCurCPU() (cpuTable[_GetCurCPU()]) #define PANICSTR_SIZE 1024 +//Get the BootInfo_t structure +#define GetBootInfo() (bootTab) //------------------------------------------// // @@ -96,17 +98,66 @@ struct Processor_t ListHead_t *timeCritProcs; }; -struct MemoryMap_t +#define FB_EGA_TEXT 2 +#define FB_INDEXED 0 +#define FB_RGB 1 + +struct BootInfo_t { - void *addr; - int length; + // The Bootloader infos (GRUB in our case) + struct { + uint grubFlags; //flags + uint modulesCount; //mods_count + uint modulesAddr; //mods_addr + uint grubName; //boot_loader_name + } btldr; + + // Informations about drives + struct { + uint bootDrv; //boot_device + uint bufferLength; //drives_length + uint bufferAddr; //drives_addr + } drives; + + // Informations about memory + struct { + //BIOS provided low and up memory + uint lowMemory; //mem_lower + uint upMemory; //mem_upper + + //GRUB provided memory map + uint mapLength; //mmap_length + uint mapAddr; //mmap_addr + } memory; + + // Informations about the video drive + struct { + uint vbeControl; //vbe_control_info + uint vbeModeInfo; //vbe_mode_info + ushort vbeMode; //vbe_mode + ushort vbeInterfaceSeg; //vbe_interface_seg + ushort vbeInterfaceOff; //vbe_interface_off + ushort vbeInterfaceLen; //vbe_interface_len + ullong framebufferAddr; //framebuffer_addr + uint framebufferPitch; //framebuffer_pitch + uint framebufferWidth; //framebuffer_width + uint framebufferHeight; //framebuffer_height + uchar framebufferBpp; //framebuffer_bpp + uchar framebufferType; //framebuffer_type + } video; + + // Informations about the microcode firmware (BIOS/EFI) + struct { + uint apmTable; //apm_table + uint romTable; //config_table + } firmware; }; //------------------------------------------// extern int cpuCount; extern Processor_t cpuTable[NCPUS]; -extern MemoryMap_t memTab; +extern BootInfo_t bootTab; //------------------------------------------// #define DEC_PER_CPU(name, field, type) \ diff --git a/kaleid/include/kernel/mm.h b/kaleid/include/kernel/mm.h index afacf69..cece795 100644 --- a/kaleid/include/kernel/mm.h +++ b/kaleid/include/kernel/mm.h @@ -25,8 +25,6 @@ #include #include -#define GetCurMemMap() (memTab) - // // Returns a pointer to the first entry of the memory map // @@ -35,6 +33,6 @@ void *GetMemoryMap(void); // // Initializes the memory map structure // -void InitMemoryMap(multiboot_info_t *mbInfo); +void InitMemoryMap(void); // -------------------------------------------------------------------------- // diff --git a/kaleid/include/multiboot/multiboot.h b/kaleid/include/multiboot/multiboot.h index 04f6322..d1f8516 100644 --- a/kaleid/include/multiboot/multiboot.h +++ b/kaleid/include/multiboot/multiboot.h @@ -93,74 +93,74 @@ #ifndef ASM_FILE -typedef unsigned char multiboot_uint8_t; -typedef unsigned short multiboot_uint16_t; -typedef unsigned int multiboot_uint32_t; -typedef unsigned long long multiboot_uint64_t; +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long long ullong; struct multiboot_header { /* Must be MULTIBOOT_MAGIC - see above. */ - multiboot_uint32_t magic; + uint magic; /* Feature flags. */ - multiboot_uint32_t flags; + uint flags; /* The above fields plus this one must equal 0 mod 2^32. */ - multiboot_uint32_t checksum; + uint checksum; /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ - multiboot_uint32_t header_addr; - multiboot_uint32_t load_addr; - multiboot_uint32_t load_end_addr; - multiboot_uint32_t bss_end_addr; - multiboot_uint32_t entry_addr; + uint header_addr; + uint load_addr; + uint load_end_addr; + uint bss_end_addr; + uint entry_addr; /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ - multiboot_uint32_t mode_type; - multiboot_uint32_t width; - multiboot_uint32_t height; - multiboot_uint32_t depth; + uint mode_type; + uint width; + uint height; + uint depth; }; /* The symbol table for a.out. */ struct multiboot_aout_symbol_table { - multiboot_uint32_t tabsize; - multiboot_uint32_t strsize; - multiboot_uint32_t addr; - multiboot_uint32_t reserved; + uint tabsize; + uint strsize; + uint addr; + uint reserved; }; typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; /* The section header table for ELF. */ struct multiboot_elf_section_header_table { - multiboot_uint32_t num; - multiboot_uint32_t size; - multiboot_uint32_t addr; - multiboot_uint32_t shndx; + uint num; + uint size; + uint addr; + uint shndx; }; typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; struct multiboot_info { /* Multiboot info version number */ - multiboot_uint32_t flags; + uint flags; /* Available memory from BIOS */ - multiboot_uint32_t mem_lower; - multiboot_uint32_t mem_upper; + uint mem_lower; + uint mem_upper; /* "root" partition */ - multiboot_uint32_t boot_device; + uint boot_device; /* Kernel command line */ - multiboot_uint32_t cmdline; + uint cmdline; /* Boot-Module list */ - multiboot_uint32_t mods_count; - multiboot_uint32_t mods_addr; + uint mods_count; + uint mods_addr; union { @@ -169,54 +169,54 @@ struct multiboot_info } u; /* Memory Mapping buffer */ - multiboot_uint32_t mmap_length; - multiboot_uint32_t mmap_addr; + uint mmap_length; + uint mmap_addr; /* Drive Info buffer */ - multiboot_uint32_t drives_length; - multiboot_uint32_t drives_addr; + uint drives_length; + uint drives_addr; /* ROM configuration table */ - multiboot_uint32_t config_table; + uint config_table; /* Boot Loader Name */ - multiboot_uint32_t boot_loader_name; + uint boot_loader_name; /* APM table */ - multiboot_uint32_t apm_table; + uint apm_table; /* Video */ - multiboot_uint32_t vbe_control_info; - multiboot_uint32_t vbe_mode_info; - multiboot_uint16_t vbe_mode; - multiboot_uint16_t vbe_interface_seg; - multiboot_uint16_t vbe_interface_off; - multiboot_uint16_t vbe_interface_len; + uint vbe_control_info; + uint vbe_mode_info; + ushort vbe_mode; + ushort vbe_interface_seg; + ushort vbe_interface_off; + ushort vbe_interface_len; - multiboot_uint64_t framebuffer_addr; - multiboot_uint32_t framebuffer_pitch; - multiboot_uint32_t framebuffer_width; - multiboot_uint32_t framebuffer_height; - multiboot_uint8_t framebuffer_bpp; + ullong framebuffer_addr; + uint framebuffer_pitch; + uint framebuffer_width; + uint framebuffer_height; + uchar framebuffer_bpp; #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 - multiboot_uint8_t framebuffer_type; + uchar framebuffer_type; union { struct { - multiboot_uint32_t framebuffer_palette_addr; - multiboot_uint16_t framebuffer_palette_num_colors; + uint framebuffer_palette_addr; + ushort framebuffer_palette_num_colors; }; struct { - multiboot_uint8_t framebuffer_red_field_position; - multiboot_uint8_t framebuffer_red_mask_size; - multiboot_uint8_t framebuffer_green_field_position; - multiboot_uint8_t framebuffer_green_mask_size; - multiboot_uint8_t framebuffer_blue_field_position; - multiboot_uint8_t framebuffer_blue_mask_size; + uchar framebuffer_red_field_position; + uchar framebuffer_red_mask_size; + uchar framebuffer_green_field_position; + uchar framebuffer_green_mask_size; + uchar framebuffer_blue_field_position; + uchar framebuffer_blue_mask_size; }; }; }; @@ -224,51 +224,51 @@ typedef struct multiboot_info multiboot_info_t; struct multiboot_color { - multiboot_uint8_t red; - multiboot_uint8_t green; - multiboot_uint8_t blue; + uchar red; + uchar green; + uchar blue; }; struct multiboot_mmap_entry { - multiboot_uint32_t size; - multiboot_uint64_t addr; - multiboot_uint64_t len; + uint size; + ullong addr; + ullong len; #define MULTIBOOT_MEMORY_AVAILABLE 1 #define MULTIBOOT_MEMORY_RESERVED 2 #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 #define MULTIBOOT_MEMORY_NVS 4 #define MULTIBOOT_MEMORY_BADRAM 5 - multiboot_uint32_t type; + uint type; } __attribute__((packed)); typedef struct multiboot_mmap_entry multiboot_memory_map_t; struct multiboot_mod_list { /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */ - multiboot_uint32_t mod_start; - multiboot_uint32_t mod_end; + uint mod_start; + uint mod_end; /* Module command line */ - multiboot_uint32_t cmdline; + uint cmdline; /* padding to take it to 16 bytes (must be zero) */ - multiboot_uint32_t pad; + uint pad; }; typedef struct multiboot_mod_list multiboot_module_t; /* APM BIOS info. */ struct multiboot_apm_info { - multiboot_uint16_t version; - multiboot_uint16_t cseg; - multiboot_uint32_t offset; - multiboot_uint16_t cseg_16; - multiboot_uint16_t dseg; - multiboot_uint16_t flags; - multiboot_uint16_t cseg_len; - multiboot_uint16_t cseg_16_len; - multiboot_uint16_t dseg_len; + ushort version; + ushort cseg; + uint offset; + ushort cseg_16; + ushort dseg; + ushort flags; + ushort cseg_len; + ushort cseg_16_len; + ushort dseg_len; }; #endif /* ! ASM_FILE */ diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 5a5ebdb..2f634dc 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -27,6 +27,28 @@ #include #include +// +// BootInfo_t initialization. It is necessary because grub will potentially be +// wiped since it is below 1MB.... +// +void InitBootInfo(multiboot_info_t *mbi) +{ + //Retrieves the bootloader informations + GetBootInfo().btldr.grubFlags = mbi->flags; + GetBootInfo().btldr.grubName = mbi->boot_loader_name; + GetBootInfo().btldr.modulesCount = mbi->mods_count; + GetBootInfo().btldr.modulesAddr = mbi->mods_addr; + DebugLog("[InitBootInfo] %s\n", GetBootInfo().btldr.grubName); + + //Retrieves the drives informations + GetBootInfo().drives.bootDrv = mbi->boot_device; + GetBootInfo().drives.bufferLength = mbi->drives_length; + GetBootInfo().drives.bufferAddr = mbi->drives_addr; + DebugLog("[InitBootInfo] Root drive : %x\n", + GetBootInfo().drives.bootDrv); +} + + // // Entry point of the Kaleid kernel // @@ -42,11 +64,13 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) KernLog("%c%c%c OS/K\n\n", 219, 219, 219); KernLog("[Init] We have magic : %x\n", mbMagic); + //Initialize the BootInfo_t structure + InitBootInfo(mbInfo); + //Memory mapping - InitMemoryMap(mbInfo); + InitMemoryMap(); // We're out KernLog("\n[Init] Evil never dies"); CrashSystem(); //yay } - diff --git a/kaleid/kernel/init/table.c b/kaleid/kernel/init/table.c index 2d1292c..0294ddd 100644 --- a/kaleid/kernel/init/table.c +++ b/kaleid/kernel/init/table.c @@ -27,6 +27,6 @@ int cpuCount = 1; Processor_t cpuTable[NCPUS] = {0}; -MemoryMap_t memTab = {0}; +BootInfo_t bootTab = {0}; Terminal_t *stdOut = 0, *stdDbg = 0; diff --git a/kaleid/kernel/mm/map.c b/kaleid/kernel/mm/map.c index 56cbed3..056e71e 100644 --- a/kaleid/kernel/mm/map.c +++ b/kaleid/kernel/mm/map.c @@ -26,15 +26,14 @@ #include #include -void InitMemoryMap(multiboot_info_t *mbInfo) +void InitMemoryMap(void) { - memTab.addr = (void*)mbInfo->mmap_addr; - memTab.length = (int)mbInfo->mmap_length; - - KernLog("[InitMemoryMap] Address: %p, Length: %d\n", GetCurMemMap().addr, GetCurMemMap().length ); + return; } void *GetMemoryMap(void) { - return (void*)GetCurMemMap().addr; + return (void*)0; } + +