aarch64: minor modify

master
equation314 6 years ago
parent 264600f145
commit d30c7e59ca

@ -0,0 +1,108 @@
[[package]]
name = "aarch64"
version = "0.1.0"
dependencies = [
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ux 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bare-metal"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bit_field"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "os_bootinfo"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "register"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"tock-registers 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "tock-registers"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "usize_conversions"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ux"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a"
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a"
"checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum tock-registers 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a385d94f3f62e60445a0adb9ff8d9621faa272234530d4c0f848ec98f88e316"
"checksum usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5"
"checksum ux 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53d8df5dd8d07fedccd202de1887d94481fadaea3db70479f459e8163a1fab41"

@ -1,31 +1,9 @@
//! Miscellaneous assembly instructions and functions
use paging::PhysFrame;
use addr::{PhysAddr, VirtAddr};
use regs::*;
#[inline(always)]
pub fn tlb_invalidate_all() {
unsafe {
asm!(
"dsb ishst
tlbi vmalle1is
dsb ish
isb"
);
}
}
#[inline(always)]
pub fn tlb_invalidate(vaddr: VirtAddr) {
unsafe {
asm!(
"dsb ishst
tlbi vaae1is, $0
dsb ish
isb" :: "r"(vaddr.as_u64() >> 12)
);
}
}
/// Returns the current stack pointer.
#[inline(always)]
pub fn sp() -> *const u8 {
@ -37,91 +15,32 @@ pub fn sp() -> *const u8 {
ptr as *const u8
}
/// Returns the current point counter.
#[inline(always)]
pub unsafe fn get_pc() -> usize {
let pc: usize;
asm!("ADR $0, ." : "=r"(pc));
asm!("adr $0, ." : "=r"(pc));
pc
}
/// Returns the current exception level.
///
/// # Safety
/// This function should only be called when EL is >= 1.
#[inline(always)]
pub unsafe fn current_el() -> u8 {
let el_reg: u64;
asm!("mrs $0, CurrentEL" : "=r"(el_reg));
((el_reg & 0b1100) >> 2) as u8
}
#[inline(always)]
pub unsafe fn get_far() -> usize {
let far: usize;
asm!("mrs $0, far_el1" : "=r"(far));
far
}
#[inline(always)]
pub unsafe fn get_ttbr0() -> usize {
let ttbr0: usize;
asm!("mrs $0, ttbr0_el1" : "=r"(ttbr0));
ttbr0
}
#[inline(always)]
pub unsafe fn get_ttbr1() -> usize {
let ttbr0: usize;
asm!("mrs $0, ttbr1_el1" : "=r"(ttbr0));
ttbr0
}
#[inline(always)]
pub fn address_translate(vaddr: usize) -> usize {
let paddr: usize;
unsafe {
asm!("at S1E1R, $1; mrs $0, par_el1" : "=r"(paddr) : "r"(vaddr));
}
paddr
}
/// Returns the SPSel value.
#[inline(always)]
pub fn sp_sel() -> u8 {
let ptr: u32;
unsafe {
asm!("mrs $0, SPSel" : "=r"(ptr));
}
(ptr & 1) as u8
}
/// Returns the core currently executing.
///
/// # Safety
///
/// This function should only be called when EL is >= 1.
pub unsafe fn affinity() -> usize {
let x: usize;
asm!("mrs $0, mpidr_el1
and $0, $0, #3"
: "=r"(x));
x
}
/// The classic no-op
#[inline]
pub fn nop() {
match () {
#[cfg(target_arch = "aarch64")]
() => unsafe { asm!("nop" :::: "volatile") },
pub fn wfi() {
unsafe {
asm!("wfi" :::: "volatile");
#[cfg(not(target_arch = "aarch64"))]
() => unimplemented!(),
}
}
/// The classic no-op
/// Wait For Interrupt
#[inline]
pub fn nop() {
pub fn wfi() {
match () {
#[cfg(target_arch = "aarch64")]
() => unsafe { asm!("nop" :::: "volatile") },
() => unsafe { asm!("wfi" :::: "volatile") },
#[cfg(not(target_arch = "aarch64"))]
() => unimplemented!(),
@ -160,7 +79,44 @@ pub fn eret() -> ! {
}
}
pub fn ttbr_el1_read(which: u8) -> (PhysFrame) {
/// Invalidate all TLB entries.
#[inline(always)]
pub fn tlb_invalidate_all() {
unsafe {
asm!(
"dsb ishst
tlbi vmalle1is
dsb ish
isb"
);
}
}
/// Invalidate TLB entries that would be used to translate the specified address.
#[inline(always)]
pub fn tlb_invalidate(vaddr: VirtAddr) {
unsafe {
asm!(
"dsb ishst
tlbi vaae1is, $0
dsb ish
isb" :: "r"(vaddr.as_u64() >> 12)
);
}
}
/// Address Translate.
#[inline(always)]
pub fn address_translate(vaddr: usize) -> usize {
let paddr: usize;
unsafe {
asm!("at S1E1R, $1; mrs $0, par_el1" : "=r"(paddr) : "r"(vaddr));
}
paddr
}
/// Read TTBRx_EL1 as PhysFrame
pub fn ttbr_el1_read(which: u8) -> PhysFrame {
let baddr = match which {
0 => TTBR0_EL1.get_baddr(),
1 => TTBR1_EL1.get_baddr(),
@ -169,6 +125,7 @@ pub fn ttbr_el1_read(which: u8) -> (PhysFrame) {
PhysFrame::containing_address(PhysAddr::new(baddr))
}
/// Write TTBRx_EL1 from PhysFrame
pub fn ttbr_el1_write(which: u8, frame: PhysFrame) {
let baddr = frame.start_address().as_u64();
match which {
@ -178,6 +135,7 @@ pub fn ttbr_el1_write(which: u8, frame: PhysFrame) {
};
}
/// write TTBRx_EL1 from PhysFrame and ASID
pub fn ttbr_el1_write_asid(which: u8, asid: u16, frame: PhysFrame) {
let baddr = frame.start_address().as_u64();
match which {

18
kernel/Cargo.lock generated

@ -5,7 +5,6 @@ dependencies = [
"bare-metal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -177,14 +176,6 @@ name = "redox_syscall"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "register"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"tock-registers 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "register"
version = "0.2.1"
@ -247,11 +238,6 @@ dependencies = [
"remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tock-registers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "tock-registers"
version = "0.2.0"
@ -279,13 +265,11 @@ dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bootloader 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-a 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"once 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"register 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"riscv 0.3.0",
"simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust)",
"spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -399,7 +383,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8361e81576d2e02643b04950e487ec172b687180da65c731c03cf336784e6c07"
"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum register 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e985243ba7e1c336b62444ef2a10d7bd87cf41a222285ae3de605c859006479"
"checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust)" = "<none>"
@ -407,7 +390,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "37b5646825922b96b5d7d676b5bb3458a54498e96ed7b0ce09dc43a07038fea4"
"checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum tock-registers 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2acc33f980e23cee18d234a32d0637fbc1ea55e13ab04012fa857b899fa1b7a9"
"checksum tock-registers 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a385d94f3f62e60445a0adb9ff8d9621faa272234530d4c0f848ec98f88e316"
"checksum uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "269f953d8de3226f7c065c589c7b4a3e83d10a419c7c3b5e2e0f197e6acc966e"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"

@ -32,7 +32,6 @@ bit-allocator = { path = "../crate/bit-allocator" }
ucore-memory = { path = "../crate/memory" }
ucore-process = { path = "../crate/process" }
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" }
register="0.1.0"
[target.'cfg(target_arch = "x86_64")'.dependencies]
bootloader = "0.3"
@ -45,7 +44,6 @@ riscv = { path = "../crate/riscv" }
bbl = { path = "../crate/bbl" }
[target.'cfg(target_arch = "aarch64")'.dependencies]
cortex-a = "2.2.1"
aarch64 = { path = "../crate/aarch64" }
atags = { path = "../crate/atags" }
bcm2837 = { path = "../crate/bcm2837", features = ["use_generic_timer"] }

@ -4,7 +4,8 @@ mod handler;
mod context;
mod syndrome;
use super::cortex_a::regs::*;
use aarch64::regs::*;
pub use self::context::*;
pub use self::handler::*;

@ -1,7 +1,6 @@
//! Entrance and initialization for aarch64.
extern crate atags;
extern crate cortex_a;
pub mod io;
pub mod paging;

@ -146,19 +146,29 @@ impl Entry for PageEntry {
self.as_flags().set(EF::nG, value); // set non-global to use ASID
}
fn execute(&self) -> bool {
match self.user() {
true => !self.0.flags().contains(EF::XN),
false => !self.0.flags().contains(EF::PXN),
if self.user() {
!self.0.flags().contains(EF::XN)
} else {
!self.0.flags().contains(EF::PXN)
}
}
fn set_execute(&mut self, value: bool) {
match self.user() {
true => self.as_flags().set(EF::XN, !value),
false => self.as_flags().set(EF::PXN, !value),
if self.user() {
self.as_flags().set(EF::XN, !value)
} else {
self.as_flags().set(EF::PXN, !value)
}
}
fn mmio(&self) -> bool {
self.0.attr().value == MairDevice::attr_value().value
}
fn set_mmio(&mut self, value: bool) {
if value {
self.0.modify_attr(MairDevice::attr_value())
} else {
self.0.modify_attr(MairNormal::attr_value())
}
}
fn mmio(&self) -> bool { self.0.attr().value == MairDevice::attr_value().value }
fn set_mmio(&mut self, value: bool) { self.0.modify_attr(MairDevice::attr_value()); }
}
impl PageEntry {

Loading…
Cancel
Save