[Denali] Begin porting to rust.
This commit is contained in:
parent
72e5d8c618
commit
51478e7ccf
12 changed files with 110 additions and 16 deletions
21
rust/sys/denali/Cargo.toml
Normal file
21
rust/sys/denali/Cargo.toml
Normal 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"]
|
||||
14
rust/sys/denali/build.rs
Normal file
14
rust/sys/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.");
|
||||
}
|
||||
49
rust/sys/denali/src/ahci/controller.rs
Normal file
49
rust/sys/denali/src/ahci/controller.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
3
rust/sys/denali/src/ahci/mod.rs
Normal file
3
rust/sys/denali/src/ahci/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
mod controller;
|
||||
|
||||
pub use controller::AhciController;
|
||||
29
rust/sys/denali/src/bin/denali.rs
Normal file
29
rust/sys/denali/src/bin/denali.rs
Normal 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
|
||||
}
|
||||
7
rust/sys/denali/src/lib.rs
Normal file
7
rust/sys/denali/src/lib.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#![no_std]
|
||||
|
||||
use core::include;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/yunq.rs"));
|
||||
|
||||
pub mod ahci;
|
||||
Loading…
Add table
Add a link
Reference in a new issue