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 e55340a..3d2d1d4 100755 Binary files a/ramdisk/test.elf and b/ramdisk/test.elf differ 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) {