Compare commits

...

4 Commits

24 changed files with 228 additions and 38 deletions

23
rust/Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "autocfg"
@ -39,6 +39,23 @@ dependencies = [
"yunqc",
]
[[package]]
name = "denali_client"
version = "0.1.0"
dependencies = [
"mammoth",
"yunq",
"yunqc",
]
[[package]]
name = "ext2"
version = "0.1.0"
dependencies = [
"denali_client",
"mammoth",
]
[[package]]
name = "linked_list_allocator"
version = "0.10.5"
@ -154,6 +171,8 @@ checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
name = "victoriafalls"
version = "0.1.0"
dependencies = [
"denali_client",
"ext2",
"mammoth",
"yellowstone-yunq",
"yunq",
@ -174,7 +193,7 @@ dependencies = [
name = "yellowstone"
version = "0.1.0"
dependencies = [
"denali",
"denali_client",
"mammoth",
"victoriafalls",
"voyageurs",

View File

@ -1,7 +1,16 @@
[workspace]
members = [
"lib/mammoth", "lib/victoriafalls", "lib/voyageurs", "lib/yellowstone", "lib/yunq", "lib/yunq-test", "sys/denali", "sys/teton", "sys/yellowstone", "usr/testbed",
"lib/client/denali_client", "lib/fs/ext2",
"lib/mammoth",
"lib/voyageurs",
"lib/yellowstone",
"lib/yunq",
"lib/yunq-test",
"sys/denali",
"sys/teton",
"sys/victoriafalls",
"sys/yellowstone",
"usr/testbed",
]
resolver = "2"

View File

@ -0,0 +1,11 @@
[package]
name = "denali_client"
version = "0.1.0"
edition = "2024"
[dependencies]
mammoth = { path = "../../mammoth" }
yunq = { path = "../../yunq" }
[build-dependencies]
yunqc = { path = "../../../../yunq/rust" }

View 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.");
}

View File

@ -0,0 +1,31 @@
use mammoth::{cap::Capability, zion::ZError};
use crate::{DenaliClient, DiskBlock, ReadRequest};
pub struct DiskReader {
client: DenaliClient,
disk_id: u64,
lba_offset: u64,
}
impl DiskReader {
pub fn new(client: DenaliClient, disk_id: u64, lba_offset: u64) -> Self {
Self {
client,
disk_id,
lba_offset,
}
}
pub fn read(&mut self, lba: u64, cnt: u64) -> Result<Capability, ZError> {
let read_resp = self.client.read(&ReadRequest {
device_id: self.disk_id,
block: DiskBlock {
lba: self.lba_offset + lba,
size: cnt,
},
})?;
Ok(Capability::take(read_resp.memory))
}
}

View File

@ -0,0 +1,9 @@
#![no_std]
use core::include;
include!(concat!(env!("OUT_DIR"), "/yunq.rs"));
mod disk_reader;
pub use disk_reader::DiskReader;

View File

@ -0,0 +1,8 @@
[package]
name = "ext2"
version = "0.1.0"
edition = "2024"
[dependencies]
denali_client = { path = "../../client/denali_client" }
mammoth = { path = "../../mammoth" }

View File

@ -0,0 +1,19 @@
use denali_client::DiskReader;
use mammoth::mem::MemoryRegion;
use crate::types::Superblock;
pub struct Ext2Driver {
reader: DiskReader,
}
impl Ext2Driver {
pub fn new(mut reader: DiskReader) -> Self {
let super_block_mem = MemoryRegion::from_cap(reader.read(2, 2).unwrap()).unwrap();
let super_block: &Superblock = super_block_mem.as_ref();
let inodes = super_block.inodes_count;
let magic = super_block.magic;
mammoth::debug!("Superblock ({:#x}): inodes: {:#x}", magic, inodes);
Self { reader }
}
}

View File

@ -0,0 +1,8 @@
#![no_std]
extern crate alloc;
mod ext2_driver;
mod types;
pub use ext2_driver::Ext2Driver;

View File

@ -0,0 +1,30 @@
#[repr(C, packed)]
pub struct Superblock {
pub inodes_count: u32,
pub blocks_count: u32,
pub reserved_blocks_count: u32,
pub free_blocks_count: u32,
pub free_inodes_count: u32,
pub first_data_blok: u32,
pub log_block_size: u32,
pub log_frag_size: u32,
pub blocks_per_group: u32,
pub frags_per_group: u32,
pub inodes_per_group: u32,
pub mtime: u32,
pub wtime: u32,
pub mnt_count: u16,
pub max_mnt_count: u16,
pub magic: u16,
pub state: u16,
pub errors: u16,
pub minor_rev_level: u16,
pub lastcheck: u32,
pub checkinterval: u32,
pub creator_os: u32,
pub rev_level: u32,
pub def_resuid: u16,
pub def_resgid: u16,
pub first_ino: u32,
pub inode_size: u16,
}

View File

@ -103,6 +103,12 @@ impl MemoryRegion {
}
}
impl<T> AsRef<T> for MemoryRegion {
fn as_ref(&self) -> &T {
unsafe { (self.virt_addr as *const T).as_ref().unwrap() }
}
}
impl Drop for MemoryRegion {
fn drop(&mut self) {
// FIXME: We shouldn't have to do this manual adjustment.

View File

@ -1,14 +0,0 @@
[package]
name = "victoriafalls"
version = "0.1.0"
edition = "2021"
[dependencies]
mammoth = { path = "../mammoth" }
yellowstone-yunq = { path = "../yellowstone" }
yunq = {path = "../yunq"}
[build-dependencies]
yunqc = {path = "../../../yunq/rust"}

View File

@ -6,17 +6,11 @@ edition = "2021"
[dependencies]
bitfield-struct = "0.8.0"
mammoth = { path = "../../lib/mammoth" }
yunq = {path = "../../lib/yunq"}
yellowstone-yunq = { path = "../../lib/yellowstone", optional = true }
yunq = { path = "../../lib/yunq" }
yellowstone-yunq = { path = "../../lib/yellowstone" }
[[bin]]
name = "denali"
required-features = ["binary"]
[build-dependencies]
yunqc = {path = "../../../yunq/rust"}
[features]
default = ["binary"]
binary = ["dep:yellowstone-yunq"]
yunqc = { path = "../../../yunq/rust" }

View File

@ -155,8 +155,13 @@ impl AhciController {
mammoth::debug!("Sector size: {:#0x}", new_sector_size);
mammoth::debug!("LBA Count: {:#0x}", lba_count);
//self.sector_size = Some(new_sector_size as u64);
//self.sector_cnt = Some(lba_count);
// We hardcode assumptions about sector size in a few places, better to panic if we
// are wrong.
assert_eq!(
new_sector_size, 512,
"Sector size {} differs from 512.",
new_sector_size
);
} else {
mammoth::debug!("Skipping non-sata sig: {:#0x}", sig);
}

View File

@ -5,6 +5,6 @@ edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }
victoriafalls = { path = "../../lib/victoriafalls" }
victoriafalls = { path = "../victoriafalls" }
voyageurs = { path = "../../lib/voyageurs" }
yellowstone-yunq = { path = "../../lib/yellowstone" }

View File

@ -0,0 +1,17 @@
[package]
name = "victoriafalls"
version = "0.1.0"
edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }
yellowstone-yunq = { path = "../../lib/yellowstone" }
yunq = { path = "../../lib/yunq" }
denali_client = { path = "../../lib/client/denali_client" }
ext2 = { path = "../../lib/fs/ext2" }
[build-dependencies]
yunqc = { path = "../../../yunq/rust" }
[[bin]]
name = "victoriafalls"

View File

@ -0,0 +1,24 @@
#![no_std]
#![no_main]
use denali_client::{DenaliClient, DiskReader};
use ext2::Ext2Driver;
use mammoth::{cap::Capability, define_entry, zion::z_err_t};
define_entry!();
#[no_mangle]
extern "C" fn main() -> z_err_t {
let yellowstone = yellowstone_yunq::from_init_endpoint();
let denali_info = yellowstone.get_denali().unwrap();
let client = DenaliClient::new(Capability::take(denali_info.denali_endpoint));
let driver = Ext2Driver::new(DiskReader::new(
client,
denali_info.device_id,
denali_info.lba_offset,
));
0
}

View File

@ -5,8 +5,8 @@ edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }
denali = { path = "../../sys/denali", default-features = false}
victoriafalls = { path = "../../lib/victoriafalls" }
denali_client = { path = "../../lib/client/denali_client" }
victoriafalls = { path = "../victoriafalls" }
voyageurs = { path = "../../lib/voyageurs" }
yellowstone-yunq = { path = "../../lib/yellowstone" }
yunq = { path = "../../lib/yunq" }

View File

@ -1,4 +1,4 @@
use denali::DenaliClient;
use denali_client::DenaliClient;
use mammoth::{cap::Capability, zion::ZError};
const MBR_SIG: u16 = 0xAA55;
@ -47,9 +47,9 @@ struct PartitionEntry {
}
pub fn read_gpt(mut denali: DenaliClient) -> Result<u64, ZError> {
let resp = denali.read(&denali::ReadRequest {
let resp = denali.read(&denali_client::ReadRequest {
device_id: 0,
block: denali::DiskBlock { lba: 0, size: 2 },
block: denali_client::DiskBlock { lba: 0, size: 2 },
})?;
let first_lbas = mammoth::mem::MemoryRegion::from_cap(Capability::take(resp.memory))?;
@ -99,9 +99,9 @@ pub fn read_gpt(mut denali: DenaliClient) -> Result<u64, ZError> {
num_blocks
);
let resp = denali.read(&denali::ReadRequest {
let resp = denali.read(&denali_client::ReadRequest {
device_id: 0,
block: denali::DiskBlock {
block: denali_client::DiskBlock {
lba: lba_partition_entries,
size: num_blocks,
},

View File

@ -122,7 +122,7 @@ impl YellowstoneServerHandler for YellowstoneServerImpl {
fn get_denali(&mut self) -> Result<DenaliInfo, ZError> {
match self.context.service_map.lock().get("denali") {
Some(ep_cap) => crate::gpt::read_gpt(denali::DenaliClient::new(
Some(ep_cap) => crate::gpt::read_gpt(denali_client::DenaliClient::new(
ep_cap.duplicate(Capability::PERMS_ALL).unwrap(),
))
.map(|lba| DenaliInfo {