diff options
-rwxr-xr-x | run | 3 | ||||
-rw-r--r-- | src/kernel/fs/marfs/read_whole_file.c | 2 | ||||
-rw-r--r-- | src/kernel/gdt/gdt.c | 6 | ||||
-rw-r--r-- | src/kernel/kernel.c | 10 | ||||
-rw-r--r-- | src/kernel/memory/paging.c | 15 | ||||
-rw-r--r-- | src/kernel/memory/paging.h | 4 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.c | 3 | ||||
-rw-r--r-- | src/kernel/tasks/task.c | 10 | ||||
-rw-r--r-- | src/kernel/tasks/task.h | 2 | ||||
-rw-r--r-- | src/kernel/timer/timer.c | 2 | ||||
-rw-r--r-- | src/userspace/linker.ld | 21 | ||||
-rw-r--r-- | src/userspace/main.c | 19 | ||||
-rw-r--r-- | src/userspace/start.asm | 7 | ||||
-rw-r--r-- | src/userspace/syscall.h | 2 |
14 files changed, 34 insertions, 72 deletions
@@ -101,7 +101,6 @@ make_build() { # Userspace # TODO: Find out why userspace optimizations (-Os) cause fatal errors - nasm -f elf ./src/userspace/start.asm -o ./build/userspace/start.o || exit find ./src/userspace/ -name \*.c >./build/tmp while read -r line; do stripped=$(echo "${line}" | sed -r 's/\//_/g') @@ -110,7 +109,7 @@ make_build() { compile_with_flags -O2 -c ./"${line}" -I ./src/userspace -o ./build/userspace/"${stripped}" done <./build/tmp rm ./build/tmp - compile_with_flags -O2 ./build/userspace/*.o -T ./src/userspace/linker.ld -I ./src/userspace -o ./build/user.bin + compile_with_flags -Wl,--oformat=binary -emain -O2 ./build/userspace/*.o -I ./src/userspace -o ./build/user.bin # Create ISO mkdir -p ./iso/boot/ diff --git a/src/kernel/fs/marfs/read_whole_file.c b/src/kernel/fs/marfs/read_whole_file.c index dda5daf..4507f66 100644 --- a/src/kernel/fs/marfs/read_whole_file.c +++ b/src/kernel/fs/marfs/read_whole_file.c @@ -66,4 +66,4 @@ uint8_t *marfs_allocate_and_read_whole_file(uint32_t lba_inode) uint8_t *buffer = (uint8_t *) kmalloc((uint32_t) size); marfs_read_whole_file(lba_inode, buffer); return buffer; -} +}
\ No newline at end of file diff --git a/src/kernel/gdt/gdt.c b/src/kernel/gdt/gdt.c index efff8a3..5b43025 100644 --- a/src/kernel/gdt/gdt.c +++ b/src/kernel/gdt/gdt.c @@ -97,6 +97,7 @@ void gdt_install() // Remove old GDT and install the new changes! gdt_flush(); + tss_flush(); vga_log("Installed Global Descriptor Table"); } @@ -114,13 +115,10 @@ void tss_write(int32_t num, uint16_t ss0, uint32_t esp0) tss_entry.esp0 = esp0; tss_entry.cs = 0x0b; tss_entry.ss = tss_entry.ds = tss_entry.es = tss_entry.fs = tss_entry.gs = 0x13; - - tss_entry.iomap_base = sizeof(struct tss_entry_struct); } -void tss_flush(void) +void tss_flush() { - tss_entry.esp0 = 4096 + (uint32_t) kmalloc(4096); asm volatile ("ltr %%ax": : "a" (0x2B)); } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index e49861c..bd6fac1 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -6,12 +6,10 @@ #include <kernel/memory/paging.h> #include <kernel/input/input.h> #include <kernel/acpi/acpi.h> -#include <kernel/smbios/smbios.h> #include <kernel/lib/lib.h> #include <kernel/syscall/syscall.h> #include <kernel/pci/pci.h> #include <kernel/net/network.h> -#include <kernel/lib/stdio.h> #include <kernel/tasks/task.h> #include <kernel/fs/load.h> @@ -42,8 +40,10 @@ void kernel_main(uint32_t initial_stack) network_install(); asm ("sti"); + tasking_install(); + // Get hardware information - get_smbios(); + // get_smbios(); // Print total memory info("Total memory found: %dMiB", (memory_get_all() >> 10) + 1); @@ -55,10 +55,8 @@ void kernel_main(uint32_t initial_stack) install_melvix(); #endif - tasking_install(); syscalls_install(); - tss_flush(); - switch_to_usermode(userspace); + exec(userspace); panic("This should NOT happen!"); diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 861cdcb..bca5ed3 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -2,7 +2,6 @@ #include <kernel/memory/kheap.h> #include <kernel/lib/lib.h> #include <kernel/system.h> -#include <kernel/lib/stdio.h> int paging_enabled = 0; @@ -89,7 +88,7 @@ void paging_install() kernel_directory = (page_directory_t *) kmalloc_a(sizeof(page_directory_t)); memset(kernel_directory, 0, sizeof(page_directory_t)); - kernel_directory->physicalAddr = (uint32_t) kernel_directory->tablesPhysical; + kernel_directory->physical_address = (uint32_t) kernel_directory->tables_physical; for (uint32_t i = KHEAP_START; i < KHEAP_START + KHEAP_INITIAL_SIZE; i += 0x1000) paging_get_page((uint32_t) i, 1, kernel_directory); @@ -115,7 +114,7 @@ void paging_install() void paging_switch_directory(page_directory_t *dir) { current_directory = dir; - asm volatile("mov %0, %%cr3"::"r"(dir->physicalAddr)); + asm volatile("mov %0, %%cr3"::"r"(dir->physical_address)); uint32_t cr0; asm volatile("mov %%cr0, %0": "=r"(cr0)); cr0 |= 0x80000000; // Enable paging! @@ -148,7 +147,7 @@ page_t *paging_get_page(uint32_t address, int make, page_directory_t *dir) uint32_t tmp; dir->tables[table_idx] = (page_table_t *) kmalloc_ap(sizeof(page_table_t), &tmp); memset(dir->tables[table_idx], 0, 0x1000); - dir->tablesPhysical[table_idx] = tmp | 0x7; // PRESENT, RW, US + dir->tables_physical[table_idx] = tmp | 0x7; // PRESENT, RW, US return &dir->tables[table_idx]->pages[address % 1024]; } else { return 0; @@ -183,9 +182,9 @@ page_directory_t *paging_clone_directory(page_directory_t *src) page_directory_t *dir = (page_directory_t *) kmalloc_ap(sizeof(page_directory_t), &phys); memset(dir, 0, sizeof(page_directory_t)); - uint32_t offset = (uint32_t) dir->tablesPhysical - (uint32_t) dir; + uint32_t offset = (uint32_t) dir->tables_physical - (uint32_t) dir; - dir->physicalAddr = phys + offset; + dir->physical_address = phys + offset; for (int i = 0; i < 1024; i++) { if (!src->tables[i]) @@ -193,11 +192,11 @@ page_directory_t *paging_clone_directory(page_directory_t *src) if (kernel_directory->tables[i] == src->tables[i]) { dir->tables[i] = src->tables[i]; - dir->tablesPhysical[i] = src->tablesPhysical[i]; + dir->tables_physical[i] = src->tables_physical[i]; } else { uint32_t phys; dir->tables[i] = paging_clone_table(src->tables[i], &phys); - dir->tablesPhysical[i] = phys | 0x07; + dir->tables_physical[i] = phys | 0x07; } } return dir; diff --git a/src/kernel/memory/paging.h b/src/kernel/memory/paging.h index 77258b7..74d486f 100644 --- a/src/kernel/memory/paging.h +++ b/src/kernel/memory/paging.h @@ -20,8 +20,8 @@ typedef struct page_table { typedef struct page_directory { page_table_t *tables[1024]; - uint32_t tablesPhysical[1024]; - uint32_t physicalAddr; + uint32_t tables_physical[1024]; + uint32_t physical_address; } page_directory_t; int paging_enabled; diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index 7ca7f99..bb3a01e 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -28,7 +28,8 @@ void syscall_handler(struct regs *r) if (!location) return; - //serial_printf("[SYSCALL] %d (0x%x) 0x%x 0x%x 0x%x 0x%x 0x%x", r->eax, location, r->ebx, r->ecx, r->edx, r->esi, r->edi); + serial_printf("[SYSCALL] %d (0x%x) 0x%x 0x%x 0x%x 0x%x 0x%x", r->eax, location, r->ebx, r->ecx, r->edx, r->esi, + r->edi); r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi); } diff --git a/src/kernel/tasks/task.c b/src/kernel/tasks/task.c index e6caf9a..5451288 100644 --- a/src/kernel/tasks/task.c +++ b/src/kernel/tasks/task.c @@ -4,6 +4,7 @@ #include <kernel/lib/lib.h> #include <kernel/gdt/gdt.h> #include <kernel/system.h> +#include <kernel/syscall.h> volatile task_t *current_task; volatile task_t *ready_queue; @@ -22,7 +23,8 @@ void tasking_install() current_task = ready_queue = (task_t *) kmalloc(sizeof(task_t)); current_task->id = (int) next_pid++; - current_task->esp = current_task->ebp = 0; + current_task->esp = 0; + current_task->ebp = 0; current_task->eip = 0; current_task->page_directory = current_directory; current_task->next = 0; @@ -98,7 +100,8 @@ void switch_task() set_kernel_stack(current_task->kernel_stack + KERNEL_STACK_SIZE); - perform_task_switch(eip, current_directory->physicalAddr, ebp, esp); + paging_switch_directory(current_directory); + perform_task_switch(eip, current_directory->physical_address, ebp, esp); } int fork() @@ -143,7 +146,7 @@ int getpid() return current_task->id; } -void switch_to_usermode(uint32_t binary) +void exec(uint32_t binary) { set_kernel_stack(current_task->kernel_stack + KERNEL_STACK_SIZE); @@ -163,6 +166,5 @@ void switch_to_usermode(uint32_t binary) pushl $0x1B; \ push %0; \ iret; \ - 1: \ " : : "r" (binary)); }
\ No newline at end of file diff --git a/src/kernel/tasks/task.h b/src/kernel/tasks/task.h index 97aeb15..60047eb 100644 --- a/src/kernel/tasks/task.h +++ b/src/kernel/tasks/task.h @@ -25,6 +25,6 @@ void move_stack(void *new_stack_start, uint32_t size); int getpid(); -void switch_to_usermode(uint32_t); +void exec(uint32_t binary); #endif diff --git a/src/kernel/timer/timer.c b/src/kernel/timer/timer.c index 9bf6014..064d807 100644 --- a/src/kernel/timer/timer.c +++ b/src/kernel/timer/timer.c @@ -17,7 +17,7 @@ void timer_phase(int hz) void timer_handler(struct regs *r) { timer_ticks++; - // switch_task(); + switch_task(); } // "Delay" function with CPU sleep diff --git a/src/userspace/linker.ld b/src/userspace/linker.ld deleted file mode 100644 index 720acdc..0000000 --- a/src/userspace/linker.ld +++ /dev/null @@ -1,21 +0,0 @@ -OUTPUT_FORMAT("binary") - -SECTIONS -{ - . = 0; - - .text ALIGN(4): - { - *(.text) - } - - .data ALIGN(4): - { - *(.data) - } - - .rodata ALIGN(4): - { - *(.rodata*) - } -}
\ No newline at end of file diff --git a/src/userspace/main.c b/src/userspace/main.c index c2307a8..da9ee5b 100644 --- a/src/userspace/main.c +++ b/src/userspace/main.c @@ -1,5 +1,4 @@ #include <syscall.h> -#include <mlibc/stdio.h> #include <mlibc/stdlib.h> int32_t starts_with(const char *a, const char *b) @@ -9,18 +8,12 @@ int32_t starts_with(const char *a, const char *b) return length_main < length_pre ? 0 : memcmp(b, a, length_pre) == 0; } -void user_main() +void main() { - char text[] = "> Successfully switched to usermode!\n"; - printf(text); + // As char[]: 0xC105BFD6 + // As const char *: 0x8048B20 - // TODO: PLEASE - printf("If this message shows up, I'll be happy.\n"); - - while (1) { - char *input = readline(); - if (starts_with(input, "ls")) { - printf(text); - } - }; + char test[] = "banane"; + syscall_write(test); + syscall_halt(); }
\ No newline at end of file diff --git a/src/userspace/start.asm b/src/userspace/start.asm deleted file mode 100644 index c6bb2a0..0000000 --- a/src/userspace/start.asm +++ /dev/null @@ -1,7 +0,0 @@ -bits 32 - -section .text - global _start - extern user_main - _start: - call user_main
\ No newline at end of file diff --git a/src/userspace/syscall.h b/src/userspace/syscall.h index bd402a1..2d79458 100644 --- a/src/userspace/syscall.h +++ b/src/userspace/syscall.h @@ -77,4 +77,4 @@ DECL_SYSCALL1(alloc, uint32_t); DECL_SYSCALL1(free, uint32_t); -#endif +#endif
\ No newline at end of file |