1 | /* |
---|
2 | * hal_remote.c - implementation of Generic Remote Access API for TSAR-MIPS32 |
---|
3 | * |
---|
4 | * Authors : Mohammed Karaoui (2015) |
---|
5 | * Alain Greiner (2016,2017,2018,2019) |
---|
6 | * |
---|
7 | * Copyright (c) UPMC Sorbonne Universites |
---|
8 | * |
---|
9 | * This file is part of ALMOS-MKH.. |
---|
10 | * |
---|
11 | * ALMOS-MKH. is free software; you can redistribute it and/or modify it |
---|
12 | * under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation; version 2.0 of the License. |
---|
14 | * |
---|
15 | * ALMOS-MKH. is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | */ |
---|
24 | |
---|
25 | #include <hal_kernel_types.h> |
---|
26 | #include <hal_irqmask.h> |
---|
27 | #include <hal_remote.h> |
---|
28 | |
---|
29 | //////////////////////////////// |
---|
30 | void hal_remote_sb( xptr_t xp, |
---|
31 | uint8_t data ) |
---|
32 | { |
---|
33 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
34 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
35 | |
---|
36 | asm volatile( |
---|
37 | ".set noreorder \n" |
---|
38 | "mfc0 $14, $12 \n" /* $14 <= CP0_SR */ |
---|
39 | "srl $13, $14, 1 \n" |
---|
40 | "sll $13, $13, 1 \n" /* $13 <= SR masked */ |
---|
41 | "mtc0 $13, $12 \n" /* IRQ disabled */ |
---|
42 | |
---|
43 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
44 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cxy */ |
---|
45 | "sb %0, 0(%1) \n" /* *paddr <= value */ |
---|
46 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
47 | |
---|
48 | "mtc0 $14, $12 \n" /* SR restored */ |
---|
49 | |
---|
50 | "sync \n" |
---|
51 | ".set reorder \n" |
---|
52 | : : "r" (data), "r" (ptr), "r" (cxy) : "$13", "$14", "$15" ); |
---|
53 | } |
---|
54 | |
---|
55 | ///////////////////////////////// |
---|
56 | void hal_remote_s32( xptr_t xp, |
---|
57 | uint32_t data ) |
---|
58 | { |
---|
59 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
60 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
61 | |
---|
62 | asm volatile( |
---|
63 | ".set noreorder \n" |
---|
64 | "mfc0 $14, $12 \n" /* $14 <= CP0_SR */ |
---|
65 | "srl $13, $14, 1 \n" |
---|
66 | "sll $13, $13, 1 \n" /* $13 <= SR masked */ |
---|
67 | "mtc0 $13, $12 \n" /* IRQ disabled */ |
---|
68 | |
---|
69 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
70 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cxy */ |
---|
71 | "sw %0, 0(%1) \n" /* *paddr <= value */ |
---|
72 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
73 | |
---|
74 | "mtc0 $14, $12 \n" /* SR restored */ |
---|
75 | |
---|
76 | "sync \n" |
---|
77 | ".set reorder \n" |
---|
78 | : : "r" (data), "r" (ptr), "r" (cxy) : "$13", "$14", "$15" ); |
---|
79 | } |
---|
80 | |
---|
81 | ////////////////////////////////// |
---|
82 | void hal_remote_s64( xptr_t xp, |
---|
83 | uint64_t data ) |
---|
84 | { |
---|
85 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
86 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
87 | |
---|
88 | uint32_t data_lsb = (uint32_t)data; |
---|
89 | uint32_t data_msb = (uint32_t)(data>>32); |
---|
90 | |
---|
91 | asm volatile( |
---|
92 | ".set noreorder \n" |
---|
93 | "mfc0 $14, $12 \n" /* $14 <= CP0_SR */ |
---|
94 | "srl $13, $14, 1 \n" |
---|
95 | "sll $13, $13, 1 \n" /* $13 <= SR masked */ |
---|
96 | "mtc0 $13, $12 \n" /* IRQ disabled */ |
---|
97 | |
---|
98 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
99 | "mtc2 %3, $24 \n" /* PADDR_EXT <= cxy */ |
---|
100 | "sw %0, 0(%2) \n" /* *paddr <= lsb */ |
---|
101 | "sw %1, 4(%2) \n" /* *(paddr+4) <= msb */ |
---|
102 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
103 | |
---|
104 | "mtc0 $14, $12 \n" /* SR restored */ |
---|
105 | |
---|
106 | "sync \n" |
---|
107 | ".set reorder \n" |
---|
108 | : : "r" (data_lsb), "r" (data_msb), "r" (ptr), "r" (cxy) : "$13", "$14", "$15" ); |
---|
109 | } |
---|
110 | |
---|
111 | //////////////////////////////////// |
---|
112 | void hal_remote_spt( xptr_t xp, |
---|
113 | void * pt ) |
---|
114 | { |
---|
115 | hal_remote_s32 ( xp , (uint32_t)pt ); |
---|
116 | } |
---|
117 | |
---|
118 | //////////////////////////////// |
---|
119 | uint8_t hal_remote_lb( xptr_t xp ) |
---|
120 | { |
---|
121 | char data; |
---|
122 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
123 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
124 | |
---|
125 | asm volatile( |
---|
126 | ".set noreorder \n" |
---|
127 | "mfc0 $14, $12 \n" /* $14 <= CP0_SR */ |
---|
128 | "srl $13, $14, 1 \n" |
---|
129 | "sll $13, $13, 1 \n" /* $13 <= SR masked */ |
---|
130 | "mtc0 $13, $12 \n" /* IRQ disabled */ |
---|
131 | |
---|
132 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
133 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cxy */ |
---|
134 | "lb %0, 0(%1) \n" /* data <= *paddr */ |
---|
135 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
136 | |
---|
137 | "mtc0 $14, $12 \n" /* SR restored */ |
---|
138 | ".set reorder \n" |
---|
139 | : "=r" (data) : "r" (ptr), "r" (cxy) : "$13", "$14", "$15" ); |
---|
140 | |
---|
141 | return ( data ); |
---|
142 | } |
---|
143 | |
---|
144 | //////////////////////////////////// |
---|
145 | uint32_t hal_remote_l32( xptr_t xp ) |
---|
146 | { |
---|
147 | uint32_t data; |
---|
148 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
149 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
150 | |
---|
151 | asm volatile( |
---|
152 | ".set noreorder \n" |
---|
153 | "mfc0 $14, $12 \n" /* $14 <= CP0_SR */ |
---|
154 | "srl $13, $14, 1 \n" |
---|
155 | "sll $13, $13, 1 \n" /* $13 <= SR masked */ |
---|
156 | "mtc0 $13, $12 \n" /* IRQ disabled */ |
---|
157 | |
---|
158 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
159 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cxy */ |
---|
160 | "lw %0, 0(%1) \n" /* data <= *paddr */ |
---|
161 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
162 | |
---|
163 | "mtc0 $14, $12 \n" /* SR restored */ |
---|
164 | ".set reorder \n" |
---|
165 | : "=r" (data) : "r" (ptr), "r" (cxy) : "$13", "$14", "$15" ); |
---|
166 | |
---|
167 | return ( data ); |
---|
168 | } |
---|
169 | |
---|
170 | ///////////////////////////////////// |
---|
171 | uint64_t hal_remote_l64( xptr_t xp ) |
---|
172 | { |
---|
173 | uint32_t data_lsb; |
---|
174 | uint32_t data_msb; |
---|
175 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
176 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
177 | |
---|
178 | asm volatile( |
---|
179 | ".set noreorder \n" |
---|
180 | "mfc0 $14, $12 \n" /* $14 <= CP0_SR */ |
---|
181 | "srl $13, $14, 1 \n" |
---|
182 | "sll $13, $13, 1 \n" /* $13 <= SR masked */ |
---|
183 | "mtc0 $13, $12 \n" /* IRQ disabled */ |
---|
184 | |
---|
185 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
186 | "mtc2 %3, $24 \n" /* PADDR_EXT <= cxy */ |
---|
187 | "lw %0, 0(%2) \n" /* data_lsb <= *paddr */ |
---|
188 | "lw %1, 4(%2) \n" /* data_msb <= *paddr+4 */ |
---|
189 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
190 | |
---|
191 | "mtc0 $14, $12 \n" /* SR restored */ |
---|
192 | ".set reorder \n" |
---|
193 | : "=r" (data_lsb), "=r"(data_msb) : "r" (ptr), "r" (cxy) : "$13", "$14", "$15" ); |
---|
194 | |
---|
195 | return ( (((uint64_t)data_msb)<<32) + (((uint64_t)data_lsb)) ); |
---|
196 | |
---|
197 | } |
---|
198 | |
---|
199 | //////////////////////////////////// |
---|
200 | void * hal_remote_lpt( xptr_t xp ) |
---|
201 | { |
---|
202 | return (void *)hal_remote_l32 ( xp ); |
---|
203 | } |
---|
204 | |
---|
205 | /////////////////////////////////////////// |
---|
206 | bool_t hal_remote_atomic_cas( xptr_t xp, |
---|
207 | uint32_t old, |
---|
208 | uint32_t new ) |
---|
209 | { |
---|
210 | uint32_t save_sr; |
---|
211 | bool_t isAtomic; |
---|
212 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
213 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
214 | |
---|
215 | hal_disable_irq( &save_sr ); |
---|
216 | |
---|
217 | asm volatile( |
---|
218 | ".set noreorder \n" |
---|
219 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
220 | "mtc2 %4, $24 \n" /* PADDR_EXT <= cxy */ |
---|
221 | "or $8, $0, %3 \n" /* $8 <= new */ |
---|
222 | "ll $3, 0(%1) \n" /* $3 <= *ptr */ |
---|
223 | "bne $3, %2, 1f \n" /* if ($3 != old) */ |
---|
224 | "li $7, 0 \n" /* $7 <= 0 */ |
---|
225 | "sc $8, (%1) \n" /* *ptr <= new */ |
---|
226 | "or $7, $8, $0 \n" /* $7 <= atomic */ |
---|
227 | "sync \n" |
---|
228 | "1: \n" |
---|
229 | "or %0, $7, $0 \n" /* isAtomic <= $7 */ |
---|
230 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
231 | ".set reorder \n" |
---|
232 | : "=&r" (isAtomic) : "r" (ptr), "r" (old) , "r" (new), "r" (cxy) |
---|
233 | : "$3", "$7", "$8", "$15" ); |
---|
234 | |
---|
235 | hal_restore_irq( save_sr ); |
---|
236 | |
---|
237 | return isAtomic; |
---|
238 | |
---|
239 | } // end hal_remote_atomic_cas() |
---|
240 | |
---|
241 | //////////////////////////////////////////// |
---|
242 | uint32_t hal_remote_atomic_add( xptr_t xp, |
---|
243 | uint32_t incr ) |
---|
244 | { |
---|
245 | uint32_t save_sr; |
---|
246 | uint32_t current; |
---|
247 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
248 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
249 | |
---|
250 | hal_disable_irq( &save_sr ); |
---|
251 | |
---|
252 | asm volatile( |
---|
253 | ".set noreorder \n" |
---|
254 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
255 | "mtc2 %3, $24 \n" /* PADDR_EXT <= cxy */ |
---|
256 | "1: \n" |
---|
257 | "ll %0, (%1) \n" /* current <= *paddr */ |
---|
258 | "addu $3, %0, %2 \n" /* $3 <= current + incr */ |
---|
259 | "sc $3, (%1) \n" /* *paddr <= $3 */ |
---|
260 | "beq $3, $0, 1b \n" /* retry if failure */ |
---|
261 | "nop \n" |
---|
262 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
263 | ".set reorder \n" |
---|
264 | : "=&r" (current) : "r" (ptr), "r" (incr), "r" (cxy) : "$3", "$15" ); |
---|
265 | |
---|
266 | hal_restore_irq( save_sr ); |
---|
267 | |
---|
268 | return current; |
---|
269 | |
---|
270 | } // end hal_remote_atomic_add() |
---|
271 | |
---|
272 | //////////////////////////////////////////// |
---|
273 | uint32_t hal_remote_atomic_and( xptr_t xp, |
---|
274 | uint32_t mask ) |
---|
275 | { |
---|
276 | uint32_t save_sr; |
---|
277 | uint32_t current; |
---|
278 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
279 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
280 | |
---|
281 | hal_disable_irq( &save_sr ); |
---|
282 | |
---|
283 | asm volatile( |
---|
284 | ".set noreorder \n" |
---|
285 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
286 | "mtc2 %3, $24 \n" /* PADDR_EXT <= cxy */ |
---|
287 | "1: \n" |
---|
288 | "ll %0, (%1) \n" /* current <= *paddr */ |
---|
289 | "and $3, %0, %2 \n" /* $3 <= current & mask */ |
---|
290 | "sc $3, (%1) \n" /* *paddr <= $3 */ |
---|
291 | "beq $3, $0, 1b \n" /* retry if failure */ |
---|
292 | "nop \n" |
---|
293 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
294 | ".set reorder \n" |
---|
295 | : "=&r" (current) : "r" (ptr), "r" (mask), "r" (cxy) : "$3", "$15" ); |
---|
296 | |
---|
297 | hal_restore_irq( save_sr ); |
---|
298 | |
---|
299 | return current; |
---|
300 | |
---|
301 | } // end hal_remote_atomic_and() |
---|
302 | |
---|
303 | //////////////////////////////////////////// |
---|
304 | uint32_t hal_remote_atomic_or( xptr_t xp, |
---|
305 | uint32_t mask ) |
---|
306 | { |
---|
307 | uint32_t save_sr; |
---|
308 | uint32_t current; |
---|
309 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
310 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
311 | |
---|
312 | hal_disable_irq( &save_sr ); |
---|
313 | |
---|
314 | asm volatile( |
---|
315 | ".set noreorder \n" |
---|
316 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
317 | "mtc2 %3, $24 \n" /* PADDR_EXT <= cxy */ |
---|
318 | "1: \n" |
---|
319 | "ll %0, (%1) \n" /* current <= *paddr */ |
---|
320 | "or $3, %0, %2 \n" /* $3 <= current | mask */ |
---|
321 | "sc $3, (%1) \n" /* *paddr <= $3 */ |
---|
322 | "beq $3, $0, 1b \n" /* retry if failure */ |
---|
323 | "nop \n" |
---|
324 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
325 | ".set reorder \n" |
---|
326 | : "=&r" (current) : "r" (ptr), "r" (mask), "r" (cxy) : "$3", "$15" ); |
---|
327 | |
---|
328 | hal_restore_irq( save_sr ); |
---|
329 | |
---|
330 | return current; |
---|
331 | |
---|
332 | } // end hal_remote_atomic_or() |
---|
333 | |
---|
334 | ///////////////////////////////////////////////// |
---|
335 | error_t hal_remote_atomic_try_add( xptr_t xp, |
---|
336 | uint32_t incr, |
---|
337 | uint32_t * old ) |
---|
338 | { |
---|
339 | uint32_t save_sr; |
---|
340 | uint32_t current; |
---|
341 | error_t error; |
---|
342 | uint32_t ptr = (uint32_t)GET_PTR( xp ); |
---|
343 | uint32_t cxy = (uint32_t)GET_CXY( xp ); |
---|
344 | |
---|
345 | hal_disable_irq( &save_sr ); |
---|
346 | |
---|
347 | asm volatile( |
---|
348 | ".set noreorder \n" |
---|
349 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
350 | "mtc2 %4, $24 \n" /* PADDR_EXT <= cxy */ |
---|
351 | "ll %0, (%2) \n" /* current <= *paddr */ |
---|
352 | "addu $3, %0, %3 \n" /* $3 <= current + incr */ |
---|
353 | "sc $3, (%2) \n" /* *paddr <= $3 */ |
---|
354 | "beq $3, $0, 1f \n" /* exit if failure */ |
---|
355 | "ori %1, $0, 1 \n" /* fail: ret <= 1 */ |
---|
356 | "and %1, $0, $0 \n" /* success: ret <= 0 */ |
---|
357 | "1: \n" |
---|
358 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
359 | ".set reorder \n" |
---|
360 | : "=&r" (current), "=&r" (error) : "r" (ptr), "r" (incr), "r" (cxy) : "$3", "$15" ); |
---|
361 | |
---|
362 | hal_restore_irq( save_sr ); |
---|
363 | |
---|
364 | *old = current; |
---|
365 | |
---|
366 | return error; |
---|
367 | |
---|
368 | } // end hal_remote_atomic_try_add() |
---|
369 | |
---|
370 | ///////////////////////////////////// |
---|
371 | void hal_remote_memcpy( xptr_t dst, |
---|
372 | xptr_t src, |
---|
373 | uint32_t size ) |
---|
374 | { |
---|
375 | uint32_t save_sr; |
---|
376 | uint32_t i; |
---|
377 | uint32_t wsize; |
---|
378 | uint32_t dptr = (uint32_t)GET_PTR( dst ); |
---|
379 | uint32_t dcxy = (uint32_t)GET_CXY( dst ); |
---|
380 | uint32_t sptr = (uint32_t)GET_PTR( src ); |
---|
381 | uint32_t scxy = (uint32_t)GET_CXY( src ); |
---|
382 | |
---|
383 | hal_disable_irq( &save_sr ); |
---|
384 | |
---|
385 | if( (dptr & 0x3) || (sptr & 0x3) ) wsize = 0; // do it all in bytes |
---|
386 | else wsize = size >> 2; |
---|
387 | |
---|
388 | for( i = 0 ; i < wsize ; i++ ) // transfer one word per iteration |
---|
389 | { |
---|
390 | asm volatile( |
---|
391 | ".set noreorder \n" |
---|
392 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
393 | "mtc2 %0, $24 \n" /* PADDR_EXT <= scxy */ |
---|
394 | "lw $3, 0(%1) \n" /* $3 <= *src */ |
---|
395 | "mtc2 %2, $24 \n" /* PADDR_EXT <= dcxy */ |
---|
396 | "sw $3, 0(%3) \n" /* *dst <= $3 */ |
---|
397 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
398 | ".set reorder \n" |
---|
399 | : : "r"(scxy), "r" (sptr+(i<<2)), "r"(dcxy), "r" (dptr+(i<<2)) : "$3", "$15" ); |
---|
400 | } |
---|
401 | |
---|
402 | for( i = wsize << 2 ; i < size ; i++ ) // transfer one byte per iteration |
---|
403 | { |
---|
404 | asm volatile( |
---|
405 | ".set noreorder \n" |
---|
406 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
407 | "mtc2 %0, $24 \n" /* PADDR_EXT <= scxy */ |
---|
408 | "lb $3, 0(%1) \n" /* $3 <= *src */ |
---|
409 | "mtc2 %2, $24 \n" /* PADDR_EXT <= dcxy */ |
---|
410 | "sb $3, 0(%3) \n" /* *dst <= $3 */ |
---|
411 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
412 | ".set reorder \n" |
---|
413 | : : "r"(scxy), "r" (sptr+i), "r"(dcxy), "r" (dptr+i) : "$3", "$15" ); |
---|
414 | } |
---|
415 | |
---|
416 | hal_restore_irq( save_sr ); |
---|
417 | |
---|
418 | } // end hal_remote_memcpy() |
---|
419 | |
---|
420 | /////////////////////////////////// |
---|
421 | void hal_remote_strcpy( xptr_t dst, |
---|
422 | xptr_t src ) |
---|
423 | { |
---|
424 | uint32_t save_sr; |
---|
425 | uint32_t dptr = (uint32_t)GET_PTR( dst ); |
---|
426 | uint32_t dcxy = (uint32_t)GET_CXY( dst ); |
---|
427 | uint32_t sptr = (uint32_t)GET_PTR( src ); |
---|
428 | uint32_t scxy = (uint32_t)GET_CXY( src ); |
---|
429 | |
---|
430 | hal_disable_irq( &save_sr ); |
---|
431 | |
---|
432 | // loop on characters while non NUL |
---|
433 | asm volatile( |
---|
434 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
435 | "1: \n" /* loop entry */ |
---|
436 | "mtc2 %0, $24 \n" /* PADDR_EXT <= scxy */ |
---|
437 | "lb $13, 0(%1) \n" /* read char from src string */ |
---|
438 | "mtc2 %2, $24 \n" /* PADDR_EXT <= dcxy */ |
---|
439 | "sb $13, 0(%3) \n" /* store char to dst string */ |
---|
440 | "addi %1, %1, 1 \n" /* increment sptr pointer */ |
---|
441 | "addi %3, %3, 1 \n" /* increment dptr pointer */ |
---|
442 | "bne $13, $0, 1b \n" /* test NUL */ |
---|
443 | "nop \n" |
---|
444 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
445 | : : "r"(scxy), "r"(sptr), "r"(dcxy), "r"(dptr) : "$13","$15", "memory" ); |
---|
446 | |
---|
447 | hal_restore_irq( save_sr ); |
---|
448 | |
---|
449 | } // end hal_remote_strcpy() |
---|
450 | |
---|
451 | //////////////////////////////////////// |
---|
452 | void hal_remote_memset( xptr_t buf_xp, |
---|
453 | uint8_t byte, |
---|
454 | uint32_t size ) |
---|
455 | { |
---|
456 | uint32_t save_sr; |
---|
457 | uint32_t i; |
---|
458 | uint32_t wsize; |
---|
459 | uint32_t buf_ptr = (uint32_t)GET_PTR( buf_xp ); |
---|
460 | uint32_t buf_cxy = (uint32_t)GET_CXY( buf_xp ); |
---|
461 | uint32_t word = ((uint32_t)byte)<<24 | |
---|
462 | ((uint32_t)byte)<<16 | |
---|
463 | ((uint32_t)byte)<<8 | |
---|
464 | ((uint32_t)byte) ; |
---|
465 | |
---|
466 | hal_disable_irq( &save_sr ); |
---|
467 | |
---|
468 | if( (buf_ptr & 0x3) ) wsize = 0; // do it all in bytes |
---|
469 | else wsize = size >> 2; |
---|
470 | |
---|
471 | for( i = 0 ; i < wsize ; i++ ) // transfer one word per iteration |
---|
472 | { |
---|
473 | asm volatile( |
---|
474 | ".set noreorder \n" |
---|
475 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
476 | "mtc2 %0, $24 \n" /* PADDR_EXT <= buf_cxy */ |
---|
477 | "sw %2, 0(%1) \n" /* set one word */ |
---|
478 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
479 | ".set reorder \n" |
---|
480 | : : "r"(buf_cxy), "r" (buf_ptr+(i<<2)), "r"(byte) : "$15" ); |
---|
481 | } |
---|
482 | |
---|
483 | for( i = wsize << 2 ; i < size ; i++ ) // transfer one byte per iteration |
---|
484 | { |
---|
485 | asm volatile( |
---|
486 | ".set noreorder \n" |
---|
487 | "mfc2 $15, $24 \n" /* $15 <= PADDR_EXT */ |
---|
488 | "mtc2 %0, $24 \n" /* PADDR_EXT <= buf_cxy */ |
---|
489 | "sb %2, 0(%1) \n" /* set one byte */ |
---|
490 | "mtc2 $15, $24 \n" /* PADDR_EXT <= $15 */ |
---|
491 | ".set reorder \n" |
---|
492 | : : "r"(buf_cxy), "r"(buf_ptr+i), "r"(word) : "$15" ); |
---|
493 | } |
---|
494 | |
---|
495 | hal_restore_irq( save_sr ); |
---|
496 | |
---|
497 | } // end hal_remote_memset() |
---|
498 | |
---|