diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..55c0d45 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Build output and other log files from arceos +/target +*.asm +*.img +*.bin +*.elf +actual.out +qemu.log +rusty-tags.vi + +# Visual Studio Code settings +/.vscode + +# macOS system files +.DS_Store + +# We ignore Cargo.lock because `axvcpu` is just a library +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index 11b059c..ccfb65e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ resolver = "2" members = [ "axdevice_base", + "vgic" ] [workspace.package] @@ -13,4 +14,5 @@ homepage = "" repository = "" [workspace.dependencies] -axdevice_base = { path = "axdevice_base", version = "0.1"} \ No newline at end of file +axdevice_base = { path = "axdevice_base", version = "0.1"} +vgic = { path = "vgic", version = "0.1"} diff --git a/vgic/Cargo.toml b/vgic/Cargo.toml new file mode 100644 index 0000000..2685de8 --- /dev/null +++ b/vgic/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "vgic" +edition = "2021" +version.workspace = true +authors.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +axdevice_base = { path = "../axdevice_base" } +axaddrspace = { path = "../../axaddrspace" } +memory_addr = "0.3.0" +axerrno = "0.1.0" +crate_interface = "0.1.0" +log = "0.4" +spin = "0.9" \ No newline at end of file diff --git a/vgic/src/gic_traits.rs b/vgic/src/gic_traits.rs new file mode 100644 index 0000000..32ca63e --- /dev/null +++ b/vgic/src/gic_traits.rs @@ -0,0 +1,66 @@ +use crate_interface::call_interface; + +#[crate_interface::def_interface] +pub trait GicTrait { + fn set_enable(vector: usize, enable: bool); + fn get_enable(vector: usize) -> bool; + fn get_typer() -> u32; + fn get_iidr() -> u32; + + fn set_state(int_id: usize, state: usize, current_cpu_id: usize); + fn get_state(int_id: usize) -> usize; + + fn set_icfgr(int_id: usize, cfg: u8); + + fn get_target_cpu(int_id: usize) -> usize; + fn set_target_cpu(int_id: usize, target: u8); + + fn get_priority(int_id: usize) -> usize; + fn set_priority(int_id: usize, priority: u8); +} + +pub struct GicInterface; + +/// Implementation of [`GicTrait`] by crate_interface::call_interface, +/// to provide an easy-to-use interface to +/// the [vgic] crate. +impl GicInterface { + pub fn set_enable(vector: usize, enable: bool) { + call_interface!(GicTrait::set_enable(vector, enable)); + } + pub fn get_enable(vector: usize) -> bool { + call_interface!(GicTrait::get_enable(vector)) + } + + pub fn get_typer() -> u32 { + call_interface!(GicTrait::get_typer()) + } + fn get_iidr() -> u32 { + call_interface!(GicTrait::get_iidr()) + } + + pub fn set_state(int_id: usize, state: usize, current_cpu_id: usize) { + call_interface!(GicTrait::set_state(int_id, state, current_cpu_id)); + } + fn get_state(int_id: usize) -> usize { + call_interface!(GicTrait::get_state(int_id)) + } + + fn set_icfgr(int_id: usize, cfg: u8) { + call_interface!(GicTrait::set_icfgr(int_id, cfg)); + } + + fn get_target_cpu(int_id: usize) -> usize { + call_interface!(GicTrait::get_target_cpu(int_id)) + } + fn set_target_cpu(int_id: usize, target: u8) { + call_interface!(GicTrait::set_target_cpu(int_id, target)); + } + + fn get_priority(int_id: usize) -> usize { + call_interface!(GicTrait::get_priority(int_id)) + } + fn set_priority(int_id: usize, priority: u8) { + call_interface!(GicTrait::set_priority(int_id, priority)); + } +} diff --git a/vgic/src/lib.rs b/vgic/src/lib.rs new file mode 100644 index 0000000..3da45e5 --- /dev/null +++ b/vgic/src/lib.rs @@ -0,0 +1,6 @@ +#![no_std] + +mod gic_traits; + +pub use gic_traits::GicInterface; +pub use gic_traits::GicTrait; \ No newline at end of file