[USER] Load and run ELF module in userspace
This commit is contained in:
@@ -7,15 +7,8 @@
|
||||
#include <cpu.h>
|
||||
#include <timer.h>
|
||||
#include <string.h>
|
||||
|
||||
void thread_function()
|
||||
{
|
||||
int i = 0;
|
||||
while(1)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
#include <cpu.h>
|
||||
#include <elf.h>
|
||||
|
||||
int kmain(uint64_t multiboot_magic, void *multiboot_data)
|
||||
{
|
||||
@@ -32,18 +25,11 @@ int kmain(uint64_t multiboot_magic, void *multiboot_data)
|
||||
pit_init();
|
||||
|
||||
process_t *p1 = process_spawn(0);
|
||||
uint64_t addr = 0x200000;
|
||||
thread_t *th = new_thread((void *)addr, 1);
|
||||
|
||||
// Write thread code to address
|
||||
procmm_map(p1->mmap, addr, addr+PAGE_SIZE, 0);
|
||||
vmm_p4_memcpy(p1->mmap->P4, (void *)addr, 0, thread_function, PAGE_SIZE);
|
||||
procmm_setup(p1);
|
||||
thread_t *th = exec_elf(p1, mboot_data.init);
|
||||
scheduler_insert(th);
|
||||
|
||||
procmm_print_map(p1->mmap);
|
||||
|
||||
process_attach(p1, th);
|
||||
scheduler_insert(th);
|
||||
|
||||
asm("sti");
|
||||
debug_info("BOOT COMPLETE\n");
|
||||
|
||||
@@ -25,6 +25,16 @@ void parse_multiboot1()
|
||||
mboot_data.mmap_size = data->mmap_len/sizeof(mboot1_mmap_entry);
|
||||
mboot_data.mmap = P2V(data->mmap_addr);
|
||||
}
|
||||
if(data->flags & (1<<3))
|
||||
{
|
||||
if(data->mods_count)
|
||||
{
|
||||
mboot1_module_entry *mod = P2V(data->mods_addr);
|
||||
mboot_data.init = P2V(mod->mod_start);
|
||||
mboot_data.init_len = mod->mod_end - mod->mod_start;
|
||||
debug_ok("[MBOOT1] init executable: %x (%x bytes)\n", mboot_data.init, mboot_data.init_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *mboot_tags_type[] = {
|
||||
@@ -120,6 +130,8 @@ void multiboot_init(uint64_t magic, void *data)
|
||||
|
||||
int multiboot_page_used(uintptr_t addr)
|
||||
{
|
||||
if(overlapsz(addr, PAGE_SIZE, V2P(mboot_data.init), mboot_data.init_len))
|
||||
return 1;
|
||||
if(mboot_data.version == 1)
|
||||
{
|
||||
mboot1_info *data = mboot_data.data;
|
||||
|
||||
Reference in New Issue
Block a user