diff options
author | Marvin Borner | 2020-04-28 23:33:34 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-28 23:33:34 +0200 |
commit | 34c752f6fe4f71169172f1b3e46b1eddf69eba6e (patch) | |
tree | c9acf3f6cac1791861d3506c4fe6f2c1dfedeae5 | |
parent | 5f8b5ce7efb7738eaebad43f9648975788ae19ff (diff) |
Added support for multiple user applications
-rw-r--r-- | CMakeLists.txt | 27 | ||||
-rwxr-xr-x | run | 18 | ||||
-rw-r--r-- | src/bootloader/grub.cfg | 2 | ||||
-rw-r--r-- | src/kernel/acpi/acpi.c | 1 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.c | 2 | ||||
-rw-r--r-- | src/kernel/kernel.c | 8 | ||||
-rw-r--r-- | src/kernel/lib/memory.c | 1 | ||||
-rw-r--r-- | src/kernel/multiboot.c | 3 | ||||
-rw-r--r-- | src/kernel/syscall.c | 20 | ||||
-rw-r--r-- | src/kernel/syscall.h | 87 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.c | 2 | ||||
-rw-r--r-- | src/userspace/libc/syscall.h | 12 | ||||
-rw-r--r-- | src/userspace/linker.ld | 2 | ||||
-rw-r--r-- | src/userspace/programs/init.c | 6 |
14 files changed, 46 insertions, 145 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 843493e..a650621 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,30 +32,33 @@ set(CMAKE_ASM_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS # Recursive sources file(GLOB_RECURSE kernel_sources src/kernel/*.c src/kernel/*.asm) file(GLOB_RECURSE resources_sources src/resources/*.c) -file(GLOB_RECURSE user_sources src/userspace/programs/*.c src/userspace/libc/*.c) +file(GLOB_RECURSE user_sources src/userspace/programs/*.c) +file(GLOB_RECURSE user_libc_sources src/userspace/libc/*.c) # KERNEL add_executable(kernel ${kernel_sources}) target_include_directories(kernel PRIVATE "src") -set_target_properties(kernel PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/kernel.bin") +set_target_properties(kernel PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/kernel/kernel.bin") target_compile_options(kernel PRIVATE "-D ${NETWORK}") target_link_libraries(kernel PRIVATE "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/linker.ld") # RESOURCES add_executable(resources ${resources_sources}) -set_target_properties(resources PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/font.o") -target_compile_options(resources PRIVATE "-Os") +set_target_properties(resources PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/res/font.o") +target_compile_options(resources PRIVATE "-Os") # This is needed to preserve my fixed function order ig add_custom_command( TARGET resources POST_BUILD - COMMAND cross/opt/bin/i686-elf-objcopy -O binary build/font.o build/font.bin + COMMAND cross/opt/bin/i686-elf-objcopy -O binary build/res/font.o build/res/font.bin WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) # USERSPACE -add_executable(user ${user_sources}) -target_include_directories(user PUBLIC "src/userspace/libc/") -set_target_properties(user PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/sh.o") -target_link_libraries(user PRIVATE "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/linker.ld -emain") - -# Dependencies -add_dependencies(kernel resources user) +add_library(userspace_lib ${user_libc_sources}) +target_include_directories(userspace_lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/libc/") +foreach(loop_file ${user_sources}) + get_filename_component(testname ${loop_file} NAME_WE) + add_executable(${testname} ${loop_file}) + target_include_directories(${testname} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/libc/") + target_link_libraries(${testname} userspace_lib "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/linker.ld") + set_target_properties(${testname} PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/user/${testname}") +endforeach(loop_file ${user_sources}) @@ -93,20 +93,22 @@ make_build() { mkdir -p iso/ echo "Building..." - mkdir -p build - cd build + mkdir -p build/kernel/ + mkdir -p build/res/ + mkdir -p build/user/ + cd build/ cmake .. >/dev/null make cd .. # Create ISO mkdir -p ./iso/boot/grub/ - cp ./build/kernel.bin ./iso/boot/kernel.bin + cp ./build/kernel/kernel.bin ./iso/boot/kernel.bin cp ./src/bootloader/grub.cfg ./iso/boot/grub/ grub-mkrescue -o ./build/melvix.iso ./iso/ # Check ISO - if grub-file --is-x86-multiboot2 ./build/kernel.bin; then + if grub-file --is-x86-multiboot2 ./build/kernel/kernel.bin; then echo "Multiboot confirmed" else echo "Kernel is corrupted!" @@ -119,8 +121,8 @@ make_build() { mkdir -p ./mnt/etc/ mkdir -p ./mnt/usr/ mkdir -p ./mnt/bin/ - cp ./build/font.bin ./mnt/bin/font - cp ./build/sh.o ./mnt/bin/sh + cp ./build/res/font.bin ./mnt/bin/font + cp ./build/user/* ./mnt/bin/ echo "Hello world, ext2!" | tee -a ./mnt/etc/test /usr/local/bin/genext2fs -B 4096 -d mnt -U -N 4096 -b 65536 ./build/disk.img rm -r mnt/ @@ -155,8 +157,8 @@ make_image() { make_sync() { rm tags compile_commands.json ctags -R --exclude=.git --exclude=build --exclude=iso --exclude=cross . - mkdir -p cmake - cd cmake + mkdir -p build + cd build cmake .. >/dev/null mv compile_commands.json .. cd .. diff --git a/src/bootloader/grub.cfg b/src/bootloader/grub.cfg index 75d4934..cdd19b4 100644 --- a/src/bootloader/grub.cfg +++ b/src/bootloader/grub.cfg @@ -1,6 +1,6 @@ set timeout=0 set default=0 menuentry "Melvix" { - multiboot2 /boot/kernel.bin + multiboot2 /boot/kernel.bin foo bar boot }
\ No newline at end of file diff --git a/src/kernel/acpi/acpi.c b/src/kernel/acpi/acpi.c index 865435f..3e07171 100644 --- a/src/kernel/acpi/acpi.c +++ b/src/kernel/acpi/acpi.c @@ -35,6 +35,7 @@ void acpi_init(struct rsdp *rsdp) hpet = (struct hpet *)kmalloc(sizeof(struct hpet)); madt = (struct madt *)kmalloc(sizeof(struct madt)); + // TODO: Fix ACPI table discovering (HPET & MADT missing) if (strncmp(rsdp->signature, "RSD PTR ", 8) == 0) { memcpy(rsdt, rsdp->rsdt_address, sizeof(struct rsdt) + 32); debug("Found RSDT"); diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index 43b0799..898a0f3 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -122,6 +122,8 @@ void set_optimal_resolution() if (mode_info->width > vbe_width || (mode_info->width == vbe_width && (mode_info->bpp >> 3) > vbe_bpl)) { // if (mode_info->bpp == 32) { // Force specific bpp for debugging + debug("Found mode: %dx%dx%d", mode_info->width, mode_info->height, + mode_info->bpp); highest = *mode; vbe_width = mode_info->width; vbe_height = mode_info->height; diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 3efe193..90b967f 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -44,9 +44,8 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp) isrs_install(); irq_install(); + // multiboot_parse(multiboot_address); // TODO: Why does this break graphics? paging_install(); - log("0x%x", multiboot_address); // TODO: Fix multiboot table mmap - multiboot_parse(multiboot_address); // Install drivers cli(); @@ -65,10 +64,10 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp) load_binaries(); set_optimal_resolution(); - printf("%s", read_file("/etc/test")); + printf("Content of /etc/test: %s", read_file("/etc/test")); syscalls_install(); - struct process *proc = elf_load("/bin/sh"); + struct process *proc = elf_load("/bin/init"); if (proc) { proc->stdin = NULL; proc->stdout = NULL; @@ -76,7 +75,6 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp) process_init(proc); } - log("Okidoko!"); halt_loop(); // asm ("div %0" :: "r"(0)); // Exception testing x/0 }
\ No newline at end of file diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c index 30f75f9..819a70f 100644 --- a/src/kernel/lib/memory.c +++ b/src/kernel/lib/memory.c @@ -58,6 +58,7 @@ uint32_t memory_get_free() void memory_print() { if (meminfo != NULL) { + // TODO: Fix multiboot mem lower/upper info("Mem lower: 0x%x", meminfo->mem_lower); info("Mem upper: 0x%x", meminfo->mem_upper); } diff --git a/src/kernel/multiboot.c b/src/kernel/multiboot.c index 086e628..e922ee7 100644 --- a/src/kernel/multiboot.c +++ b/src/kernel/multiboot.c @@ -15,7 +15,8 @@ void multiboot_parse(uint32_t multiboot_address) tag = (struct multiboot_tag *)((multiboot_uint8_t *)tag + ((tag->size + 7) & ~7))) { switch (tag->type) { case MULTIBOOT_TAG_TYPE_CMDLINE: - debug("Got cmdline"); + // TODO: Add cmdline config support + debug("Got cmdline: %s", ((struct multiboot_tag_string *)tag)->string); break; case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME: debug("Got bootloader name: %s", diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c deleted file mode 100644 index 68750e1..0000000 --- a/src/kernel/syscall.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <kernel/syscall.h> - -/** - * DEFINITIONS - */ -DEFN_SYSCALL0(halt, 0); - -DEFN_SYSCALL1(write, 1, const char *); - -DEFN_SYSCALL1(read, 2, const char *); - -DEFN_SYSCALL1(writec, 3, char); - -DEFN_SYSCALL0(readc, 4); - -DEFN_SYSCALL0(get_pointers, 5); - -DEFN_SYSCALL1(alloc, 6, uint32_t); - -DEFN_SYSCALL1(free, 7, uint32_t);
\ No newline at end of file diff --git a/src/kernel/syscall.h b/src/kernel/syscall.h deleted file mode 100644 index 9f5bdb0..0000000 --- a/src/kernel/syscall.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef MELVIX_SYSCALL_H -#define MELVIX_SYSCALL_H - -#include <stdint.h> - -#define DECL_SYSCALL0(fn) int syscall_##fn(); -#define DECL_SYSCALL1(fn, p1) int syscall_##fn(p1); -#define DECL_SYSCALL2(fn, p1, p2) int syscall_##fn(p1, p2); -#define DECL_SYSCALL3(fn, p1, p2, p3) int syscall_##fn(p1, p2, p3); -#define DECL_SYSCALL4(fn, p1, p2, p3, p4) int syscall_##fn(p1, p2, p3, p4); -#define DECL_SYSCALL5(fn, p1, p2, p3, p4, p5) int syscall_##fn(p1, p2, p3, p4, p5); - -#define DEFN_SYSCALL0(fn, num) \ - int syscall_##fn() \ - { \ - int a; \ - asm volatile("int $0x80" : "=a"(a) : "0"(num)); \ - return a; \ - } - -#define DEFN_SYSCALL1(fn, num, P1) \ - int syscall_##fn(P1 p1) \ - { \ - int a; \ - asm volatile("int $0x80" : "=a"(a) : "0"(num), "b"((int)p1)); \ - return a; \ - } - -#define DEFN_SYSCALL2(fn, num, P1, P2) \ - int syscall_##fn(P1 p1, P2 p2) \ - { \ - int a; \ - asm volatile("int $0x80" : "=a"(a) : "0"(num), "b"((int)p1), "c"((int)p2)); \ - return a; \ - } - -#define DEFN_SYSCALL3(fn, num, P1, P2, P3) \ - int syscall_##fn(P1 p1, P2 p2, P3 p3) \ - { \ - int a; \ - asm volatile("int $0x80" \ - : "=a"(a) \ - : "0"(num), "b"((int)p1), "c"((int)p2), "d"((int)p3)); \ - return a; \ - } - -#define DEFN_SYSCALL4(fn, num, P1, P2, P3, P4) \ - int syscall_##fn(P1 p1, P2 p2, P3 p3, P4 p4) \ - { \ - int a; \ - asm volatile("int $0x80" \ - : "=a"(a) \ - : "0"(num), "b"((int)p1), "c"((int)p2), "d"((int)p3), "S"((int)p4)); \ - return a; \ - } - -#define DEFN_SYSCALL5(fn, num) \ - int syscall_##fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \ - { \ - int a; \ - asm volatile("int $0x80" \ - : "=a"(a) \ - : "0"(num), "b"((int)p1), "c"((int)p2), "d"((int)p3), "S"((int)p4), \ - "D"((int)p5)); \ - return a; \ - } - -/** - * DECLARATIONS - */ -DECL_SYSCALL0(halt); - -DECL_SYSCALL1(write, const char *); - -DECL_SYSCALL1(read, const char *); - -DECL_SYSCALL1(writec, char); - -DECL_SYSCALL0(readc); - -DECL_SYSCALL0(get_pointers); - -DECL_SYSCALL1(alloc, uint32_t); - -DECL_SYSCALL1(free, uint32_t); - -#endif
\ No newline at end of file diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index a106f07..ca12118 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -8,7 +8,7 @@ typedef uint32_t (*syscall_func)(uint32_t, ...); uint32_t (*syscalls[])() = { [0] = (uint32_t(*)())halt_loop, // DEBUG! - [1] = sys_putch, + [1] = (uint32_t(*)())sys_putch, [2] = sys_getch, [3] = sys_malloc, [4] = sys_free }; diff --git a/src/userspace/libc/syscall.h b/src/userspace/libc/syscall.h index 9f5bdb0..61ffecc 100644 --- a/src/userspace/libc/syscall.h +++ b/src/userspace/libc/syscall.h @@ -70,17 +70,11 @@ */ DECL_SYSCALL0(halt); -DECL_SYSCALL1(write, const char *); +DECL_SYSCALL1(putch, const char *); -DECL_SYSCALL1(read, const char *); +DECL_SYSCALL0(getch); -DECL_SYSCALL1(writec, char); - -DECL_SYSCALL0(readc); - -DECL_SYSCALL0(get_pointers); - -DECL_SYSCALL1(alloc, uint32_t); +DECL_SYSCALL1(malloc, uint32_t); DECL_SYSCALL1(free, uint32_t); diff --git a/src/userspace/linker.ld b/src/userspace/linker.ld index 8ede485..69018c4 100644 --- a/src/userspace/linker.ld +++ b/src/userspace/linker.ld @@ -1,4 +1,4 @@ -ENTRY(_start) +ENTRY(main) SECTIONS { .text 0x40000000: diff --git a/src/userspace/programs/init.c b/src/userspace/programs/init.c new file mode 100644 index 0000000..bf3c7f4 --- /dev/null +++ b/src/userspace/programs/init.c @@ -0,0 +1,6 @@ +void main() +{ + // TODO: Exec shell + while (1) { + }; +}
\ No newline at end of file |