source: trunk/hal/i386/__kentry.S @ 43

Last change on this file since 43 was 16, checked in by alain, 7 years ago

mprove the HAL for interrupt, exception, syscall handling.

File size: 4.5 KB
Line 
1/*
2 * __kentry.S - unified kernel entry point
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#define DECLARE_EXCEPT_ERR(n)     \
24.align 16                       ; \
25        cli                     ; \
26        pushl   $##n            ; \
27        jmp     unified_except_entry ; \
28        movl    %eax,   %eax
29       
30#define DECLARE_EXCEPT(n)       \
31.align 16                       ; \
32        cli                     ; \
33        pushl   $0x0            ; \
34        pushl   $##n            ; \
35        jmp     unified_except_entry
36
37#define DECLARE_IRQ(n)          \
38.align 16                       ; \
39        cli                     ; \
40        pushl   $0x0            ; \
41        pushl   $##n            ; \
42        jmp     unified_irq_entry
43       
44.text
45.global __except
46.align 16
47__except:       
48DECLARE_EXCEPT(0)               /* Division By Zero Exception   */
49DECLARE_EXCEPT(1)               /* Debug Exception              */
50DECLARE_EXCEPT(2)               /* Non Maskable Interrupt Exception */
51DECLARE_EXCEPT(3)               /* Breakpoint Exception         */
52DECLARE_EXCEPT(4)               /* Into Detected Overflow Exception */
53DECLARE_EXCEPT(5)               /* Out of Bounds Exception */
54DECLARE_EXCEPT(6)               /* Invalid Opcode Exception */
55DECLARE_EXCEPT(7)               /* No Coprocessor Exception */
56DECLARE_EXCEPT_ERR(8)           /* Double Fault Exception */
57DECLARE_EXCEPT(9)               /* Coprocessor Segment Overrun Exception */
58DECLARE_EXCEPT_ERR(10)          /* Bad TSS Exception */
59DECLARE_EXCEPT_ERR(11)          /* Segment Not Present Exception */
60DECLARE_EXCEPT_ERR(12)          /* Stack Fault Exception */
61DECLARE_EXCEPT_ERR(13)          /* General Protection Fault Exception */
62DECLARE_EXCEPT_ERR(14)          /* Page Fault Exception */
63DECLARE_EXCEPT(15)              /* Unknown Interrupt Exception */
64DECLARE_EXCEPT(16)              /* Coprocessor Fault Exception */
65DECLARE_EXCEPT(17)              /* Alignment Check Exception (486+) */
66DECLARE_EXCEPT(18)              /* Machine Check Exception (Pentium/586+) */
67DECLARE_EXCEPT(19)              /* Reserved */
68DECLARE_EXCEPT(20)              /* Reserved */
69DECLARE_EXCEPT(21)              /* Reserved */
70DECLARE_EXCEPT(22)              /* Reserved */
71DECLARE_EXCEPT(23)              /* Reserved */
72DECLARE_EXCEPT(24)              /* Reserved */
73DECLARE_EXCEPT(25)              /* Reserved */
74DECLARE_EXCEPT(26)              /* Reserved */
75DECLARE_EXCEPT(27)              /* Reserved */
76DECLARE_EXCEPT(28)              /* Reserved */
77DECLARE_EXCEPT(29)              /* Reserved */
78DECLARE_EXCEPT(30)              /* Reserved */
79DECLARE_EXCEPT(31)              /* Reserved */
80
81.text
82.global __irq
83.align 16
84__irq: 
85DECLARE_IRQ(0)
86DECLARE_IRQ(1)
87DECLARE_IRQ(2)
88DECLARE_IRQ(3)
89DECLARE_IRQ(4)
90DECLARE_IRQ(5)
91DECLARE_IRQ(6)
92DECLARE_IRQ(7)
93DECLARE_IRQ(8)
94DECLARE_IRQ(9)
95DECLARE_IRQ(10)
96DECLARE_IRQ(11)
97DECLARE_IRQ(12)
98DECLARE_IRQ(13)
99DECLARE_IRQ(14)
100DECLARE_IRQ(15)
101DECLARE_IRQ(16)
102DECLARE_IRQ(17)
103DECLARE_IRQ(18)
104DECLARE_IRQ(19)
105DECLARE_IRQ(20)
106DECLARE_IRQ(21)
107DECLARE_IRQ(22)
108DECLARE_IRQ(23)
109DECLARE_IRQ(24)
110DECLARE_IRQ(25)
111DECLARE_IRQ(26)
112DECLARE_IRQ(27)
113DECLARE_IRQ(28)
114DECLARE_IRQ(29)
115DECLARE_IRQ(30)
116DECLARE_IRQ(31)
117DECLARE_IRQ(32)
118DECLARE_IRQ(33)
119DECLARE_IRQ(34)
120DECLARE_IRQ(35)
121DECLARE_IRQ(36)
122DECLARE_IRQ(37)
123DECLARE_IRQ(38)
124DECLARE_IRQ(39)
125DECLARE_IRQ(40)
126DECLARE_IRQ(41)
127DECLARE_IRQ(42)
128DECLARE_IRQ(43)
129DECLARE_IRQ(44)
130DECLARE_IRQ(45)
131DECLARE_IRQ(46)
132DECLARE_IRQ(47)
133DECLARE_IRQ(48)
134DECLARE_IRQ(49)
135DECLARE_IRQ(50)
136DECLARE_IRQ(51)
137DECLARE_IRQ(52)
138DECLARE_IRQ(53)
139DECLARE_IRQ(54)
140DECLARE_IRQ(55)
141DECLARE_IRQ(56)
142DECLARE_IRQ(57)
143DECLARE_IRQ(58)
144DECLARE_IRQ(59)
145DECLARE_IRQ(60)
146DECLARE_IRQ(61)
147DECLARE_IRQ(62)
148DECLARE_IRQ(63)
149DECLARE_IRQ(64) /* End of Available IRQ in this version, this is also the syscall gate (INT 96).
150                 * this value is used by PIC_IRQ_MAX macor */
151
152#define SAVE_REGS         \
153        pusha           ; \
154        push    %ds     ; \
155        push    %es     ; \
156        push    %fs     ; \
157        push    %gs     ; \
158
159#define RESTORE_REGS      \
160        pop     %gs     ; \
161        pop     %fs     ; \
162        pop     %es     ; \
163        pop     %ds     ; \
164        popa
165
166#define LOAD_KERNEL_SEGMENT       \
167        mov     $0x10,  %ax     ; \
168        mov     %ax,    %ds     ; \
169        mov     %ax,    %es     ; \
170        mov     %ax,    %fs     ; \
171        mov     %ax,    %gs     ; \
172       
173.extern __do_exception
174.extern __do_interrupt
175       
176unified_except_entry:
177        SAVE_REGS
178        LOAD_KERNEL_SEGMENT
179        mov     %esp,   %eax
180        push    %eax
181        call    __do_exception
182        pop     %eax
183        RESTORE_REGS
184        add     $0x8,   %esp
185        iret
186
187unified_irq_entry:     
188        SAVE_REGS
189        LOAD_KERNEL_SEGMENT     
190        mov     %esp,   %eax
191        push    %eax
192        call    __do_interrupt
193        pop     %eax
194        RESTORE_REGS
195        add     $0x8,   %esp
196        iret
197       
Note: See TracBrowser for help on using the repository browser.