diff --git a/headers/debug.h b/headers/debug.h index f0fc17b..6b23d44 100644 --- a/headers/debug.h +++ b/headers/debug.h @@ -1,10 +1,18 @@ #pragma once +#include "kprintf.h" #include +#define PRINT_VAR(var) kprintf("%s: %d\n", #var, var) + +struct function_entry { + uint32_t addr; + char name[64]; +}; + struct stackframe { struct stackframe *ebp; uint32_t eip; }; -void print_stack(void); \ No newline at end of file +void print_stack(void); diff --git a/headers/memory.h b/headers/memory.h index fcde430..30294c7 100644 --- a/headers/memory.h +++ b/headers/memory.h @@ -8,6 +8,7 @@ #define ACCESSED (1 << 4) #define INIT_FLAGS (PRESENT | RW | SUPERVISOR) #define PAGE_SIZE 4096 +#define KERN_START 0xC0000000 void init_memory(void); void *alloc_frames(size_t size); diff --git a/headers/signal.h b/headers/signal.h new file mode 100644 index 0000000..4960b19 --- /dev/null +++ b/headers/signal.h @@ -0,0 +1,54 @@ +#pragma once + +#define SIG_DFL -1 +#define SIG_IGN 0 + +enum { + SIGABRT, // Abort signal from abort(3) + SIGALRM, // Timer signal from alarm(2) + SIGBUS, // Bus error (bad memory access) + SIGCHLD, // Child stopped or terminated + SIGCLD, // A synonym for SIGCHLD + SIGCONT, // Continue if stopped + SIGEMT, // Emulator trap + SIGFPE, // Floating-point exception + SIGHUP, // Hangup detected on controlling terminal or death of + // controlling process + SIGILL, // Illegal Instruction + SIGINFO, // A synonym for SIGPWR + SIGINT, // Interrupt from keyboard + SIGIO, // I/O now possible (4.2BSD) + SIGIOT, // IOT trap. A synonym for SIGABRT + SIGKILL, // Kill signal + SIGLOST, // File lock lost (unused) + SIGPIPE, // Broken pipe: write to pipe with no readers; see pipe(7) + SIGPOLL, // Pollable event (Sys V); synonym for SIGIO + SIGPROF, // Profiling timer expired + SIGPWR, // Power failure (System V) + SIGQUIT, // Quit from keyboard + SIGSEGV, // Invalid memory reference + SIGSTKFLT, // Stack fault on coprocessor (unused) + SIGSTOP, // Stop process + SIGTSTP, // Stop typed at terminal + SIGSYS, // Bad system call (SVr4); see also seccomp(2) + SIGTERM, // Termination signal + SIGTRAP, // Trace/breakpoint trap + SIGTTIN, // Terminal input for background process + SIGTTOU, // Terminal output for background process + SIGUNUSED, // Synonymous with SIGSYS + SIGURG, // Urgent condition on socket (4.2BSD) + SIGUSR1, // User-defined signal 1 + SIGUSR2, // User-defined signal 2 + SIGVTALRM, // Virtual alarm clock (4.2BSD) + SIGXCPU, // CPU time limit exceeded (4.2BSD); see setrlimit(2) + SIGXFSZ, // File size limit exceeded (4.2BSD); see setrlimit(2) + SIGWINCH, // Window resize signal (4.3BSD, Sun) + SIG_INT, // Interrupt from keyboard +}; + +typedef void (*sighandler_t)(int); + +struct signal { + int signum; + sighandler_t handler; +}; diff --git a/headers/terminal.h b/headers/terminal.h index 5a7bca0..5a86393 100644 --- a/headers/terminal.h +++ b/headers/terminal.h @@ -1,7 +1,6 @@ #pragma once #include "keyboard.h" -#include "kprintf.h" #include #include #include @@ -58,4 +57,4 @@ void terminal_set_default_fg_color(uint8_t fg_color); void terminal_set_default_bg_color(uint8_t fg_color); void terminal_change_default_fg_color(uint8_t color); uint8_t terminal_get_default_color(void); -uint8_t terminal_get_char(int column, int row); \ No newline at end of file +uint8_t terminal_get_char(int column, int row); diff --git a/src/boot.s b/src/boot.s index 611aa50..6cf49d4 100644 --- a/src/boot.s +++ b/src/boot.s @@ -91,7 +91,7 @@ _start: # Enable paging and the write-protect bit. movl %cr0, %ecx - orl $0x80010000, %ecx + orl $0x80000000, %ecx movl %ecx, %cr0 # Jump to higher half with an absolute jump. @@ -119,4 +119,4 @@ _start: # Infinite loop if the system has nothing more to do. cli 1: hlt - jmp 1b \ No newline at end of file + jmp 1b diff --git a/src/debug/print_stack.c b/src/debug/print_stack.c index e3ed9d2..c131c7c 100644 --- a/src/debug/print_stack.c +++ b/src/debug/print_stack.c @@ -1,5 +1,6 @@ #include "debug.h" #include "kprintf.h" +#include void print_stack(void) { diff --git a/src/interrupt/signals/signal.c b/src/interrupt/signals/signal.c new file mode 100644 index 0000000..b1310f8 --- /dev/null +++ b/src/interrupt/signals/signal.c @@ -0,0 +1,10 @@ +#include "signal.h" +#include + +void (*signal(int sig, void (*func)(int)))(int) +{ + // TODO after multi tasking and processes + (void)sig; + (void)func; + return NULL; +} diff --git a/src/kernel.c b/src/kernel.c index 1bf9676..fc1a7ab 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -6,6 +6,7 @@ #include "memory.h" #include "power.h" #include "shell.h" +#include "string.h" #include "terminal.h" #include @@ -28,13 +29,15 @@ void kernel_main(void) terminal_initialize(); init_gdt(); init_idt(); - /* init_memory(); */ + init_memory(); load_drivers(); + memset((void *)0x10001, 'a', 10); kprintf(KERN_ALERT "I see no way to confuse an array of 256 seg:off pairs with a " "complex 8*unknown quantity -byte descriptor table. -- Troy " "Martin 03:50, 22 March 2009 (UTC)\n"); - while (!kmalloc(10)) - ; + /* vmalloc(10); */ + /* while (!vmalloc(10)) */ + /* ; */ shell_init(); } diff --git a/src/kpanic.c b/src/kpanic.c index 605da59..6bf7d58 100644 --- a/src/kpanic.c +++ b/src/kpanic.c @@ -8,15 +8,18 @@ void kpanic(const char *format, ...) { va_list va; - terminal_set_bg_color(VGA_COLOR_BLUE); - terminal_clear(); + /* terminal_set_bg_color(VGA_COLOR_BLUE); */ + /* terminal_clear(); */ va_start(va, format); kvprintf(format, va); va_end(va); - kprintf("\n\n"); - print_stack(); - kprintf("\n\n"); - kprintf("PRESS SPACE TO REBOOT"); + uint32_t faulting_address; + __asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address)); + kprintf("fault at address: %p\n", faulting_address); + /* kprintf("\n\n"); */ + /* print_stack(); */ + /* kprintf("\n\n"); */ + /* kprintf("PRESS SPACE TO REBOOT"); */ while (terminal_getkey().scan_code != KEY_SPACE) ; reboot(); diff --git a/src/memory/page.c b/src/memory/page.c index d25ccd1..5f63d7b 100644 --- a/src/memory/page.c +++ b/src/memory/page.c @@ -6,10 +6,10 @@ #include "memory.h" #include "utils.h" -#define PT_SIZE 0x300 +#define PT_SIZE 1024 #define MAX_TLB_ENTRIES 32 -extern uint32_t page_table_entries[PT_SIZE] __attribute__((aligned(4096))); +extern uint32_t page_table_entries[PT_SIZE]; static int16_t find_next_block(size_t nb_pages) {