Add entrypoint to rust mammoth.

This commit is contained in:
Drew Galbraith 2024-07-26 14:44:05 -07:00
parent d6833be0ad
commit 40a50e8d00
5 changed files with 75 additions and 7 deletions

View File

@ -3,6 +3,9 @@ name = "mammoth"
version = "0.1.0"
edition = "2021"
[lib]
name = "mammoth"
[dependencies]
[build-dependencies]

View File

@ -1,5 +1,7 @@
/* automatically generated by rust-bindgen 0.69.4 */
pub type zcap = u64;
pub const _STDINT_H: u32 = 1;
pub const _FEATURES_H: u32 = 1;
pub const _ISOC95_SOURCE: u32 = 1;

View File

@ -8,13 +8,14 @@ use core::panic::PanicInfo;
include!("bindings.rs");
fn syscall<T>(id: u64, req: &T) -> u64 {
pub fn syscall<T>(id: u64, req: &T) -> u64 {
unsafe { SysCall1(id, req as *const T as *const c_void) }
}
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
let req = ZProcessExitReq { code: 1 };
// Internal error.
let req = ZProcessExitReq { code: 0x100 };
syscall(kZionProcessExit, &req);
unreachable!()
}
@ -26,3 +27,60 @@ pub fn debug(msg: &str) {
};
syscall(kZionDebug, &req);
}
// From /zion/include/ztypes.h
const Z_INIT_SELF_PROC: u64 = 0x4000_0000;
const Z_INIT_SELF_VMAS: u64 = 0x4000_0001;
const Z_INIT_ENDPOINT: u64 = 0x4100_0000;
static mut SELF_PROC_CAP: zcap = 0;
static mut SELF_VMAS_CAP: zcap = 0;
static mut INIT_ENDPOINT: zcap = 0;
pub fn parse_init_port(port_cap: zcap) {
loop {
let mut num_bytes: u64 = 8;
let mut init_sig: u64 = 0;
let mut caps: [u64; 1] = [0];
let mut num_caps: u64 = 1;
let req = ZPortPollReq {
port_cap,
num_bytes: &mut num_bytes as *mut u64,
data: &mut init_sig as *mut u64 as *mut c_void,
caps: &mut caps as *mut u64,
num_caps: &mut num_caps as *mut u64,
};
let resp = syscall(kZionPortPoll, &req);
if resp != 0 {
break;
}
unsafe {
match init_sig {
Z_INIT_SELF_PROC => SELF_PROC_CAP = caps[0],
Z_INIT_SELF_VMAS => SELF_VMAS_CAP = caps[0],
Z_INIT_ENDPOINT => INIT_ENDPOINT = caps[0],
_ => debug("Unknown Cap in Init"),
}
}
}
}
#[macro_export]
macro_rules! define_entry {
() => {
#[no_mangle]
pub extern "C" fn _start(init_port: mammoth::zcap) -> ! {
extern "C" {
fn main() -> z_err_t;
}
mammoth::parse_init_port(init_port);
unsafe {
let err = main();
let req = mammoth::ZProcessExitReq { code: err };
mammoth::syscall(mammoth::kZionProcessExit, &req);
}
unreachable!()
}
};
}

View File

@ -2,9 +2,13 @@
#![no_main]
use mammoth::debug;
use mammoth::define_entry;
use mammoth::z_err_t;
define_entry!();
#[no_mangle]
pub extern "C" fn _start() -> ! {
debug("Test!");
panic!()
pub extern "C" fn main() -> z_err_t {
debug("Testing!");
0
}

View File

@ -72,9 +72,10 @@ glcr::Status GptReader::ParsePartitionTables() {
}
MbrPartition* first_partition =
reinterpret_cast<MbrPartition*>(lba_1_and_2.vaddr() + 0x1BE);
if (first_partition->boot_indicator != 0) {
return glcr::FailedPrecondition(glcr::StrFormat(
"Boot indicator set: {}", first_partition->boot_indicator));
// FIXME: This shouldn't be set but I can't figure out why it is.
dbgln("WARN: Boot indicator set: {}", first_partition->boot_indicator);
}
if (first_partition->os_type != 0xEE) {
return glcr::FailedPrecondition(