Subversion Repositories HelenOS-historic

Rev

Rev 353 | 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
 
137 vana 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
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
.global inb
41
.global inw
42
.global inl
205 jermar 43
.global memcpy
132 vana 44
.global memsetb
45
.global memsetw
46
.global memcmp
47
 
48
 
49
## Turn paging on
50
#
51
# Enable paging and write-back caching in CR0.
52
#
53
paging_on:
316 jermar 54
	movl %cr0,%edx
55
	orl $(1<<31),%edx		# paging on
56
	andl $~((1<<30)|(1<<29)),%edx	# clear Cache Disable and not Write Though
57
	movl %edx,%cr0
132 vana 58
	jmp 0f
59
0:
60
	ret
61
 
62
 
63
## Enable local APIC
64
#
65
# Enable local APIC in MSR.
66
#
67
enable_l_apic_in_msr:
316 jermar 68
	push %eax
69
 
132 vana 70
	movl $0x1b, %ecx
71
	rdmsr
72
	orl $(1<<11),%eax
73
	orl $(0xfee00000),%eax
74
	wrmsr
316 jermar 75
 
76
	pop %eax
132 vana 77
	ret
78
 
79
 
80
## Declare interrupt handlers
81
#
82
# Declare interrupt handlers for n interrupt
83
# vectors starting at vector i.
84
#
85
# The handlers setup data segment registers
86
# and call trap_dispatcher().
87
#
88
.macro handler i n
89
	push %ebp
90
	movl %esp,%ebp
91
	pusha
92
 
93
	push %ds
94
	push %es
95
 
96
	# we must fill the data segment registers
97
	movw $16,%ax
98
	movw %ax,%ds
99
	movw %ax,%es
100
 
101
	movl $(\i),%edi
102
	pushl %ebp
103
	addl $4,(%esp)
104
	pushl %edi
105
	call trap_dispatcher
106
	addl $8,%esp
107
 
108
	pop %es
109
	pop %ds
110
 
137 vana 111
 
141 vana 112
# CLNT
316 jermar 113
	pushfl
114
	pop %eax
115
	and $0xFFFFBFFF,%eax
116
	push %eax
117
	popfl
141 vana 118
 
119
 
120
 
137 vana 121
# Test if this is interrupt with error word or not
316 jermar 122
	mov $\i,%cl
123
	movl $1,%eax
124
	test $0xe0,%cl
125
	jnz 0f
126
	and $0x1f,%cl
127
	shl %cl,%eax
128
	and $ERROR_WORD_INTERRUPT_LIST,%eax
129
	jz 0f
132 vana 130
 
137 vana 131
 
132
# Return with error word
316 jermar 133
	popa
134
	pop %ebp
135
	add $4,%esp	# Skip error word
136
	iret
132 vana 137
 
138
0:
137 vana 139
# Return with no error word
132 vana 140
	popa
141
	pop %ebp
142
	iret
143
 
144
	.if (\n-\i)-1
145
	handler "(\i+1)",\n
146
	.endif
147
.endm
148
 
149
# keep in sync with pm.h !!!
150
IDT_ITEMS=64
151
interrupt_handlers:
152
h_start:
153
	handler 0 64
154
#	handler 64 128	
155
#	handler 128 192
156
#	handler 192 256
157
h_end:
158
 
159
 
160
## Copy memory
161
#
162
# Copy a given number of bytes (3rd argument)
198 jermar 163
# from the memory location defined by 2nd argument
164
# to the memory location defined by 1st argument.
132 vana 165
# The memory areas cannot overlap.
166
#
316 jermar 167
SRC=16
168
DST=12
169
CNT=20
205 jermar 170
memcpy:
316 jermar 171
	push %esi
172
	push %edi
132 vana 173
 
316 jermar 174
	movl CNT(%esp),%ecx
175
	movl DST(%esp),%edi
176
	movl SRC(%esp),%esi
132 vana 177
 
178
	rep movsb %ds:(%esi),%es:(%edi)
179
 
316 jermar 180
	pop %edi
181
	pop %esi
132 vana 182
	ret
183
 
184
 
185
## Fill memory with bytes
186
#
187
# Fill a given number of bytes (2nd argument)
188
# at memory defined by 1st argument with the
189
# byte value defined by 3rd argument.
190
#
316 jermar 191
DST=12
192
CNT=16
193
X=20
132 vana 194
memsetb:
316 jermar 195
	push %eax
196
	push %edi
132 vana 197
 
316 jermar 198
	movl CNT(%esp),%ecx
199
	movl DST(%esp),%edi
200
	movl X(%esp),%eax
132 vana 201
 
202
	rep stosb %al,%es:(%edi)
203
 
316 jermar 204
	pop %edi
205
	pop %eax
132 vana 206
	ret
207
 
208
 
209
## Fill memory with words
210
#
211
# Fill a given number of words (2nd argument)
212
# at memory defined by 1st argument with the
213
# word value defined by 3rd argument.
214
#
316 jermar 215
DST=12
216
CNT=16
217
X=20
132 vana 218
memsetw:
316 jermar 219
	push %eax
220
	push %edi
132 vana 221
 
316 jermar 222
	movl CNT(%esp),%ecx
223
	movl DST(%esp),%edi
224
	movl X(%esp),%eax
132 vana 225
 
226
	rep stosw %ax,%es:(%edi)
227
 
316 jermar 228
	pop %edi
229
	pop %eax
230
 
132 vana 231
	ret
232
 
233
 
234
## Compare memory regions for equality
235
#
236
# Compare a given number of bytes (3rd argument)
237
# at memory locations defined by 1st and 2nd argument
238
# for equality. If the bytes are equal, EAX contains
239
# 0.
240
#
241
SRC=12
242
DST=16
243
CNT=20
244
memcmp:
316 jermar 245
	push %esi
246
	push %edi
132 vana 247
 
316 jermar 248
	movl CNT(%esp),%ecx
249
	movl DST(%esp),%edi
250
	movl SRC(%esp),%esi
132 vana 251
 
252
	repe cmpsb %es:(%edi),%ds:(%esi)
316 jermar 253
	movl %ecx,%eax		# %ecx contains the return value (zero on success)
132 vana 254
 
316 jermar 255
	pop %edi
256
	pop %esi
132 vana 257
 
258
	ret
259
 
260
 
261
# THIS IS USERSPACE CODE
262
.global utext
263
utext:
316 jermar 264
	xor %ax,%ax
265
	mov %ax,%ds
266
	mov %ax,%es
267
	mov %ax,%fs
268
	mov %ax,%gs
132 vana 269
0:
168 jermar 270
	int $48
132 vana 271
	jmp 0b
272
	# not reached
273
utext_end:
274
 
275
.data
276
.global utext_size
277
utext_size:
278
	.long utext_end - utext 
279
 
280
.global interrupt_handler_size
281
 
282
interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS