Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
162 decky 1
#
2071 jermar 2
# Copyright (c) 2005 Martin Decky
162 decky 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
 
845 decky 29
#include <arch/asm/regname.h>
191 decky 30
 
162 decky 31
.text
32
 
1220 decky 33
.global userspace_asm
1004 decky 34
.global iret
1277 decky 35
.global iret_syscall
210 decky 36
.global memsetb
37
.global memcpy
1288 jermar 38
.global memcpy_from_uspace
39
.global memcpy_to_uspace
40
.global memcpy_from_uspace_failover_address
41
.global memcpy_to_uspace_failover_address
185 decky 42
 
1220 decky 43
userspace_asm:
44
 
45
	# r3 = uspace_uarg
46
	# r4 = stack
1267 decky 47
	# r5 = entry
48
 
49
	# disable interrupts
1220 decky 50
 
51
	mfmsr r31
52
	rlwinm r31, r31, 0, 17, 15
53
	mtmsr r31
54
 
55
	# set entry point
56
 
57
	mtsrr0 r5
58
 
59
	# set problem state, enable interrupts
60
 
1267 decky 61
	ori r31, r31, msr_pr
62
	ori r31, r31, msr_ee
1220 decky 63
	mtsrr1 r31
64
 
65
	# set stack
66
 
67
	mr sp, r4
68
 
69
	# jump to userspace
70
 
71
	rfi
72
 
1004 decky 73
iret:
1277 decky 74
 
75
	# disable interrupts
76
 
77
	mfmsr r31
78
	rlwinm r31, r31, 0, 17, 15
79
	mtmsr r31
80
 
1355 decky 81
	lwz r0, 8(sp)
82
	lwz r2, 12(sp)
83
	lwz r3, 16(sp)
84
	lwz r4, 20(sp)
85
	lwz r5, 24(sp)
86
	lwz r6, 28(sp)
87
	lwz r7, 32(sp)
88
	lwz r8, 36(sp)
89
	lwz r9, 40(sp)
90
	lwz r10, 44(sp)
91
	lwz r11, 48(sp)
92
	lwz r13, 52(sp)
93
	lwz r14, 56(sp)
94
	lwz r15, 60(sp)
95
	lwz r16, 64(sp)
96
	lwz r17, 68(sp)
97
	lwz r18, 72(sp)
98
	lwz r19, 76(sp)
99
	lwz r20, 80(sp)
100
	lwz r21, 84(sp)
101
	lwz r22, 88(sp)
102
	lwz r23, 92(sp)
103
	lwz r24, 96(sp)
104
	lwz r25, 100(sp)
105
	lwz r26, 104(sp)
106
	lwz r27, 108(sp)
107
	lwz r28, 112(sp)
108
	lwz r29, 116(sp)
109
	lwz r30, 120(sp)
110
	lwz r31, 124(sp)
1004 decky 111
 
1355 decky 112
	lwz r12, 128(sp)
1277 decky 113
	mtcr r12
114
 
1355 decky 115
	lwz r12, 132(sp)
1267 decky 116
	mtsrr0 r12
1004 decky 117
 
1355 decky 118
	lwz r12, 136(sp)
1267 decky 119
	mtsrr1 r12
120
 
1355 decky 121
	lwz r12, 140(sp)
1267 decky 122
	mtlr r12
123
 
1355 decky 124
	lwz r12, 144(sp)
1277 decky 125
	mtctr r12
126
 
1355 decky 127
	lwz r12, 148(sp)
1277 decky 128
	mtxer r12
129
 
1355 decky 130
	lwz r12, 152(sp)
131
	lwz sp, 156(sp)
1277 decky 132
 
133
	rfi
134
 
135
iret_syscall:
136
 
1384 decky 137
	# reset decrementer
138
 
139
	li r31, 1000
140
	mtdec r31
141
 
1277 decky 142
	# disable interrupts
143
 
144
	mfmsr r31
145
	rlwinm r31, r31, 0, 17, 15
146
	mtmsr r31
147
 
1355 decky 148
	lwz r0, 8(sp)
149
	lwz r2, 12(sp)
150
	lwz r4, 20(sp)
151
	lwz r5, 24(sp)
152
	lwz r6, 28(sp)
153
	lwz r7, 32(sp)
154
	lwz r8, 36(sp)
155
	lwz r9, 40(sp)
156
	lwz r10, 44(sp)
157
	lwz r11, 48(sp)
158
	lwz r13, 52(sp)
159
	lwz r14, 56(sp)
160
	lwz r15, 60(sp)
161
	lwz r16, 64(sp)
162
	lwz r17, 68(sp)
163
	lwz r18, 72(sp)
164
	lwz r19, 76(sp)
165
	lwz r20, 80(sp)
166
	lwz r21, 84(sp)
167
	lwz r22, 88(sp)
168
	lwz r23, 92(sp)
169
	lwz r24, 96(sp)
170
	lwz r25, 100(sp)
171
	lwz r26, 104(sp)
172
	lwz r27, 108(sp)
173
	lwz r28, 112(sp)
174
	lwz r29, 116(sp)
175
	lwz r30, 120(sp)
176
	lwz r31, 124(sp)
1277 decky 177
 
1355 decky 178
	lwz r12, 128(sp)
1267 decky 179
	mtcr r12
180
 
1355 decky 181
	lwz r12, 132(sp)
1277 decky 182
	mtsrr0 r12
183
 
1355 decky 184
	lwz r12, 136(sp)
1277 decky 185
	mtsrr1 r12
186
 
1355 decky 187
	lwz r12, 140(sp)
1277 decky 188
	mtlr r12
189
 
1355 decky 190
	lwz r12, 144(sp)
1267 decky 191
	mtctr r12
192
 
1355 decky 193
	lwz r12, 148(sp)
1267 decky 194
	mtxer r12
1277 decky 195
 
1355 decky 196
	lwz r12, 152(sp)
197
	lwz sp, 156(sp)
1267 decky 198
 
1004 decky 199
	rfi
200
 
210 decky 201
memsetb:
3200 svoboda 202
	b _memsetb
210 decky 203
 
204
memcpy:
1288 jermar 205
memcpy_from_uspace:
206
memcpy_to_uspace:
207
 
860 decky 208
	srwi. r7, r5, 3
209
	addi r6, r3, -4
210
	addi r4, r4, -4
211
	beq	2f
212
 
213
	andi. r0, r6, 3
214
	mtctr r7
215
	bne 5f
216
 
217
	1:
218
 
219
	lwz r7, 4(r4)
220
	lwzu r8, 8(r4)
221
	stw r7, 4(r6)
222
	stwu r8, 8(r6)
223
	bdnz 1b
224
 
225
	andi. r5, r5, 7
226
 
227
	2:
228
 
229
	cmplwi 0, r5, 4
230
	blt 3f
231
 
232
	lwzu r0, 4(r4)
233
	addi r5, r5, -4
234
	stwu r0, 4(r6)
235
 
236
	3:
237
 
238
	cmpwi 0, r5, 0
239
	beqlr
240
	mtctr r5
241
	addi r4, r4, 3
242
	addi r6, r6, 3
243
 
244
	4:
245
 
246
	lbzu r0, 1(r4)
247
	stbu r0, 1(r6)
248
	bdnz 4b
210 decky 249
	blr
860 decky 250
 
251
	5:
252
 
253
	subfic r0, r0, 4
254
	mtctr r0
255
 
256
	6:
257
 
258
	lbz r7, 4(r4)
259
	addi r4, r4, 1
260
	stb r7, 4(r6)
261
	addi r6, r6, 1
262
	bdnz 6b
263
	subf r5, r0, r5
264
	rlwinm. r7, r5, 32-3, 3, 31
265
	beq 2b
266
	mtctr r7
267
	b 1b
1288 jermar 268
 
269
memcpy_from_uspace_failover_address:
270
memcpy_to_uspace_failover_address:
3189 jermar 271
	# return zero, failure
272
	xor r3, r3, r3
273
	blr