Subversion Repositories HelenOS

Rev

Rev 242 | Go to most recent revision | Details | 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
#define __ASM__
37
#include <arch/pm.h>
38
 
39
.text
40
.global interrupt_handlers
41
.global panic_printf
42
 
43
panic_printf:
44
	movq $halt, (%rsp)
45
	jmp printf
46
 
47
# Push all general purpose registers on stack except %rbp, %rsp
48
.macro push_all_gpr
49
	pushq %rax 
50
	pushq %rbx
51
	pushq %rcx
52
	pushq %rdx
53
	pushq %rsi
54
	pushq %rdi
55
	pushq %r8
56
	pushq %r9
57
	pushq %r10
58
	pushq %r11
59
	pushq %r12
60
	pushq %r13
61
	pushq %r14
62
	pushq %r15
63
.endm
64
 
65
.macro pop_all_gpr
66
	popq %r15
67
	popq %r14
68
	popq %r13
69
	popq %r12
70
	popq %r11
71
	popq %r10
72
	popq %r9
73
	popq %r8
74
	popq %rdi
75
	popq %rsi
76
	popq %rdx
77
	popq %rcx
78
	popq %rbx
79
	popq %rax
80
.endm
81
 
82
## Declare interrupt handlers
83
#
84
# Declare interrupt handlers for n interrupt
85
# vectors starting at vector i.
86
#
87
# The handlers setup data segment registers
88
# and call trap_dispatcher().
89
#
90
.macro handler i n
91
	pushq %rbp
92
	movq %rsp,%rbp
93
 
94
	push_all_gpr
95
 
96
	# trap_dispatcher(i, stack)
97
	movq $(\i),%rdi   # %rdi - first parameter
98
	movq %rbp, %rsi
99
	addq $8, %rsi     # %rsi - second parameter - original stack
100
	call trap_dispatcher
101
 
102
# Test if this is interrupt with error word or not
103
	mov $\i,%cl;
104
	movl $1,%eax;
105
	test $0xe0,%cl;
106
	jnz 0f;
107
	and $0x1f,%cl;
108
	shl %cl,%eax;
109
	and $ERROR_WORD_INTERRUPT_LIST,%eax;
110
	jz 0f;
111
 
112
 
113
# Return with error word
114
	pop_all_gpr
115
 
116
	popq %rbp;
117
	add $8,%esp;    # Skip error word
118
	iretq
119
 
120
0:
121
# Return with no error word
122
	pop_all_gpr
123
 
124
	popq %rbp
125
	iretq
126
 
127
	.if (\n-\i)-1
128
	handler "(\i+1)",\n
129
	.endif
130
.endm
131
 
132
interrupt_handlers:
133
h_start:
134
	handler 0 IDT_ITEMS
135
#	handler 64 128	
136
#	handler 128 192
137
#	handler 192 256
138
h_end:
139
 
140
 
141
.data
142
.global interrupt_handler_size
143
 
144
interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS