quark/src/kernel/main.c

77 líneas
2,3 KiB
C
Original Vista normal Històric

2022-06-17 00:44:56 +02:00
#include <stdint.h>
2022-06-19 19:17:15 +02:00
#include "lib/stdio.h"
2022-06-18 00:44:37 +02:00
#include "hal/hal.h"
2022-06-19 19:08:16 +02:00
#include "drivers/keyboard.h"
#include "drivers/uart.h"
2022-10-21 17:53:12 +02:00
#include "drivers/initrd.h"
2022-07-15 21:45:56 +02:00
#include "fs/vfs.h"
2022-07-24 18:35:30 +02:00
#include "arch/i686/mm/pmm.h"
#include "arch/i686/mm/vmm.h"
2022-07-18 21:28:03 +02:00
#include "multiboot.h"
#include "lib/debug.h"
#include "arch/i686/fdc.h"
#include "shell.h"
2022-06-17 00:44:56 +02:00
2022-07-18 21:28:03 +02:00
extern uint8_t end; // Kernel end
void __attribute__((cdecl)) kmain(multiboot_info_t *multiboot_info){
2022-07-15 21:45:56 +02:00
// Clear screen
clear_screen();
// Initialize chip-specific hardware
2022-06-18 00:44:37 +02:00
hal_initialize();
2022-07-15 21:45:56 +02:00
// Initialize serial
uart_initialize(COM1, 2);
// Initialize drivers
keyboard_initialize();
2022-07-18 21:28:03 +02:00
// Initialize physical memory manager
uint32_t mem_size = 1024 + multiboot_info->mem_lower + multiboot_info->mem_upper*64;
2022-07-24 18:35:30 +02:00
i686_pmm_initialize(mem_size, (int)(&end));
2022-07-18 21:28:03 +02:00
// Memory map
debug_printf("= Memory map =\n");
2022-07-18 21:28:03 +02:00
for(int i = 0; i < multiboot_info->mmap_length; i += sizeof(multiboot_memory_map_t)){
multiboot_memory_map_t *memory_map = (multiboot_memory_map_t *)(multiboot_info->mmap_addr + i);
debug_printf("Start Addr: 0x%x%x | Length: 0x%x%x | Size: 0x%x | Type: %i\n", memory_map->addr_h, memory_map->addr_l, memory_map->len_h, memory_map->len_l, memory_map->size, memory_map->type);
2022-07-18 21:28:03 +02:00
if(memory_map->type == 1){
2022-07-24 18:35:30 +02:00
i686_pmm_init_region(memory_map->addr_l, memory_map->len_l);
2022-07-18 21:28:03 +02:00
}
}
2022-07-24 18:35:30 +02:00
i686_pmm_deinit_region(0x100000, (int)(&end) - 0x100000); // Deinit the section the kernel is in
2022-07-18 21:28:03 +02:00
2022-07-23 01:42:19 +02:00
// Initialize virtual memory
2022-07-24 18:35:30 +02:00
i686_vmm_initialize();
2022-06-18 00:44:37 +02:00
// Floppy disk controller
i686_fdc_set_working_drive(0);
i686_fdc_initialize();
2022-10-21 17:53:12 +02:00
debug_printf("Multiboot modules: (%d)\n", multiboot_info->mods_count);
if(multiboot_info->mods_count == 1){
debug_printf("Loading initrd...\n");
multiboot_module_t *module;
module = (multiboot_module_t *)multiboot_info->mods_addr;
debug_printf("Initrd module structure: start=0x%x end=0x%x cmdline=%s\n", module->start, module->end, module->cmdline);
debug_printf("%d\n", module->start);
}
else{
debug_printf("WARNING: mods_count is not 1, not loading the initrd");
}
2022-07-15 21:45:56 +02:00
// Initialize FS
vfs_initialize();
// Run shell
shell();
// Halt at end
debug_printf("Kernel execution ended\n");
2022-06-18 03:56:45 +02:00
for(;;);
2022-06-17 00:44:56 +02:00
}