mirror of
https://github.com/iceHtwoO/novaOS.git
synced 2026-04-16 20:22:26 +00:00
feat: map text area to kernel memory space, first application_manager
implementation
This commit is contained in:
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@@ -3,7 +3,7 @@
|
||||
"compounds": [
|
||||
{
|
||||
"name": "Run QEMU + Attach LLDB",
|
||||
"configurations": ["Attach LLDB"],
|
||||
"configurations": ["LLDB"],
|
||||
"preLaunchTask": "Run QEMU"
|
||||
}
|
||||
],
|
||||
@@ -61,9 +61,11 @@
|
||||
{
|
||||
"name": "LLDB",
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"request": "attach",
|
||||
"program": "${workspaceFolder}/target/aarch64-unknown-none/debug/nova",
|
||||
"preLaunchTask": "Run QEMU wo window"
|
||||
"preLaunchTask": "Run QEMU",
|
||||
"stopOnEntry": true,
|
||||
"processCreateCommands": ["gdb-remote localhost:1234"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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 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);
|
||||
|
||||
|
||||
44
src/application_manager.rs
Normal file
44
src/application_manager.rs
Normal 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()) }
|
||||
}
|
||||
@@ -10,8 +10,12 @@ el2_to_el1:
|
||||
msr SPSR_EL2, x0
|
||||
|
||||
// Set return address to kernel_main
|
||||
adrp x0, KERNEL_VIRTUAL_MEM_SPACE
|
||||
ldr x1, [x0, :lo12:KERNEL_VIRTUAL_MEM_SPACE]
|
||||
|
||||
adrp x0, kernel_main
|
||||
add x0, x0, :lo12:kernel_main
|
||||
orr x0, x0, x1
|
||||
msr ELR_EL2, x0
|
||||
|
||||
// Set SP_EL1 to stack base
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use crate::{
|
||||
aarch64::mmu::{
|
||||
alloc_block_l2_explicit, allocate_memory, map_l2_block, map_page,
|
||||
physical_mapping::reserve_page, reserve_range, PhysAddr, PhysSource, VirtAddr, DEVICE_MEM,
|
||||
EL0_ACCESSIBLE, GRANULARITY, KERNEL_VIRTUAL_MEM_SPACE, LEVEL1_BLOCK_SIZE,
|
||||
LEVEL2_BLOCK_SIZE, NORMAL_MEM, PXN, READ_ONLY, STACK_START_ADDR, TRANSLATIONTABLE_TTBR0,
|
||||
UXN, WRITABLE,
|
||||
alloc_block_l2_explicit, allocate_memory, map_page, physical_mapping::reserve_page,
|
||||
reserve_range, PhysAddr, PhysSource, VirtAddr, DEVICE_MEM, EL0_ACCESSIBLE, GRANULARITY,
|
||||
KERNEL_VIRTUAL_MEM_SPACE, LEVEL1_BLOCK_SIZE, LEVEL2_BLOCK_SIZE, NORMAL_MEM, PXN, READ_ONLY,
|
||||
STACK_START_ADDR, TRANSLATIONTABLE_TTBR0, TRANSLATIONTABLE_TTBR1, UXN, WRITABLE,
|
||||
},
|
||||
PERIPHERAL_BASE,
|
||||
};
|
||||
@@ -44,6 +43,16 @@ pub fn initialize_mmu_translation_tables() {
|
||||
.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) {
|
||||
map_page(
|
||||
addr,
|
||||
@@ -54,12 +63,12 @@ pub fn initialize_mmu_translation_tables() {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
for addr in (shared_segment_end..kernel_end).step_by(LEVEL2_BLOCK_SIZE) {
|
||||
map_l2_block(
|
||||
for addr in (text_end..shared_segment_end).step_by(GRANULARITY) {
|
||||
map_page(
|
||||
addr | KERNEL_VIRTUAL_MEM_SPACE,
|
||||
addr,
|
||||
addr,
|
||||
core::ptr::addr_of_mut!(TRANSLATIONTABLE_TTBR0),
|
||||
WRITABLE | UXN | NORMAL_MEM,
|
||||
core::ptr::addr_of_mut!(TRANSLATIONTABLE_TTBR1),
|
||||
EL0_ACCESSIBLE | WRITABLE | NORMAL_MEM,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use crate::{
|
||||
allocate_memory, PhysSource, KERNEL_VIRTUAL_MEM_SPACE, LEVEL2_BLOCK_SIZE, NORMAL_MEM, UXN,
|
||||
WRITABLE,
|
||||
},
|
||||
application_manager::initialize_app_manager,
|
||||
interrupt_handlers::irq::initialize_interrupt_handler,
|
||||
pi3::timer::sleep_s,
|
||||
terminal::{flush_terminal, init_terminal},
|
||||
@@ -57,6 +58,7 @@ pub mod configuration;
|
||||
pub mod framebuffer;
|
||||
pub mod interrupt_handlers;
|
||||
|
||||
pub mod application_manager;
|
||||
pub mod pi3;
|
||||
pub mod terminal;
|
||||
|
||||
@@ -85,6 +87,7 @@ pub fn get_current_el() -> u64 {
|
||||
pub fn initialize_kernel() {
|
||||
unsafe { initialize_kernel_heap() };
|
||||
initialize_interrupt_handler();
|
||||
initialize_app_manager();
|
||||
init_terminal();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user