[Denali] Begin porting to rust.

This commit is contained in:
Drew Galbraith 2024-08-30 00:38:15 -07:00
parent 72e5d8c618
commit 51478e7ccf
12 changed files with 110 additions and 16 deletions

1
rust/Cargo.lock generated
View File

@ -22,6 +22,7 @@ name = "denali"
version = "0.1.0"
dependencies = [
"mammoth",
"yellowstone-yunq",
"yunq",
"yunqc",
]

View File

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

View File

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

View File

@ -0,0 +1,21 @@
[package]
name = "denali"
version = "0.1.0"
edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }
yunq = {path = "../../lib/yunq"}
yellowstone-yunq = { path = "../../lib/yellowstone", optional = true }
[[bin]]
name = "denali"
required-features = ["binary"]
[build-dependencies]
yunqc = {path = "../../../yunq/rust"}
[features]
default = ["binary"]
binary = ["dep:yellowstone-yunq"]

View File

@ -0,0 +1,49 @@
use mammoth::mem::MemoryRegion;
#[repr(C, packed)]
pub struct PciDeviceHeader {
pub vendor_id: u16,
pub device_id: u16,
pub command_reg: u16,
pub status_reg: u16,
pub revision: u8,
pub prog_interface: u8,
pub subclass: u8,
pub class_code: u8,
pub cache_line_size: u8,
pub latency_timer: u8,
pub header_type: u8,
pub bist: u8,
pub bars: [u32; 5],
pub abar: u32,
pub reserved0: u32,
pub subsystem_id: u32,
pub expansion_rom: u16,
pub cap_ptr: u8,
pub reserved1: [u8; 7],
pub interrupt_line: u8,
pub interrupt_pin: u8,
pub min_grant: u8,
pub max_latency: u8,
}
pub struct AhciController {
pci_memory: MemoryRegion,
}
impl AhciController {
pub fn new(pci_memory: MemoryRegion) -> Self {
Self { pci_memory }
}
pub fn pci_header(&self) -> &mut PciDeviceHeader {
unsafe {
self.pci_memory
.mut_slice::<u8>()
.as_mut_ptr()
.cast::<PciDeviceHeader>()
.as_mut()
.unwrap()
}
}
}

View File

@ -0,0 +1,3 @@
mod controller;
pub use controller::AhciController;

View File

@ -0,0 +1,29 @@
#![no_std]
#![no_main]
extern crate alloc;
use mammoth::{define_entry, zion::z_err_t};
use denali::ahci::AhciController;
define_entry!();
#[no_mangle]
extern "C" fn main() -> z_err_t {
mammoth::debug!("IN Denali!");
let yellowstone = yellowstone_yunq::from_init_endpoint();
let ahci_info = yellowstone
.get_ahci_info()
.expect("Failed to get ahci info");
let ahci_controller = AhciController::new(
mammoth::mem::MemoryRegion::from_cap(mammoth::cap::Capability::take(ahci_info.ahci_region))
.unwrap(),
);
mammoth::debug!("AHCI ABAR {:#x}", ahci_controller.pci_header().abar as u64);
0
}

View File

@ -3,3 +3,5 @@
use core::include;
include!(concat!(env!("OUT_DIR"), "/yunq.rs"));
pub mod ahci;

View File

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

View File

@ -40,7 +40,7 @@ cp ../zion/boot/limine.cfg efi/
cp zion/zion efi/
mkdir -p efi/sys
cp ../sysroot/bin/yellowstone efi/sys/yellowstone
cp sys/denali/denali efi/sys/denali
cp ../sysroot/bin/denali efi/sys/denali
cp sys/victoriafalls/victoriafalls efi/sys/victoriafalls
mkdir -p sysroot

View File

@ -23,7 +23,7 @@ for BIN in ${DIR}/../rust/usr/*/; do
done
for BIN in ${DIR}/../rust/sys/*/; do
cargo install --force --path "${BIN}" --root $CARGO_SYS_ROOT
cargo install --all-features --force --path "${BIN}" --root $CARGO_SYS_ROOT
done
popd