From 6a0bd9b757d221b4d9dc5dd532b851681d498966 Mon Sep 17 00:00:00 2001 From: guillaume didier Date: Sun, 22 Dec 2019 15:24:21 +0100 Subject: [PATCH] Start work on the cache info module --- .idea/DendrobatesTinctoriusAzureus.iml | 5 +++ Cargo.lock | 8 +++++ Cargo.toml | 2 ++ cache_info/Cargo.toml | 10 ++++++ cache_info/src/lib.rs | 42 ++++++++++++++++++++++++++ src/main.rs | 3 ++ 6 files changed, 70 insertions(+) create mode 100644 cache_info/Cargo.toml create mode 100644 cache_info/src/lib.rs diff --git a/.idea/DendrobatesTinctoriusAzureus.iml b/.idea/DendrobatesTinctoriusAzureus.iml index 73c366e..8f5daf7 100644 --- a/.idea/DendrobatesTinctoriusAzureus.iml +++ b/.idea/DendrobatesTinctoriusAzureus.iml @@ -18,6 +18,11 @@ + + + + + diff --git a/Cargo.lock b/Cargo.lock index acfab46..668ccfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,13 @@ dependencies = [ "bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cache_info" +version = "0.1.0" +dependencies = [ + "polling_serial 0.1.0", +] + [[package]] name = "cast" version = "0.2.2" @@ -41,6 +48,7 @@ name = "dendrobates_tinctoreus_azureus" version = "0.1.0" dependencies = [ "bootloader 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cache_info 0.1.0", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "linked_list_allocator 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "polling_serial 0.1.0", diff --git a/Cargo.toml b/Cargo.toml index ce634d7..284cff1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "vga_buffer", "polling_serial", + "cache_info", ] [package] @@ -28,6 +29,7 @@ vga_buffer = { path = "vga_buffer" } polling_serial = { path = "polling_serial" } volatile = "0.2.6" linked_list_allocator = "0.6.4" +cache_info = { path = "cache_info" } [dependencies.lazy_static] version = "1.0" diff --git a/cache_info/Cargo.toml b/cache_info/Cargo.toml new file mode 100644 index 0000000..15276dd --- /dev/null +++ b/cache_info/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "cache_info" +version = "0.1.0" +authors = ["guillaume didier "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +polling_serial = { path = "../polling_serial" } \ No newline at end of file diff --git a/cache_info/src/lib.rs b/cache_info/src/lib.rs new file mode 100644 index 0000000..43cfcf5 --- /dev/null +++ b/cache_info/src/lib.rs @@ -0,0 +1,42 @@ +#![no_std] + +/// Stuff to do in here : +/// This module is meant to compute and return info about the caching structure +/// Should include if needed the work for reverse engineering L3 complex addressing +/// May also have a module to deal with prefetchers +extern crate alloc; + +use alloc::boxed::Box; +use core::arch::x86_64 as arch_x86; +use polling_serial::serial_println; + +pub fn test() { + let x = Box::new(41); + let cr = unsafe { arch_x86::__cpuid_count(0x04, 0) }; + serial_println!("{:?}", cr); +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum CacheType { + Null = 0, + Data = 1, + Instruction = 2, + Unified = 3, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct CacheInfo { + cache_type: CacheType, + level: u8, + self_init: bool, + fully_assoc: bool, + core_for_cache: u16, + core_in_package: u16, + cache_line_size: u16, + physical_line_partition: u16, + associativity: u16, + sets: u32, + wbinvd_no_guarantee: bool, + inclusive: bool, + complex_cache_indexing: bool, +} diff --git a/src/main.rs b/src/main.rs index fd024f2..c6aab98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ extern crate alloc; use alloc::boxed::Box; use bootloader::{entry_point, BootInfo}; +use cache_info; use core::panic::PanicInfo; use dendrobates_tinctoreus_azureus::allocator; use polling_serial::serial_print; @@ -84,6 +85,8 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { let x = Box::new(41); + cache_info::test(); + serial_print!("Input a character: "); let c = { polling_serial::SERIAL1.lock().read() };