[Yellowstone] Wireframe for moving yellowstone to rust.

This commit is contained in:
Drew Galbraith 2024-08-17 20:19:45 -07:00
parent 0aa4a1f5f1
commit c9b484089e
24 changed files with 265 additions and 25 deletions

View file

@ -13,9 +13,7 @@ const ELF_IDENT_64BIT: u8 = 0x2;
const ELF_ENDIAN_LITTLE: u8 = 0x1;
const ELF_ENDIAN_BIG: u8 = 0x2;
const ELF_VERSION_CURRENT: u8 = 0x1;
const ELF_ABI_SYSV: u8 = 0x0;
const ELF_ABI_LINUX: u8 = 0x3;
@ -312,7 +310,10 @@ fn load_elf_program(elf_file: &[u8], vmas: &Capability) -> Result<u64, ZError> {
Ok(header.entry)
}
pub fn spawn_process_from_elf(elf_file: &[u8]) -> Result<Capability, ZError> {
pub fn spawn_process_from_elf_and_init(
elf_file: &[u8],
init_cap: Capability,
) -> Result<Capability, ZError> {
let self_cap = Capability::take_copy(unsafe { init::SELF_PROC_CAP })?;
let port_cap = syscall::port_create()?;
@ -328,8 +329,7 @@ pub fn spawn_process_from_elf(elf_file: &[u8]) -> Result<Capability, ZError> {
new_proc_cap.duplicate(Capability::PERMS_ALL)?,
)?;
port.write_u64_and_cap(crate::init::Z_INIT_SELF_VMAS, new_as_cap)?;
let yellowstone = Capability::take_copy(unsafe { crate::init::INIT_ENDPOINT })?;
port.write_u64_and_cap(crate::init::Z_INIT_ENDPOINT, yellowstone)?;
port.write_u64_and_cap(crate::init::Z_INIT_ENDPOINT, init_cap)?;
let thread_cap = syscall::thread_create(&new_proc_cap)?;
@ -337,3 +337,8 @@ pub fn spawn_process_from_elf(elf_file: &[u8]) -> Result<Capability, ZError> {
Ok(new_proc_cap)
}
pub fn spawn_process_from_elf(elf_file: &[u8]) -> Result<Capability, ZError> {
let yellowstone = Capability::take_copy(unsafe { crate::init::INIT_ENDPOINT })?;
spawn_process_from_elf_and_init(elf_file, yellowstone)
}

View file

@ -6,11 +6,21 @@ use crate::zion::z_cap_t;
pub const Z_INIT_SELF_PROC: u64 = 0x4000_0000;
pub const Z_INIT_SELF_VMAS: u64 = 0x4000_0001;
pub const Z_INIT_ENDPOINT: u64 = 0x4100_0000;
const Z_BOOT_DENALI_VMMO: u64 = 0x4200_0000;
const Z_BOOT_VICTORIA_FALLS_VMMO: u64 = 0x4200_0001;
const Z_BOOT_PCI_VMMO: u64 = 0x4200_0002;
const Z_BOOT_FRAMEBUFFER_INFO_VMMO: u64 = 0x4200_0003;
pub static mut SELF_PROC_CAP: z_cap_t = 0;
pub static mut SELF_VMAS_CAP: z_cap_t = 0;
pub static mut INIT_ENDPOINT: z_cap_t = 0;
// Boot capabilities, are generally only passed to yellowstone.
pub static mut BOOT_DENALI_VMMO: z_cap_t = 0;
pub static mut BOOT_VICTORIA_FALLS_VMMO: z_cap_t = 0;
pub static mut BOOT_PCI_VMMO: z_cap_t = 0;
pub static mut BOOT_FRAMEBUFFER_INFO_VMMO: z_cap_t = 0;
pub fn parse_init_port(port_cap: z_cap_t) {
let init_port = Capability::take(port_cap);
loop {
@ -29,6 +39,10 @@ pub fn parse_init_port(port_cap: z_cap_t) {
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],
Z_BOOT_DENALI_VMMO => BOOT_DENALI_VMMO = caps[0],
Z_BOOT_VICTORIA_FALLS_VMMO => BOOT_VICTORIA_FALLS_VMMO = caps[0],
Z_BOOT_PCI_VMMO => BOOT_PCI_VMMO = caps[0],
Z_BOOT_FRAMEBUFFER_INFO_VMMO => BOOT_FRAMEBUFFER_INFO_VMMO = caps[0],
_ => syscall::debug("Unknown Cap in Init"),
}
}

View file

@ -14,6 +14,7 @@ pub mod elf;
pub mod init;
pub mod mem;
pub mod port;
pub mod sync;
pub mod syscall;
pub mod thread;
pub mod zion;

View file

@ -0,0 +1,19 @@
use crate::{cap::Capability, syscall, zion::ZError};
pub struct Semaphore {
cap: Capability,
}
impl Semaphore {
pub fn new() -> Result<Self, ZError> {
syscall::semaphore_create().map(|cap| Self { cap })
}
pub fn wait(&self) -> Result<(), ZError> {
syscall::semaphone_wait(&self.cap)
}
pub fn signal(&self) -> Result<(), ZError> {
syscall::semaphone_signal(&self.cap)
}
}

View file

@ -363,3 +363,33 @@ pub fn reply_port_recv(
Ok((num_bytes, num_caps))
}
pub fn semaphore_create() -> Result<Capability, ZError> {
let mut sem_cap: z_cap_t = 0;
syscall(
zion::kZionSemaphoreCreate,
&zion::ZSemaphoreCreateReq {
semaphore_cap: &mut sem_cap,
},
)?;
Ok(Capability::take(sem_cap))
}
pub fn semaphone_signal(sem_cap: &Capability) -> Result<(), ZError> {
syscall(
zion::kZionSemaphoreSignal,
&zion::ZSemaphoreSignalReq {
semaphore_cap: sem_cap.raw(),
},
)
}
pub fn semaphone_wait(sem_cap: &Capability) -> Result<(), ZError> {
syscall(
zion::kZionSemaphoreWait,
&zion::ZSemaphoreWaitReq {
semaphore_cap: sem_cap.raw(),
},
)
}