Subversion Repositories HelenOS-historic

Rev

Rev 352 | Rev 356 | 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
## I/O input (byte)
161
#
162
# Get a byte from I/O port and store it AL.
163
#
164
inb:
165
	xorl %eax,%eax
316 jermar 166
	movl 4(%esp),%edx
132 vana 167
	inb %dx,%al
168
	ret
169
 
170
 
171
## I/O input (word)
172
#
173
# Get a word from I/O port and store it AX.
174
#
175
inw:
176
	xorl %eax,%eax
316 jermar 177
	movl 4(%esp),%edx
132 vana 178
	inw %dx,%ax
179
	ret
180
 
181
 
182
## I/O input (dword)
183
#
184
# Get a dword from I/O port and store it EAX.
185
#
186
inl:
187
	xorl %eax,%eax
316 jermar 188
	movl 4(%esp),%edx
132 vana 189
	inl %dx,%eax
190
	ret
191
 
192
 
193
## Copy memory
194
#
195
# Copy a given number of bytes (3rd argument)
198 jermar 196
# from the memory location defined by 2nd argument
197
# to the memory location defined by 1st argument.
132 vana 198
# The memory areas cannot overlap.
199
#
316 jermar 200
SRC=16
201
DST=12
202
CNT=20
205 jermar 203
memcpy:
316 jermar 204
	push %esi
205
	push %edi
132 vana 206
 
316 jermar 207
	movl CNT(%esp),%ecx
208
	movl DST(%esp),%edi
209
	movl SRC(%esp),%esi
132 vana 210
 
211
	rep movsb %ds:(%esi),%es:(%edi)
212
 
316 jermar 213
	pop %edi
214
	pop %esi
132 vana 215
	ret
216
 
217
 
218
## Fill memory with bytes
219
#
220
# Fill a given number of bytes (2nd argument)
221
# at memory defined by 1st argument with the
222
# byte value defined by 3rd argument.
223
#
316 jermar 224
DST=12
225
CNT=16
226
X=20
132 vana 227
memsetb:
316 jermar 228
	push %eax
229
	push %edi
132 vana 230
 
316 jermar 231
	movl CNT(%esp),%ecx
232
	movl DST(%esp),%edi
233
	movl X(%esp),%eax
132 vana 234
 
235
	rep stosb %al,%es:(%edi)
236
 
316 jermar 237
	pop %edi
238
	pop %eax
132 vana 239
	ret
240
 
241
 
242
## Fill memory with words
243
#
244
# Fill a given number of words (2nd argument)
245
# at memory defined by 1st argument with the
246
# word value defined by 3rd argument.
247
#
316 jermar 248
DST=12
249
CNT=16
250
X=20
132 vana 251
memsetw:
316 jermar 252
	push %eax
253
	push %edi
132 vana 254
 
316 jermar 255
	movl CNT(%esp),%ecx
256
	movl DST(%esp),%edi
257
	movl X(%esp),%eax
132 vana 258
 
259
	rep stosw %ax,%es:(%edi)
260
 
316 jermar 261
	pop %edi
262
	pop %eax
263
 
132 vana 264
	ret
265
 
266
 
267
## Compare memory regions for equality
268
#
269
# Compare a given number of bytes (3rd argument)
270
# at memory locations defined by 1st and 2nd argument
271
# for equality. If the bytes are equal, EAX contains
272
# 0.
273
#
274
SRC=12
275
DST=16
276
CNT=20
277
memcmp:
316 jermar 278
	push %esi
279
	push %edi
132 vana 280
 
316 jermar 281
	movl CNT(%esp),%ecx
282
	movl DST(%esp),%edi
283
	movl SRC(%esp),%esi
132 vana 284
 
285
	repe cmpsb %es:(%edi),%ds:(%esi)
316 jermar 286
	movl %ecx,%eax		# %ecx contains the return value (zero on success)
132 vana 287
 
316 jermar 288
	pop %edi
289
	pop %esi
132 vana 290
 
291
	ret
292
 
293
 
294
# THIS IS USERSPACE CODE
295
.global utext
296
utext:
316 jermar 297
	xor %ax,%ax
298
	mov %ax,%ds
299
	mov %ax,%es
300
	mov %ax,%fs
301
	mov %ax,%gs
132 vana 302
0:
168 jermar 303
	int $48
132 vana 304
	jmp 0b
305
	# not reached
306
utext_end:
307
 
308
.data
309
.global utext_size
310
utext_size:
311
	.long utext_end - utext 
312
 
313
.global interrupt_handler_size
314
 
315
interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS