feature (drivers): created infrastructure to config drivers to load on startup
This commit is contained in:
parent
d7c79e1bdf
commit
91f7aa4009
|
@ -2,4 +2,4 @@ build
|
||||||
cmake-build-debug
|
cmake-build-debug
|
||||||
noxos.log
|
noxos.log
|
||||||
ramdisk/shell.elf
|
ramdisk/shell.elf
|
||||||
ramdisk/*.nxkm
|
*.nxkm
|
4
build.sh
4
build.sh
|
@ -56,7 +56,9 @@ libnxdrv_build() {
|
||||||
cd ../drivers/test
|
cd ../drivers/test
|
||||||
bash build.sh
|
bash build.sh
|
||||||
cd ../../kernel
|
cd ../../kernel
|
||||||
cp ../drivers/build/test.nxkm ramdisk/test.nxkm
|
|
||||||
|
mkdir -pv ramdisk/drv/
|
||||||
|
cp ../drivers/build/test.nxkm ramdisk/drv/test.nxkm
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_build() {
|
shell_build() {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"BOOT": [
|
||||||
|
"/initrd/drv/test.nxkm"
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,9 +1,4 @@
|
||||||
{
|
{
|
||||||
"PS2_ACPI_VALIDATION": true,
|
"PS2_ACPI_VALIDATION": true,
|
||||||
"LOG_GRAPHICAL": true,
|
"LOG_GRAPHICAL": true
|
||||||
|
|
||||||
"drivers": [
|
|
||||||
"/initrd/drv/test.nxkm",
|
|
||||||
"/initrd/drv/nx_std_fat32.nxkm"
|
|
||||||
]
|
|
||||||
}
|
}
|
|
@ -84,10 +84,6 @@ void kmain(boot_info_T boot_info) {
|
||||||
//
|
//
|
||||||
// syscall_perform(SYSCALL_PROCESS_SIGNAL, pid, PROCESS_SIGNAL_START, 0, 0);
|
// syscall_perform(SYSCALL_PROCESS_SIGNAL, pid, PROCESS_SIGNAL_START, 0, 0);
|
||||||
|
|
||||||
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);
|
driver_T* resolved = driver_lookup_pci_device(0x8086, 0x2922);
|
||||||
|
|
||||||
DEBUG("resolved: 0x%x", resolved);
|
DEBUG("resolved: 0x%x", resolved);
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
#include <drivers/driver.h>
|
#include <drivers/driver.h>
|
||||||
#include <drivers/builtin/elf/relocation.h>
|
#include <drivers/builtin/elf/relocation.h>
|
||||||
|
#include <drivers/builtin/json.h>
|
||||||
#include <utils/logger.h>
|
#include <utils/logger.h>
|
||||||
#include <utils/memory.h>
|
#include <utils/memory.h>
|
||||||
#include <proc/scheduler.h>
|
#include <proc/scheduler.h>
|
||||||
|
#include <platform/syscall.h>
|
||||||
#include <mm/region.h>
|
#include <mm/region.h>
|
||||||
|
|
||||||
driver_manager_T g_driver_manager;
|
driver_manager_T g_driver_manager;
|
||||||
|
@ -15,6 +17,47 @@ void driver_manager_init() {
|
||||||
g_driver_manager.lookup_table_usb = hashmap_create(DRIVER_MANAGER_HASHMAP_SIZE);
|
g_driver_manager.lookup_table_usb = hashmap_create(DRIVER_MANAGER_HASHMAP_SIZE);
|
||||||
g_driver_manager.lookup_table_fs_gpt = hashmap_create(DRIVER_MANAGER_HASHMAP_SIZE);
|
g_driver_manager.lookup_table_fs_gpt = hashmap_create(DRIVER_MANAGER_HASHMAP_SIZE);
|
||||||
g_driver_manager.lookup_table_fs_mbr = hashmap_create(DRIVER_MANAGER_HASHMAP_SIZE);
|
g_driver_manager.lookup_table_fs_mbr = hashmap_create(DRIVER_MANAGER_HASHMAP_SIZE);
|
||||||
|
|
||||||
|
vfs_node_T* node = vfs_resolve_path(&g_root_fs, "/initrd/drivers.json");
|
||||||
|
if (node == NULL || node->type != VFS_NODE_FILE) {
|
||||||
|
log(LOG_WARNING, "No drivers config file found. !!! THIS WILL VERY LIKELY CAUSE THE OS TO NOT WORK!!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* buffer = memory_allocate(node->size + 1);
|
||||||
|
vfs_file_read(node, 0, node->size, buffer);
|
||||||
|
buffer[node->size] = 0;
|
||||||
|
|
||||||
|
json_T* json = json_from_string(buffer);
|
||||||
|
|
||||||
|
json_node_T* child = json->root_node->childs_start;
|
||||||
|
while (child != NULL) {
|
||||||
|
if (string_compare("BOOT", child->string)) {
|
||||||
|
if (&child->childs_start[0] == NULL || child->childs_start[0].type != JSON_NODE_ARRAY) {
|
||||||
|
log(LOG_WARNING, "sysconfig -> failed to parse field 'BOOT' (expected array)");
|
||||||
|
} else {
|
||||||
|
log(LOG_INFO, "Loading drivers for level 'BOOT':");
|
||||||
|
json_node_T* array_child = child->childs_start[0].childs_start;
|
||||||
|
while (array_child != NULL) {
|
||||||
|
uint64_t drv_id, fd;
|
||||||
|
log(LOG_INFO, " > %s", array_child->string);
|
||||||
|
syscall_perform(SYSCALL_NX_FS_OPEN, (uint64_t)array_child->string, 0, (uint64_t)&fd, 0);
|
||||||
|
syscall_perform(SYSCALL_NX_DRV_REGISTER, fd, (uint64_t)&drv_id, 0, 0);
|
||||||
|
syscall_perform(SYSCALL_NX_FS_CLOSE, fd, 0, 0, 0);
|
||||||
|
array_child = array_child->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log(LOG_WARNING, "sysconfig -> skipping field '%s' (unknown identifier)", child->string);
|
||||||
|
}
|
||||||
|
|
||||||
|
child = child->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
json_destruct(json);
|
||||||
|
|
||||||
|
memory_free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
driver_manager_chunk_T* driver_manager_chunk_alloc(driver_manager_chunk_T* prev) {
|
driver_manager_chunk_T* driver_manager_chunk_alloc(driver_manager_chunk_T* prev) {
|
||||||
|
|
Loading…
Reference in New Issue