mirror of
https://github.com/iceHtwoO/novaOS.git
synced 2026-04-17 04:32:27 +00:00
feat: start application via application_manager
This commit is contained in:
@@ -1,24 +1,21 @@
|
||||
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,
|
||||
find_free_kerne_page_in_block, map_page, physical_mapping::reserve_page, PageTable,
|
||||
TableEntry, VirtAddr, NORMAL_MEM, TRANSLATIONTABLE_TTBR0, TRANSLATIONTABLE_TTBR1, WRITABLE,
|
||||
},
|
||||
configuration::memory_mapping::APPLICATION_TRANSLATION_TABLE_VA,
|
||||
configuration::memory_mapping::{APPLICATION_TRANSLATION_TABLE_VA, EL0_STACK_TOP},
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
use core::arch::asm;
|
||||
use spin::Mutex;
|
||||
|
||||
pub struct Application {
|
||||
pub table_ptr: *mut TableEntry,
|
||||
}
|
||||
|
||||
impl Default for Application {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
pub start_addr: usize,
|
||||
}
|
||||
|
||||
impl Application {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(start_addr: VirtAddr) -> Self {
|
||||
let physical_addr = reserve_page();
|
||||
let virtual_address =
|
||||
find_free_kerne_page_in_block(APPLICATION_TRANSLATION_TABLE_VA).unwrap();
|
||||
@@ -31,14 +28,55 @@ impl Application {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// TODO: Temporary fix, while kernel and app share some memory regions
|
||||
#[allow(static_mut_refs)]
|
||||
unsafe {
|
||||
let table = &mut *(virtual_address as *mut PageTable);
|
||||
table.0 = TRANSLATIONTABLE_TTBR0.0;
|
||||
}
|
||||
|
||||
Self {
|
||||
table_ptr: physical_addr as *mut TableEntry,
|
||||
start_addr,
|
||||
}
|
||||
}
|
||||
pub fn start(&self) {
|
||||
unsafe {
|
||||
asm!("msr ELR_EL1, {}", in(reg) self.start_addr);
|
||||
asm!("msr SPSR_EL1, {0:x}", in(reg) 0);
|
||||
asm!("msr SP_EL0, {0:x}", in(reg) EL0_STACK_TOP);
|
||||
asm!("msr TTBR0_EL1, {}", in(reg) self.table_ptr as usize);
|
||||
asm!("eret");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub static mut APPLICATION_LIST: Option<Vec<Application>> = None;
|
||||
struct AppManager {
|
||||
apps: Option<Vec<Application>>,
|
||||
}
|
||||
|
||||
impl AppManager {
|
||||
const fn new() -> Self {
|
||||
Self { apps: None }
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for AppManager {}
|
||||
|
||||
static APP_MANAGER: Mutex<AppManager> = Mutex::new(AppManager::new());
|
||||
|
||||
pub fn initialize_app_manager() {
|
||||
unsafe { APPLICATION_LIST = Some(Vec::new()) }
|
||||
let mut guard = APP_MANAGER.lock();
|
||||
guard.apps = Some(Vec::new());
|
||||
}
|
||||
pub fn add_app(app: Application) {
|
||||
if let Some(app_list) = APP_MANAGER.lock().apps.as_mut() {
|
||||
app_list.push(app);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_app(index: usize) {
|
||||
if let Some(app_list) = APP_MANAGER.lock().apps.as_mut() {
|
||||
app_list[index].start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user