source: mainline/arch/ia32/src/asm.S@ 4e09712

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4e09712 was c7c0b89b, checked in by Ondrej Palkovsky <ondrap@…>, 19 years ago

Added uspace call to enable/disable interrupts.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1#
2# Copyright (C) 2001-2004 Jakub Jermar
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29## very low and hardware-level functions
30
31# Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error word
32# and 1 means interrupt with error word
33#define ERROR_WORD_INTERRUPT_LIST 0x00027D00
34
35.text
36
37.global paging_on
38.global enable_l_apic_in_msr
39.global interrupt_handlers
40
41## Turn paging on
42#
43# Enable paging and write-back caching in CR0.
44#
45paging_on:
46 movl %cr0,%edx
47 orl $(1<<31),%edx # paging on
48 andl $~((1<<30)|(1<<29)),%edx # clear Cache Disable and not Write Though
49 movl %edx,%cr0
50 jmp 0f
510:
52 ret
53
54
55## Enable local APIC
56#
57# Enable local APIC in MSR.
58#
59enable_l_apic_in_msr:
60 push %eax
61
62 movl $0x1b, %ecx
63 rdmsr
64 orl $(1<<11),%eax
65 orl $(0xfee00000),%eax
66 wrmsr
67
68 pop %eax
69 ret
70
71# Clear nested flag
72# overwrites %ecx
73.macro CLEAR_NT_FLAG
74 pushfl
75 pop %ecx
76 and $0xffffbfff,%ecx
77 push %ecx
78 popfl
79.endm
80
81## Declare interrupt handlers
82#
83# Declare interrupt handlers for n interrupt
84# vectors starting at vector i.
85#
86# The handlers setup data segment registers
87# and call exc_dispatch().
88#
89#define INTERRUPT_ALIGN 128
90.macro handler i n
91
92.ifeq \i-0x30 # Syscall handler
93 push %ds
94 push %es
95 push %fs
96 push %gs
97
98 # Push arguments on stack
99 push %edi
100 push %esi
101 push %edx
102 push %ecx
103 push %eax
104
105 # we must fill the data segment registers
106 movw $16,%ax
107 movw %ax,%ds
108 movw %ax,%es
109
110 sti
111 cmp $2, %edi # Is this SYS_INT_CONTROL?
112 je sys_int_ctrl
113
114 call syscall_handler # syscall_handler(ax,cx,dx,si,di)
115sysc_end:
116 cli
117 addl $20, %esp # clean-up of parameters
118
119 pop %gs
120 pop %fs
121 pop %es
122 pop %ds
123
124 CLEAR_NT_FLAG
125 iret
126sys_int_ctrl: # Interrupt control
127 mov %esp, %eax
128 add $44, %eax
129 mov %eax, 4(%esp) # Pointer to flags - 2nd argument
130 call ddi_int_control
131 jmp sysc_end
132.else
133 /*
134 * This macro distinguishes between two versions of ia32 exceptions.
135 * One version has error word and the other does not have it.
136 * The latter version fakes the error word on the stack so that the
137 * handlers and istate_t can be the same for both types.
138 */
139 .iflt \i-32
140 .if (1 << \i) & ERROR_WORD_INTERRUPT_LIST
141 /*
142 * With error word, do nothing
143 */
144 .else
145 /*
146 * Version without error word,
147 */
148 subl $4, %esp
149 .endif
150 .else
151 /*
152 * Version without error word,
153 */
154 subl $4, %esp
155 .endif
156
157 push %ds
158 push %es
159 push %fs
160 push %gs
161
162#ifdef CONFIG_DEBUG_ALLREGS
163 push %ebx
164 push %ebp
165 push %edi
166 push %esi
167#else
168 sub $16, %esp
169#endif
170 push %edx
171 push %ecx
172 push %eax
173
174 # we must fill the data segment registers
175 movw $16,%ax
176 movw %ax,%ds
177 movw %ax,%es
178
179 pushl %esp # *istate
180 pushl $(\i) # intnum
181 call exc_dispatch # excdispatch(intnum, *istate)
182 addl $8,%esp # Clear arguments from stack
183
184 CLEAR_NT_FLAG # Modifies %ecx
185
186 pop %eax
187 pop %ecx
188 pop %edx
189#ifdef CONFIG_DEBUG_ALLREGS
190 pop %esi
191 pop %edi
192 pop %ebp
193 pop %ebx
194#else
195 add $16, %esp
196#endif
197
198 pop %gs
199 pop %fs
200 pop %es
201 pop %ds
202
203 addl $4,%esp # Skip error word, no matter whether real or fake.
204 iret
205.endif
206
207 .align INTERRUPT_ALIGN
208 .if (\n-\i)-1
209 handler "(\i+1)",\n
210 .endif
211.endm
212
213# keep in sync with pm.h !!!
214IDT_ITEMS=64
215.align INTERRUPT_ALIGN
216interrupt_handlers:
217h_start:
218 handler 0 IDT_ITEMS
219h_end:
220
221.data
222.global interrupt_handler_size
223
224interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS
Note: See TracBrowser for help on using the repository browser.