feature (syscalls): implemented 'nx_drv_register'

This commit is contained in:
antifallobst 2023-06-06 21:43:23 +02:00
parent 4070959736
commit b00b57b180
3 changed files with 49 additions and 11 deletions

View File

@ -3,7 +3,6 @@
#include "utils/logger.h"
#include "utils/core.h"
#include "utils/memory.h"
#include "utils/crypto/sha1.h"
#include "boot/boot_info.h"
#include "boot/config.h"
#include "platform/interrupts.h"
@ -88,18 +87,12 @@ void kmain(boot_info_T boot_info) {
//
// syscall_perform(SYSCALL_PROCESS_SIGNAL, pid, PROCESS_SIGNAL_START, 0, 0);
vfs_node_T* node = vfs_resolve_path(&g_root_fs, "/initrd/test.nxkm");
elf_executable_T* executable = elf_executable_create(node->cache->buffer);
driver_T* drv = driver_register(executable, node->cache->buffer);
void* entry = drv->base + symbol_resolve_from_name(executable->symbols, executable->num_symbols, "_init")->address;
void (*drv_test)() = entry;
drv_test();
uint64_t drv_id, fd;
syscall_perform(SYSCALL_NX_FS_OPEN, (uint64_t)"/initrd/test.nxkm", 0, (uint64_t)&fd, 0);
syscall_perform(SYSCALL_NX_DRV_REGISTER, fd, (uint64_t)&drv_id, 0, 0);
driver_T* resolved = driver_lookup_pci_device(0x8086, 0x2922);
DEBUG("driver: 0x%x", drv);
DEBUG("resolved: 0x%x", resolved);
CORE_HALT_FOREVER

View File

@ -6,6 +6,7 @@
#include "utils/memory.h"
#include "proc/scheduler.h"
#include "drivers/builtin/fs/vfs.h"
#include "drivers/driver.h"
#include "mm/page_frame.h"
#include "mm/region.h"
@ -265,6 +266,44 @@ void syscall_handle_nx_proc_signal_send(cpu_state_T* state) {
state->rax = STATUS_SUCCESS;
}
void syscall_handle_nx_drv_register(cpu_state_T* state) {
file_descriptor_t fd = (file_descriptor_t)state->rdi; // arg1
uint64_t* id_ptr = (uint64_t*)state->rsi; // arg2
process_T* process = scheduler_get_current_process();
vfs_node_T* node = file_descriptor_resolve(process->fd_array, fd);
if (node == NULL) {
log(LOG_ERROR, "failed to register driver (file descriptor error)");
state->rax = STATUS_RESOURCE_NOT_AVAILABLE;
return;
}
uint8_t* buffer = memory_allocate(node->size);
vfs_file_read(node, 0, node->size, buffer);
elf_executable_T* exec = elf_executable_create(buffer);
if (exec == NULL) {
memory_free(buffer);
log(LOG_ERROR, "failed to register driver (elf parsing error)");
state->rax = STATUS_NOT_SUPPORTED;
return;
}
driver_T* drv = driver_register(exec, buffer);
if (drv == NULL) {
log(LOG_ERROR, "failed to register driver (registration error)");
state->rax = STATUS_GENERIC_ERROR;
return;
}
void (*drv_init)() = drv->base + symbol_resolve_from_name(exec->symbols, exec->num_symbols, "_init")->address;;
drv_init();
*id_ptr = drv->id;
state->rax = STATUS_SUCCESS;
}
cpu_state_T* syscall_handle(cpu_state_T* state) {
cpu_state_T* return_state = state;
syscall_group_E group_id = (state->rax & 0xFF00) >> 8;
@ -331,6 +370,12 @@ cpu_state_T* syscall_handle(cpu_state_T* state) {
}
case SYSCALLS_DRIVERS: {
switch (state->rax) {
case SYSCALL_NX_DRV_REGISTER: {
syscall_handle_nx_drv_register(state);
break;
}
}
break;
}

View File

@ -57,7 +57,7 @@ void scheduler_init(boot_info_T* boot_info) {
process_kernel_spawn(elf_executable_create(boot_info->kernel_file->address));
syscall_perform(SYSCALL_KERNEL_SCHEDULER_START, 0, 0, 0, 0);
syscall_perform(SYSCALL_NX_KERNEL_SCHEDULER_START, 0, 0, 0, 0);
}
cpu_state_T* scheduler_start(cpu_state_T* state) {