From 1530a85d5aefcf6497ff2129023e9a0b002603dd Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 4 May 2021 15:30:24 +0200 Subject: Solving many issues: Aligning kernel stack, improve syscall mechanism, DISABLING RED-ZONE !!!! --- src/core/scheduler_asm.S | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/core/scheduler_asm.S') diff --git a/src/core/scheduler_asm.S b/src/core/scheduler_asm.S index 0c9d5ba..24eaa8d 100644 --- a/src/core/scheduler_asm.S +++ b/src/core/scheduler_asm.S @@ -1,22 +1,35 @@ .globl switch - switch: # Load task page table mov (%rdi), %rax mov %rax, %cr3 + # ds + mov 96(%rdi), %rax + mov %ax, %ds + # es + mov 104(%rdi), %rax + mov %ax, %es + # fs + mov 112(%rdi), %rax + mov %ax, %fs + # gs + mov 120(%rdi), %rax + mov %ax, %gs + # First load the task stack mov 64(%rdi), %rsp # Prepare for iret - push 96(%rdi) # ds + push 56(%rdi) # ss push 64(%rdi) # rsp push 128(%rdi) # Flags pop %rax - or $0x200, %rax # Enable interrupt - mov $0xffffffffbfff, %rbx # NT flag - and %rbx, %rax + bts $9, %rax # Enable interrupt + not %rax + bts $14, %rax # NT flag + not %rax push %rax # Apply flags changes push 40(%rdi) # cs push 48(%rdi) # rip @@ -32,19 +45,12 @@ switch: push 144(%rdi) # r8 push 152(%rdi) # r9 push 160(%rdi) # r10 - push 160(%rdi) # r11 + push 168(%rdi) # r11 push 176(%rdi) # r12 push 184(%rdi) # r13 push 192(%rdi) # r14 push 200(%rdi) # r15 - # ds - mov 96(%rdi), %ax - mov %ax, %ds - mov %ax, %gs - mov %ax, %fs - mov %ax, %es - # Restore general registers pop %r15 pop %r14 @@ -61,7 +67,6 @@ switch: pop %rcx pop %rbx pop %rax - # Perform task switching iretq -- cgit v1.2.3