Subversion Repositories HelenOS

Rev

Rev 3343 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
426 jermar 1
#
2071 jermar 2
# Copyright (c) 2005 Jakub Jermar
426 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
 
1865 jermar 29
#include <arch/arch.h>
1784 jermar 30
#include <arch/stack.h>
31
 
426 jermar 32
.text
33
 
1865 jermar 34
.register       %g2, #scratch
35
.register       %g3, #scratch
36
 
37
/*
38
 * This is the assembly language version of our _memcpy() generated by gcc.
39
 */
426 jermar 40
.global memcpy
41
memcpy:
3274 jermar 42
	mov	%o0, %o3		! save dst
1790 jermar 43
	add	%o1, 7, %g1
44
	and	%g1, -8, %g1
45
	cmp	%o1, %g1
46
	be,pn	%xcc, 3f
47
	add	%o0, 7, %g1
48
	mov	0, %g3
49
0:
50
	brz,pn	%o2, 2f
51
	mov	0, %g2
52
1:
53
	ldub	[%g3 + %o1], %g1
54
	add	%g2, 1, %g2
55
	cmp	%o2, %g2
56
	stb	%g1, [%g3 + %o0]
57
	bne,pt	%xcc, 1b
58
	mov	%g2, %g3
59
2:
60
	jmp	%o7 + 8			! exit point
3274 jermar 61
	mov	%o3, %o0
1790 jermar 62
3:
63
	and	%g1, -8, %g1
64
	cmp	%o0, %g1
65
	bne,pt	%xcc, 0b
66
	mov	0, %g3
67
	srlx	%o2, 3, %g4
68
	brz,pn	%g4, 5f
69
	mov	0, %g5
70
4:
71
	sllx	%g3, 3, %g2
72
	add	%g5, 1, %g3
73
	ldx	[%o1 + %g2], %g1
74
	mov	%g3, %g5
75
	cmp	%g4, %g3
76
	bne,pt	%xcc, 4b
77
	stx	%g1, [%o0 + %g2]
78
5:
79
	and	%o2, 7, %o2
80
	brz,pn	%o2, 2b
81
	sllx	%g4, 3, %g1
82
	mov	0, %g2
83
	add	%g1, %o0, %o0
84
	add	%g1, %o1, %g4
85
	mov	0, %g3
86
6:
87
	ldub	[%g2 + %g4], %g1
88
	stb	%g1, [%g2 + %o0]
89
	add	%g3, 1, %g2
90
	cmp	%o2, %g2
91
	bne,pt	%xcc, 6b
92
	mov	%g2, %g3
1288 jermar 93
 
1790 jermar 94
	jmp	%o7 + 8			! exit point
3274 jermar 95
	mov	%o3, %o0
426 jermar 96
 
1865 jermar 97
/*
98
 * Almost the same as memcpy() except the loads are from userspace.
99
 */
100
.global memcpy_from_uspace
101
memcpy_from_uspace:
3274 jermar 102
	mov	%o0, %o3		! save dst
1865 jermar 103
	add	%o1, 7, %g1
104
	and	%g1, -8, %g1
105
	cmp	%o1, %g1
106
	be,pn	%xcc, 3f
107
	add	%o0, 7, %g1
108
	mov	0, %g3
109
0:
110
	brz,pn	%o2, 2f
111
	mov	0, %g2
112
1:
113
	lduba	[%g3 + %o1] ASI_AIUS, %g1
114
	add	%g2, 1, %g2
115
	cmp	%o2, %g2
116
	stb	%g1, [%g3 + %o0]
117
	bne,pt	%xcc, 1b
118
	mov	%g2, %g3
119
2:
120
	jmp	%o7 + 8			! exit point
3274 jermar 121
	mov	%o3, %o0
1865 jermar 122
3:
123
	and	%g1, -8, %g1
124
	cmp	%o0, %g1
125
	bne,pt	%xcc, 0b
126
	mov	0, %g3
127
	srlx	%o2, 3, %g4
