diff --git a/arch/i686/bootstrap.s b/arch/i686/bootstrap.s index 80283e3..4b89f26 100644 --- a/arch/i686/bootstrap.s +++ b/arch/i686/bootstrap.s @@ -28,7 +28,7 @@ undefined behavior. .section .bss, "aw", @nobits .align 16 stack_bottom: -.skip 16384 # 16 KiB +.skip (1 << 16) # 16 KiB stack_top: .global boot_page_directory diff --git a/arch/i686/interrupts/interrupt.c b/arch/i686/interrupts/interrupt.c index 6c2eac4..b4cd565 100644 --- a/arch/i686/interrupts/interrupt.c +++ b/arch/i686/interrupts/interrupt.c @@ -56,7 +56,7 @@ __attribute__((interrupt)) void exception(struct interrupt_frame*) while (1) { } } -__attribute__((interrupt)) void page_fault(struct interrupt_frame*) +__attribute__((interrupt)) void page_fault(struct interrupt_frame* frame) { asm("cli"); terminal_writestring("Page Fault\n"); diff --git a/arch/i686/interrupts/irq0.s b/arch/i686/interrupts/irq0.s index 76be602..214a75b 100644 --- a/arch/i686/interrupts/irq0.s +++ b/arch/i686/interrupts/irq0.s @@ -33,12 +33,11 @@ mov %ax, %es mov %ax, %fs mov %ax, %gs +pop %eax popa mov (esp), %esp -push (ss) -push (esp) push (eflags) push (cs) push (eip) @@ -55,6 +54,7 @@ mov %ax, %es mov %ax, %fs mov %ax, %gs +pop %eax popa push (ss) diff --git a/arch/i686/interrupts/syscall.s b/arch/i686/interrupts/syscall.s index 78af821..d0500f6 100644 --- a/arch/i686/interrupts/syscall.s +++ b/arch/i686/interrupts/syscall.s @@ -1,4 +1,12 @@ .extern _syscall + +.section .bss, "aw", @nobits +.align 16 +syscall_stack_bottom: +.skip (1 << 16) # 16 KiB +syscall_stack_top: + +.section .text .global syscall syscall: mov $0x10, %edx @@ -8,7 +16,8 @@ mov %ax, %fs mov %ax, %gs mov %esp, %edx -mov $0x00f00000, %esp + +mov $syscall_stack_top, %esp push 0x10(%edx) push 0x0C(%edx) push 0x08(%edx) diff --git a/arch/i686/paging.c b/arch/i686/paging.c index e52ee0f..e410133 100644 --- a/arch/i686/paging.c +++ b/arch/i686/paging.c @@ -58,6 +58,7 @@ static void set_page_directory_entry(uintptr_t address, struct x86_Page_Table* t boot_page_directory[address >> 22].address = ((uintptr_t)(table) - 0xC0000000) >> 12; boot_page_directory[address >> 22].present = true; boot_page_directory[address >> 22].read_write = true; + boot_page_directory[address >> 22].user_supervisor = true; } @@ -92,5 +93,7 @@ void setup_paging() { user_data_table.read_write = true; user_data_table.user_supervisor = true; + user_data[0] = 'B'; + reload_pages(); } diff --git a/arch/i686/tty.c b/arch/i686/tty.c index b2cce30..3c4ce5d 100644 --- a/arch/i686/tty.c +++ b/arch/i686/tty.c @@ -88,6 +88,7 @@ static uint16_t terminal_getentryat(size_t x, size_t y) static void terminal_scroll() { + /* for (size_t y = 0; y < VGA_HEIGHT; y++) { for (size_t x = 0; x < VGA_WIDTH; x++) { if (y == VGA_HEIGHT - 1) { @@ -99,7 +100,11 @@ static void terminal_scroll() terminal_putentryat(scrolled, color, x, y); } } - terminal_row = VGA_HEIGHT - 1; + */ + + terminal_initialize(); + + terminal_row = 0; terminal_column = 0; } diff --git a/kernel/elf.c b/kernel/elf.c index 9438826..d979187 100644 --- a/kernel/elf.c +++ b/kernel/elf.c @@ -18,7 +18,7 @@ extern void jump_to_userspace(); void run_program(uint8_t* code, size_t code_length, uint8_t* data, size_t data_length) { - uint8_t* userland_code = (uint8_t*) 0x00000000; + uint8_t* userland_code = (uint8_t*) 0x00000010; uint8_t* userland_data = (uint8_t*) 0x00400000; memcpy(userland_code, code, code_length); @@ -26,7 +26,7 @@ void run_program(uint8_t* code, size_t code_length, uint8_t* data, size_t data_l struct CPUState target = { .eip = (size_t) userland_code, - .esp = 0x00400000, + .esp = 0x00401000, .eax = 0, .ebx = 0, .ecx = 0, @@ -34,7 +34,7 @@ void run_program(uint8_t* code, size_t code_length, uint8_t* data, size_t data_l .cs = 0x18 | 0x3, .ds = 0x20 | 0x3, .eflags = 0x0200, - .ebp = 0x00c00f00, + .ebp = 0, }; struct Task task = { diff --git a/kernel/kernel.c b/kernel/kernel.c index 09bbcbe..e699644 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -14,11 +14,15 @@ #endif uint8_t program[] = { - 0xcd, 0x80, // int 0x80 + // 0xcd, 0x80, // int $0x80 + 0xb9, 0x02, 0x00, 0x00, 0x00, // mov $0, %ecx + 0xff, 0xe1, // jmp *%ecx }; -uint8_t data[] = "Hello From Userspace\n"; +// uint8_t data[] = "Hello From Userspace\n"; +uint8_t data[] = {}; +void irq0(); void kernel_main(void) { @@ -38,9 +42,10 @@ void kernel_main(void) run_program(program, sizeof(program), data, sizeof(data)); asm("sti"); + asm("int $0x20"); while (true) { terminal_writestring("Hello from Kernelspace 1\n"); - terminal_writestring("Hello from Kernelspace 2\n"); + // terminal_writestring("Hello from Kernelspace 2\n"); } } diff --git a/kernel/syscall.c b/kernel/syscall.c index 84b4c5a..ab12ace 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -35,5 +35,5 @@ void _syscall(uint32_t a, uint32_t b, uint32_t c) break; } */ - terminal_writestring("waow :3"); + terminal_writestring("waow :3\n"); } diff --git a/kernel/task.c b/kernel/task.c index 74a8086..d9bd9ee 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -118,6 +118,7 @@ void next_task() { eip = s.eip; if ((cs & 3) == 0) { + // esp -= 4; jump_kernel( s.edi, s.esi,