feat: map text area to kernel memory space, first application_manager

implementation
This commit is contained in:
2026-03-24 18:50:20 +01:00
parent f33100d36b
commit 6798f6b56d
6 changed files with 77 additions and 14 deletions

8
.vscode/launch.json vendored
View File

@@ -3,7 +3,7 @@
"compounds": [ "compounds": [
{ {
"name": "Run QEMU + Attach LLDB", "name": "Run QEMU + Attach LLDB",
"configurations": ["Attach LLDB"], "configurations": ["LLDB"],
"preLaunchTask": "Run QEMU" "preLaunchTask": "Run QEMU"
} }
], ],
@@ -61,9 +61,11 @@
{ {
"name": "LLDB", "name": "LLDB",
"type": "lldb", "type": "lldb",
"request": "launch", "request": "attach",
"program": "${workspaceFolder}/target/aarch64-unknown-none/debug/nova", "program": "${workspaceFolder}/target/aarch64-unknown-none/debug/nova",
"preLaunchTask": "Run QEMU wo window" "preLaunchTask": "Run QEMU",
"stopOnEntry": true,
"processCreateCommands": ["gdb-remote localhost:1234"]
} }
] ]
} }

View File

@@ -43,7 +43,8 @@ const L2_BLOCK_BITMAP_WORDS: usize = LEVEL2_BLOCK_SIZE / (64 * GRANULARITY);
const MAX_PAGE_COUNT: usize = 1024 * 1024 * 1024 / GRANULARITY; const MAX_PAGE_COUNT: usize = 1024 * 1024 * 1024 / GRANULARITY;
const TRANSLATION_TABLE_BASE_ADDR: usize = 0xFFFF_FF82_0000_0000; const TRANSLATION_TABLE_BASE_ADDR: usize = 0xFFFF_FF82_0000_0000;
pub const KERNEL_VIRTUAL_MEM_SPACE: usize = 0xFFFF_FF80_0000_0000; #[no_mangle]
pub static KERNEL_VIRTUAL_MEM_SPACE: usize = 0xFFFF_FF80_0000_0000;
pub const STACK_START_ADDR: usize = !KERNEL_VIRTUAL_MEM_SPACE & (!0xF); pub const STACK_START_ADDR: usize = !KERNEL_VIRTUAL_MEM_SPACE & (!0xF);

View File

@@ -0,0 +1,44 @@
use alloc::vec::Vec;
use crate::{
aarch64::mmu::{
find_free_kerne_page_in_block, map_page, physical_mapping::reserve_page, TableEntry,
NORMAL_MEM, TRANSLATIONTABLE_TTBR1, WRITABLE,
},
configuration::memory_mapping::APPLICATION_TRANSLATION_TABLE_VA,
};
pub struct Application {
pub table_ptr: *mut TableEntry,
}
impl Default for Application {
fn default() -> Self {
Self::new()
}
}
impl Application {
pub fn new() -> Self {
let physical_addr = reserve_page();
let virtual_address =
find_free_kerne_page_in_block(APPLICATION_TRANSLATION_TABLE_VA).unwrap();
map_page(
virtual_address,
physical_addr,
core::ptr::addr_of_mut!(TRANSLATIONTABLE_TTBR1),
NORMAL_MEM | WRITABLE,
)
.unwrap();
Self {
table_ptr: physical_addr as *mut TableEntry,
}
}
}
pub static mut APPLICATION_LIST: Option<Vec<Application>> = None;
pub fn initialize_app_manager() {
unsafe { APPLICATION_LIST = Some(Vec::new()) }
}

View File

@@ -10,8 +10,12 @@ el2_to_el1:
msr SPSR_EL2, x0 msr SPSR_EL2, x0
// Set return address to kernel_main // Set return address to kernel_main
adrp x0, KERNEL_VIRTUAL_MEM_SPACE
ldr x1, [x0, :lo12:KERNEL_VIRTUAL_MEM_SPACE]
adrp x0, kernel_main adrp x0, kernel_main
add x0, x0, :lo12:kernel_main add x0, x0, :lo12:kernel_main
orr x0, x0, x1
msr ELR_EL2, x0 msr ELR_EL2, x0
// Set SP_EL1 to stack base // Set SP_EL1 to stack base

View File

@@ -1,10 +1,9 @@
use crate::{ use crate::{
aarch64::mmu::{ aarch64::mmu::{
alloc_block_l2_explicit, allocate_memory, map_l2_block, map_page, alloc_block_l2_explicit, allocate_memory, map_page, physical_mapping::reserve_page,
physical_mapping::reserve_page, reserve_range, PhysAddr, PhysSource, VirtAddr, DEVICE_MEM, reserve_range, PhysAddr, PhysSource, VirtAddr, DEVICE_MEM, EL0_ACCESSIBLE, GRANULARITY,
EL0_ACCESSIBLE, GRANULARITY, KERNEL_VIRTUAL_MEM_SPACE, LEVEL1_BLOCK_SIZE, KERNEL_VIRTUAL_MEM_SPACE, LEVEL1_BLOCK_SIZE, LEVEL2_BLOCK_SIZE, NORMAL_MEM, PXN, READ_ONLY,
LEVEL2_BLOCK_SIZE, NORMAL_MEM, PXN, READ_ONLY, STACK_START_ADDR, TRANSLATIONTABLE_TTBR0, STACK_START_ADDR, TRANSLATIONTABLE_TTBR0, TRANSLATIONTABLE_TTBR1, UXN, WRITABLE,
UXN, WRITABLE,
}, },
PERIPHERAL_BASE, PERIPHERAL_BASE,
}; };
@@ -44,6 +43,16 @@ pub fn initialize_mmu_translation_tables() {
.unwrap(); .unwrap();
} }
for addr in (0..text_end).step_by(GRANULARITY) {
map_page(
addr | KERNEL_VIRTUAL_MEM_SPACE,
addr,
core::ptr::addr_of_mut!(TRANSLATIONTABLE_TTBR1),
READ_ONLY | NORMAL_MEM,
)
.unwrap();
}
for addr in (text_end..shared_segment_end).step_by(GRANULARITY) { for addr in (text_end..shared_segment_end).step_by(GRANULARITY) {
map_page( map_page(
addr, addr,
@@ -54,12 +63,12 @@ pub fn initialize_mmu_translation_tables() {
.unwrap(); .unwrap();
} }
for addr in (shared_segment_end..kernel_end).step_by(LEVEL2_BLOCK_SIZE) { for addr in (text_end..shared_segment_end).step_by(GRANULARITY) {
map_l2_block( map_page(
addr | KERNEL_VIRTUAL_MEM_SPACE,
addr, addr,
addr, core::ptr::addr_of_mut!(TRANSLATIONTABLE_TTBR1),
core::ptr::addr_of_mut!(TRANSLATIONTABLE_TTBR0), EL0_ACCESSIBLE | WRITABLE | NORMAL_MEM,
WRITABLE | UXN | NORMAL_MEM,
) )
.unwrap(); .unwrap();
} }

View File

@@ -18,6 +18,7 @@ use crate::{
allocate_memory, PhysSource, KERNEL_VIRTUAL_MEM_SPACE, LEVEL2_BLOCK_SIZE, NORMAL_MEM, UXN, allocate_memory, PhysSource, KERNEL_VIRTUAL_MEM_SPACE, LEVEL2_BLOCK_SIZE, NORMAL_MEM, UXN,
WRITABLE, WRITABLE,
}, },
application_manager::initialize_app_manager,
interrupt_handlers::irq::initialize_interrupt_handler, interrupt_handlers::irq::initialize_interrupt_handler,
pi3::timer::sleep_s, pi3::timer::sleep_s,
terminal::{flush_terminal, init_terminal}, terminal::{flush_terminal, init_terminal},
@@ -57,6 +58,7 @@ pub mod configuration;
pub mod framebuffer; pub mod framebuffer;
pub mod interrupt_handlers; pub mod interrupt_handlers;
pub mod application_manager;
pub mod pi3; pub mod pi3;
pub mod terminal; pub mod terminal;
@@ -85,6 +87,7 @@ pub fn get_current_el() -> u64 {
pub fn initialize_kernel() { pub fn initialize_kernel() {
unsafe { initialize_kernel_heap() }; unsafe { initialize_kernel_heap() };
initialize_interrupt_handler(); initialize_interrupt_handler();
initialize_app_manager();
init_terminal(); init_terminal();
} }