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 (defin !! 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 (defin !! 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
>> 030 /** The variable holding the nested level of the IRQ handlers */
>> 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_counter
>> 069
065 /* Send EOI to PIC. See Intel 070 /* Send EOI to PIC. See Intel 8259 datasheet
066 available on Kos website */ 071 available on Kos website */
067 movb $0x20, %al 072 movb $0x20, %al
068 outb %al, $0x20 073 outb %al, $0x20
069 074
070 /* 075 /*
071 * Call the handler with IRQ n 076 * Call the handler with IRQ number as argument
072 */ 077 */
073 pushl $\id 078 pushl $\id
074 leal sos_irq_handler_array,%e 079 leal sos_irq_handler_array,%edi
075 call *\id*4(%edi) 080 call *\id*4(%edi)
076 addl $4, %esp 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 ! */
077 099
078 /* Restore the context */ 100 /* Restore the context */
079 popw %gs 101 popw %gs
080 popw %fs 102 popw %fs
081 popw %es 103 popw %es
082 popw %ds 104 popw %ds
083 popw %ss 105 popw %ss
084 addl $2,%esp 106 addl $2,%esp
085 popl %eax 107 popl %eax
086 popl %ebx 108 popl %ebx
087 popl %ecx 109 popl %ecx
088 popl %edx 110 popl %edx
089 popl %esi 111 popl %esi
090 popl %edi 112 popl %edi
091 popl %ebp 113 popl %ebp
092 114
093 /* Remove fake error code */ 115 /* Remove fake error code */
094 addl $4, %esp 116 addl $4, %esp
095 117
096 iret 118 iret
097 .endr 119 .endr
098 120
099 121
100 /* These pre-handlers are for IRQ (Slave PIC) 122 /* These pre-handlers are for IRQ (Slave PIC) */
101 .irp id, 8,9,10,11,12,13,14,15 123 .irp id, 8,9,10,11,12,13,14,15
102 124
103 .p2align 2, 0x90 125 .p2align 2, 0x90
104 126
105 sos_irq_wrapper_\id: 127 sos_irq_wrapper_\id:
106 .type sos_irq_wrapper_\id,@function 128 .type sos_irq_wrapper_\id,@function
107 129
108 /* 130 /*
109 * Backup the CPU context 131 * Backup the CPU context
110 */ 132 */
111 133
112 /* Fake error code */ 134 /* Fake error code */
113 pushl $0 135 pushl $0
114 136
115 /* Backup the actual context * 137 /* Backup the actual context */
116 pushl %ebp 138 pushl %ebp
117 movl %esp, %ebp 139 movl %esp, %ebp
118 140
119 pushl %edi 141 pushl %edi
120 pushl %esi 142 pushl %esi
121 pushl %edx 143 pushl %edx
122 pushl %ecx 144 pushl %ecx
123 pushl %ebx 145 pushl %ebx
124 pushl %eax 146 pushl %eax
125 subl $2,%esp 147 subl $2,%esp
126 pushw %ss 148 pushw %ss
127 pushw %ds 149 pushw %ds
128 pushw %es 150 pushw %es
129 pushw %fs 151 pushw %fs
130 pushw %gs 152 pushw %gs
131 153
>> 154 /*
>> 155 * Increment IRQ nested level
>> 156 */
>> 157 incl sos_irq_nested_level_counter
>> 158
132 /* Send EOI to PIC. See Intel 159 /* Send EOI to PIC. See Intel 8259 datasheet
133 available on Kos website */ 160 available on Kos website */
134 movb $0x20, %al 161 movb $0x20, %al
135 outb %al, $0xa0 162 outb %al, $0xa0
136 outb %al, $0x20 163 outb %al, $0x20
137 164
138 /* 165 /*
139 * Call the handler with IRQ n 166 * Call the handler with IRQ number as argument
140 */ 167 */
141 pushl $\id 168 pushl $\id
142 leal sos_irq_handler_array,%e 169 leal sos_irq_handler_array,%edi
143 call *\id*4(%edi) 170 call *\id*4(%edi)
144 addl $4, %esp 171 addl $4, %esp
145 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
146 /* Restore the context */ 190 /* Restore the context */
147 popw %gs 191 popw %gs
148 popw %fs 192 popw %fs
149 popw %es 193 popw %es
150 popw %ds 194 popw %ds
151 popw %ss 195 popw %ss
152 addl $2,%esp 196 addl $2,%esp
153 popl %eax 197 popl %eax
154 popl %ebx 198 popl %ebx
155 popl %ecx 199 popl %ecx
156 popl %edx 200 popl %edx
157 popl %esi 201 popl %esi
158 popl %edi 202 popl %edi
159 popl %ebp 203 popl %ebp
160 204
161 /* Remove fake error code */ 205 /* Remove fake error code */
162 addl $4, %esp 206 addl $4, %esp
163 207
164 iret 208 iret
165 .endr 209 .endr
166 210
167 /* Build the sos_irq_wrapper_array, shared wit <<
168 .section ".rodata" 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 */
169 .p2align 5, 0x0 216 .p2align 5, 0x0
170 sos_irq_wrapper_array: 217 sos_irq_wrapper_array:
171 .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
172 .long (sos_irq_wrapper_\id) 219 .long (sos_irq_wrapper_\id)
173 .endr 220 .endr