Files
KatauOS/src/kernel/kernel.c
T

161 lines
3.3 KiB
C

#include "../include/isr.h"
#include "../include/screen.h"
#include "../include/stdio.h"
#include "../include/utils.h"
#include "../include/disk.h"
#include "../include/string.h"
#include "../include/pic.h"
#include "../include/pit.h"
#include "../include/paging.h"
#include "../include/fat.h"
#include "../include/task.h"
#include "../include/multiboot.h"
#include "../include/liballoc.h"
#include "../include/kheap.h"
#include "../include/exec_from_file.h"
#include "../include/atapi.h"
#include "../include/vfs.h"
#include "../include/apic.h"
#include <stdint.h>
void kmain(unsigned int magic, unsigned int info)
{
struct multiboot_info mbi;
memcpy(&mbi, (void*)info, sizeof(struct multiboot_info));
terminal_initialize();
printf("KatauOS booting up\n");
if(magic != MULTIBOOT_BOOTLOADER_MAGIC) {
printf("invalid magic number!\n");
while(1){}
}
if(mbi.flags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
printf("bootloader: %s\n", mbi.boot_loader_name);
}
printf("init_allocator...");
init_allocator();
printf("done\n");
printf("grub_memory_map...");
grub_memory_map(magic, &mbi);
printf("done\n");
isr_install();
if(cpu_has_msr())
{
printf("CPU has MSR\n");
}
if(check_apic() && cpu_has_msr())
{
printf("APIC is present\n");
lapic_enabled = true;
}
if(!lapic_enabled)
{
pic_remap(0x20, 0x28);
pit_init(100);
pic_apply_masks();
}
else
{
pic_disable();
enable_symmetric_io_mode();
enable_apic();
ioapic_init();
printf("IOAPIC init done\n");
ioapic_redirect(2, 32);//timer
ioapic_redirect(1, 33);//keyboard
init_apic_timer();
mask_pit_interrupt();
}
printf("done fucking with pages and memory map!\n");
char *test_str;
printf("test_str: %X, &test_str %X\n", test_str, &test_str);
test_str = alloc_page();
printf("test_str: %X, &test_str %X\n", test_str, &test_str);
free_page(test_str);
//reserve first 16 pages (64KB) for the stack whose top address is defined as 0xC0010000 in the boot.asm
for(int i = 0; i < 16; i++)
{
alloc_page();
}
//while(1){}
//paging_init();
//printf("paging_init done\n");
//test_paging();
//heap_init();
//printf("after heap_init\n");
kheap_init();
__asm__ __volatile__ ("sti");
scheduler_init();
printf("Kernel init sequence completed\n");
char yooo[256] = "heheh";
printf("test string: %s\n", yooo);
disk_info info1;
get_disk_info(&info1);
printf("CYL HEAD SECT: %X %X %X\n", info1.cylinders, info1.heads, info1.sectors);
//file_fuckery();
char *huy;
char *huy2;
char temp1[1024] = "rusya_krutoy";
char temp2[1024] = "katya_tozhe_krutaya";
huy = kvalloc(1);//alloc_page();
huy2 = kvalloc(2);//alloc_page();
memcpy(huy, temp1, sizeof(temp1));
memcpy(huy2, temp2, sizeof(temp1));
printf("huy1 address: 0x%X huy2 address:0x%X\n", &huy, &huy2);
printf("huy1 points to: 0x%X huy2 points to:0x%X\n", huy, huy2);
printf("huy1: %s\nhuy2: %s", huy, huy2);
mount_fs();
l9660_dir dir;
l9660_file file;
follow_path("/katau/caller.", &file, &dir);
exec_from_file(&file, ".");
while(1)
{
if(timer_ticks % 1000 == 0)
{
//printf("a second should have passed!\n");
}
/* if(inportb(0x64) & 0x1)
{
unsigned char key = inportb(0x60);
if(key == 2)
terminal_writestring("1\n");
else if(key == 4)
terminal_writestring("3\n");
else
terminal_writestring("dunno what is it\n");
}
*/ }
}