Skip to content

Commit d56a889

Browse files
committed
aarch64: set ttbr0_el1 to null for kernel thread, fixed #56
1 parent 55cfce6 commit d56a889

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

bootloader/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootloader/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ xmas-elf = "0.6.2"
99
fixedvec = "0.2.3"
1010

1111
[target.'cfg(target_arch = "aarch64")'.dependencies]
12-
aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "2.6.1" }
12+
aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "2.7.0" }
1313
bcm2837 = { git = "https://github.com/rcore-os/bcm2837", version = "1.0.0" }
1414

1515
[build-dependencies]

bootloader/src/arch/aarch64/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use aarch64::addr::{PhysAddr, VirtAddr};
2-
use aarch64::paging::{memory_attribute::*, Page, PageTable, PageTableFlags as EF, PhysFrame};
2+
use aarch64::paging::{memory_attribute::*, Page, PageTable, PageTableAttribute, PageTableFlags as EF, PhysFrame};
33
use aarch64::paging::{Size1GiB, Size2MiB, Size4KiB};
44
use aarch64::{asm::*, barrier, regs::*};
55
use bcm2837::consts::RAW_IO_BASE;
@@ -42,7 +42,7 @@ fn create_page_table(start_paddr: usize, end_paddr: usize) {
4242
p3.zero();
4343
p2.zero();
4444

45-
let block_flags = EF::VALID | EF::AF | EF::WRITE | EF::UXN;
45+
let block_flags = EF::default_block() | EF::UXN;
4646
// normal memory
4747
for frame in PhysFrame::<Size2MiB>::range_of(start_paddr as u64, end_paddr as u64) {
4848
let paddr = frame.start_address();
@@ -58,10 +58,10 @@ fn create_page_table(start_paddr: usize, end_paddr: usize) {
5858
p2[page.p2_index()].set_block::<Size2MiB>(paddr, block_flags | EF::PXN, MairDevice::attr_value());
5959
}
6060

61-
p3[0].set_frame(frame_lvl2, EF::default(), MairNormal::attr_value());
61+
p3[0].set_frame(frame_lvl2, EF::default_table(), PageTableAttribute::new(0, 0, 0));
6262
p3[1].set_block::<Size1GiB>(PhysAddr::new(0x4000_0000), block_flags | EF::PXN, MairDevice::attr_value());
6363

64-
p4[0].set_frame(frame_lvl3, EF::default(), MairNormal::attr_value());
64+
p4[0].set_frame(frame_lvl3, EF::default_table(), PageTableAttribute::new(0, 0, 0));
6565

6666
// the bootloader is still running at the lower virtual address range,
6767
// so the TTBR0_EL1 also needs to be set.

kernel/Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kernel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ aml = "0.4"
8686
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
8787

8888
[target.'cfg(target_arch = "aarch64")'.dependencies]
89-
aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "2.6.1" }
89+
aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "2.7.0" }
9090
bcm2837 = { git = "https://github.com/rcore-os/bcm2837", version = "1.0.0", optional = true }
9191

9292
[target.'cfg(target_arch = "mips")'.dependencies]

kernel/src/arch/aarch64/memory.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
33
use crate::consts::MEMORY_OFFSET;
44
use crate::memory::{init_heap, virt_to_phys, FRAME_ALLOCATOR};
5+
use aarch64::{paging::frame::PhysFrame, asm::ttbr_el1_write};
56
use log::*;
67
use rcore_memory::PAGE_SIZE;
78

89
/// Memory initialization.
910
pub fn init() {
11+
ttbr_el1_write(0, PhysFrame::of_addr(0));
1012
init_frame_allocator();
1113
init_heap();
1214
info!("memory: init end");

kernel/src/arch/aarch64/paging.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use aarch64::paging::{
99
page_table::{PageTable as Aarch64PageTable, PageTableEntry, PageTableFlags as EF},
1010
FrameAllocator, FrameDeallocator, Page as PageAllSizes, Size4KiB,
1111
};
12-
use aarch64::{PhysAddr, VirtAddr};
12+
use aarch64::PhysAddr;
1313
use core::mem::ManuallyDrop;
1414
use log::*;
1515
use rcore_memory::paging::*;
@@ -26,7 +26,7 @@ pub struct PageEntry(&'static mut PageTableEntry, Page);
2626

2727
impl PageTable for PageTableImpl {
2828
fn map(&mut self, addr: usize, target: usize) -> &mut dyn Entry {
29-
let flags = EF::default();
29+
let flags = EF::default_page() | EF::PXN | EF::UXN;
3030
let attr = MairNormal::attr_value();
3131
unsafe {
3232
self.page_table
@@ -85,6 +85,7 @@ pub enum MMIOType {
8585
Unsupported = 3,
8686
}
8787

88+
// TODO: software dirty bit needs to be reconsidered
8889
impl Entry for PageEntry {
8990
fn update(&mut self) {
9091
tlb_invalidate(self.1.start_address());
@@ -161,9 +162,11 @@ impl Entry for PageEntry {
161162
}
162163
fn set_execute(&mut self, value: bool) {
163164
if self.user() {
164-
self.as_flags().set(EF::UXN, !value)
165+
self.as_flags().set(EF::UXN, !value);
166+
self.as_flags().set(EF::PXN, true);
165167
} else {
166-
self.as_flags().set(EF::PXN, !value)
168+
self.as_flags().set(EF::PXN, !value);
169+
self.as_flags().set(EF::UXN, true)
167170
}
168171
}
169172
fn mmio(&self) -> u8 {

0 commit comments

Comments
 (0)