Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
224 palkovsky 1
#
2
# Copyright (C) 2005 Ondrej Palkovsky
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
 
30
#  Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error word
31
# and 1 means interrupt with error word
32
 
33
 
34
#define ERROR_WORD_INTERRUPT_LIST 0x00027D00
35
 
36
#include <arch/pm.h>
799 palkovsky 37
#include <arch/context_offset.h>
224 palkovsky 38
 
39
.text
40
.global interrupt_handlers
41
.global panic_printf
42
 
43
panic_printf:
44
	movq $halt, (%rsp)
45
	jmp printf
46
 
252 palkovsky 47
.global memcpy
48
memcpy:
49
	jmp _memcpy
50
 
51
.global cpuid
242 palkovsky 52
.global has_cpuid
53
.global rdtsc
251 palkovsky 54
.global read_efer_flag
55
.global set_efer_flag
56
 
242 palkovsky 57
## Determine CPUID support
58
#
59
# Return 0 in EAX if CPUID is not support, 1 if supported.
60
#
61
has_cpuid:
62
	pushfq			# store flags
63
	popq %rax		# read flags
348 jermar 64
	movq %rax,%rdx		# copy flags
65
	btcl $21,%edx		# swap the ID bit
66
	pushq %rdx
242 palkovsky 67
	popfq			# propagate the change into flags
68
	pushfq
348 jermar 69
	popq %rdx		# read flags	
242 palkovsky 70
	andl $(1<<21),%eax	# interested only in ID bit
348 jermar 71
	andl $(1<<21),%edx
72
	xorl %edx,%eax		# 0 if not supported, 1 if supported
242 palkovsky 73
	ret
74
 
251 palkovsky 75
cpuid:
76
	movq %rbx, %r10  # we have to preserve rbx across function calls
242 palkovsky 77
 
251 palkovsky 78
	movl %edi,%eax	# load the command into %eax
79
 
80
	cpuid	
81
	movl %eax,0(%rsi)
82
	movl %ebx,4(%rsi)
83
	movl %ecx,8(%rsi)
84
	movl %edx,12(%rsi)
85
 
86
	movq %r10, %rbx
87
	ret
88
 
242 palkovsky 89
rdtsc:
90
	xorq %rax,%rax
91
	rdtsc
92
	ret
251 palkovsky 93
 
94
set_efer_flag:
95
	movq $0xc0000080, %rcx
96
	rdmsr
97
	btsl %edi, %eax
98
	wrmsr
99
	ret
242 palkovsky 100
 
251 palkovsky 101
read_efer_flag:	
102
	movq $0xc0000080, %rcx
103
	rdmsr
104
	ret 		
242 palkovsky 105
 
224 palkovsky 106
# Push all general purpose registers on stack except %rbp, %rsp
799 palkovsky 107
.macro save_all_gpr
108
	movq %rbp, IOFFSET_RBP(%rsp)
109
	movq %rax, IOFFSET_RAX(%rsp)
110
	movq %rbx, IOFFSET_RBX(%rsp)
111
	movq %rcx, IOFFSET_RCX(%rsp)
112
	movq %rdx, IOFFSET_RDX(%rsp)
113
	movq %rsi, IOFFSET_RSI(%rsp)
114
	movq %rdi, IOFFSET_RDI(%rsp)
115
	movq %r8, IOFFSET_R8(%rsp)
116
	movq %r9, IOFFSET_R9(%rsp)
117
	movq %r10, IOFFSET_R10(%rsp)
118
	movq %r11, IOFFSET_R11(%rsp)
119
	movq %r12, IOFFSET_R12(%rsp)
120
	movq %r13, IOFFSET_R13(%rsp)
121
	movq %r14, IOFFSET_R14(%rsp)
122
	movq %r15, IOFFSET_R15(%rsp)
224 palkovsky 123
.endm
124
 
799 palkovsky 125
.macro restore_all_gpr
126
	movq IOFFSET_RBP(%rsp), %rbp
127
	movq IOFFSET_RAX(%rsp), %rax
128
	movq IOFFSET_RBX(%rsp), %rbx
129
	movq IOFFSET_RCX(%rsp), %rcx
130
	movq IOFFSET_RDX(%rsp), %rdx
131
	movq IOFFSET_RSI(%rsp), %rsi
132
	movq IOFFSET_RDI(%rsp), %rdi
133
	movq IOFFSET_R8(%rsp), %r8
134
	movq IOFFSET_R9(%rsp), %r9
135
	movq IOFFSET_R10(%rsp), %r10
136
	movq IOFFSET_R11(%rsp), %r11
137
	movq IOFFSET_R12(%rsp), %r12
138
	movq IOFFSET_R13(%rsp), %r13
139
	movq IOFFSET_R14(%rsp), %r14
140
	movq IOFFSET_R15(%rsp), %r15
224 palkovsky 141
.endm
142
 
143
## Declare interrupt handlers
144
#
145
# Declare interrupt handlers for n interrupt
146
# vectors starting at vector i.
147
#
148
# The handlers setup data segment registers
576 palkovsky 149
# and call exc_dispatch().
224 palkovsky 150
#
151
.macro handler i n
799 palkovsky 152
	subq $IREGISTER_SPACE, %rsp
153
	save_all_gpr
224 palkovsky 154
 
155
	movq $(\i),%rdi   # %rdi - first parameter
799 palkovsky 156
	movq %rsp, %rsi   # %rsi - pointer to interrupt_context
576 palkovsky 157
	call exc_dispatch 	# exc_dispatch(i, stack)
224 palkovsky 158
 
159
# Test if this is interrupt with error word or not
160
	mov $\i,%cl;
161
	movl $1,%eax;
162
	test $0xe0,%cl;
163
	jnz 0f;
164
	and $0x1f,%cl;
165
	shl %cl,%eax;
166
	and $ERROR_WORD_INTERRUPT_LIST,%eax;
167
	jz 0f;
168
 
169
 
170
# Return with error word
799 palkovsky 171
	restore_all_gpr
172
	# $8 = Skip error word
173
	addq $IREGISTER_SPACE + 0x8, %rsp
224 palkovsky 174
	iretq
175
 
176
0:
177
# Return with no error word
799 palkovsky 178
	restore_all_gpr
179
	addq $IREGISTER_SPACE, %rsp
224 palkovsky 180
	iretq
181
 
182
	.if (\n-\i)-1
183
	handler "(\i+1)",\n
184
	.endif
185
.endm
186
 
187
interrupt_handlers:
188
h_start:
189
	handler 0 IDT_ITEMS
190
h_end:
191
 
192
.data
193
.global interrupt_handler_size
194
 
195
interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS