mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2025-12-17 12:24:37 +03:00
lesson 23, initial commit
This commit is contained in:
36
23-fixes/kernel/kernel.c
Normal file
36
23-fixes/kernel/kernel.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "../cpu/isr.h"
|
||||
#include "../drivers/screen.h"
|
||||
#include "kernel.h"
|
||||
#include "../libc/string.h"
|
||||
#include "../libc/mem.h"
|
||||
|
||||
void main() {
|
||||
isr_install();
|
||||
irq_install();
|
||||
|
||||
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 */
|
||||
u32 phys_addr;
|
||||
u32 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> ");
|
||||
}
|
||||
6
23-fixes/kernel/kernel.h
Normal file
6
23-fixes/kernel/kernel.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef KERNEL_H
|
||||
#define KERNEL_H
|
||||
|
||||
void user_input(char *input);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user