Commit ed6cd1a6 authored by Nifou's avatar Nifou

Save all registers during syscalls and process switchs

parent 651dbdaa
Pipeline #164495484 passed with stages
in 8 minutes and 45 seconds
......@@ -68,28 +68,33 @@ pub extern "x86-interrupt" fn timer_interrupt_handler(_: &mut InterruptStackFram
pop rdi
// Registers
mov qword ptr [r15 + 8], r11
mov qword ptr [r15 + 16], r10
mov qword ptr [r15 + 24], r9
mov qword ptr [r15 + 32], r8
mov qword ptr [r15 + 40], rsi
mov qword ptr [r15 + 48], rdi
mov qword ptr [r15 + 56], rdx
mov qword ptr [r15 + 64], rcx
mov qword ptr [r15 + 72], rbx
mov qword ptr [r15 + 80], rax
mov qword ptr [r15 + 8], rbp
mov qword ptr [r15 + 16], r15
mov qword ptr [r15 + 24], r14
mov qword ptr [r15 + 32], r13
mov qword ptr [r15 + 40], r12
mov qword ptr [r15 + 48], r11
mov qword ptr [r15 + 56], r10
mov qword ptr [r15 + 64], r9
mov qword ptr [r15 + 72], r8
mov qword ptr [r15 + 80], rsi
mov qword ptr [r15 + 88], rdi
mov qword ptr [r15 + 96], rdx
mov qword ptr [r15 + 104], rcx
mov qword ptr [r15 + 112], rbx
mov qword ptr [r15 + 120], rax
// Stack frame
mov rax, qword ptr [rsp + 16]
mov qword ptr [r15 + 88], rax
mov qword ptr [r15 + 128], rax
mov rax, qword ptr [rsp + 24]
mov qword ptr [r15 + 96], rax
mov qword ptr [r15 + 136], rax
mov rax, qword ptr [rsp + 32]
mov qword ptr [r15 + 104], rax
mov qword ptr [r15 + 144], rax
mov rax, qword ptr [rsp + 40]
mov qword ptr [r15 + 112], rax
mov qword ptr [r15 + 152], rax
mov rax, qword ptr [rsp + 48]
mov qword ptr [r15 + 120], rax"
mov qword ptr [r15 + 160], rax"
:
: "{r15}"(get_kstack())
:
......
......@@ -52,7 +52,8 @@ pub unsafe fn init() {
/// * Restores the register's values
pub unsafe extern fn syscall() {
#[inline(never)]
unsafe fn inner(stack: &'static mut Registers) -> isize {
#[no_mangle]
unsafe fn syscall_inner(stack: &'static mut Registers) -> isize {
Syscall::new(stack).syscall()
}
......@@ -80,16 +81,18 @@ pub unsafe extern fn syscall() {
push r9
push r10
push r11
push r12
push r13
push r14
push r15
push rbp
mov r11, cr3
push r11"
: : : : "intel", "volatile");
// Get reference to stack variables
let rsp: usize;
llvm_asm!("" : "={rsp}"(rsp) : : : "intel", "volatile");
// Call the inner function
let _a = inner(&mut *(rsp as *mut Registers));
llvm_asm!("mov rdi, rsp
call syscall_inner
" : : : : "intel", "volatile");
// The return value of the syscall (RAX) is already set because the return value
// of a function is stored in RAX, so nothing to do!
......@@ -97,6 +100,11 @@ pub unsafe extern fn syscall() {
// Interrupt return
llvm_asm!("pop r11
mov cr3, r11
pop rbp
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
......
......@@ -51,6 +51,11 @@ pub trait SchedulerAlgo {
// Load the new context
llvm_asm!("pop r11
mov cr3, r11
pop rbp
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
......
......@@ -24,6 +24,21 @@ pub struct Registers {
/// The CR3 register (which contains the page table)
pub cr3: usize,
/// The RBP register (base pointer)
pub rbp: usize,
/// The R15 register
pub r15: usize,
/// The R14 register
pub r14: usize,
/// The R13 register
pub r13: usize,
/// The R12 register
pub r12: usize,
/// The R11 register
pub r11: usize,
......@@ -74,6 +89,11 @@ impl core::default::Default for Registers {
fn default() -> Self {
Self {
cr3: 0x0,
rbp: 0x0,
r15: 0x0,
r14: 0x0,
r13: 0x0,
r12: 0x0,
r11: 0x0,
r10: 0x0,
r9: 0x0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment