feature (syscalls): implemented basic stdout printing
This commit is contained in:
parent
766110435a
commit
cae02e598d
|
@ -23,8 +23,7 @@ typedef enum {
|
||||||
SYSCALL_FILES_WRITE = 0x0104,
|
SYSCALL_FILES_WRITE = 0x0104,
|
||||||
SYSCALL_FILES_DELETE = 0x0105,
|
SYSCALL_FILES_DELETE = 0x0105,
|
||||||
SYSCALL_FILES_LIST = 0x0106,
|
SYSCALL_FILES_LIST = 0x0106,
|
||||||
SYSCALL_FILES_FOLLOW = 0x0107, // Warning: nx_follow will probably be kicked out of the ABI
|
SYSCALL_FILES_INFO = 0x0107,
|
||||||
SYSCALL_FILES_INFO = 0x0108,
|
|
||||||
|
|
||||||
SYSCALL_MEMORY_MAP = 0x0201,
|
SYSCALL_MEMORY_MAP = 0x0201,
|
||||||
SYSCALL_MEMORY_UNMAP = 0x0202,
|
SYSCALL_MEMORY_UNMAP = 0x0202,
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
void io_out_byte(unsigned short port, unsigned char data) {
|
#include "nox/stdio.h"
|
||||||
asm volatile ("outb %0, %1" : : "a"(data), "Nd"(port));
|
|
||||||
}
|
|
||||||
|
|
||||||
int _start() {
|
void _start() {
|
||||||
// asm("int $0x01");
|
printf("hello libc");
|
||||||
while (1){
|
|
||||||
io_out_byte(0x3F8, 'A');
|
while(1) asm("hlt");
|
||||||
}
|
|
||||||
}
|
}
|
BIN
ramdisk/test.elf
BIN
ramdisk/test.elf
Binary file not shown.
|
@ -58,19 +58,19 @@ void kmain(boot_info_T boot_info) {
|
||||||
log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n");
|
log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n");
|
||||||
|
|
||||||
|
|
||||||
// vfs_node_T* node = vfs_resolve_path(&g_root_fs, "/initrd/test.elf");
|
vfs_node_T* node = vfs_resolve_path(&g_root_fs, "/initrd/test.elf");
|
||||||
// void* buffer = memory_allocate(node->size);
|
void* buffer = memory_allocate(node->size);
|
||||||
// vfs_file_read(node, 0, node->size, buffer);
|
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));
|
|
||||||
|
|
||||||
// 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
|
CORE_HALT_FOREVER
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,28 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) {
|
||||||
uint8_t* mem = (uint8_t*)state->rdx; // arg3
|
uint8_t* mem = (uint8_t*)state->rdx; // arg3
|
||||||
uint64_t n = state->rcx; // arg4
|
uint64_t n = state->rcx; // arg4
|
||||||
|
|
||||||
|
switch (fd) {
|
||||||
|
case FILE_DESCRIPTOR_INVALID:
|
||||||
|
case FILE_DESCRIPTOR_STDIN:
|
||||||
|
case FILE_DESCRIPTOR_STDERR: {
|
||||||
|
state->rax = STATUS_RESOURCE_NOT_AVAILABLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case FILE_DESCRIPTOR_STDOUT: {
|
||||||
|
log(LOG_DEBUG, "Syscall (nx_fwrite) to stdout: %s", mem);
|
||||||
|
state->rax = STATUS_SUCCESS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd);
|
vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd);
|
||||||
|
|
||||||
vfs_file_write(node, offset, n, mem);
|
vfs_file_write(node, offset, n, mem);
|
||||||
|
|
||||||
state->rax = STATUS_SUCCESS;
|
state->rax = STATUS_SUCCESS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void syscall_handle_nx_fdelete(cpu_state_T* state) {
|
void syscall_handle_nx_fdelete(cpu_state_T* state) {
|
||||||
|
|
Loading…
Reference in New Issue