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