diff --git a/rust/lib/mammoth/Cargo.toml b/rust/lib/mammoth/Cargo.toml index 5caf191..4577b56 100644 --- a/rust/lib/mammoth/Cargo.toml +++ b/rust/lib/mammoth/Cargo.toml @@ -3,6 +3,9 @@ name = "mammoth" version = "0.1.0" edition = "2021" +[lib] +name = "mammoth" + [dependencies] [build-dependencies] diff --git a/rust/lib/mammoth/src/bindings.rs b/rust/lib/mammoth/src/bindings.rs index 24556e8..31568ef 100644 --- a/rust/lib/mammoth/src/bindings.rs +++ b/rust/lib/mammoth/src/bindings.rs @@ -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; diff --git a/rust/lib/mammoth/src/lib.rs b/rust/lib/mammoth/src/lib.rs index be5f1e6..863d06d 100644 --- a/rust/lib/mammoth/src/lib.rs +++ b/rust/lib/mammoth/src/lib.rs @@ -8,13 +8,14 @@ use core::panic::PanicInfo; include!("bindings.rs"); -fn syscall(id: u64, req: &T) -> u64 { +pub fn syscall(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!() + } + }; +} diff --git a/rust/usr/testbed/src/main.rs b/rust/usr/testbed/src/main.rs index e06f819..53a54fe 100644 --- a/rust/usr/testbed/src/main.rs +++ b/rust/usr/testbed/src/main.rs @@ -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 } diff --git a/sys/yellowstone/hw/gpt.cpp b/sys/yellowstone/hw/gpt.cpp index 43704cd..a7b2bb3 100644 --- a/sys/yellowstone/hw/gpt.cpp +++ b/sys/yellowstone/hw/gpt.cpp @@ -72,9 +72,10 @@ glcr::Status GptReader::ParsePartitionTables() { } MbrPartition* first_partition = reinterpret_cast(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(