Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / arch / x86_64 / isrs.c
blobc008a3bb040ca77d826e54ff01ead465ef9ff492
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <system.h>
21 #include <arch/io.h>
22 #include <string.h>
24 /* These are function prototypes for all of the exception
25 * handlers: The first 32 entries in the IDT are reserved
26 * by Intel, and are designed to service exceptions! */
27 extern void isr0();
28 extern void isr1();
29 extern void isr2();
30 extern void isr3();
31 extern void isr4();
32 extern void isr5();
33 extern void isr6();
34 extern void isr7();
35 extern void isr8();
36 extern void isr9();
37 extern void isr10();
38 extern void isr11();
39 extern void isr12();
40 extern void isr13();
41 extern void isr14();
42 extern void isr15();
43 extern void isr16();
44 extern void isr17();
45 extern void isr18();
46 extern void isr19();
47 extern void isr20();
48 extern void isr21();
49 extern void isr22();
50 extern void isr23();
51 extern void isr24();
52 extern void isr25();
53 extern void isr26();
54 extern void isr27();
55 extern void isr28();
56 extern void isr29();
57 extern void isr30();
58 extern void isr31();
61 /* This is a very repetitive function... it's not hard, it's
62 * just annoying. As you can see, we set the first 32 entries
63 * in the IDT to the first 32 ISRs. We can't use a for loop
64 * for this, because there is no way to get the function names
65 * that correspond to that given entry. We set the access
66 * flags to 0x8E. This means that the entry is present, is
67 * running in ring 0 (kernel level), and has the lower 5 bits
68 * set to the required '14', which is represented by 'E' in
69 * hex. */
70 unsigned int isrs_install ()
72 idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
73 idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E);
74 idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E);
75 idt_set_gate(3, (unsigned)isr3, 0x08, 0x8E);
76 idt_set_gate(4, (unsigned)isr4, 0x08, 0x8E);
77 idt_set_gate(5, (unsigned)isr5, 0x08, 0x8E);
78 idt_set_gate(6, (unsigned)isr6, 0x08, 0x8E);
79 idt_set_gate(7, (unsigned)isr7, 0x08, 0x8E);
81 idt_set_gate(8, (unsigned)isr8, 0x08, 0x8E);
82 idt_set_gate(9, (unsigned)isr9, 0x08, 0x8E);
83 idt_set_gate(10, (unsigned)isr10, 0x08, 0x8E);
84 idt_set_gate(11, (unsigned)isr11, 0x08, 0x8E);
85 idt_set_gate(12, (unsigned)isr12, 0x08, 0x8E);
86 idt_set_gate(13, (unsigned)isr13, 0x08, 0x8E);
87 idt_set_gate(14, (unsigned)isr14, 0x08, 0x8E);
88 idt_set_gate(15, (unsigned)isr15, 0x08, 0x8E);
90 idt_set_gate(16, (unsigned)isr16, 0x08, 0x8E);
91 idt_set_gate(17, (unsigned)isr17, 0x08, 0x8E);
92 idt_set_gate(18, (unsigned)isr18, 0x08, 0x8E);
93 idt_set_gate(19, (unsigned)isr19, 0x08, 0x8E);
94 idt_set_gate(20, (unsigned)isr20, 0x08, 0x8E);
95 idt_set_gate(21, (unsigned)isr21, 0x08, 0x8E);
96 idt_set_gate(22, (unsigned)isr22, 0x08, 0x8E);
97 idt_set_gate(23, (unsigned)isr23, 0x08, 0x8E);
99 idt_set_gate(24, (unsigned)isr24, 0x08, 0x8E);
100 idt_set_gate(25, (unsigned)isr25, 0x08, 0x8E);
101 idt_set_gate(26, (unsigned)isr26, 0x08, 0x8E);
102 idt_set_gate(27, (unsigned)isr27, 0x08, 0x8E);
103 idt_set_gate(28, (unsigned)isr28, 0x08, 0x8E);
104 idt_set_gate(29, (unsigned)isr29, 0x08, 0x8E);
105 idt_set_gate(30, (unsigned)isr30, 0x08, 0x8E);
106 idt_set_gate(31, (unsigned)isr31, 0x08, 0x8E);
108 return 1;
111 /* This is a simple string array. It contains the message that
112 * corresponds to each and every exception. We get the correct
113 * message by accessing like:
114 * exception_message[interrupt_number] */
115 char *exception_messages[] =
117 "Division By Zero",
118 "Debug",
119 "Non Maskable Interrupt",
120 "Breakpoint",
121 "Into Detected Overflow",
122 "Out of Bounds",
123 "Invalid Opcode",
124 "No Coprocessor",
126 "Double Fault",
127 "Coprocessor Segment Overrun",
128 "Bad TSS",
129 "Segment Not Present",
130 "Stack Fault",
131 "General Protection Fault",
132 "Page Fault",
133 "Unknown Interrupt",
135 "Coprocessor Fault",
136 "Alignment Check",
137 "Machine Check",
138 "Reserved",
139 "Reserved",
140 "Reserved",
141 "Reserved",
142 "Reserved",
144 "Reserved",
145 "Reserved",
146 "Reserved",
147 "Reserved",
148 "Reserved",
149 "Reserved",
150 "Reserved",
151 "Reserved"
154 /* All of our Exception handling Interrupt Service Routines will
155 * point to this function. This will tell us what exception has
156 * happened! Right now, we simply halt the system by hitting an
157 * endless loop. All ISRs disable interrupts while they are being
158 * serviced as a 'locking' mechanism to prevent an IRQ from
159 * happening and messing up kernel data structures */
160 void fault_handler (struct regs *r)
162 if (r->int_no < 32)
164 settextcolor (4, 0);
165 puts ((unsigned char*) "Kernel panic -> ");
166 settextcolor (15, 0);
167 puts ((unsigned char*) exception_messages[r->int_no]);
168 puts ((unsigned char*) " Exception. System Halted!\n");
169 for (;;);