128
	brz,pn	%g4, 5f
129
	mov	0, %g5
130
4:
131
	sllx	%g3, 3, %g2
132
	add	%g5, 1, %g3
133
	ldxa	[%o1 + %g2] ASI_AIUS, %g1
134
	mov	%g3, %g5
135
	cmp	%g4, %g3
136
	bne,pt	%xcc, 4b
137
	stx	%g1, [%o0 + %g2]
138
5:
139
	and	%o2, 7, %o2
140
	brz,pn	%o2, 2b
141
	sllx	%g4, 3, %g1
142
	mov	0, %g2
143
	add	%g1, %o0, %o0
144
	add	%g1, %o1, %g4
145
	mov	0, %g3
146
6:
147
	lduba	[%g2 + %g4] ASI_AIUS, %g1
148
	stb	%g1, [%g2 + %o0]
149
	add	%g3, 1, %g2
150
	cmp	%o2, %g2
151
	bne,pt	%xcc, 6b
152
	mov	%g2, %g3
153
 
154
	jmp	%o7 + 8			! exit point
3274 jermar 155
	mov	%o3, %o0
1865 jermar 156
 
157
/*
158
 * Almost the same as memcpy() except the stores are to userspace.
159
 */
160
.global memcpy_to_uspace
161
memcpy_to_uspace:
3274 jermar 162
	mov	%o0, %o3		! save dst
1865 jermar 163
	add	%o1, 7, %g1
164
	and	%g1, -8, %g1
165
	cmp	%o1, %g1
166
	be,pn	%xcc, 3f
167
	add	%o0, 7, %g1
168
	mov	0, %g3
169
0:
170
	brz,pn	%o2, 2f
171
	mov	0, %g2
172
1:
173
	ldub	[%g3 + %o1], %g1
174
	add	%g2, 1, %g2
175
	cmp	%o2, %g2
176
	stba	%g1, [%g3 + %o0] ASI_AIUS
177
	bne,pt	%xcc, 1b
178
	mov	%g2, %g3
179
2:
180
	jmp	%o7 + 8			! exit point
3274 jermar 181
	mov	%o3, %o0
1865 jermar 182
3:
183
	and	%g1, -8, %g1
184
	cmp	%o0, %g1
185
	bne,pt	%xcc, 0b
186
	mov	0, %g3
187
	srlx	%o2, 3, %g4
188
	brz,pn	%g4, 5f
189
	mov	0, %g5
190
4:
191
	sllx	%g3, 3, %g2
192
	add	%g5, 1, %g3
193
	ldx	[%o1 + %g2], %g1
194
	mov	%g3, %g5
195
	cmp	%g4, %g3
196
	bne,pt	%xcc, 4b
197
	stxa	%g1, [%o0 + %g2] ASI_AIUS
198
5:
199
	and	%o2, 7, %o2
200
	brz,pn	%o2, 2b
201
	sllx	%g4, 3, %g1
202
	mov	0, %g2
203
	add	%g1, %o0, %o0
204
	add	%g1, %o1, %g4
205
	mov	0, %g3
206
6:
207
	ldub	[%g2 + %g4], %g1
208
	stba	%g1, [%g2 + %o0] ASI_AIUS
209
	add	%g3, 1, %g2
210
	cmp	%o2, %g2
211
	bne,pt	%xcc, 6b
212
	mov	%g2, %g3
213
 
214
	jmp	%o7 + 8			! exit point
3274 jermar 215
	mov	%o3, %o0
1865 jermar 216
 
217
.global memcpy_from_uspace_failover_address
218
.global memcpy_to_uspace_failover_address
1288 jermar 219
memcpy_from_uspace_failover_address:
220
memcpy_to_uspace_failover_address:
1790 jermar 221
	jmp	%o7 + 8			! exit point
222
	mov	%g0, %o0		! return 0 on failure
1288 jermar 223
 
1865 jermar 224
.global memsetb
426 jermar 225
memsetb:
226
	b _memsetb
227
	nop
1856 jermar 228
 
229