[Yellowstone] Wireframe for moving yellowstone to rust.
This commit is contained in:
parent
0aa4a1f5f1
commit
c9b484089e
24 changed files with 265 additions and 25 deletions
12
rust/lib/denali/Cargo.toml
Normal file
12
rust/lib/denali/Cargo.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "denali"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
mammoth = { path = "../mammoth" }
|
||||
yunq = {path = "../yunq"}
|
||||
yunq-derive = {path = "../yunq-derive"}
|
||||
|
||||
[build-dependencies]
|
||||
yunqc = {path = "../../../yunq/rust"}
|
||||
14
rust/lib/denali/build.rs
Normal file
14
rust/lib/denali/build.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let input_file = "../../../sys/denali/lib/denali/denali.yunq";
|
||||
|
||||
println!("cargo::rerun-if-changed={input_file}");
|
||||
|
||||
let input = fs::read_to_string(input_file).expect("Failed to read input file");
|
||||
|
||||
let code = yunqc::codegen(&input).expect("Failed to generate yunq code.");
|
||||
|
||||
let out = std::env::var("OUT_DIR").unwrap() + "/yunq.rs";
|
||||
fs::write(out, code).expect("Failed to write generated code.");
|
||||
}
|
||||
5
rust/lib/denali/src/lib.rs
Normal file
5
rust/lib/denali/src/lib.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![no_std]
|
||||
|
||||
use core::include;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/yunq.rs"));
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
19
rust/lib/mammoth/src/sync.rs
Normal file
19
rust/lib/mammoth/src/sync.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
mammoth = { path = "../mammoth" }
|
||||
yellowstone = { path = "../yellowstone" }
|
||||
yellowstone-yunq = { path = "../yellowstone" }
|
||||
yunq = {path = "../yunq"}
|
||||
yunq-derive = {path = "../yunq-derive"}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ static mut VFS_CLIENT: Option<VFSClient> = None;
|
|||
fn get_client() -> &'static mut VFSClient {
|
||||
unsafe {
|
||||
if let None = VFS_CLIENT {
|
||||
let endpoint_cap = yellowstone::from_init_endpoint()
|
||||
.get_endpoint(&yellowstone::GetEndpointRequest {
|
||||
let endpoint_cap = yellowstone_yunq::from_init_endpoint()
|
||||
.get_endpoint(&yellowstone_yunq::GetEndpointRequest {
|
||||
endpoint_name: "victoriafalls".to_string(),
|
||||
})
|
||||
.expect("Failed to get VFS endpoint");
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
mammoth = { path = "../mammoth" }
|
||||
yellowstone = { path = "../yellowstone" }
|
||||
yellowstone-yunq = { path = "../yellowstone" }
|
||||
yunq = {path = "../yunq"}
|
||||
yunq-derive = {path = "../yunq-derive"}
|
||||
|
||||
|
|
|
|||
|
|
@ -211,8 +211,8 @@ impl KeyboardListener {
|
|||
handler,
|
||||
});
|
||||
|
||||
let voyageur_endpoint = yellowstone::from_init_endpoint()
|
||||
.get_endpoint(&yellowstone::GetEndpointRequest {
|
||||
let voyageur_endpoint = yellowstone_yunq::from_init_endpoint()
|
||||
.get_endpoint(&yellowstone_yunq::GetEndpointRequest {
|
||||
endpoint_name: "voyageurs".to_string(),
|
||||
})?
|
||||
.endpoint;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "yellowstone"
|
||||
name = "yellowstone-yunq"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue