kern

view src/intr-asm.S @ 49:50730d42d2d3

fuck yeah, now do priviledge levels and TSS
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Jul 2011 07:21:54 +0300
parents f65b348780e3
children 1d8877d12de0
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 jmp 0f
75 .globl intr_ret
76 intr_ret:
77 /* if called as a function from context_switch, we must
78 * remove the pushed return address before continuing
79 */
80 add $4, %esp
81 0: /* ... we skip to here otherwise */
82 popa
83 /* remove error code and intr num from stack */
84 add $8, %esp
85 iret
87 /* by including interrupts.h with ASM defined, the macros above
88 * are expanded to generate all required interrupt entry points
89 */
90 #define ASM
91 #include <interrupts.h>