mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 16:16:16 +04:00
aarch64: set ttbr0_el1 to null for kernel thread, fixed #56
This commit is contained in:
parent
55cfce6c02
commit
d56a88947e
8
bootloader/Cargo.lock
generated
8
bootloader/Cargo.lock
generated
@ -2,8 +2,8 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aarch64"
|
name = "aarch64"
|
||||||
version = "2.6.1"
|
version = "2.7.0"
|
||||||
source = "git+https://github.com/rcore-os/aarch64#65d1453f11f3cc113247352dffa02d8dcdd34769"
|
source = "git+https://github.com/rcore-os/aarch64#b2806c9f0fe0120a838cf8afdec8c4899241ef7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field 0.9.0 (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)",
|
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -104,7 +104,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
name = "rcore-bootloader"
|
name = "rcore-bootloader"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aarch64 2.6.1 (git+https://github.com/rcore-os/aarch64)",
|
"aarch64 2.7.0 (git+https://github.com/rcore-os/aarch64)",
|
||||||
"bcm2837 1.0.0 (git+https://github.com/rcore-os/bcm2837)",
|
"bcm2837 1.0.0 (git+https://github.com/rcore-os/bcm2837)",
|
||||||
"cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -211,7 +211,7 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
"checksum aarch64 2.6.1 (git+https://github.com/rcore-os/aarch64)" = "<none>"
|
"checksum aarch64 2.7.0 (git+https://github.com/rcore-os/aarch64)" = "<none>"
|
||||||
"checksum bcm2837 1.0.0 (git+https://github.com/rcore-os/bcm2837)" = "<none>"
|
"checksum bcm2837 1.0.0 (git+https://github.com/rcore-os/bcm2837)" = "<none>"
|
||||||
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
|
"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 bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||||
|
@ -9,7 +9,7 @@ xmas-elf = "0.6.2"
|
|||||||
fixedvec = "0.2.3"
|
fixedvec = "0.2.3"
|
||||||
|
|
||||||
[target.'cfg(target_arch = "aarch64")'.dependencies]
|
[target.'cfg(target_arch = "aarch64")'.dependencies]
|
||||||
aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "2.6.1" }
|
aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "2.7.0" }
|
||||||
bcm2837 = { git = "https://github.com/rcore-os/bcm2837", version = "1.0.0" }
|
bcm2837 = { git = "https://github.com/rcore-os/bcm2837", version = "1.0.0" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use aarch64::addr::{PhysAddr, VirtAddr};
|
use aarch64::addr::{PhysAddr, VirtAddr};
|
||||||
use aarch64::paging::{memory_attribute::*, Page, PageTable, PageTableFlags as EF, PhysFrame};
|
use aarch64::paging::{memory_attribute::*, Page, PageTable, PageTableAttribute, PageTableFlags as EF, PhysFrame};
|
||||||
use aarch64::paging::{Size1GiB, Size2MiB, Size4KiB};
|
use aarch64::paging::{Size1GiB, Size2MiB, Size4KiB};
|
||||||
use aarch64::{asm::*, barrier, regs::*};
|
use aarch64::{asm::*, barrier, regs::*};
|
||||||
use bcm2837::consts::RAW_IO_BASE;
|
use bcm2837::consts::RAW_IO_BASE;
|
||||||
@ -42,7 +42,7 @@ fn create_page_table(start_paddr: usize, end_paddr: usize) {
|
|||||||
p3.zero();
|
p3.zero();
|
||||||
p2.zero();
|
p2.zero();
|
||||||
|
|
||||||
let block_flags = EF::VALID | EF::AF | EF::WRITE | EF::UXN;
|
let block_flags = EF::default_block() | EF::UXN;
|
||||||
// normal memory
|
// normal memory
|
||||||
for frame in PhysFrame::<Size2MiB>::range_of(start_paddr as u64, end_paddr as u64) {
|
for frame in PhysFrame::<Size2MiB>::range_of(start_paddr as u64, end_paddr as u64) {
|
||||||
let paddr = frame.start_address();
|
let paddr = frame.start_address();
|
||||||
@ -58,10 +58,10 @@ fn create_page_table(start_paddr: usize, end_paddr: usize) {
|
|||||||
p2[page.p2_index()].set_block::<Size2MiB>(paddr, block_flags | EF::PXN, MairDevice::attr_value());
|
p2[page.p2_index()].set_block::<Size2MiB>(paddr, block_flags | EF::PXN, MairDevice::attr_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
p3[0].set_frame(frame_lvl2, EF::default(), MairNormal::attr_value());
|
p3[0].set_frame(frame_lvl2, EF::default_table(), PageTableAttribute::new(0, 0, 0));
|
||||||
p3[1].set_block::<Size1GiB>(PhysAddr::new(0x4000_0000), block_flags | EF::PXN, MairDevice::attr_value());
|
p3[1].set_block::<Size1GiB>(PhysAddr::new(0x4000_0000), block_flags | EF::PXN, MairDevice::attr_value());
|
||||||
|
|
||||||
p4[0].set_frame(frame_lvl3, EF::default(), MairNormal::attr_value());
|
p4[0].set_frame(frame_lvl3, EF::default_table(), PageTableAttribute::new(0, 0, 0));
|
||||||
|
|
||||||
// the bootloader is still running at the lower virtual address range,
|
// the bootloader is still running at the lower virtual address range,
|
||||||
// so the TTBR0_EL1 also needs to be set.
|
// so the TTBR0_EL1 also needs to be set.
|
||||||
|
10
kernel/Cargo.lock
generated
10
kernel/Cargo.lock
generated
@ -2,8 +2,8 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aarch64"
|
name = "aarch64"
|
||||||
version = "2.6.1"
|
version = "2.7.0"
|
||||||
source = "git+https://github.com/rcore-os/aarch64#65d1453f11f3cc113247352dffa02d8dcdd34769"
|
source = "git+https://github.com/rcore-os/aarch64#b2806c9f0fe0120a838cf8afdec8c4899241ef7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field 0.9.0 (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.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -68,7 +68,7 @@ name = "bcm2837"
|
|||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "git+https://github.com/rcore-os/bcm2837#bf1e4ec63c52827bc199399f214f39a4fdcbe228"
|
source = "git+https://github.com/rcore-os/bcm2837#bf1e4ec63c52827bc199399f214f39a4fdcbe228"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aarch64 2.6.1 (git+https://github.com/rcore-os/aarch64)",
|
"aarch64 2.7.0 (git+https://github.com/rcore-os/aarch64)",
|
||||||
"volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -380,7 +380,7 @@ dependencies = [
|
|||||||
name = "rcore"
|
name = "rcore"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aarch64 2.6.1 (git+https://github.com/rcore-os/aarch64)",
|
"aarch64 2.7.0 (git+https://github.com/rcore-os/aarch64)",
|
||||||
"acpi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"acpi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"aml 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"aml 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)",
|
"apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)",
|
||||||
@ -751,7 +751,7 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
"checksum aarch64 2.6.1 (git+https://github.com/rcore-os/aarch64)" = "<none>"
|
"checksum aarch64 2.7.0 (git+https://github.com/rcore-os/aarch64)" = "<none>"
|
||||||
"checksum acpi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c18d706bdc322dd4f8f7930a5879ad8df3d78d4452a678d5419c72f9f69acea"
|
"checksum acpi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c18d706bdc322dd4f8f7930a5879ad8df3d78d4452a678d5419c72f9f69acea"
|
||||||
"checksum aml 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7669e841017880c2710777c46ec654272163379bbe55de6e17a2a2388d44d92"
|
"checksum aml 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7669e841017880c2710777c46ec654272163379bbe55de6e17a2a2388d44d92"
|
||||||
"checksum apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)" = "<none>"
|
"checksum apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)" = "<none>"
|
||||||
|
@ -86,7 +86,7 @@ aml = "0.4"
|
|||||||
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
|
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "aarch64")'.dependencies]
|
[target.'cfg(target_arch = "aarch64")'.dependencies]
|
||||||
aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "2.6.1" }
|
aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "2.7.0" }
|
||||||
bcm2837 = { git = "https://github.com/rcore-os/bcm2837", version = "1.0.0", optional = true }
|
bcm2837 = { git = "https://github.com/rcore-os/bcm2837", version = "1.0.0", optional = true }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "mips")'.dependencies]
|
[target.'cfg(target_arch = "mips")'.dependencies]
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
use crate::consts::MEMORY_OFFSET;
|
use crate::consts::MEMORY_OFFSET;
|
||||||
use crate::memory::{init_heap, virt_to_phys, FRAME_ALLOCATOR};
|
use crate::memory::{init_heap, virt_to_phys, FRAME_ALLOCATOR};
|
||||||
|
use aarch64::{paging::frame::PhysFrame, asm::ttbr_el1_write};
|
||||||
use log::*;
|
use log::*;
|
||||||
use rcore_memory::PAGE_SIZE;
|
use rcore_memory::PAGE_SIZE;
|
||||||
|
|
||||||
/// Memory initialization.
|
/// Memory initialization.
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
|
ttbr_el1_write(0, PhysFrame::of_addr(0));
|
||||||
init_frame_allocator();
|
init_frame_allocator();
|
||||||
init_heap();
|
init_heap();
|
||||||
info!("memory: init end");
|
info!("memory: init end");
|
||||||
|
@ -9,7 +9,7 @@ use aarch64::paging::{
|
|||||||
page_table::{PageTable as Aarch64PageTable, PageTableEntry, PageTableFlags as EF},
|
page_table::{PageTable as Aarch64PageTable, PageTableEntry, PageTableFlags as EF},
|
||||||
FrameAllocator, FrameDeallocator, Page as PageAllSizes, Size4KiB,
|
FrameAllocator, FrameDeallocator, Page as PageAllSizes, Size4KiB,
|
||||||
};
|
};
|
||||||
use aarch64::{PhysAddr, VirtAddr};
|
use aarch64::PhysAddr;
|
||||||
use core::mem::ManuallyDrop;
|
use core::mem::ManuallyDrop;
|
||||||
use log::*;
|
use log::*;
|
||||||
use rcore_memory::paging::*;
|
use rcore_memory::paging::*;
|
||||||
@ -26,7 +26,7 @@ pub struct PageEntry(&'static mut PageTableEntry, Page);
|
|||||||
|
|
||||||
impl PageTable for PageTableImpl {
|
impl PageTable for PageTableImpl {
|
||||||
fn map(&mut self, addr: usize, target: usize) -> &mut dyn Entry {
|
fn map(&mut self, addr: usize, target: usize) -> &mut dyn Entry {
|
||||||
let flags = EF::default();
|
let flags = EF::default_page() | EF::PXN | EF::UXN;
|
||||||
let attr = MairNormal::attr_value();
|
let attr = MairNormal::attr_value();
|
||||||
unsafe {
|
unsafe {
|
||||||
self.page_table
|
self.page_table
|
||||||
@ -85,6 +85,7 @@ pub enum MMIOType {
|
|||||||
Unsupported = 3,
|
Unsupported = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: software dirty bit needs to be reconsidered
|
||||||
impl Entry for PageEntry {
|
impl Entry for PageEntry {
|
||||||
fn update(&mut self) {
|
fn update(&mut self) {
|
||||||
tlb_invalidate(self.1.start_address());
|
tlb_invalidate(self.1.start_address());
|
||||||
@ -161,9 +162,11 @@ impl Entry for PageEntry {
|
|||||||
}
|
}
|
||||||
fn set_execute(&mut self, value: bool) {
|
fn set_execute(&mut self, value: bool) {
|
||||||
if self.user() {
|
if self.user() {
|
||||||
self.as_flags().set(EF::UXN, !value)
|
self.as_flags().set(EF::UXN, !value);
|
||||||
|
self.as_flags().set(EF::PXN, true);
|
||||||
} else {
|
} else {
|
||||||
self.as_flags().set(EF::PXN, !value)
|
self.as_flags().set(EF::PXN, !value);
|
||||||
|
self.as_flags().set(EF::UXN, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn mmio(&self) -> u8 {
|
fn mmio(&self) -> u8 {
|
||||||
|
Loading…
Reference in New Issue
Block a user