feature (modules): started work on kernel modules

This commit is contained in:
antifallobst 2023-05-17 00:18:25 +02:00
parent 7f711d853e
commit 9a35aa6648
5 changed files with 107 additions and 0 deletions

32
inc/modules/loader.h Normal file
View File

@ -0,0 +1,32 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_MODULES_LOADER_H
#define NOXOS_MODULES_LOADER_H
#include <modules/module.h>
#include <utils/bitmap.h>
#define MODULE_MANAGER_CHUNK_SIZE 16
typedef struct module_manager_chunk_T module_manager_chunk_T;
struct module_manager_chunk_T {
module_T* modules [MODULE_MANAGER_CHUNK_SIZE];
bitmap_T modules_bitmap;
uint32_t num_modules;
module_manager_chunk_T* prev;
module_manager_chunk_T* next;
};
typedef struct {
module_manager_chunk_T* chunks;
} module_manager_T;
void module_manager_init ();
module_manager_chunk_T* module_manager_chunk_alloc (module_manager_chunk_T* prev);
module_T* module_load (string_t name, string_t path);
void module_unload (module_T* module);
#endif //NOXOS_MODULES_LOADER_H

16
inc/modules/module.h Normal file
View File

@ -0,0 +1,16 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_MODULE_H
#define NOXOS_MODULE_H
#include <utils/stdtypes.h>
#include <utils/string.h>
#include <drivers/elf/elf.h>
typedef struct {
string_t name;
string_t path;
elf_executable_T* executable;
} module_T;
#endif //NOXOS_MODULE_H

View File

@ -20,6 +20,7 @@
#include "drivers/ps2/controller.h"
#include "drivers/tty.h"
#include "proc/scheduler.h"
#include "modules/loader.h"
void limine_terminal_print(boot_info_T* boot_info, string_t string) {
boot_info->terminal->write(boot_info->terminal->terminals[0], string, string_length(string));
@ -50,6 +51,8 @@ void kernel_init(boot_info_T* boot_info) {
acpi_init(boot_info);
module_manager_init();
drive_manager_init();
pci_init();

53
src/modules/loader.c Normal file
View File

@ -0,0 +1,53 @@
// This file is part of noxos and licensed under the MIT open source license
#include <modules/loader.h>
#include <utils/memory.h>
#include <utils/logger.h>
#include <drivers/fs/vfs.h>
module_manager_T g_module_manager;
void module_manager_init() {
g_module_manager.chunks = module_manager_chunk_alloc(NULL);
}
module_manager_chunk_T* module_manager_chunk_alloc(module_manager_chunk_T* prev) {
module_manager_chunk_T* chunk = memory_allocate(sizeof(module_manager_chunk_T));
chunk->modules_bitmap = bitmap_init(MODULE_MANAGER_CHUNK_SIZE);
chunk->num_modules = 0;
chunk->next = NULL;
chunk->prev = prev;
if (prev != NULL) {
prev->next = chunk;
}
return chunk;
}
module_T* module_load(string_t name, string_t path) {
module_T* module = memory_allocate(sizeof(module_T));
module->name = name;
module->path = path;
vfs_node_T* node = vfs_resolve_path(&g_root_fs, path);
if (node == NULL || node->type != VFS_NODE_FILE) {
memory_free(module);
log(LOG_ERROR, "failed to load module '%s' from '%s' (file not found)", name, path);
return NULL;
}
void* buffer = memory_allocate(node->size);
vfs_file_read(node, 0, node->size, buffer);
module->executable = elf_executable_create(buffer);
log(LOG_INFO, "loaded module '%s' from '%s'", name, path);
return module;
}
void module_unload(module_T* module) {
}

3
src/modules/module.c Normal file
View File

@ -0,0 +1,3 @@
// This file is part of noxos and licensed under the MIT open source license
#include <modules/module.h>