Diff markup
001 /* Copyright (C) 2004 The KOS Team 001 /* Copyright (C) 2004 The KOS Team
002 Copyright (C) 1999 Free Software Foundatio <<
003 002
004 This program is free software; you can redi 003 This program is free software; you can redistribute it and/or
005 modify it under the terms of the GNU Genera 004 modify it under the terms of the GNU General Public License
006 as published by the Free Software Foundatio 005 as published by the Free Software Foundation; either version 2
007 of the License, or (at your option) any lat 006 of the License, or (at your option) any later version.
008 007
009 This program is distributed in the hope tha 008 This program is distributed in the hope that it will be useful,
010 but WITHOUT ANY WARRANTY; without even the 009 but WITHOUT ANY WARRANTY; without even the implied warranty of
011 MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 GNU General Public License for more details 011 GNU General Public License for more details.
013 012
014 You should have received a copy of the GNU 013 You should have received a copy of the GNU General Public License
015 along with this program; if not, write to t 014 along with this program; if not, write to the Free Software
016 Foundation, Inc., 59 Temple Place - Suite 3 015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
017 USA. 016 USA.
018 */ 017 */
019 #define ASM_SOURCE 1 <<
020 018
021 .file "irq_wrappers.S" 019 .file "irq_wrappers.S"
022 020
023 .text 021 .text
024 022
025 /** The address of the table of handlers (defi 023 /** The address of the table of handlers (defined in irq.c) */
026 .extern sos_irq_handler_array 024 .extern sos_irq_handler_array
027 025
028 /** The address of the table of wrappers (defi 026 /** The address of the table of wrappers (defined below, and shared
029 with irq.c */ 027 with irq.c */
030 .globl sos_irq_wrapper_array 028 .globl sos_irq_wrapper_array
031 029
032 /** The variable holding the nested level of t 030 /** The variable holding the nested level of the IRQ handlers */
033 .extern sos_irq_nested_level_counter 031 .extern sos_irq_nested_level_counter
034 032
035 /* These pre-handlers are for IRQ (Master PIC) 033 /* These pre-handlers are for IRQ (Master PIC) */
036 .irp id, 0,1,2,3,4,5,6,7 034 .irp id, 0,1,2,3,4,5,6,7
037 035
038 .p2align 2, 0x90 036 .p2align 2, 0x90
039 037
040 sos_irq_wrapper_\id: 038 sos_irq_wrapper_\id:
041 .type sos_irq_wrapper_\id,@function 039 .type sos_irq_wrapper_\id,@function
042 040
043 /* 041 /*
044 * Backup the CPU context 042 * Backup the CPU context
045 */ 043 */
046 044
047 /* Fake error code */ 045 /* Fake error code */
048 pushl $0 046 pushl $0
049 047
050 /* Backup the actual context * 048 /* Backup the actual context */
051 pushl %ebp 049 pushl %ebp
052 movl %esp, %ebp 050 movl %esp, %ebp
053 051
054 pushl %edi 052 pushl %edi
055 pushl %esi 053 pushl %esi
056 pushl %edx 054 pushl %edx
057 pushl %ecx 055 pushl %ecx
058 pushl %ebx 056 pushl %ebx
059 pushl %eax 057 pushl %eax
060 subl $2,%esp 058 subl $2,%esp
061 pushw %ss 059 pushw %ss
062 pushw %ds 060 pushw %ds
063 pushw %es 061 pushw %es
064 pushw %fs 062 pushw %fs
065 pushw %gs 063 pushw %gs
066 064
067 /* 065 /*
068 * Increment IRQ nested level 066 * Increment IRQ nested level
069 */ 067 */
070 incl sos_irq_nested_level_coun 068 incl sos_irq_nested_level_counter
071 069
072 /* Send EOI to PIC. See Intel 070 /* Send EOI to PIC. See Intel 8259 datasheet
073 available on Kos website */ 071 available on Kos website */
074 movb $0x20, %al 072 movb $0x20, %al
075 outb %al, $0x20 073 outb %al, $0x20
076 074
077 /* 075 /*
078 * Call the handler with the I !! 076 * Call the handler with IRQ number as argument
079 * address of the stored CPU c <<
080 */ 077 */
081 pushl %esp <<
082 pushl $\id 078 pushl $\id
083 leal sos_irq_handler_array,%e 079 leal sos_irq_handler_array,%edi
084 call *\id*4(%edi) 080 call *\id*4(%edi)
085 /* Unallocate the arguments pa !! 081 addl $4, %esp
086 addl $8, %esp <<
087 082
088 /* 083 /*
089 * Decrement IRQ nested level 084 * Decrement IRQ nested level
090 */ 085 */
091 cli /* Just in case we messed 086 cli /* Just in case we messed up everything in the handler */
092 subl $1, sos_irq_nested_level_ 087 subl $1, sos_irq_nested_level_counter
093 088
094 /* sos_irq_nested_level_counte 089 /* sos_irq_nested_level_counter went below 0 ?! */
095 jnc 2f 090 jnc 2f
096 091
097 1: /* Yes: Print fatal error mess 092 1: /* Yes: Print fatal error message */
098 pushl $msg_nested_level_overfl 093 pushl $msg_nested_level_overflow
099 call sos_display_fatal_error 094 call sos_display_fatal_error
100 addl $4, %esp ; jmp 1b 095 addl $4, %esp ; jmp 1b
101 /* Never returns */ 096 /* Never returns */
102 097
103 2: /* No: all right ! */ 098 2: /* No: all right ! */
104 099
105 /* Restore the context */ 100 /* Restore the context */
106 popw %gs 101 popw %gs
107 popw %fs 102 popw %fs
108 popw %es 103 popw %es
109 popw %ds 104 popw %ds
110 popw %ss 105 popw %ss
111 addl $2,%esp 106 addl $2,%esp
112 popl %eax 107 popl %eax
113 popl %ebx 108 popl %ebx
114 popl %ecx 109 popl %ecx
115 popl %edx 110 popl %edx
116 popl %esi 111 popl %esi
117 popl %edi 112 popl %edi
118 popl %ebp 113 popl %ebp
119 114
120 /* Remove fake error code */ 115 /* Remove fake error code */
121 addl $4, %esp 116 addl $4, %esp
122 117
123 iret 118 iret
124 .endr 119 .endr
125 120
126 121
127 /* These pre-handlers are for IRQ (Slave PIC) 122 /* These pre-handlers are for IRQ (Slave PIC) */
128 .irp id, 8,9,10,11,12,13,14,15 123 .irp id, 8,9,10,11,12,13,14,15
129 124
130 .p2align 2, 0x90 125 .p2align 2, 0x90
131 126
132 sos_irq_wrapper_\id: 127 sos_irq_wrapper_\id:
133 .type sos_irq_wrapper_\id,@function 128 .type sos_irq_wrapper_\id,@function
134 129
135 /* 130 /*
136 * Backup the CPU context 131 * Backup the CPU context
137 */ 132 */
138 133
139 /* Fake error code */ 134 /* Fake error code */
140 pushl $0 135 pushl $0
141 136
142 /* Backup the actual context * 137 /* Backup the actual context */
143 pushl %ebp 138 pushl %ebp
144 movl %esp, %ebp 139 movl %esp, %ebp
145 140
146 pushl %edi 141 pushl %edi
147 pushl %esi 142 pushl %esi
148 pushl %edx 143 pushl %edx
149 pushl %ecx 144 pushl %ecx
150 pushl %ebx 145 pushl %ebx
151 pushl %eax 146 pushl %eax
152 subl $2,%esp 147 subl $2,%esp
153 pushw %ss 148 pushw %ss
154 pushw %ds 149 pushw %ds
155 pushw %es 150 pushw %es
156 pushw %fs 151 pushw %fs
157 pushw %gs 152 pushw %gs
158 153
159 /* 154 /*
160 * Increment IRQ nested level 155 * Increment IRQ nested level
161 */ 156 */
162 incl sos_irq_nested_level_coun 157 incl sos_irq_nested_level_counter
163 158
164 /* Send EOI to PIC. See Intel 159 /* Send EOI to PIC. See Intel 8259 datasheet
165 available on Kos website */ 160 available on Kos website */
166 movb $0x20, %al 161 movb $0x20, %al
167 outb %al, $0xa0 162 outb %al, $0xa0
168 outb %al, $0x20 163 outb %al, $0x20
169 164
170 /* 165 /*
171 * Call the handler with the I !! 166 * Call the handler with IRQ number as argument
172 * address of the stored CPU c <<
173 */ 167 */
174 pushl %esp <<
175 pushl $\id 168 pushl $\id
176 leal sos_irq_handler_array,%e 169 leal sos_irq_handler_array,%edi
177 call *\id*4(%edi) 170 call *\id*4(%edi)
178 /* Unallocate the arguments pa !! 171 addl $4, %esp
179 addl $8, %esp <<
180 172
181 /* 173 /*
182 * Decrement IRQ nested level 174 * Decrement IRQ nested level
183 */ 175 */
184 cli /* Just in case we messed 176 cli /* Just in case we messed up everything in the handler */
185 subl $1, sos_irq_nested_level_ 177 subl $1, sos_irq_nested_level_counter
186 178
187 /* sos_irq_nested_level_counte 179 /* sos_irq_nested_level_counter went below 0 ?! */
188 jnc 2f 180 jnc 2f
189 181
190 1: /* Yes: Print fatal error mess 182 1: /* Yes: Print fatal error message */
191 pushl $msg_nested_level_overfl 183 pushl $msg_nested_level_overflow
192 call sos_display_fatal_error 184 call sos_display_fatal_error
193 addl $4, %esp ; jmp 1b 185 addl $4, %esp ; jmp 1b
194 /* Never returns */ 186 /* Never returns */
195 187
196 2: /* No: all right ! */ 188 2: /* No: all right ! */
197 189
198 /* Restore the context */ 190 /* Restore the context */
199 popw %gs 191 popw %gs
200 popw %fs 192 popw %fs
201 popw %es 193 popw %es
202 popw %ds 194 popw %ds
203 popw %ss 195 popw %ss
204 addl $2,%esp 196 addl $2,%esp
205 popl %eax 197 popl %eax
206 popl %ebx 198 popl %ebx
207 popl %ecx 199 popl %ecx
208 popl %edx 200 popl %edx
209 popl %esi 201 popl %esi
210 popl %edi 202 popl %edi
211 popl %ebp 203 popl %ebp
212 204
213 /* Remove fake error code */ 205 /* Remove fake error code */
214 addl $4, %esp 206 addl $4, %esp
215 207
216 iret 208 iret
217 .endr 209 .endr
218 210
219 .section ".rodata" 211 .section ".rodata"
220 msg_nested_level_overflow: 212 msg_nested_level_overflow:
221 .string "irq_wrappers.S: IRQ Nested le 213 .string "irq_wrappers.S: IRQ Nested level overflow ! System halted."
222 214
223 /* Build the sos_irq_wrapper_array, shared wit 215 /* Build the sos_irq_wrapper_array, shared with irq.c */
224 .p2align 5, 0x0 216 .p2align 5, 0x0
225 sos_irq_wrapper_array: 217 sos_irq_wrapper_array:
226 .irp id, 0,1,2,3,4,5,6,7,8,9,10,11,12, 218 .irp id, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
227 .long (sos_irq_wrapper_\id) 219 .long (sos_irq_wrapper_\id)
228 .endr 220 .endr