Introduce Phys/Virt addresses

This commit is contained in:
Berkus Decker 2019-01-20 19:43:37 +02:00
parent ef2796a583
commit 2abf70fe90
1 changed files with 12 additions and 13 deletions

View File

@ -1,6 +1,8 @@
// mod arch::aarch64
mod boot;
mod memory;
pub use self::memory::{PhysicalAddress, VirtualAddress};
use cortex_a::{asm, barrier, regs::*};
@ -54,12 +56,12 @@ pub fn loop_until<F: Fn() -> bool>(f: F) {
}
}
pub fn read_translation_table_base() -> u64 {
let mut base: u64 = 0;
pub fn read_translation_table_base() -> PhysicalAddress {
let mut base: PhysicalAddress = 0;
unsafe {
asm!("mrs $0, ttbr0_el1" : "=r"(base) ::: "volatile");
}
return base;
base
}
pub fn read_translation_control() -> u64 {
@ -78,14 +80,14 @@ pub fn read_mair() -> u64 {
return mair;
}
pub fn write_translation_table_base(base: usize) {
pub fn write_translation_table_base(base: PhysicalAddress) {
unsafe {
asm!("msr ttbr0_el1, $0" :: "r"(base) :: "volatile");
}
}
// Helper function similar to u-boot
pub fn write_ttbr_tcr_mair(el: u8, base: u64, tcr: u64, attr: u64) {
pub fn write_ttbr_tcr_mair(el: u8, base: PhysicalAddress, tcr: u64, attr: u64) {
unsafe {
asm!("dsb sy" :::: "volatile");
}
@ -121,9 +123,6 @@ pub fn write_ttbr_tcr_mair(el: u8, base: u64, tcr: u64, attr: u64) {
// aarch64 granules and page sizes howto:
// https://stackoverflow.com/questions/34269185/simultaneous-existence-of-different-sized-pages-on-aarch64
// #[repr(align=0x4000)]
// let page_tables: [4096; u32] = ...;
// Code from redox-os:
// pub static mut IDTR: DescriptorTablePointer = DescriptorTablePointer {
@ -183,8 +182,8 @@ bitflags! {
}
struct MemMapRegion {
virt: usize,
phys: usize,
virt: VirtualAddress,
phys: PhysicalAddress,
size: usize,
attr: MemType, // MAIR flags
}
@ -199,7 +198,7 @@ fn setup_paging() {
// Check mmu and dcache states, loop forever on some setting
write_ttbr_tcr_mair(
1,
1, // EL1
read_translation_table_base(),
read_translation_control(),
read_mair(),
@ -226,7 +225,7 @@ pub struct BcmHost;
impl BcmHost {
// As per https://www.raspberrypi.org/documentation/hardware/raspberrypi/peripheral_addresses.md
/// This returns the ARM-side physical address where peripherals are mapped.
pub fn get_peripheral_address() -> usize {
pub fn get_peripheral_address() -> PhysicalAddress {
0x3f00_0000
}
@ -236,7 +235,7 @@ impl BcmHost {
}
/// This returns the bus address of the SDRAM.
pub fn get_sdram_address() -> usize {
pub fn get_sdram_address() -> PhysicalAddress {
0xC000_0000 // uncached
}
}