You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
#include "src/fs.h"
|
|
#include "src/gdt.h"
|
|
#include "src/idt.h"
|
|
#include "src/keyboard.h"
|
|
#include "src/memory.h"
|
|
#include "src/panic.h"
|
|
#include "src/path.h"
|
|
#include "src/pic.h"
|
|
#include "src/process.h"
|
|
#include "src/syscall.h"
|
|
#include "src/util.h"
|
|
#include "src/vga.h"
|
|
|
|
__attribute__((interrupt)) void isr_divide_by_zero(__attribute__((unused)) struct interrupt_frame *frame) {
|
|
vga_set_string(VGA_HEIGHT - 1, 0, "EXCEPTION: divide by zero", 0x4F);
|
|
while (1)
|
|
;
|
|
}
|
|
|
|
__attribute__((interrupt)) void isr_page_fault(__attribute__((unused)) struct interrupt_frame *frame) {
|
|
vga_set_string(VGA_HEIGHT - 1, 0, "EXCEPTION: page fault", 0x4F);
|
|
while (1)
|
|
;
|
|
}
|
|
|
|
__attribute__((interrupt)) void isr_general_violation(__attribute__((unused)) struct interrupt_frame *frame) {
|
|
vga_set_string(VGA_HEIGHT - 1, 0, "EXCEPTION: general violation", 0x4F);
|
|
while (1)
|
|
;
|
|
}
|
|
|
|
__attribute__((interrupt)) void isr_ata_primary(__attribute__((unused)) struct interrupt_frame *frame) {
|
|
outb(0x20, 0x20);
|
|
outb(0xA0, 0x20);
|
|
}
|
|
|
|
void kernel_main() {
|
|
pic_init();
|
|
idt_init();
|
|
outb(0x21, inb(0x21) | 0x01); // mask out timer interrupt
|
|
idt_set_entry(0, isr_divide_by_zero, 0x8E);
|
|
idt_set_entry(0x0E, isr_page_fault, 0x8E);
|
|
idt_set_entry(0x0D, isr_general_violation, 0x8E);
|
|
idt_set_entry(46, isr_ata_primary, 0x8E);
|
|
__asm__ volatile("sti");
|
|
|
|
gdt_init();
|
|
syscall_init();
|
|
|
|
memory_init();
|
|
|
|
process_t *kp = memory_allocate(sizeof(process_t));
|
|
kp->root = fs_mount();
|
|
kp->cwd = memory_allocate(sizeof(path_t));
|
|
kp->stdin = keyboard_init();
|
|
kp->stdout = vga_init();
|
|
|
|
fs_node_t *hello = fs_open_by(kp->root, "HELLO.BIN");
|
|
|
|
ASSERT(hello, "kernel: hello.bin not found");
|
|
|
|
uint8_t *hello_code = memory_allocate(hello->size);
|
|
fs_read(hello, 0, hello->size, hello_code);
|
|
|
|
process_t *proc = process_create(kp, hello_code, hello->size);
|
|
|
|
memory_free(hello_code);
|
|
fs_close(hello);
|
|
|
|
process_run(proc);
|
|
|
|
while (1);
|
|
|
|
fs_unmount(kp->root);
|
|
|
|
outw(0x604, 0x2000); // TODO: parse ACPI tables for real hardware
|
|
__asm__ volatile("cli; hlt");
|
|
}
|
|
|