1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <asm/interrupt.h>
26
27
28struct idt_entry {
29 u16 base_low;
30 u16 selector;
31 u8 res;
32 u8 access;
33 u16 base_high;
34} __attribute__ ((packed));
35
36
37struct idt_entry idt[256];
38
39
40asm (".globl irq_return\n"
41 "irq_return:\n"
42 " addl $4, %esp\n"
43 " popa\n"
44 " iret\n");
45
46void __attribute__ ((regparm(0))) default_isr(void);
47asm ("default_isr: iret\n");
48
49asm ("idt_ptr:\n"
50 ".word 0x800\n"
51 ".long idt\n"
52 ".word 0x18\n");
53
54void set_vector(u8 intnum, void *routine)
55{
56 idt[intnum].base_high = (u16)((u32)(routine + gd->reloc_off) >> 16);
57 idt[intnum].base_low = (u16)((u32)(routine + gd->reloc_off) & 0xffff);
58}
59
60
61int cpu_init_interrupts(void)
62{
63 int i;
64
65
66 disable_interrupts();
67
68
69 for (i=0;i<256;i++) {
70 idt[i].access = 0x8e;
71 idt[i].res = 0;
72 idt[i].selector = 0x10;
73 set_vector(i, default_isr);
74 }
75
76 asm ("cs lidt idt_ptr\n");
77
78
79 enable_interrupts();
80
81 return 0;
82}
83
84void enable_interrupts(void)
85{
86 asm("sti\n");
87}
88
89int disable_interrupts(void)
90{
91 long flags;
92
93 asm volatile ("pushfl ; popl %0 ; cli\n" : "=g" (flags) : );
94
95 return (flags&0x200);
96}
97