-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·118 lines (105 loc) · 2.86 KB
/
main.c
File metadata and controls
executable file
·118 lines (105 loc) · 2.86 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <intdef.h>
#include <page.h>
#include <multiboot.h>
#include <str.h>
#include <proc.h>
#include <kmalloc.h>
#include <ide.h>
#include <idt.h>
#include <isrs.h>
#include <irqs.h>
#include <timer.h>
#include <keyboard.h>
#include <syscall_handler.h>
#include <blk_dev.h>
#include <io.h>
#include <console.h>
#include "dev/tty/include/tty.h"
#include <swap.h>
#include <print.h>
#include <dynlibs.h>
#include <devfs.h>
#include <cpuid.h>
uint32_t init_esp;
#ifndef _BUILD_TIME
#define _BUILD_TIME 00
#endif
uint32_t initrd_start, initrd_end;
extern void little_test();
extern void vga_install();
void int_assert() {
//Gone~
}
void install_step0() {
int_assert();
serial_install();
gdt_install();
idt_install();
isrs_install();
irq_install();
paging_install();
}
void install_step1() {
cpuid_install();
timer_install();
keyboard_install();
syscall_install();
proc_install();
vfs_install();
blk_dev_install();
ide_install();
vga_install();
console_install();
swap_install();
dynlibs_install();
tty_install();
}
int kernel_init() {
install_step1();
setpid(1);
mount_rootfs(initrd_start);
screen_clear();
tty_write(&ttys[0], 1, 50, "\n"
" DCat's Kernel"
"\n\n");
for (int x = 0; x < SCREEN_MAX_X; x++)
tty_write(&ttys[0], 1, 1, "-");
little_test();
PANIC("Hey!I'm here!");
for (;;);
}
int load_initrd(multiboot_info_t *mul) {
if (mul->mods_count <= 0) PANIC("initrd module not found..")
initrd_start = *((uint32_t *) mul->mods_addr);
initrd_end = *(uint32_t *) (mul->mods_addr + 4);
heap_placement_addr = initrd_end;
dprintf("initrd: start:%x end:%x", initrd_start, initrd_end);
ASSERTM(initrd_start < 0x01000000, "Bad initrd addr.!!");
}
int move_kernel_stack(uint32_t start_addr, uint32_t size) {
uint32_t ebp, esp;
for (int32_t x = size; x >= 0; x -= 0x1000) {
page_t *page = get_page(start_addr - x, true, kernel_dir);
ASSERT(page);
alloc_frame(page, false, true);
}
ebp = 0xBB0000 - 0x4;
esp = 0xBB0000 - 0x8;
dprintf("new kernel stack:ebp:%x esp:%x", ebp, esp);
uint32_t old_esp;
__asm__ __volatile__("mov %%esp,%0;":"=r"(old_esp));
dprintf("init esp:%x current:%x used:%x", init_esp, old_esp, init_esp - old_esp);
if (init_esp - old_esp > 1024) PANIC("Some code are covered by kernel init stack.");
change_stack(ebp, esp);
__asm__ __volatile__("jmp %%eax;"::"a"(kernel_init));
}
int main(uint32_t magic, multiboot_info_t *mul_arg, uint32_t init_esp_arg) {
putf(" deep dark fantasy");
ASSERT(magic == 0x2BADB002);
init_esp = init_esp_arg;
dprintf("multiboot info table:%x init_esp:%x", mul_arg, init_esp_arg);
load_initrd(mul_arg);
install_step0();
move_kernel_stack(0xBB0000, 0x10000);
PANIC("Hey!I'm here!");
}