1 ; pcboot - bootable PC demo/game kernel
2 ; Copyright (C) 2018-2023 John Tsiombikas <nuclear@member.fsf.org>
4 ; This program is free software: you can redistribute it and/or modify
5 ; it under the terms of the GNU General Public License as published by
6 ; the Free Software Foundation, either version 3 of the License, or
7 ; (at your option) any later version.
9 ; This program is distributed in the hope that it will be useful,
10 ; but WITHOUT ANY WARRANTY, without even the implied warranty of
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ; GNU General Public License for more details.
14 ; You should have received a copy of the GNU General Public License
15 ; along with this program. If not, see <https://www.gnu.org/licenses/>.
25 ; void set_idt(uint32_t addr, uint16_t limit)
40 ; bit 9 of eflags is IF
45 ; void set_intr_flag(int onoff)
48 cmp dword [esp + 4], 0
55 ; interrupt entry with error code macro
56 ; this macro generates an interrupt entry point for the
57 ; exceptions which include error codes in the stack frame
65 ; interrupt entry without error code macro
66 ; this macro generates an interrupt entry point for the interrupts
67 ; and exceptions which do not include error codes in the stack frame
68 ; it pushes a dummy error code (0), to make the stack frame identical
77 ; common code used by all entry points. calls dispatch_intr()
81 ; save general purpose registers
85 ; restore general purpose registers
87 ; remove error code and intr num from stack
91 ; special case for the timer interrupt, to avoid all the overhead of
92 ; going through the C interrupt dispatcher 250 times each second
94 ; global intr_entry_fast_timer
95 ;intr_entry_fast_timer:
97 ; ; signal end of interrupt
104 ; special case for IRQ 7 and IRQ 15, to catch spurious interrupts
110 global irq7_entry_check_spurious
111 irq7_entry_check_spurious:
121 global irq15_entry_check_spurious
122 irq15_entry_check_spurious:
129 ; it was spurious, send EOI to master PIC and iret
138 ; XXX not necessary for now, just leaving it in in case it's useful
141 ; intr_ret is called by context_switch to return from the kernel
142 ; to userspace. The argument is a properly formed intr_frame
143 ; structure with the saved context of the new task.
145 ; First thing to do is remove the return address pointing back
146 ; to context_switch, which then leaves us with a proper interrupt
147 ; stack frame, so we can jump right in the middle of the regular
148 ; interrupt return code above.
154 ; by including interrupts.h with ASM defined, the macros above
155 ; are expanded to generate all required interrupt entry points
156 %define INTR_ENTRY_EC(n, name) ientry_err n, name
157 %define INTR_ENTRY_NOEC(n, name) ientry_noerr n, name
161 ; vi:set ts=8 sts=8 sw=8 ft=nasm: