[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:
@@ -8,8 +8,6 @@
|
|||||||
#include <j6/syscalls.h>
|
#include <j6/syscalls.h>
|
||||||
#include <j6/thread.hh>
|
#include <j6/thread.hh>
|
||||||
|
|
||||||
extern j6_handle_t __handle_self;
|
|
||||||
|
|
||||||
namespace j6 {
|
namespace j6 {
|
||||||
|
|
||||||
static constexpr size_t stack_size = 0x10000;
|
static constexpr size_t stack_size = 0x10000;
|
||||||
@@ -42,7 +40,7 @@ thread::start(void *user)
|
|||||||
uint64_t arg0 = reinterpret_cast<uint64_t>(this);
|
uint64_t arg0 = reinterpret_cast<uint64_t>(this);
|
||||||
uint64_t arg1 = reinterpret_cast<uint64_t>(user);
|
uint64_t arg1 = reinterpret_cast<uint64_t>(user);
|
||||||
|
|
||||||
m_status = j6_thread_create(&m_thread, __handle_self,
|
m_status = j6_thread_create(&m_thread, 0,
|
||||||
m_stack_top, reinterpret_cast<uintptr_t>(init_proc),
|
m_stack_top, reinterpret_cast<uintptr_t>(init_proc),
|
||||||
arg0, arg1);
|
arg0, arg1);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <bootproto/devices/framebuffer.h>
|
||||||
|
|
||||||
#include <j6/init.h>
|
#include <j6/init.h>
|
||||||
#include <j6/errors.h>
|
#include <j6/errors.h>
|
||||||
#include <j6/flags.h>
|
#include <j6/flags.h>
|
||||||
@@ -13,66 +15,58 @@
|
|||||||
#include "scrollback.h"
|
#include "scrollback.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int main(int, const char **);
|
|
||||||
void _get_init(size_t *initc, struct j6_init_value **initv);
|
void _get_init(size_t *initc, struct j6_init_value **initv);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern j6_handle_t __handle_sys;
|
extern "C" int
|
||||||
extern j6_handle_t __handle_self;
|
driver_main(int argc, const char **argv, const char **env, const j6_init_args *init)
|
||||||
|
|
||||||
struct entry
|
|
||||||
{
|
|
||||||
uint8_t bytes;
|
|
||||||
uint8_t area;
|
|
||||||
uint8_t severity;
|
|
||||||
uint8_t sequence;
|
|
||||||
char message[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, const char **argv)
|
|
||||||
{
|
{
|
||||||
j6_log("fb driver starting");
|
j6_log("fb driver starting");
|
||||||
|
|
||||||
size_t initc = 0;
|
using bootproto::devices::uefi_fb;
|
||||||
j6_init_value *initv = nullptr;
|
using bootproto::devices::video_mode;
|
||||||
|
using bootproto::devices::fb_layout;
|
||||||
|
|
||||||
j6_init_framebuffer *fb = nullptr;
|
const uefi_fb *fb = reinterpret_cast<const uefi_fb*>(init->args[0]);
|
||||||
for (unsigned i = 0; i < initc; ++i) {
|
|
||||||
if (initv[i].type == j6_init_desc_framebuffer) {
|
|
||||||
fb = reinterpret_cast<j6_init_framebuffer*>(initv[i].data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fb || fb->addr == 0) {
|
if (!fb || !fb->framebuffer) {
|
||||||
j6_log("fb driver didn't find a framebuffer, exiting");
|
j6_log("fb driver didn't find a framebuffer, exiting");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::buffer lfb = fb->framebuffer;
|
||||||
|
const video_mode &mode = fb->mode;
|
||||||
|
|
||||||
j6_handle_t fb_handle = j6_handle_invalid;
|
j6_handle_t fb_handle = j6_handle_invalid;
|
||||||
uint32_t flags =
|
uint32_t flags =
|
||||||
j6_vm_flag_write |
|
j6_vm_flag_write |
|
||||||
j6_vm_flag_write_combine |
|
j6_vm_flag_write_combine |
|
||||||
j6_vm_flag_mmio;
|
j6_vm_flag_mmio;
|
||||||
j6_status_t s = j6_system_map_phys(__handle_sys, &fb_handle, fb->addr, fb->size, flags);
|
|
||||||
|
j6_handle_t sys = j6_find_first_handle(j6_object_type_system);
|
||||||
|
if (sys == j6_handle_invalid)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
uintptr_t lfb_addr = reinterpret_cast<uintptr_t>(lfb.pointer);
|
||||||
|
j6_status_t s = j6_system_map_phys( sys, &fb_handle, lfb_addr, lfb.count, flags);
|
||||||
if (s != j6_status_ok) {
|
if (s != j6_status_ok) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = j6_vma_map(fb_handle, __handle_self, fb->addr);
|
s = j6_vma_map(fb_handle, 0, lfb_addr);
|
||||||
if (s != j6_status_ok) {
|
if (s != j6_status_ok) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
const screen::pixel_order order = (fb->flags & 1) ?
|
const screen::pixel_order order =
|
||||||
screen::pixel_order::bgr8 : screen::pixel_order::rgb8;
|
(mode.layout == fb_layout::bgr8) ?
|
||||||
|
screen::pixel_order::bgr8 : screen::pixel_order::rgb8;
|
||||||
|
|
||||||
screen scr(
|
screen scr(
|
||||||
reinterpret_cast<void*>(fb->addr),
|
reinterpret_cast<void*>(lfb.pointer),
|
||||||
fb->horizontal,
|
mode.horizontal,
|
||||||
fb->vertical,
|
mode.vertical,
|
||||||
fb->scanline,
|
mode.scanline,
|
||||||
order);
|
order);
|
||||||
|
|
||||||
font fnt;
|
font fnt;
|
||||||
@@ -93,13 +87,14 @@ main(int argc, const char **argv)
|
|||||||
int pending = 0;
|
int pending = 0;
|
||||||
constexpr int pending_threshold = 5;
|
constexpr int pending_threshold = 5;
|
||||||
|
|
||||||
j6_handle_t sys = __handle_sys;
|
|
||||||
size_t buffer_size = 0;
|
size_t buffer_size = 0;
|
||||||
void *message_buffer = nullptr;
|
void *message_buffer = nullptr;
|
||||||
|
|
||||||
|
uint64_t seen = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
size_t size = buffer_size;
|
size_t size = buffer_size;
|
||||||
j6_status_t s = j6_system_get_log(sys, message_buffer, &size);
|
j6_status_t s = j6_system_get_log(sys, seen, message_buffer, &size);
|
||||||
|
|
||||||
if (s == j6_err_insufficient) {
|
if (s == j6_err_insufficient) {
|
||||||
free(message_buffer);
|
free(message_buffer);
|
||||||
@@ -112,9 +107,9 @@ main(int argc, const char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
entry *e = reinterpret_cast<entry*>(message_buffer);
|
j6_log_entry *e = reinterpret_cast<j6_log_entry*>(message_buffer);
|
||||||
|
|
||||||
size_t eom = e->bytes - sizeof(entry);
|
size_t eom = e->bytes - sizeof(j6_log_entry);
|
||||||
e->message[eom] = 0;
|
e->message[eom] = 0;
|
||||||
|
|
||||||
scroll.add_line(e->message, eom);
|
scroll.add_line(e->message, eom);
|
||||||
@@ -136,3 +131,4 @@ main(int argc, const char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main () __attribute__ ((weak, alias ("driver_main")));
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# vim: ft=python
|
# vim: ft=python
|
||||||
|
|
||||||
module("drv.uefi_fb",
|
fb = module("drv.uefi_fb",
|
||||||
targets = [ "user" ],
|
targets = [ "user" ],
|
||||||
deps = [ "libc" ],
|
deps = [ "libc", "bootproto" ],
|
||||||
description = "UEFI framebuffer driver",
|
description = "UEFI framebuffer driver",
|
||||||
drivers = [ "uefi.fb" ],
|
drivers = [ "uefi.fb" ],
|
||||||
sources = [
|
sources = [
|
||||||
@@ -12,3 +12,4 @@ module("drv.uefi_fb",
|
|||||||
"scrollback.cpp",
|
"scrollback.cpp",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
fb.variables['asflags'] = ["${asflags}", "-dmain_func=driver_main"]
|
||||||
|
|||||||
@@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
using bootproto::module;
|
using bootproto::module;
|
||||||
|
|
||||||
extern j6_handle_t __handle_self;
|
|
||||||
|
|
||||||
constexpr uintptr_t load_addr = 0xf8000000;
|
constexpr uintptr_t load_addr = 0xf8000000;
|
||||||
constexpr size_t stack_size = 0x10000;
|
constexpr size_t stack_size = 0x10000;
|
||||||
constexpr uintptr_t stack_top = 0x80000000000;
|
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)
|
if (!addr)
|
||||||
addr = phys;
|
addr = phys;
|
||||||
|
|
||||||
res = j6_vma_map(vma, __handle_self, addr);
|
res = j6_vma_map(vma, 0, addr);
|
||||||
if (res != j6_status_ok)
|
if (res != j6_status_ok)
|
||||||
return j6_handle_invalid;
|
return j6_handle_invalid;
|
||||||
|
|
||||||
@@ -43,7 +41,7 @@ load_program(
|
|||||||
util::const_buffer data,
|
util::const_buffer data,
|
||||||
j6_handle_t sys, j6_handle_t slp,
|
j6_handle_t sys, j6_handle_t slp,
|
||||||
char *err_msg,
|
char *err_msg,
|
||||||
module *arg)
|
const module *arg)
|
||||||
{
|
{
|
||||||
uintptr_t base_address = reinterpret_cast<uintptr_t>(data.pointer);
|
uintptr_t base_address = reinterpret_cast<uintptr_t>(data.pointer);
|
||||||
|
|
||||||
@@ -106,7 +104,7 @@ load_program(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = j6_vma_unmap(sub_vma, __handle_self);
|
res = j6_vma_unmap(sub_vma, 0);
|
||||||
if (res != j6_status_ok) {
|
if (res != j6_status_ok) {
|
||||||
sprintf(err_msg, " ** error loading program '%s': unmapping sub vma: %lx", name, res);
|
sprintf(err_msg, " ** error loading program '%s': unmapping sub vma: %lx", name, res);
|
||||||
return false;
|
return false;
|
||||||
@@ -125,12 +123,11 @@ load_program(
|
|||||||
uint64_t *stack = reinterpret_cast<uint64_t*>(load_addr + stack_size);
|
uint64_t *stack = reinterpret_cast<uint64_t*>(load_addr + stack_size);
|
||||||
memset(stack - 512, 0, 512 * sizeof(uint64_t)); // Zero top page
|
memset(stack - 512, 0, 512 * sizeof(uint64_t)); // Zero top page
|
||||||
|
|
||||||
stack -= 2; // add null frame
|
size_t stack_consumed = 0;
|
||||||
size_t stack_consumed = 2 * sizeof(uint64_t);
|
|
||||||
|
|
||||||
if (arg) {
|
if (arg) {
|
||||||
size_t arg_size = arg->bytes - sizeof(module);
|
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;
|
uint8_t *arg_dest = reinterpret_cast<uint8_t*>(stack) - arg_size;
|
||||||
memcpy(arg_dest, arg_data, arg_size);
|
memcpy(arg_dest, arg_data, arg_size);
|
||||||
stack_consumed += arg_size;
|
stack_consumed += arg_size;
|
||||||
@@ -143,7 +140,7 @@ load_program(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = j6_vma_unmap(stack_vma, __handle_self);
|
res = j6_vma_unmap(stack_vma, 0);
|
||||||
if (res != j6_status_ok) {
|
if (res != j6_status_ok) {
|
||||||
sprintf(err_msg, " ** error loading program '%s': unmapping stack vma: %lx", name, res);
|
sprintf(err_msg, " ** error loading program '%s': unmapping stack vma: %lx", name, res);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ bool load_program(
|
|||||||
util::const_buffer data,
|
util::const_buffer data,
|
||||||
j6_handle_t sys, j6_handle_t slp,
|
j6_handle_t sys, j6_handle_t slp,
|
||||||
char *err_msg,
|
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);
|
j6_handle_t map_phys(j6_handle_t sys, uintptr_t phys, size_t len, uintptr_t addr = 0);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
#include <j6/init.h>
|
#include <j6/init.h>
|
||||||
#include <j6/syscalls.h>
|
#include <j6/syscalls.h>
|
||||||
#include <j6/types.h>
|
#include <j6/types.h>
|
||||||
|
|
||||||
#include <bootproto/init.h>
|
#include <bootproto/init.h>
|
||||||
|
#include <bootproto/devices/framebuffer.h>
|
||||||
|
|
||||||
#include "j6romfs.h"
|
#include "j6romfs.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
@@ -23,8 +25,6 @@ extern "C" {
|
|||||||
|
|
||||||
uintptr_t _arg_modules_phys; // This gets filled in in _start
|
uintptr_t _arg_modules_phys; // This gets filled in in _start
|
||||||
|
|
||||||
extern j6_handle_t __handle_self;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
load_driver(
|
load_driver(
|
||||||
j6romfs::fs &initrd,
|
j6romfs::fs &initrd,
|
||||||
@@ -32,7 +32,7 @@ load_driver(
|
|||||||
const char *name,
|
const char *name,
|
||||||
j6_handle_t sys,
|
j6_handle_t sys,
|
||||||
j6_handle_t slp,
|
j6_handle_t slp,
|
||||||
module *arg = nullptr)
|
const module *arg = nullptr)
|
||||||
{
|
{
|
||||||
const j6romfs::inode *in = initrd.lookup_inode_in_dir(dir, name);
|
const j6romfs::inode *in = initrd.lookup_inode_in_dir(dir, name);
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ main(int argc, const char **argv)
|
|||||||
return s;
|
return s;
|
||||||
|
|
||||||
std::vector<const module*> mods;
|
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;
|
module const *initrd_module;
|
||||||
std::vector<module const*> devices;
|
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);
|
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",
|
initrd.for_each("/jsix/services",
|
||||||
[=, &message](const j6romfs::inode *in, const char *name) {
|
[=, &message](const j6romfs::inode *in, const char *name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user