kern

view src/intr-asm.S @ 50:1d8877d12de0

tidyed up the intr_ret bit, made it a bit more reasonably structured, and cleaned up some debugging things
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Jul 2011 07:35:53 +0300
parents 50730d42d2d3
children 4eaecb14fe31
line source
1 .data
2 .align 4
3 .short 0
4 /* memory reserved for set_idt */
5 lim:.short 0
6 addr:.long 0
8 .text
9 /* set_idt(uint32_t addr, uint16_t limit)
10 * loads the IDTR with the new address and limit for the IDT */
11 .globl set_idt
12 set_idt:
13 movl 4(%esp), %eax
14 movl %eax, (addr)
15 movw 8(%esp), %ax
16 movw %ax, (lim)
17 lidt (lim)
18 ret
20 /* get_intr_state()
21 * returns 1 if interrutps are enabled, 0 if disabled */
22 .globl get_intr_state
23 get_intr_state:
24 pushf
25 popl %eax
26 shr $9, %eax /* bit 9 of eflags is IF */
27 andl $1, %eax
28 ret
30 /* set_intr_state(int state)
31 * enables interrupts if the argument is non-zero, disables them otherwise */
32 .globl set_intr_state
33 set_intr_state:
34 cmpl $0, 4(%esp)
35 jz 0f
36 sti
37 ret
38 0: cli
39 ret
42 /* interrupt entry with error code macro
43 * this macro generates an interrupt entry point for the
44 * exceptions which include error codes in the stack frame
45 */
46 .macro ientry_err n name
47 .globl intr_entry_\name
48 intr_entry_\name:
49 pushl $\n
50 jmp intr_entry_common
51 .endm
53 /* interrupt entry without error code macro
54 * this macro generates an interrupt entry point for the interrupts
55 * and exceptions which do not include error codes in the stack frame
56 * it pushes a dummy error code (0), to make the stack frame identical
57 */
58 .macro ientry_noerr n name
59 .globl intr_entry_\name
60 intr_entry_\name:
61 pushl $0
62 pushl $\n
63 jmp intr_entry_common
64 .endm
66 /* common code used by all entry points. calls dispatch_intr()
67 * defined in intr.c
68 */
69 .extern dispatch_intr
70 intr_entry_common:
71 pusha
72 call dispatch_intr
73 intr_ret_local:
74 popa
75 /* remove error code and intr num from stack */
76 add $8, %esp
77 iret
79 /* intr_ret is called by context_switch to return from the kernel
80 * to userspace. The argument is a properly formed intr_frame
81 * structure with the saved context of the new task.
82 *
83 * First thing to do is remove the return address pointing back
84 * to context_switch, which then leaves us with a proper interrupt
85 * stack frame, so we can jump right in the middle of the regular
86 * interrupt return code above.
87 */
88 .globl intr_ret
89 intr_ret:
90 add $4, %esp
91 jmp intr_ret_local
93 /* by including interrupts.h with ASM defined, the macros above
94 * are expanded to generate all required interrupt entry points
95 */
96 #define ASM
97 #include <interrupts.h>