[init] Let init pass module data to drivers

First pass at passing module data to drivers in init. Also fix some
remaining __handle_self references.
This commit is contained in:
Justin C. Miller
2023-02-19 14:44:16 -08:00
parent 7c194950bb
commit cca8e8b3ad
6 changed files with 59 additions and 56 deletions

View File

@@ -13,8 +13,6 @@
using bootproto::module;
extern j6_handle_t __handle_self;
constexpr uintptr_t load_addr = 0xf8000000;
constexpr size_t stack_size = 0x10000;
constexpr uintptr_t stack_top = 0x80000000000;
@@ -30,7 +28,7 @@ map_phys(j6_handle_t sys, uintptr_t phys, size_t len, uintptr_t addr)
if (!addr)
addr = phys;
res = j6_vma_map(vma, __handle_self, addr);
res = j6_vma_map(vma, 0, addr);
if (res != j6_status_ok)
return j6_handle_invalid;
@@ -43,7 +41,7 @@ load_program(
util::const_buffer data,
j6_handle_t sys, j6_handle_t slp,
char *err_msg,
module *arg)
const module *arg)
{
uintptr_t base_address = reinterpret_cast<uintptr_t>(data.pointer);
@@ -106,7 +104,7 @@ load_program(
return false;
}
res = j6_vma_unmap(sub_vma, __handle_self);
res = j6_vma_unmap(sub_vma, 0);
if (res != j6_status_ok) {
sprintf(err_msg, " ** error loading program '%s': unmapping sub vma: %lx", name, res);
return false;
@@ -125,12 +123,11 @@ load_program(
uint64_t *stack = reinterpret_cast<uint64_t*>(load_addr + stack_size);
memset(stack - 512, 0, 512 * sizeof(uint64_t)); // Zero top page
stack -= 2; // add null frame
size_t stack_consumed = 2 * sizeof(uint64_t);
size_t stack_consumed = 0;
if (arg) {
size_t arg_size = arg->bytes - sizeof(module);
uint8_t *arg_data = arg->data<uint8_t>();
const uint8_t *arg_data = arg->data<uint8_t>();
uint8_t *arg_dest = reinterpret_cast<uint8_t*>(stack) - arg_size;
memcpy(arg_dest, arg_data, arg_size);
stack_consumed += arg_size;
@@ -143,7 +140,7 @@ load_program(
return false;
}
res = j6_vma_unmap(stack_vma, __handle_self);
res = j6_vma_unmap(stack_vma, 0);
if (res != j6_status_ok) {
sprintf(err_msg, " ** error loading program '%s': unmapping stack vma: %lx", name, res);
return false;

View File

@@ -14,7 +14,7 @@ bool load_program(
util::const_buffer data,
j6_handle_t sys, j6_handle_t slp,
char *err_msg,
bootproto::module *arg = nullptr);
const bootproto::module *arg = nullptr);
j6_handle_t map_phys(j6_handle_t sys, uintptr_t phys, size_t len, uintptr_t addr = 0);

View File

@@ -7,7 +7,9 @@
#include <j6/init.h>
#include <j6/syscalls.h>
#include <j6/types.h>
#include <bootproto/init.h>
#include <bootproto/devices/framebuffer.h>
#include "j6romfs.h"
#include "loader.h"
@@ -23,8 +25,6 @@ extern "C" {
uintptr_t _arg_modules_phys; // This gets filled in in _start
extern j6_handle_t __handle_self;
void
load_driver(
j6romfs::fs &initrd,
@@ -32,7 +32,7 @@ load_driver(
const char *name,
j6_handle_t sys,
j6_handle_t slp,
module *arg = nullptr)
const module *arg = nullptr)
{
const j6romfs::inode *in = initrd.lookup_inode_in_dir(dir, name);
@@ -90,7 +90,7 @@ main(int argc, const char **argv)
return s;
std::vector<const module*> mods;
load_modules(_arg_modules_phys, sys, __handle_self, mods);
load_modules(_arg_modules_phys, sys, 0, mods);
module const *initrd_module;
std::vector<module const*> devices;
@@ -136,6 +136,17 @@ main(int argc, const char **argv)
}
load_driver(initrd, driver_dir, "drv.uart.elf", sys_child, slp_mb_child);
for (const module *m : devices) {
switch (m->type_id) {
case bootproto::devices::type_id_uefi_fb:
load_driver(initrd, driver_dir, "drv.uefi_fb.elf", sys_child, slp_mb_child, m);
break;
default:
sprintf(message, "Unknown device type id: %lx", m->type_id);
j6_log(message);
}
}
initrd.for_each("/jsix/services",
[=, &message](const j6romfs::inode *in, const char *name) {