From cae02e598d7ff5dbf6d2b54ae32e06b3c0f3ab00 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Fri, 21 Apr 2023 13:45:58 +0200 Subject: [PATCH] feature (syscalls): implemented basic stdout printing --- inc/platform/syscall.h | 3 +-- ramdisk/test.c | 13 +++++-------- ramdisk/test.elf | Bin 13744 -> 17816 bytes src/boot/kmain.c | 24 ++++++++++++------------ src/platform/syscall.c | 23 ++++++++++++++++++++--- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/inc/platform/syscall.h b/inc/platform/syscall.h index 4b82a3e..1e2293e 100644 --- a/inc/platform/syscall.h +++ b/inc/platform/syscall.h @@ -23,8 +23,7 @@ typedef enum { SYSCALL_FILES_WRITE = 0x0104, SYSCALL_FILES_DELETE = 0x0105, SYSCALL_FILES_LIST = 0x0106, - SYSCALL_FILES_FOLLOW = 0x0107, // Warning: nx_follow will probably be kicked out of the ABI - SYSCALL_FILES_INFO = 0x0108, + SYSCALL_FILES_INFO = 0x0107, SYSCALL_MEMORY_MAP = 0x0201, SYSCALL_MEMORY_UNMAP = 0x0202, diff --git a/ramdisk/test.c b/ramdisk/test.c index f466505..4189764 100644 --- a/ramdisk/test.c +++ b/ramdisk/test.c @@ -1,10 +1,7 @@ -void io_out_byte(unsigned short port, unsigned char data) { - asm volatile ("outb %0, %1" : : "a"(data), "Nd"(port)); -} +#include "nox/stdio.h" -int _start() { -// asm("int $0x01"); - while (1){ - io_out_byte(0x3F8, 'A'); - } +void _start() { + printf("hello libc"); + + while(1) asm("hlt"); } \ No newline at end of file diff --git a/ramdisk/test.elf b/ramdisk/test.elf index e55340add0e4e0ffab280245e60f95a5980f111e..3d2d1d4185b433d8aacb87482590057026e76441 100755 GIT binary patch literal 17816 zcmeHPdu&_P89(RR*LLDGahuSlG%T)o6tu-jLnsW|P&dA<-8yz=JEfIi7srp-t7B(= zuojA7Dh4e+kjiADg;8=;Bz>_ecl zY2wXln#vtssx77goy`OlcAtVB#ra{AfIVik_hE4{;AM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!DxeCe0;+&2pbDr0s(>n>3aA3AfGY4mSK#^IQIm(bF6X7) znQ|)sDP^2d{!PmLG9NzE%l1(W?)Ncg-EU*@G5i(9?Nb&bm)PG8xlva1I{4Ph5s-J$Pc=NARiH)j6;4 z-Z7BxbMfPT0`%i^?OAHSbMb)6Z2S(Qo4>e)-`KEi{RI;o`|iy2>61kh1SC!{GaDSA zn?5}g%pRLFwPw&kt!-lOT z<2RZ%^sh9Q{iRlODQwx*gsZ$4CUGy diff --git a/src/boot/kmain.c b/src/boot/kmain.c index 6e2d21e..9799a00 100644 --- a/src/boot/kmain.c +++ b/src/boot/kmain.c @@ -58,19 +58,19 @@ void kmain(boot_info_T boot_info) { log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n"); -// vfs_node_T* node = vfs_resolve_path(&g_root_fs, "/initrd/test.elf"); -// void* buffer = memory_allocate(node->size); -// vfs_file_read(node, 0, node->size, buffer); -// -// elf_executable_T* exec = elf_executable_create(buffer); -// -// pid_t process = process_spawn(PROCESS_KERNEL, "test 1", exec, buffer); -// void* func = (void*)symbol_resolve_from_name(scheduler_get_process(process)->executable->symbols, -// scheduler_get_process(process)->executable->num_symbols, -// "_start")->address + MEM_REGION_PROCESS_EXEC; -// thread_start(thread_spawn(process, func)); + vfs_node_T* node = vfs_resolve_path(&g_root_fs, "/initrd/test.elf"); + void* buffer = memory_allocate(node->size); + vfs_file_read(node, 0, node->size, buffer); -// scheduler_dump_info(scheduler_get_process(PROCESS_KERNEL), 0); + elf_executable_T* exec = elf_executable_create(buffer); + + pid_t process = process_spawn(PROCESS_KERNEL, "test 1", exec, buffer); + void* func = (void*)symbol_resolve_from_name(scheduler_get_process(process)->executable->symbols, + scheduler_get_process(process)->executable->num_symbols, + "_start")->address + MEM_REGION_PROCESS_EXEC; + thread_start(thread_spawn(process, func)); + + scheduler_dump_info(scheduler_get_process(PROCESS_KERNEL), 0); CORE_HALT_FOREVER } diff --git a/src/platform/syscall.c b/src/platform/syscall.c index 7cdd061..da72cd2 100644 --- a/src/platform/syscall.c +++ b/src/platform/syscall.c @@ -50,11 +50,28 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) { uint8_t* mem = (uint8_t*)state->rdx; // arg3 uint64_t n = state->rcx; // arg4 - vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd); + switch (fd) { + case FILE_DESCRIPTOR_INVALID: + case FILE_DESCRIPTOR_STDIN: + case FILE_DESCRIPTOR_STDERR: { + state->rax = STATUS_RESOURCE_NOT_AVAILABLE; + break; + } - vfs_file_write(node, offset, n, mem); + case FILE_DESCRIPTOR_STDOUT: { + log(LOG_DEBUG, "Syscall (nx_fwrite) to stdout: %s", mem); + state->rax = STATUS_SUCCESS; + break; + } - state->rax = STATUS_SUCCESS; + default: { + vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd); + + vfs_file_write(node, offset, n, mem); + state->rax = STATUS_SUCCESS; + break; + } + } } void syscall_handle_nx_fdelete(cpu_state_T* state) {