-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
executable file
·74 lines (61 loc) · 1.64 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "console.h"
#include "util.h"
#include "multiboot.h"
#include "string.h"
#include "io.h"
#include "panic.h"
#include "gdt.h"
#include "ata.h"
#include "kmalloc.h"
#include "stdbool.h"
#include "idt.h"
#include "kb.h"
#include "part.h"
#include "ata.h"
#include "fs/vfs.h"
#include "fs/fat.h"
#include "task.h"
#include "trap.h"
#include "paging.h"
void kmain(struct multiboot_info* mbd, unsigned int magic)
{
if(magic != MULTIBOOT_BOOTLOADER_MAGIC)
{
panic("Multiboot did not pass correct magic number");
}
if(mbd->mem_upper < 16*1024)
{
panic("Not enough memory");
}
char tmp[513];
uchar boot_drive = (mbd->boot_device >> 24) & 0xff;
paging_init((mbd->mem_upper + mbd->mem_lower + 1023) / 1024);
console_init();
console_clear();
kprintf("\n\nWelcome to CSOS. Booted by %s, running on %s\n\n", mbd->boot_loader_name, cpuid(tmp));
kprintf("Mem lower: %d, mem upper: %d. Total memory: %d MiB\n\n", mbd->mem_lower, mbd->mem_upper, (mbd->mem_upper + mbd->mem_lower) / 1024);
kmalloc_init(0x00200000, 0x00400000);
gdt_init();
cli();
idt_init();
trap_init();
sti();
kb_init();
task_init(0x00800000, mbd->mem_upper);
partition_t part;
part_read(boot_drive, 0, &part);
kprint("Initializing FAT filesystem... ");
vfs_init(fat_vfs(boot_drive, &part));
kprint("Ok.\n");
uint init_size = vfs_size("/init.bin");
char* buff = kmalloc(((init_size + PAGE_SIZE-1) / PAGE_SIZE) * PAGE_SIZE);
vfs_readfile("/init.bin", 0, init_size, buff);
task_create(init_size, buff, 4096);
// task_create(init_size, buff, 4096);
kfree(buff);
cli();
idt_register_handler(32, (uint)task_switch);
sti();
__asm__("hlt");
panic("init exited");
}