quark/src/kernel/main.c

52 líneas
1,5 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-18 19:19:03 +02:00
#include "drivers/timer.h"
2022-06-19 19:08:16 +02:00
#include "drivers/keyboard.h"
#include "drivers/uart.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"
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);
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
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);
serial_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-07-23 01:42:19 +02:00
2022-07-15 21:45:56 +02:00
// Initialize drivers
2022-06-18 19:19:03 +02:00
timer_initialize();
2022-06-19 19:08:16 +02:00
keyboard_initialize();
2022-06-18 00:44:37 +02:00
2022-07-15 21:45:56 +02:00
// Initialize FS
vfs_initialize();
2022-06-18 03:56:45 +02:00
for(;;);
2022-06-17 00:44:56 +02:00
}