Boot to desktop on aarch64.

This commit is contained in:
4lDO2
2024-03-07 14:46:36 +01:00
parent 57c3119a83
commit b97e733d94
4 changed files with 18 additions and 25 deletions
+2 -3
View File
@@ -113,9 +113,7 @@ pub struct InterruptStack {
}
impl InterruptStack {
pub fn setup_minimal(&mut self, ip: usize, _singlestep: bool) {
self.set_instr_pointer(ip);
}
pub fn init(&mut self) {}
pub fn set_stack_pointer(&mut self, sp: usize) {
self.iret.sp_el0 = sp;
}
@@ -405,6 +403,7 @@ macro_rules! exception_stack {
#[naked]
pub unsafe extern "C" fn enter_usermode() -> ! {
core::arch::asm!(concat!(
"blr x28\n",
// Restore all userspace registers
pop_special!(),
pop_scratch!(),
-16
View File
@@ -218,19 +218,3 @@ pub struct KernelArgsAp {
pub unsafe extern "C" fn kstart_ap(args_ptr: *const KernelArgsAp) -> ! {
loop {}
}
#[naked]
//TODO: AbiCompatBool
//TODO: clear all regs?
pub unsafe extern "C" fn usermode(_ip: usize, _sp: usize, _arg: usize, _is_singlestep: usize) -> ! {
core::arch::asm!(
"
msr spsr_el1, xzr // spsr
msr elr_el1, x0 // ip
msr sp_el0, x1 // sp
mov x0, x2 // arg
eret
",
options(noreturn),
);
}
+4
View File
@@ -80,6 +80,10 @@ impl Context {
self.sp = address;
}
pub fn set_x28(&mut self, x28: usize) {
self.x28 = x28;
}
pub fn set_lr(&mut self, address: usize) {
self.lr = address;
}
+12 -6
View File
@@ -117,14 +117,19 @@ impl ContextList {
let mut stack_top = unsafe { stack.as_mut_ptr().add(KSTACK_SIZE) };
unsafe {
if userspace_allowed {
const INT_REGS_SIZE: usize = core::mem::size_of::<crate::interrupt::InterruptStack>();
if userspace_allowed {
unsafe {
// Zero-initialize InterruptStack registers.
const INT_REGS_SIZE: usize = core::mem::size_of::<crate::interrupt::InterruptStack>();
stack_top = stack_top.sub(INT_REGS_SIZE);
stack_top.write_bytes(0_u8, INT_REGS_SIZE);
(&mut *stack_top.cast::<InterruptStack>()).init();
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
unsafe {
if userspace_allowed {
stack_top = stack_top.sub(core::mem::size_of::<usize>());
stack_top.cast::<usize>().write(crate::interrupt::syscall::enter_usermode as usize);
}
@@ -134,8 +139,9 @@ impl ContextList {
}
#[cfg(target_arch = "aarch64")]
{
context.arch.set_lr(func as usize);
unsafe {
context.arch.set_lr(crate::interrupt::syscall::enter_usermode as usize);
context.arch.set_x28(func as usize);
context.arch.set_context_handle();
}