Subversion Repositories HelenOS

Rev

Rev 952 | Rev 1008 | 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
 
71
 
72
## Declare interrupt handlers
73
#
74
# Declare interrupt handlers for n interrupt
75
# vectors starting at vector i.
76
#
77
# The handlers setup data segment registers
576 palkovsky 78
# and call exc_dispatch().
132 vana 79
#
80
.macro handler i n
958 jermar 81
	push %eax
82
 
83
	# Test if this is interrupt with error word or not
84
	movl $(1<<\i), %eax
85
	andl $ERROR_WORD_INTERRUPT_LIST,%eax
86
 
87
	/*
88
	 * If this interrupt/exception  stores error word,
89
	 * we need to pop EAX.
90
	 * If this interrupt doesn't store error word, we emulate it
91
	 * for the sake of consistent pstate structure. In that case
92
	 * we merely leave the EAX on the stack.
93
	 */
94
	jz 0f
95
 
96
	/*
97
	 * This exception stores error word.
98
	 */
99
	pop %eax
100
	jmp 1f
101
 
102
0:
103
	/*
104
	 * This interrupt doesn't store error word.
105
	 * Just restore EAX without doing POP.
106
	 */
107
	movl (%esp), %eax
108
 
109
1:
132 vana 110
	pusha
958 jermar 111
	movl %esp, %ebp
132 vana 112
	push %ds
113
	push %es
114
 
115
	# we must fill the data segment registers
116
	movw $16,%ax
117
	movw %ax,%ds
118
	movw %ax,%es
119
 
120
	movl $(\i),%edi
121
	pushl %ebp
122
	pushl %edi
576 palkovsky 123
	call exc_dispatch
132 vana 124
	addl $8,%esp
125
 
126
	pop %es
127
	pop %ds
128
 
958 jermar 129
# Clear Nested Task flag.
316 jermar 130
	pushfl
131
	pop %eax
132
	and $0xFFFFBFFF,%eax
133
	push %eax
134
	popfl
141 vana 135
 
316 jermar 136
	popa
958 jermar 137
	add $4,%esp	# Skip error word, whether real or fake.
316 jermar 138
	iret
132 vana 139
 
140
	.if (\n-\i)-1
141
	handler "(\i+1)",\n
142
	.endif
143
.endm
144
 
145
# keep in sync with pm.h !!!
146
IDT_ITEMS=64
147
interrupt_handlers:
148
h_start:
149
	handler 0 64
150
#	handler 64 128	
151
#	handler 128 192
152
#	handler 192 256
153
h_end:
154
 
155
.data
156
.global interrupt_handler_size
157
 
158
interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS