feature (syscalls): implemented basic stdout printing

This commit is contained in:
antifallobst 2023-04-21 13:45:58 +02:00
parent 766110435a
commit cae02e598d
5 changed files with 38 additions and 25 deletions

View File

@ -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,

View File

@ -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");
}

Binary file not shown.

View File

@ -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
}

View File

@ -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) {