diff options
| author | Jake Mannens <jake72360@gmail.com> | 2018-07-28 05:31:09 +1000 |
|---|---|---|
| committer | Jake Mannens <jake72360@gmail.com> | 2018-07-28 05:31:09 +1000 |
| commit | 4a91e12af177dc50a2427d335fd522658d821194 (patch) | |
| tree | 2d2d231ff426db952be2acb819deb7263e24529b /kernel/timer.s | |
| parent | 9400716f56057d9f2fcd7f7ad033dfcb131105a2 (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/timer.s')
| -rw-r--r-- | kernel/timer.s | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/kernel/timer.s b/kernel/timer.s index c3af34b..b96e1f1 100644 --- a/kernel/timer.s +++ b/kernel/timer.s @@ -1,9 +1,11 @@ +global ticked global ticks global timer_init extern check_signals extern register_isr extern sched_tick +ticked: dd 0 ticks: dd 0 tick_handler: @@ -17,17 +19,20 @@ tick_handler: mov es, ax mov fs, ax mov gs, ax - ; handle the timer tick + mov dword [ticked], 1 inc dword [ticks] mov al, 0x20 out 0x20, al - - ; call the scheduler + ; check that the user isn't executing in kernel space + mov eax, [esp+38] + test eax, 0x03 + jz .end + ; if it isn't, call the scheduler call sched_tick ; handle any pending signals before returning to normal execution call check_signals - +.end: ; restore the data segment selectors pop ax mov ds, ax |
