Introduce Phys/Virt addresses
This commit is contained in:
parent
ef2796a583
commit
2abf70fe90
|
@ -1,6 +1,8 @@
|
||||||
// mod arch::aarch64
|
// mod arch::aarch64
|
||||||
|
|
||||||
mod boot;
|
mod boot;
|
||||||
|
mod memory;
|
||||||
|
pub use self::memory::{PhysicalAddress, VirtualAddress};
|
||||||
|
|
||||||
use cortex_a::{asm, barrier, regs::*};
|
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 {
|
pub fn read_translation_table_base() -> PhysicalAddress {
|
||||||
let mut base: u64 = 0;
|
let mut base: PhysicalAddress = 0;
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!("mrs $0, ttbr0_el1" : "=r"(base) ::: "volatile");
|
asm!("mrs $0, ttbr0_el1" : "=r"(base) ::: "volatile");
|
||||||
}
|
}
|
||||||
return base;
|
base
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_translation_control() -> u64 {
|
pub fn read_translation_control() -> u64 {
|
||||||
|
@ -78,14 +80,14 @@ pub fn read_mair() -> u64 {
|
||||||
return mair;
|
return mair;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_translation_table_base(base: usize) {
|
pub fn write_translation_table_base(base: PhysicalAddress) {
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!("msr ttbr0_el1, $0" :: "r"(base) :: "volatile");
|
asm!("msr ttbr0_el1, $0" :: "r"(base) :: "volatile");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function similar to u-boot
|
// 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 {
|
unsafe {
|
||||||
asm!("dsb sy" :::: "volatile");
|
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:
|
// aarch64 granules and page sizes howto:
|
||||||
// https://stackoverflow.com/questions/34269185/simultaneous-existence-of-different-sized-pages-on-aarch64
|
// 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:
|
// Code from redox-os:
|
||||||
|
|
||||||
// pub static mut IDTR: DescriptorTablePointer = DescriptorTablePointer {
|
// pub static mut IDTR: DescriptorTablePointer = DescriptorTablePointer {
|
||||||
|
@ -183,8 +182,8 @@ bitflags! {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MemMapRegion {
|
struct MemMapRegion {
|
||||||
virt: usize,
|
virt: VirtualAddress,
|
||||||
phys: usize,
|
phys: PhysicalAddress,
|
||||||
size: usize,
|
size: usize,
|
||||||
attr: MemType, // MAIR flags
|
attr: MemType, // MAIR flags
|
||||||
}
|
}
|
||||||
|
@ -199,7 +198,7 @@ fn setup_paging() {
|
||||||
// Check mmu and dcache states, loop forever on some setting
|
// Check mmu and dcache states, loop forever on some setting
|
||||||
|
|
||||||
write_ttbr_tcr_mair(
|
write_ttbr_tcr_mair(
|
||||||
1,
|
1, // EL1
|
||||||
read_translation_table_base(),
|
read_translation_table_base(),
|
||||||
read_translation_control(),
|
read_translation_control(),
|
||||||
read_mair(),
|
read_mair(),
|
||||||
|
@ -226,7 +225,7 @@ pub struct BcmHost;
|
||||||
impl BcmHost {
|
impl BcmHost {
|
||||||
// As per https://www.raspberrypi.org/documentation/hardware/raspberrypi/peripheral_addresses.md
|
// As per https://www.raspberrypi.org/documentation/hardware/raspberrypi/peripheral_addresses.md
|
||||||
/// This returns the ARM-side physical address where peripherals are mapped.
|
/// 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
|
0x3f00_0000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +235,7 @@ impl BcmHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This returns the bus address of the SDRAM.
|
/// This returns the bus address of the SDRAM.
|
||||||
pub fn get_sdram_address() -> usize {
|
pub fn get_sdram_address() -> PhysicalAddress {
|
||||||
0xC000_0000 // uncached
|
0xC000_0000 // uncached
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue