Subversion Repositories HelenOS-historic

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 jermar 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
 
31
.text
32
 
33
.global cpu_priority_high
34
.global cpu_priority_low
35
.global cpu_priority_restore
36
.global cpu_priority_read
37
.global cpu_halt
38
.global cpu_sleep
39
.global paging_on
40
.global cpu_read_dba
41
.global cpu_write_dba
42
.global cpu_read_cr2
43
.global enable_l_apic_in_msr
44
.global interrupt_handlers
45
.global inb
46
.global inw
47
.global inl
48
.global outb
49
.global outw
50
.global outl
51
.global memcopy
52
.global memsetb
53
.global memsetw
54
.global memcmp
55
 
56
#
57
# set priority level high
58
cpu_priority_high:
59
	pushf
60
	pop %eax
61
	cli
62
	ret
63
 
64
#
65
# set priority level low
66
cpu_priority_low:
67
        pushf
68
	pop %eax
69
	sti
70
	ret
71
 
72
#
73
# restore priority level
74
cpu_priority_restore:
75
	push 4(%esp)
76
	popf
77
	ret
78
 
79
# return raw priority level
80
cpu_priority_read:
81
	pushf
82
	pop %eax
83
	ret
84
 
85
cpu_halt:
86
cpu_sleep:
87
	hlt
88
	ret
89
 
90
paging_on:
91
	pushl %eax
92
	movl %cr0,%eax
93
	orl $(1<<31),%eax		# paging on
94
	andl $~((1<<30)|(1<<29)),%eax	# clear Cache Disable and not Write Though
95
	movl %eax,%cr0
96
	jmp 0f
97
0:
98
	popl %eax
99
	ret
100
 
101
cpu_read_dba:
102
	movl %cr3,%eax
103
	ret
104
 
105
cpu_write_dba:
106
	pushl %eax
107
	movl 8(%esp),%eax
108
	movl %eax,%cr3
109
	popl %eax
110
	ret
111
 
112
cpu_read_cr2:
113
	movl %cr2,%eax
114
	ret
115
 
116
enable_l_apic_in_msr:
117
	pusha
118
 
119
	movl $0x1b, %ecx
120
	rdmsr
121
	orl $(1<<11),%eax
122
	orl $(0xfee00000),%eax
123
	wrmsr
124
 
125
	popa
126
	ret
127
 
128
.macro handler i n
129
	push %ebp
130
	movl %esp,%ebp
131
	pusha
132
 
133
	# we must fill the data segment registers
134
	movw $16,%ax
135
	movw %ax,%ds
136
	movw %ax,%es
137
 
138
	movl $(\i),%edi
139
	pushl %ebp
140
	addl $4,(%esp)
141
	pushl %edi
142
	call trap_dispatcher
143
	addl $8,%esp
144
 
145
	popa
146
	pop %ebp
147
 
148
        iret
149
 
150
	.if (\n-\i)-1
151
	handler "(\i+1)",\n
152
	.endif
153
.endm
154
 
155
# keep in sync with pm.h !!!
156
IDT_ITEMS=64
157
interrupt_handlers:
158
h_start:
159
	handler 0 64
160
#	handler 64 128	
161
#	handler 128 192
162
#	handler 192 256
163
h_end:
164
 
165
 
166
inb:
167
	push %edx
168
	xorl %eax,%eax
169
	movl 8(%esp),%edx
170
	inb %dx,%al
171
	pop %edx
172
	ret
173
 
174
inw:
175
	push %edx
176
	xorl %eax,%eax
177
	movl 8(%esp),%edx
178
	inw %dx,%ax
179
	pop %edx
180
	ret
181
 
182
inl:
183
	push %edx
184
	xorl %eax,%eax
185
	movl 8(%esp),%edx
186
	inl %dx,%eax
187
	pop %edx
188
	ret
189
 
190
outb:
191
	push %ebp
192
	movl %esp,%ebp
193
	pusha
194
 
195
	movl 8(%ebp),%edx
196
	movl 12(%ebp),%eax
197
	outb %al,%dx
198
 
199
	popa
200
	pop %ebp
201
	ret
202
 
203
outw:
204
	push %ebp
205
	movl %esp,%ebp
206
	pusha
207
 
208
	movl 8(%ebp),%edx
209
	movl 12(%ebp),%eax
210
	outw %ax,%dx
211
 
212
	popa
213
	pop %ebp
214
	ret
215
 
216
outl:
217
	push %ebp
218
	movl %esp,%ebp
219
	pusha
220
 
221
	movl 8(%ebp),%edx
222
	movl 12(%ebp),%eax
223
	outl %eax,%dx
224
 
225
	popa
226
	pop %ebp
227
	ret
228
 
229
SRC=8
230
DST=12
231
CNT=16
232
memcopy:
233
	push %ebp
234
	movl %esp,%ebp
235
	pusha
236
 
237
	cld
238
	movl CNT(%ebp),%ecx
239
	movl DST(%ebp),%edi
240
	movl SRC(%ebp),%esi    
241
 
242
	rep movsb %ds:(%esi),%es:(%edi)
243
 
244
	popa
245
	pop %ebp
246
	ret
247
 
248
DST=8
249
CNT=12
250
X=16
251
memsetw:
252
	push %ebp
253
	movl %esp,%ebp
254
	pusha
255
 
256
	cld
257
	movl CNT(%ebp),%ecx
258
	movl DST(%ebp),%edi
259
	movl X(%ebp),%eax
260
 
261
	rep stosw %ax,%es:(%edi)
262
 
263
        popa
264
	pop %ebp
265
	ret
266
 
267
DST=8
268
CNT=12
269
X=16
270
memsetb:
271
	push %ebp
272
	movl %esp,%ebp
273
	pusha
274
 
275
	cld
276
	movl CNT(%ebp),%ecx
277
	movl DST(%ebp),%edi
278
	movl X(%ebp),%eax
279
 
280
	rep stosb %al,%es:(%edi)
281
 
282
        popa
283
	pop %ebp
284
	ret
285
 
286
SRC=12
287
DST=16
288
CNT=20
289
memcmp:
290
	push %ebp
291
	subl $4,%esp	
292
	movl %esp,%ebp
293
 
294
	pusha
295
 
296
	cld
297
	movl CNT(%ebp),%ecx
298
	movl DST(%ebp),%edi
299
	movl SRC(%ebp),%esi    
300
 
301
	repe cmpsb %es:(%edi),%ds:(%esi)
302
	movl %ecx,(%ebp)
303
 
304
	popa
305
 
306
	movl (%ebp),%eax	# return value => %eax (zero on success)
307
	addl $4,%esp
308
	pop %ebp
309
 
310
	ret
311
 
312
 
313
# THIS IS USERSPACE CODE
314
.global utext
315
utext:
316
0:
317
	movl $0xdeadbeaf, %eax
318
	int $48
319
	jmp 0b
320
	# not reached
321
utext_end:
322
 
323
.data
324
.global utext_size
325
utext_size:
326
	.long utext_end - utext 
327
 
328
 
329
.section K_DATA_START
330
.global interrupt_handler_size
331
 
332
interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS