1 ! $Id: copySUN.s,v 1.3 1996/06/04 09:00:58 paul Exp $
2
3 #include <minix/config.h>
4 #include <minix/const.h>
5
6 !****************************************************************************
7 !
8 ! C O P Y _ S U N . S M I N I X
9 !
10 ! Basic fast copy routines used by the kernel
11 !****************************************************************************
12 !
13 ! Contents:
14 !
15 ! real_zeroclicks zero a block of clicks
16 ! real_copyclicks copy a block of clicks
17 ! real_phys_copy copy a block of bytes
18 ! test_and_set Atomic testy and set of a specified byte
19 !
20 !============================================================================
21 !
22 !****************************************************************************
23
24 !****************************************************************************
25 !
26 ! r e a l _ z e r o c l i c k s
27 !
28 ! zero n clicks from source click to destination click address
29 !****************************************************************************
30 !
31 ! Input:
32 ! %i0 - physical destination click address
33 ! %i1 - number of clicks to zero
34 !
35 !****************************************************************************
36
37
38 .global real_zeroclicks
39 real_zeroclicks:
40 save %sp, -96, %sp
41 sll %i0,CLICK_SHIFT,%l0 ! abs. source address
42 sll %i1,CLICK_SHIFT-3,%l1 ! number of double words to zero
43 mov %g0, %g1 ! get two 0 registers
44 tst %l1
45 zero00:
46 be zero01
47 nop
48 std %g0,[%l0] ! zero out 8 bytes
49 add %l0, 8, %l0 ! move on to next address
50 ba zero00
51 deccc %l1 ! one less to do
52
53 zero01:
54 ret
55 restore
56
57
58 !****************************************************************************
59 !
60 ! r e a l _ c o p y c l i c k s
61 !
62 ! copy n clicks from source click to destination click address
63 !****************************************************************************
64 !
65 ! Input:
66 ! %i0 - physical source click address
67 ! %i1 - physical destination click address
68 ! %i2 - number of clicks to copy
69 !
70 !
71 !****************************************************************************
72
73 .global real_copyclicks
74 real_copyclicks:
75 save %sp, -96, %sp
76 sll %i0, CLICK_SHIFT, %l0 ! abs. source address
77 sll %i1, CLICK_SHIFT, %l1 ! abs. destination address
78 sll %i2, CLICK_SHIFT-3, %l2 ! length in double words
79 tst %l2
80 copy00:
81 be copy01
82 nop
83 ldd [%l0], %l4 ! load copy
84 std %l4, [%l1] ! store copy
85 add %l0, 8, %l0 ! update addresses
86 add %l1, 8, %l1
87 ba copy00
88 deccc %l2 ! one less to do
89 copy01:
90 ret
91 restore
92
93
94
95 !****************************************************************************
96 !
97 ! r e a l _ p h y s _ c o p y
98 !
99 ! copy n bytes from source to destination address
100 !****************************************************************************
101 !
102 ! Input:
103 ! %i0 - physical source address ptr.
104 ! %i1 - physical destination address ptr.
105 ! %i2 - number of bytes to copy
106 !
107 ! phys_copy is designed to determine which load and store instruction will
108 ! perform the copy in the least. This decision depends on whether the source
109 ! and destination are 8-byte aligned (use ldd), 4-byte aligned (use ld),
110 ! 2-byte aligned (use lduh) or not aligned (use ldub). It may be necessary
111 ! to copy several bytes (using ldub) in order to make both the source and
112 ! destination address aligned. eg. src = 6 dest = 798 can be be copied in
113 ! lots of 8 as long as the first 2 bytes are copied by the byte.
114 !
115 !****************************************************************************
116
117 .global real_phys_copy
118 real_phys_copy:
119 save %sp, -96, %sp
120 mov %i0, %l0
121 mov %i1, %l1
122 mov %i2, %l2
123 xor %l0, %l1, %l3 ! find out how aligned src and dest are
124 andcc %l3, 1, %g0
125 bne pc1 ! not aligned
126 nop
127 andcc %l3, 2, %g0
128 bne pc2 ! 2-byte
129 nop
130 andcc %l3, 4, %g0
131 bne pc4 ! 4-byte
132 nop
133
134 ! else copy in multiples of 8 bytes
135 pc8:
136 sub %l0, 1, %l3
137 and %l3, 7, %l3
138 call pcbytes ! copy any initial bytes
139 xor %l3, 7, %l3
140 ba pc8_1
141 nop
142
143 pc8_2:
144 ldd [%l0], %l4 ! copy in groups of 8
145 std %l4, [%l1]
146 inc 8, %l0
147 inc 8, %l1
148 dec 8, %l2
149 pc8_1:
150 cmp %l2, 8
151 bge pc8_2
152 nop
153
154 call pcbytes ! finish off any extra bytes
155 mov 8, %l3 ! (copy up to 8 bytes)
156 ba pcexit
157 nop
158
159
160 ! copy in lots of 4 bytes
161 pc4:
162 sub %l0, 1, %l3
163 and %l3, 3, %l3
164 call pcbytes ! initial byte copying
165 xor %l3, 3, %l3
166 ba pc4_1
167 nop
168
169 pc4_2:
170 ld [%l0], %l4 ! copy in groups of 4
171 st %l4, [%l1]
172 inc 4, %l0
173 inc 4, %l1
174 dec 4, %l2
175
176 pc4_1:
177 cmp %l2, 4
178 bge pc4_2
179 nop
180 call pcbytes ! finish off any extra bytes
181 mov 4,%l3 ! (copy upto 4 bytes)
182 ba pcexit
183 nop
184
185 ! copy in groups of 2
186 pc2:
187 sub %l0, 1, %l3
188 and %l3, 1, %l3
189 call pcbytes ! initial alignment
190 xor %l3, 1, %l3
191 ba pc2_1
192 nop
193
194
195 pc2_2:
196 lduh [%l0],%l4 ! copy 2 bytes at a time
197 sth %l4, [%l1]
198 inc 2, %l0
199 inc 2, %l1
200 dec 2, %l2
201 pc2_1:
202 cmp %l2,2
203 bge pc2_2
204 nop
205 call pcbytes ! finish off any extra bytes
206 mov 2, %l3 ! (copy upto 2 bytes)
207 ba pcexit
208 nop
209
210 ! copying byte by byte
211 pc1: call pcbytes
212 mov %l2, %l3
213
214 pcexit:
215 ret
216 restore
217
218
219 ! pcbytes is a local function for copying unaligned initial or final
220 ! portions byte by byte. It assumes the following register contents,
221 ! and uses %l7 for working storage:
222 !
223 ! Input:
224 ! %l0 - physical source address ptr.
225 ! %l1 - physical destination address ptr.
226 ! %l2 - number of bytes left to copy
227 ! %l3 - maximum number of bytes to copy
228 !
229 ! pcbytes copies B bytes (min(%l2, %l3)) from the source to the destination.
230 ! The address registers are increased by B, %l2 is decreased by B.
231
232 pcbytes: ! leaf routine
233 mov %l2, %l7 ! l7 = min(l2, l3)
234 cmp %l7, %l3
235 ble l2_less
236 nop
237 mov %l3, %l7
238 l2_less:
239 sub %l2, %l7, %l2 ! Decrease by the amount copied.
240
241 pcbytes_loop:
242 tst %l7
243 be pcbytes_end
244 nop
245 ldub [%l0], %l4
246 stb %l4, [%l1]
247 inc %l0
248 inc %l1
249 ba pcbytes_loop
250 dec %l7
251 pcbytes_end:
252 retl
253 nop
254
255
256 !****************************************************************************
257 !
258 ! t e s t _ a n d _ s e t
259 !
260 ! Atomically reads the value of a byte and then sets the value to
261 ! all 1's.
262 !
263 ! This function doesn't fit perfectly in this file, but it's
264 ! copying in a broad sense (plus there aren't many other .s files!).
265 !****************************************************************************
266 !
267 ! Input:
268 ! %o0 - the address of the byte to be "test and set"
269 ! Return value: the previous value of the byte
270 !
271 !****************************************************************************
272
273 .global test_and_set
274 test_and_set:
275 ldstub [%o0], %o0
276 retl
277 nop
278
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.