Support modules from bootloader (again)
This commit is contained in:
parent
99db031259
commit
c4fc02f87d
1
Makefile
1
Makefile
@ -54,6 +54,7 @@ EMUARGS = -sdl -kernel toaruos-kernel -m 1024
|
||||
EMUARGS += -serial stdio -vga std
|
||||
EMUARGS += -hda toaruos-disk.img -k en-us -no-frame
|
||||
EMUARGS += -rtc base=localtime -net nic,model=rtl8139 -net user
|
||||
EMUARGS += -initrd hdd/mod/debug_shell.ko
|
||||
EMUKVM = -enable-kvm
|
||||
|
||||
.PHONY: all system install test
|
||||
|
@ -16,6 +16,7 @@ typedef struct {
|
||||
hashmap_t * symbols;
|
||||
} module_data_t;
|
||||
|
||||
extern void * module_load_direct(void * blob);
|
||||
extern void * module_load(char * filename);
|
||||
extern void module_unload(char * name);
|
||||
extern void modules_install(void);
|
||||
|
@ -56,6 +56,9 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
initial_esp = esp;
|
||||
extern char * cmdline;
|
||||
|
||||
uint32_t mboot_mods_count = 0;
|
||||
uint32_t ** mboot_mods = NULL;
|
||||
|
||||
if (mboot_mag == MULTIBOOT_EAX_MAGIC) {
|
||||
/* Multiboot (GRUB, native QEMU, PXE) */
|
||||
debug_print(NOTICE, "Relocating Multiboot structures...");
|
||||
@ -68,6 +71,37 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
lfb_vid_memory = (uint8_t *)((vbe_info_t *)(mboot_ptr->vbe_mode_info))->physbase;
|
||||
}
|
||||
|
||||
kprint_to_serial = 1;
|
||||
debug_level = 1;
|
||||
|
||||
if (mboot_ptr->flags & (1 << 3)) {
|
||||
debug_print(NOTICE, "There %s %d module%s starting at 0x%x.", mboot_ptr->mods_count == 1 ? "is" : "are", mboot_ptr->mods_count, mboot_ptr->mods_count == 1 ? "" : "s", mboot_ptr->mods_addr);
|
||||
debug_print(NOTICE, "Current kernel heap start point would be 0x%x.", &end);
|
||||
if (mboot_ptr->mods_count > 0) {
|
||||
uintptr_t last_mod = (uintptr_t)&end;
|
||||
uint32_t i;
|
||||
mboot_mods = (uint32_t**)mboot_ptr->mods_addr;
|
||||
mboot_mods_count = mboot_ptr->mods_count;
|
||||
for (i = 0; i < mboot_ptr->mods_count; ++i ) {
|
||||
uint32_t module_start = *((uint32_t*)mboot_ptr->mods_addr + sizeof(uint32_t*)*2 * i);
|
||||
uint32_t module_end = *(uint32_t*)(mboot_ptr->mods_addr + sizeof(uint32_t*)*2 * i + sizeof(uint32_t*));
|
||||
if ((uintptr_t)(mboot_ptr->mods_addr + sizeof(uint32_t*) * 2 * i + sizeof(uint32_t*) * 2) > last_mod) {
|
||||
/* Just in case some silly person put this in *front*... */
|
||||
last_mod = (uintptr_t)(mboot_ptr->mods_addr + sizeof(uint32_t*) * 2 * i + sizeof(uint32_t*) * 2);
|
||||
}
|
||||
debug_print(NOTICE, "Module %d is at 0x%x:0x%x", i, module_start, module_end);
|
||||
if (last_mod < module_end) {
|
||||
last_mod = module_end;
|
||||
}
|
||||
}
|
||||
while (last_mod % 0x1000) {
|
||||
last_mod += 1;
|
||||
}
|
||||
debug_print(NOTICE, "Moving kernel heap start to 0x%x\n", last_mod);
|
||||
kmalloc_startat(last_mod);
|
||||
}
|
||||
}
|
||||
|
||||
size_t len = strlen((char *)mboot_ptr->cmdline);
|
||||
memmove(cmdline_, (char *)mboot_ptr->cmdline, len + 1);
|
||||
|
||||
@ -128,8 +162,11 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Start shell instead */
|
||||
module_load("/mod/debug_shell.ko");
|
||||
/* Load modules from bootloader */
|
||||
for (uint32_t i = 0; i < mboot_mods_count; ++i ) {
|
||||
uint32_t module_start = *((uint32_t*)mboot_mods + sizeof(uint32_t*)*2 * i);
|
||||
module_load_direct((void *)(module_start));
|
||||
}
|
||||
|
||||
/* Prepare to run /bin/init */
|
||||
char * argv[] = {
|
||||
|
@ -19,21 +19,9 @@ typedef struct {
|
||||
extern char kernel_symbols_start[];
|
||||
extern char kernel_symbols_end[];
|
||||
|
||||
/**
|
||||
* Install a module from a file and return
|
||||
* a pointer to its module_info structure.
|
||||
*/
|
||||
void * module_load(char * filename) {
|
||||
fs_node_t * file = kopen(filename, 0);
|
||||
if (!file) {
|
||||
debug_print(ERROR, "Failed to load module: %s", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
debug_print(NOTICE, "Attempting to load kernel module: %s", filename);
|
||||
|
||||
Elf32_Header * target = (Elf32_Header *)kvmalloc(file->length);
|
||||
read_fs(file, 0, file->length, (uint8_t *)target);
|
||||
void * module_load_direct(void * blob) {
|
||||
Elf32_Header * target = (Elf32_Header *)blob;
|
||||
|
||||
if (target->e_ident[0] != ELFMAG0 ||
|
||||
target->e_ident[1] != ELFMAG1 ||
|
||||
@ -216,15 +204,34 @@ void * module_load(char * filename) {
|
||||
hashmap_free(local_symbols);
|
||||
free(local_symbols);
|
||||
|
||||
close_fs(file);
|
||||
|
||||
return mod_info;
|
||||
|
||||
mod_load_error:
|
||||
close_fs(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a module from a file and return
|
||||
* a pointer to its module_info structure.
|
||||
*/
|
||||
void * module_load(char * filename) {
|
||||
fs_node_t * file = kopen(filename, 0);
|
||||
if (!file) {
|
||||
debug_print(ERROR, "Failed to load module: %s", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
debug_print(NOTICE, "Attempting to load kernel module: %s", filename);
|
||||
|
||||
void * blob = (void *)kvmalloc(file->length);
|
||||
read_fs(file, 0, file->length, (uint8_t *)blob);
|
||||
|
||||
void * result = module_load_direct(blob);
|
||||
|
||||
close_fs(file);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a loaded module.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user