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