structure project
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include "interrupts.h"
|
||||
#include "util.h"
|
||||
#include "../../util.h"
|
||||
|
||||
#define PIC1_COMMAND 0x20
|
||||
#define PIC1_DATA 0x21
|
||||
@@ -55,7 +55,7 @@ void enable_apic()
|
||||
uint64_t apic_base = rdmsr(0x1B);
|
||||
apic_base |= (1 << 11);
|
||||
wrmsr(0x1B, apic_base);
|
||||
kprintf("APIC enabled\n");
|
||||
printf("APIC enabled\n");
|
||||
}
|
||||
|
||||
void remap_pic()
|
||||
@@ -74,32 +74,32 @@ void remap_pic()
|
||||
|
||||
outb(PIC1_DATA, 0);
|
||||
outb(PIC2_DATA, 0);
|
||||
kprintf("PIC remapped\n");
|
||||
printf("PIC remapped\n");
|
||||
}
|
||||
|
||||
void disable_pic()
|
||||
{
|
||||
outb(PIC1_DATA, 0xFF);
|
||||
outb(PIC2_DATA, 0xFF);
|
||||
kprintf("PIC disabled\n");
|
||||
printf("PIC disabled\n");
|
||||
}
|
||||
|
||||
void handle_exception(const isr_frame_t* frame)
|
||||
{
|
||||
kprintf("exception[%d]: %s, error code: %d\n", frame->int_no, exception_messages[frame->int_no], frame->err_code);
|
||||
kpanic();
|
||||
printf("exception[%d]: %s, error code: %d\n", frame->int_no, exception_messages[frame->int_no], frame->err_code);
|
||||
panic();
|
||||
}
|
||||
|
||||
void register_irq_handler(uint8_t irq, irq_handler_t handler)
|
||||
{
|
||||
if (irq >= 16)
|
||||
{
|
||||
kprintf("Cannot register irq %d is out of bounds\n", irq);
|
||||
printf("Cannot register irq %d is out of bounds\n", irq);
|
||||
}
|
||||
else
|
||||
{
|
||||
irq_handlers[irq] = handler;
|
||||
kprintf("Registered irq handler at vector %d\n", irq);
|
||||
printf("Registered irq handler at vector %d\n", irq);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,6 @@ void handle_isr(const isr_frame_t* frame)
|
||||
}
|
||||
else
|
||||
{
|
||||
kprintf("interrupt[%d]: not implemented\n", frame->int_no);
|
||||
printf("interrupt[%d]: not implemented\n", frame->int_no);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "kernel.h"
|
||||
#include "../../kernel.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -26,11 +26,11 @@ void register_irq_handler(uint8_t irq, irq_handler_t handler);
|
||||
static inline void enable_interrupts()
|
||||
{
|
||||
__asm__ volatile("sti");
|
||||
kprintf("Interrupts enabled\n");
|
||||
printf("Interrupts enabled\n");
|
||||
}
|
||||
|
||||
static inline void disable_interrupts()
|
||||
{
|
||||
__asm__ volatile("cli");
|
||||
kprintf("Interrupts disabled\n");
|
||||
printf("Interrupts disabled\n");
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "keyboard.h"
|
||||
#include "../../kernel.h"
|
||||
#include "../../util.h"
|
||||
#include "interrupts.h"
|
||||
#include "kernel.h"
|
||||
#include "util.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define SCANCODE_LEFT_SHIFT 42
|
||||
@@ -96,8 +96,8 @@ void register_keypress_handler(const keyboard_handler_t handler)
|
||||
// keyboard_handlers is a dynamic list
|
||||
if (handler_index >= KEYBOARD_HANDLERS_LENGTH)
|
||||
{
|
||||
kprintf("Maximum keyboard handlers reached\n");
|
||||
kpanic();
|
||||
printf("Maximum keyboard handlers reached\n");
|
||||
panic();
|
||||
}
|
||||
|
||||
keyboard_handlers[handler_index] = handler;
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "pmm.h"
|
||||
#include "kernel.h"
|
||||
#include "mem.h"
|
||||
#include "../../kernel.h"
|
||||
#include "../../mem.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -24,8 +24,8 @@ void init_pmm(multiboot_info_t* mbd)
|
||||
|
||||
if (!(mbd->flags & (1 << 6)))
|
||||
{
|
||||
kprintf("Invalid memory map given by bootloader\n");
|
||||
kpanic();
|
||||
printf("Invalid memory map given by bootloader\n");
|
||||
panic();
|
||||
}
|
||||
|
||||
uint64_t offset = 0;
|
||||
@@ -42,13 +42,13 @@ void init_pmm(multiboot_info_t* mbd)
|
||||
|
||||
num_regions++;
|
||||
|
||||
kprintf("Available memory: 0x%x - 0x%x (%u KB)\n", mmmt->addr, mmmt->addr + mmmt->len, mmmt->len / 1024);
|
||||
printf("Available memory: 0x%x - 0x%x (%u KB)\n", mmmt->addr, mmmt->addr + mmmt->len, mmmt->len / 1024);
|
||||
}
|
||||
|
||||
offset += mmmt->size + sizeof(mmmt->size);
|
||||
}
|
||||
|
||||
kmemset(page_bitmap, 0xFF, BITMAP_SIZE);
|
||||
memset(page_bitmap, 0xFF, BITMAP_SIZE);
|
||||
|
||||
for (size_t i = 0; i < num_regions; i++)
|
||||
{
|
||||
@@ -67,7 +67,7 @@ void init_pmm(multiboot_info_t* mbd)
|
||||
}
|
||||
else
|
||||
{
|
||||
kprintf("System has more ram than the bitmap allows!\n");
|
||||
printf("System has more ram than the bitmap allows!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ void init_pmm(multiboot_info_t* mbd)
|
||||
}
|
||||
}
|
||||
|
||||
kprintf("PMM initialized\n");
|
||||
printf("PMM initialized\n");
|
||||
}
|
||||
|
||||
uint64_t pmm_alloc_page()
|
||||
18
src/kernel.c
18
src/kernel.c
@@ -1,7 +1,7 @@
|
||||
#include "kernel.h"
|
||||
#include "interrupts.h"
|
||||
#include "multiboot.h"
|
||||
#include "pmm.h"
|
||||
#include "arch/x86_64/interrupts.h"
|
||||
#include "arch/x86_64/multiboot.h"
|
||||
#include "arch/x86_64/pmm.h"
|
||||
#include "string.h"
|
||||
#include "vga.h"
|
||||
#include <stdarg.h>
|
||||
@@ -15,18 +15,18 @@ void kmain(multiboot_info_t* mbd)
|
||||
remap_pic();
|
||||
enable_interrupts();
|
||||
|
||||
kprintf("Welcome to nub OS :)\n");
|
||||
khalt();
|
||||
printf("Welcome to nub OS :)\n");
|
||||
halt();
|
||||
}
|
||||
|
||||
void kpanic()
|
||||
void panic()
|
||||
{
|
||||
kprintf("Kernel panic!\n");
|
||||
printf("Kernel panic!\n");
|
||||
disable_interrupts();
|
||||
khalt();
|
||||
halt();
|
||||
}
|
||||
|
||||
void kprintf(const char* fmt, ...)
|
||||
void printf(const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
void kpanic();
|
||||
void panic();
|
||||
|
||||
void kprintf(const char* fmt, ...);
|
||||
void printf(const char* fmt, ...);
|
||||
|
||||
static inline void khalt()
|
||||
static inline void halt()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "mem.h"
|
||||
#include <stdint.h>
|
||||
|
||||
void kmemset(void* destination, uint8_t value, size_t length)
|
||||
void memset(void* destination, uint8_t value, size_t length)
|
||||
{
|
||||
for (size_t i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void kmemset(void* destination, uint8_t value, size_t length);
|
||||
void memset(void* destination, uint8_t value, size_t length);
|
||||
Reference in New Issue
Block a user