Subversion Repositories HelenOS-historic

Rev

Rev 1212 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
132 vana 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
 
952 jermar 31
# Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error word
137 vana 32
# and 1 means interrupt with error word
132 vana 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
#
45
paging_on:
316 jermar 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
132 vana 50
	jmp 0f
51
0:
52
	ret
53
 
54
 
55
## Enable local APIC
56
#
57
# Enable local APIC in MSR.
58
#
59
enable_l_apic_in_msr:
316 jermar 60
	push %eax
61
 
132 vana 62
	movl $0x1b, %ecx
63
	rdmsr
64
	orl $(1<<11),%eax
65
	orl $(0xfee00000),%eax
66
	wrmsr
316 jermar 67
 
68
	pop %eax
132 vana 69
	ret
70
 
1100 palkovsky 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	
132 vana 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
576 palkovsky 87
# and call exc_dispatch().
132 vana 88
#
1278 palkovsky 89
#define INTERRUPT_ALIGN 64
132 vana 90
.macro handler i n
958 jermar 91
 
1100 palkovsky 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
1212 palkovsky 111
 
1100 palkovsky 112
	call syscall_handler   # syscall_handler(ax,cx,dx,si,di)
113
	cli
114
	addl $20, %esp         # clean-up of parameters
115
 
116
	pop %gs
117
	pop %fs
118
	pop %es
119
	pop %ds
120
 
121
	CLEAR_NT_FLAG
122
	iret
123
.else	
1008 jermar 124
	/*
1021 jermar 125
	 * This macro distinguishes between two versions of ia32 exceptions.
126
	 * One version has error word and the other does not have it.
127
	 * The latter version fakes the error word on the stack so that the
128
	 * handlers and istate_t can be the same for both types.
1008 jermar 129
	 */
130
	.iflt \i-32
1021 jermar 131
		.if (1 << \i) & ERROR_WORD_INTERRUPT_LIST
1100 palkovsky 132
			/* 
133
			 * With error word, do nothing
1021 jermar 134
			 */
135
                .else
136
                        /*
137
                         * Version without error word,
138
                         */
139
			subl $4, %esp
140
                .endif
141
        .else
142
                /*
143
                 * Version without error word,
144
                 */
145
		subl $4, %esp
1100 palkovsky 146
	.endif
147
 
132 vana 148
	push %ds
149
	push %es
1016 jermar 150
	push %fs
151
	push %gs
132 vana 152
 
1100 palkovsky 153
#ifdef CONFIG_DEBUG_ALLREGS
154
	push %ebx
155
	push %ebp
156
	push %edi
157
	push %esi
158
#else
159
	sub $16, %esp
160
#endif
161
	push %edx
162
	push %ecx
163
	push %eax
164
 
132 vana 165
	# we must fill the data segment registers
166
	movw $16,%ax
167
	movw %ax,%ds
168
	movw %ax,%es
169
 
1100 palkovsky 170
	pushl %esp          # *istate
171
	pushl $(\i)         # intnum
172
	call exc_dispatch   # excdispatch(intnum, *istate)
173
	addl $8,%esp        # Clear arguments from stack
132 vana 174
 
1100 palkovsky 175
	CLEAR_NT_FLAG # Modifies %ecx
176
 
177
	pop %eax
178
	pop %ecx
179
	pop %edx
180
#ifdef CONFIG_DEBUG_ALLREGS
181
	pop %esi
182
	pop %edi
183
	pop %ebp
184
	pop %ebx
185
#else
186
	add $16, %esp
187
#endif	
188
 
1016 jermar 189
	pop %gs
190
	pop %fs
132 vana 191
	pop %es
192
	pop %ds
193
 
1021 jermar 194
	addl $4,%esp	# Skip error word, no matter whether real or fake.
316 jermar 195
	iret
1100 palkovsky 196
.endif
132 vana 197
 
1100 palkovsky 198
	.align INTERRUPT_ALIGN
132 vana 199
	.if (\n-\i)-1
200
	handler "(\i+1)",\n
201
	.endif
202
.endm
203
 
204
# keep in sync with pm.h !!!
205
IDT_ITEMS=64
1100 palkovsky 206
.align INTERRUPT_ALIGN
132 vana 207
interrupt_handlers:
208
h_start:
1100 palkovsky 209
	handler 0 IDT_ITEMS
132 vana 210
h_end:
211
 
212
.data
213
.global interrupt_handler_size
214
 
215
interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS