summaryrefslogtreecommitdiff
path: root/kernel/traps.s
diff options
context:
space:
mode:
authorJake Mannens <jake72360@gmail.com>2018-07-28 05:31:09 +1000
committerJake Mannens <jake72360@gmail.com>2018-07-28 05:31:09 +1000
commit4a91e12af177dc50a2427d335fd522658d821194 (patch)
tree2d2d231ff426db952be2acb819deb7263e24529b /kernel/traps.s
parent9400716f56057d9f2fcd7f7ad033dfcb131105a2 (diff)
Added new function register_trap() which creates trap gate entries in
the IDT. This function takes the same parameters as register_isr() which creates interrupt gate entries in the IDT. The register_isr() function now sets the gate type to 0x0E regardless of what was already in the descriptor. This is to break reliance on the IDT already being initialized to a known state as well as avoiding conflicts with the new register_trap() function. Added declaration for the 'ticks' variable in kernel/sched.h so that it's value may be used throughout the kernel. Changed the system call gate to a trap gate. This means that interrupts will not be disabled prior to entry into the system call handler. This will allow hardware functions such as the timer to operate continuously even if the user makes a system call. Added checks to the timer interrupt handler. These checks prevent the scheduler from being called if the interrupt occurred during kernel mode execution. The idea here, is that the timer interrupt handler only services the hardware (increments the tick count and sends an EOI to the PIC's) if a system call was already running in the kernel. The system call handler has also been expanded to check if the timer fired prior to returning to userspace. If the timer did fire, the syscall handler will invoke the scheduler (as the timer handler would have), so that it can decide if it's time to switch tasks.
Diffstat (limited to 'kernel/traps.s')
-rw-r--r--kernel/traps.s14
1 files changed, 11 insertions, 3 deletions
diff --git a/kernel/traps.s b/kernel/traps.s
index 73e7f64..36b3423 100644
--- a/kernel/traps.s
+++ b/kernel/traps.s
@@ -11,8 +11,10 @@ extern ctask
extern idt
extern panic
extern printk
-extern register_isr
+extern register_trap
+extern reschedule
extern sighandler_default
+extern ticked
; here we define offsets into task_struct.
; if task_struct is modified, this must be
@@ -269,6 +271,7 @@ exc_reserved:
syscall_handler:
SAVE
+ mov dword [ticked], 0
; push the arguments onto the stack, then
; calculate the offset for the appropriate
; handler function and call it
@@ -282,8 +285,13 @@ syscall_handler:
add esp, 12
; preserve the syscall's return value
mov [esp+30], eax
- mov eax, esp
+ ; check if the timer fired while we were in kernel mode
+ mov eax, [ticked]
+ jz .skip
+ call reschedule
+.skip:
; check pending signals and handle them (if any)
+ mov eax, esp
push eax
call check_signals
add esp, 4
@@ -379,7 +387,7 @@ syscall_init:
push syscall_handler
push dword 3
push dword 0x80
- call register_isr
+ call register_trap
add esp, 12
pop ebp
ret