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