forked from cfenollosa/os-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.c
40 lines (36 loc) · 1.05 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
#include "../cpu/isr.h"
#include "../drivers/screen.h"
#include "kernel.h"
#include "../libc/string.h"
#include "../libc/mem.h"
#include <stdint.h>
void kernel_main() {
isr_install();
irq_install();
asm("int $2");
asm("int $3");
kprint("Type something, it will go through the kernel\n"
"Type END to halt the CPU or PAGE to request a kmalloc()\n> ");
}
void user_input(char *input) {
if (strcmp(input, "END") == 0) {
kprint("Stopping the CPU. Bye!\n");
asm volatile("hlt");
} else if (strcmp(input, "PAGE") == 0) {
/* Lesson 22: Code to test kmalloc, the rest is unchanged */
uint32_t phys_addr;
uint32_t page = kmalloc(1000, 1, &phys_addr);
char page_str[16] = "";
hex_to_ascii(page, page_str);
char phys_str[16] = "";
hex_to_ascii(phys_addr, phys_str);
kprint("Page: ");
kprint(page_str);
kprint(", physical address: ");
kprint(phys_str);
kprint("\n");
}
kprint("You said: ");
kprint(input);
kprint("\n> ");
}