diff options
author | Marvin Borner | 2019-12-01 15:47:35 +0100 |
---|---|---|
committer | Marvin Borner | 2019-12-01 15:47:35 +0100 |
commit | e9407b091b34d93014b89660601da62f13df37aa (patch) | |
tree | d60f14946e96d7e1bd72657522682032f0a99e84 | |
parent | 50f949d994c33ab23d63bdb9e8a438560ab0b4c4 (diff) |
Semi-working C-based userspace syscalls
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | src/kernel/fs/install.c | 1 | ||||
-rw-r--r-- | src/kernel/kernel.c | 4 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_write.c | 2 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.c | 3 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.h | 1 | ||||
-rw-r--r-- | src/userspace/main.asm | 12 | ||||
-rw-r--r-- | src/userspace/main.c | 10 | ||||
-rw-r--r-- | src/userspace/start.asm | 22 |
9 files changed, 47 insertions, 16 deletions
@@ -34,13 +34,19 @@ build: clean i686-elf-objcopy -O binary ./build/font.o ./build/font.bin; \ rm ./build/font.o; \ + # Userspace + nasm -f elf ./src/userspace/start.asm -o ./build/user_start.o || exit; \ + i686-elf-gcc -c ./src/userspace/main.c -o ./build/user_main.o -I ./src/mlibc -std=gnu99 -ffreestanding -O3 -Wall -Wextra -Wno-unused-parameter || exit; \ + i686-elf-gcc -I ./src/mlibc -o ./build/user.o -std=gnu99 -ffreestanding -O2 -nostdlib ./build/user_start.o ./build/user_main.o || exit; \ + i686-elf-objcopy -O binary ./build/user.o ./build/user.bin; \ + # Create ISO mkdir -p ./iso/boot/; \ mv ./build/melvix.bin ./iso/boot/kernel.bin; \ nasm ./src/bootloader/cd.asm -f bin -o ./iso/boot/cd.bin || exit; \ nasm ./src/bootloader/hdd1.asm -f bin -o ./iso/boot/hdd1.bin || exit; \ nasm ./src/bootloader/hdd2.asm -f bin -o ./iso/boot/hdd2.bin || exit; \ - nasm ./src/userspace/main.asm -f bin -o ./iso/user.bin || exit; \ + cp ./build/user.bin ./iso/user.bin || exit; \ cp ./build/font.bin ./iso/font.bin || exit; \ genisoimage -quiet -input-charset utf-8 -no-emul-boot -b boot/cd.bin -o ./build/melvix.iso ./iso; diff --git a/src/kernel/fs/install.c b/src/kernel/fs/install.c index 358bd98..1d8fe2e 100644 --- a/src/kernel/fs/install.c +++ b/src/kernel/fs/install.c @@ -78,7 +78,6 @@ void install_melvix() if (!font_e) panic("Font not found!"); uint8_t *font = kmalloc(font_e->length + 2048); - serial_write_hex(font_e->length + 2048); ATAPI_granular_read(1 + (font_e->length / 2048), font_e->lba, font); marfs_new_file(font_e->length, font, 0, 0, 0); kfree(font); diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index eb78257..f54eed2 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -51,8 +51,8 @@ void kernel_main() info("Switching to user mode..."); syscalls_install(); tss_flush(); - uint32_t userspace = paging_alloc_pages(2); - paging_set_user(userspace, 2); + uint32_t userspace = paging_alloc_pages(10); + paging_set_user(userspace, 10); marfs_read_whole_file(4, (uint8_t *) (userspace + 4096)); jump_userspace(userspace + 4096); diff --git a/src/kernel/syscall/actions/sys_write.c b/src/kernel/syscall/actions/sys_write.c index c537d12..fceaaab 100644 --- a/src/kernel/syscall/actions/sys_write.c +++ b/src/kernel/syscall/actions/sys_write.c @@ -1,8 +1,10 @@ #include <stdint-gcc.h> #include <mlibc/stdio.h> +#include <kernel/io/io.h> uint32_t sys_write(char *buf, uint32_t count) { + serial_write("WRITE"); for (uint32_t i = 0; i < count; i++) writec(*(buf++)); return count; diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index 289274b..bb32965 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -1,6 +1,7 @@ #include <stdint.h> #include <kernel/syscall/syscall.h> #include <kernel/interrupts/interrupts.h> +#include <kernel/io/io.h> void syscalls_install() { @@ -10,6 +11,8 @@ void syscalls_install() uint32_t syscall_handler(uint32_t id, uint32_t arg0, uint32_t arg1, uint32_t arg2) { + serial_write("Received syscall!\n"); + switch (id) { case 1: return sys_write((char *) arg0, arg1); diff --git a/src/kernel/syscall/syscall.h b/src/kernel/syscall/syscall.h index 7fe7862..304008d 100644 --- a/src/kernel/syscall/syscall.h +++ b/src/kernel/syscall/syscall.h @@ -2,6 +2,7 @@ #define MELVIX_SYSCALL_H extern void idt_syscall(); + void syscalls_install(); uint32_t sys_write(char *buf, uint32_t count); diff --git a/src/userspace/main.asm b/src/userspace/main.asm deleted file mode 100644 index 4369f10..0000000 --- a/src/userspace/main.asm +++ /dev/null @@ -1,12 +0,0 @@ -bits 32 -mov esp, ebp - -mov eax, 1 -lea edi, [ebp+welcome] -mov esi, welcome_sz -int 0x80 - -jmp $ - -welcome db "Welcome to the userspace!", 0x0A, 0x0A -welcome_sz equ $ - welcome
\ No newline at end of file diff --git a/src/userspace/main.c b/src/userspace/main.c new file mode 100644 index 0000000..22bb42a --- /dev/null +++ b/src/userspace/main.c @@ -0,0 +1,10 @@ +#include <stddef.h> + +extern void syscall(); + +void user_main() +{ + syscall(); + + while (1) {}; +}
\ No newline at end of file diff --git a/src/userspace/start.asm b/src/userspace/start.asm new file mode 100644 index 0000000..498f5f5 --- /dev/null +++ b/src/userspace/start.asm @@ -0,0 +1,22 @@ +bits 32 +section .start_section + dd _start + +section .text + global _start + extern user_main + _start: + mov esp, ebp + call user_main + + global syscall + syscall: + mov eax, 1 + lea edi, [ebp+welcome] + mov esi, welcome_sz + int 0x80 + ret + +section .data + welcome db "Welcome to the userspace", 0x0A, 0x0A + welcome_sz equ $ - welcome
\ No newline at end of file |