Browse Source

schedule when irqs fire

master
Mathieu Serandour 1 year ago
parent
commit
f15dd0532e
  1. 8
      kernel/int/irq.c
  2. 72
      kernel/int/irq.s
  3. 0
      kernel/int/syscalls.c
  4. 0
      kernel/int/syscalls.h

8
kernel/int/irq.c

@ -3,6 +3,7 @@
#include "../lib/panic.h"
#include "../lib/logging.h"
#include "../lib/sprintf.h"
#include "../sched/thread.h"
#include "irq.h"
@ -65,7 +66,7 @@ void release_irq(unsigned n) {
}
// called from irq.s
void irq_common_handler(uint8_t irq_n) {
void irq_common_handler(uint8_t irq_n, gp_regs_t* context) {
assert(irq_n <= IRQ_END);
assert(irq_n >= IRQ_BEGIN);
// the irq_n th irq just fired
@ -79,6 +80,11 @@ void irq_common_handler(uint8_t irq_n) {
}
sched_save(context);
handler(driver);
if(!schedule())
return;
}

72
kernel/int/irq.s

@ -1,20 +1,29 @@
[extern irq_common_handler]
; macro argument: irq number
%macro create_irq 1
[extern _irq_handler%1]
_irq_handler%1:
; enter stack frame
; push rbp
; mov rbp, rsp
; already pushed stuf:
; uint64_t RIP;
; uint64_t CS;
; uint64_t RFLAGS;
; uint64_t RSP;
; uint64_t SS;
; enter stack frame
push rbp
mov rbp, rsp
push rdi
mov dil, byte %1
; save stack pointer
; save frame pointer and enter stack frame
; mov rbp, rsp
; save rax
push rax
mov al, byte %1
jmp common_stub
@ -41,33 +50,66 @@ create_irq 47
common_stub:
push rax
; clear DF flag
; DF need to be clear on function
; entry and exit (System-V ABI)
cld
; save context
; we already saved rsp, rbp, rax
; here, al = the irq handler number
push rcx
push rdx
push rbx
push rsi
push rdi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
; put the irq handler number in dil: the
; argument for the irq_common_handler function
mov dil, al
; beginning of the interrupt stack = beginning of
; the context structure
mov rsi, rsp
; clear DF flag
; DF need to be clear on function
; entry and exit (System-V ABI)
cld
call irq_common_handler
; restore the context
; this function only returns
; if no rescheduling is done
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rdi
pop rsi
pop rbx
pop rdx
pop rcx
pop rax
pop rdi
; mov rsp, rbp
; pop rbp
leave
pop rbp
iretq

0
kernel/int/syscalls.c

0
kernel/int/syscalls.h

Loading…
Cancel
Save