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/>.
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! */
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
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);
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
[] =
119 "Non Maskable Interrupt",
121 "Into Detected Overflow",
127 "Coprocessor Segment Overrun",
129 "Segment Not Present",
131 "General Protection Fault",
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
)
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");