-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.c
70 lines (55 loc) · 1.56 KB
/
kernel.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
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "tty.h"
#include "gdt.h"
#include "idt.h"
#include "timer.h"
#include "sys.h"
#include "interrupts.h"
#include "keyboard.h"
#include "shell.h"
#include "user_space.h"
#include "syscall.h"
#include "rtc.h"
void kernel_main(void)
{
terminal_printf("Kernel start\n");
terminal_initialize();
gdt_install();
idt_install();
isr_install();
irq_install();
timer_install();
keyboard_install();
rtc_init();
terminal_printf("Kernel initialized\n");
syscall_init();
terminal_printf("Syscall initialized\n");
sys_enable_interrupts();
terminal_printf("Interrupts enabled\n");
enter_user_space();
}
enum SYSCALLS {
SYS_GETCHAR = 0,
SYS_GET_TIME,
SYS_HALT,
SYS_PRINTF,
SYS_DELAY,
SYS_CLEAR,
SYS_SHELL_INIT
};
void main(void)
{ //TODO: Rework user space calls
int ret;
for (int i = 1; i < 4; i++)
{
asm volatile("int $0x80" : "=a"(ret) : "a"(SYS_PRINTF), "b"("&cTest &7%d\n"), "c"(i));
asm volatile("int $0x80" : "=a"(ret) : "a"(SYS_DELAY), "b"(1000));
}
asm volatile("int $0x80" : "=a"(ret) : "a"(SYS_CLEAR));
asm volatile("int $0x80" : "=a"(ret) : "a"(SYS_PRINTF), "b"("Welcome to &cDeadOS&7.\n"));
asm volatile("int $0x80" : "=a"(ret) : "a"(SYS_PRINTF), "b"("You are now in user space.\n"));
asm volatile("int $0x80" : "=a"(ret) : "a"(SYS_PRINTF), "b"("Type 'help' for a list of available commands.\n"));
asm volatile("int $0x80" : "=a"(ret) : "a"(SYS_SHELL_INIT));
}