feature (drivers): implemented a function for API functions to determine the calling driver
This commit is contained in:
parent
263e7305cf
commit
a904629abd
|
@ -44,13 +44,6 @@ typedef enum {
|
||||||
|
|
||||||
} driver_category_E;
|
} driver_category_E;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
driver_transport_protocol_E transport_protocol:8;
|
|
||||||
char name [0x80];
|
|
||||||
uint16_t length;
|
|
||||||
uint8_t specific_config [];
|
|
||||||
} __attribute__((packed)) driver_config_header_T;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t vendor_id;
|
uint16_t vendor_id;
|
||||||
uint16_t device_id;
|
uint16_t device_id;
|
||||||
|
@ -76,6 +69,11 @@ typedef struct {
|
||||||
uint8_t mbr_type;
|
uint8_t mbr_type;
|
||||||
} __attribute__((packed)) driver_config_fs_T;
|
} __attribute__((packed)) driver_config_fs_T;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
driver_config_pci_T* pci;
|
||||||
|
driver_config_usb_T* usb;
|
||||||
|
driver_config_fs_T* fs;
|
||||||
|
} conf_U;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
|
@ -101,10 +99,11 @@ typedef struct {
|
||||||
void driver_manager_init ();
|
void driver_manager_init ();
|
||||||
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);
|
||||||
driver_T* driver_register (elf_executable_T* executable, uint8_t* buffer);
|
driver_T* driver_register (elf_executable_T* executable, uint8_t* buffer);
|
||||||
void driver_init (driver_T* driver, driver_config_header_T* conf);
|
void driver_init (driver_T* driver, driver_transport_protocol_E protocol, conf_U conf);
|
||||||
driver_T* driver_lookup_pci_device (uint16_t vendor_id, uint16_t device_id);
|
driver_T* driver_lookup_pci_device (uint16_t vendor_id, uint16_t device_id);
|
||||||
driver_T* driver_lookup_usb_device (uint16_t vendor_id, uint16_t device_id);
|
driver_T* driver_lookup_usb_device (uint16_t vendor_id, uint16_t device_id);
|
||||||
driver_T* driver_lookup_fs_gpt (uint8_t guid[16]);
|
driver_T* driver_lookup_fs_gpt (uint8_t guid[16]);
|
||||||
driver_T* driver_lookup_fs_mbr (uint8_t type);
|
driver_T* driver_lookup_fs_mbr (uint8_t type);
|
||||||
|
driver_T* driver_lookup_by_address (void* address);
|
||||||
|
|
||||||
#endif //NOXOS_DRIVER_H
|
#endif //NOXOS_DRIVER_H
|
||||||
|
|
|
@ -92,7 +92,7 @@ void kmain(boot_info_T boot_info) {
|
||||||
elf_executable_T* executable = elf_executable_create(node->cache->buffer);
|
elf_executable_T* executable = elf_executable_create(node->cache->buffer);
|
||||||
driver_T* drv = driver_register(executable, 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, "_start")->address;
|
void* entry = drv->base + symbol_resolve_from_name(executable->symbols, executable->num_symbols, "_init")->address;
|
||||||
|
|
||||||
void (*drv_test)() = entry;
|
void (*drv_test)() = entry;
|
||||||
drv_test();
|
drv_test();
|
||||||
|
|
|
@ -1,7 +1,21 @@
|
||||||
// This file is part of noxos and licensed under the MIT open source license
|
// This file is part of noxos and licensed under the MIT open source license
|
||||||
|
|
||||||
|
#include <drivers/driver.h>
|
||||||
#include <utils/logger.h>
|
#include <utils/logger.h>
|
||||||
|
#include <mm/stack.h>
|
||||||
|
|
||||||
|
void nx_drv_pci_config(driver_config_pci_T* config) {
|
||||||
|
driver_T* driver = driver_lookup_by_address((void*)stack_get_caller());
|
||||||
|
if (driver == NULL) return;
|
||||||
|
|
||||||
void nx_drv_init() {
|
}
|
||||||
DEBUG("hello from the driver api");
|
|
||||||
|
void nx_drv_usb_config(driver_config_usb_T* config) {
|
||||||
|
driver_T* driver = driver_lookup_by_address((void*)stack_get_caller());
|
||||||
|
if (driver == NULL) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nx_drv_fs_config(driver_config_fs_T* config) {
|
||||||
|
driver_T* driver = driver_lookup_by_address((void*)stack_get_caller());
|
||||||
|
if (driver == NULL) return;
|
||||||
}
|
}
|
|
@ -79,8 +79,9 @@ bool elf_relocate_driver(elf_executable_T* executable, uint8_t* buffer, void* lo
|
||||||
|
|
||||||
symbol_T* symbols = scheduler_get_process(PROCESS_KERNEL)->executable->symbols;
|
symbol_T* symbols = scheduler_get_process(PROCESS_KERNEL)->executable->symbols;
|
||||||
uint64_t num_symbols = scheduler_get_process(PROCESS_KERNEL)->executable->num_symbols;
|
uint64_t num_symbols = scheduler_get_process(PROCESS_KERNEL)->executable->num_symbols;
|
||||||
|
|
||||||
uint32_t num_relocations = sections[i].length / sections[i].entry_size;
|
uint32_t num_relocations = sections[i].length / sections[i].entry_size;
|
||||||
|
log(LOG_INFO, "Found RELA section with %d relocations", num_relocations);
|
||||||
|
|
||||||
for (int j = 0; j < num_relocations; j++) {
|
for (int j = 0; j < num_relocations; j++) {
|
||||||
elf_relocation_a_T* relocation = &((elf_relocation_a_T*)&buffer[sections[i].offset])[j];
|
elf_relocation_a_T* relocation = &((elf_relocation_a_T*)&buffer[sections[i].offset])[j];
|
||||||
uint64_t* relocation_offset = (uint64_t*)&((uint8_t*)load_address)[relocation->offset];
|
uint64_t* relocation_offset = (uint64_t*)&((uint8_t*)load_address)[relocation->offset];
|
||||||
|
@ -93,6 +94,8 @@ bool elf_relocate_driver(elf_executable_T* executable, uint8_t* buffer, void* lo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log(LOG_INFO, "relocating '%s(0x%x)' -> PLT_ENTRY[0x%x]", drv_symbol_name, k_symbol, relocation_offset);
|
||||||
|
|
||||||
switch (relocation_type) {
|
switch (relocation_type) {
|
||||||
case ELF_REL_JUMP_SLOT: {
|
case ELF_REL_JUMP_SLOT: {
|
||||||
*relocation_offset = k_symbol->address;
|
*relocation_offset = k_symbol->address;
|
||||||
|
|
|
@ -47,6 +47,10 @@ driver_T* driver_find_fs_mbr(uint8_t type) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void driver_init(driver_T* driver, driver_transport_protocol_E protocol, conf_U conf) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
driver_T* driver_register(elf_executable_T* executable, uint8_t* buffer) {
|
driver_T* driver_register(elf_executable_T* executable, uint8_t* buffer) {
|
||||||
uint64_t chunk_id = 0;
|
uint64_t chunk_id = 0;
|
||||||
driver_manager_chunk_T* chunk = g_driver_manager.driver_pool;
|
driver_manager_chunk_T* chunk = g_driver_manager.driver_pool;
|
||||||
|
@ -65,7 +69,7 @@ driver_T* driver_register(elf_executable_T* executable, uint8_t* buffer) {
|
||||||
bitmap_set(&chunk->drivers_bitmap, i, true);
|
bitmap_set(&chunk->drivers_bitmap, i, true);
|
||||||
chunk->free_slots -= 1;
|
chunk->free_slots -= 1;
|
||||||
driver = &chunk->drivers[i];
|
driver = &chunk->drivers[i];
|
||||||
driver->id = chunk_id + i;
|
driver->id = (chunk_id * DRIVER_MANAGER_CHUNK_SIZE) + i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,10 +89,6 @@ driver_T* driver_register(elf_executable_T* executable, uint8_t* buffer) {
|
||||||
return driver;
|
return driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
void driver_init(driver_T* driver, driver_config_header_T* conf) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
driver_T* driver_lookup_pci_device(uint16_t vendor_id, uint16_t device_id) {
|
driver_T* driver_lookup_pci_device(uint16_t vendor_id, uint16_t device_id) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -104,3 +104,23 @@ driver_T* driver_lookup_fs_gpt(uint8_t guid[16]) {
|
||||||
driver_T* driver_lookup_fs_mbr(uint8_t type) {
|
driver_T* driver_lookup_fs_mbr(uint8_t type) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
driver_T* driver_lookup_by_address(void* address) {
|
||||||
|
uint64_t value = (uint64_t)address;
|
||||||
|
value &= 0xFFFFFFFF00000000;
|
||||||
|
value -= MEM_REGION_KERNEL_DRIVERS;
|
||||||
|
value >>= 32;
|
||||||
|
|
||||||
|
uint64_t chunk_id = value / DRIVER_MANAGER_CHUNK_SIZE;
|
||||||
|
uint64_t local_id = value % DRIVER_MANAGER_CHUNK_SIZE;
|
||||||
|
|
||||||
|
driver_manager_chunk_T* chunk = g_driver_manager.driver_pool;
|
||||||
|
for (uint64_t i = 0; i < chunk_id; i++) {
|
||||||
|
if (chunk->next == NULL) return NULL;
|
||||||
|
chunk = chunk->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bitmap_get(&chunk->drivers_bitmap, local_id)) return NULL;
|
||||||
|
|
||||||
|
return &chunk->drivers[local_id];
|
||||||
|
}
|
Loading…
Reference in New Issue