1 /* $NetBSD: blockio.S,v 1.5 2002/08/15 01:38:16 briggs Exp $ */
4 * Copyright (c) 2001 Ben Harris.
5 * Copyright (c) 1994 Mark Brinicombe.
6 * Copyright (c) 1994 Brini.
9 * This code is derived from software written for Brini by Mark Brinicombe
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Brini.
22 * 4. The name of the company nor the name of the author may be used to
23 * endorse or promote products derived from this software without specific
24 * prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * RiscBSD kernel project
42 * optimised block read/write from/to IO routines.
45 * Modified : 22/01/99 -- R.Earnshaw
46 * Faster, and small tweaks for StrongARM
49 #include <machine/asm.h>
51 __FBSDID("$FreeBSD$");
54 * Read bytes from an I/O address into a block of memory
56 * r0 = address to read from (IO)
57 * r1 = address to write to (memory)
61 /* This code will look very familiar if you've read _memcpy(). */
64 stmfd sp!, {fp, ip, lr, pc}
66 subs r2, r2, #4 /* r2 = length - 4 */
67 blt .Lrm1_l4 /* less than 4 bytes */
69 beq .Lrm1_main /* aligned destination */
84 orr r3, r3, r12, lsl #8
86 orr r3, r3, r12, lsl #16
88 orr r3, r3, r12, lsl #24
93 adds r2, r2, #4 /* r2 = length again */
94 ldmeqdb fp, {fp, sp, pc}
103 ldmdb fp, {fp, sp, pc}
107 * Write bytes to an I/O address from a block of memory
109 * r0 = address to write to (IO)
110 * r1 = address to read from (memory)
114 /* This code will look very familiar if you've read _memcpy(). */
117 stmfd sp!, {fp, ip, lr, pc}
119 subs r2, r2, #4 /* r2 = length - 4 */
120 blt .Lwm1_l4 /* less than 4 bytes */
122 beq .Lwm1_main /* aligned source */
146 adds r2, r2, #4 /* r2 = length again */
147 ldmeqdb fp, {fp, sp, pc}
155 ldmdb fp, {fp, sp, pc}
159 * Reads short ints (16 bits) from an I/O address into a block of memory
161 * r0 = address to read from (IO)
162 * r1 = address to write to (memory)
167 /* Make sure that we have a positive length */
171 /* If the destination address and the size is word aligned, do it fast */
174 tsteq r1, #0x00000003
177 /* Non aligned insw */
181 subs r2, r2, #0x00000001 /* Loop test in load delay slot */
182 strb r3, [r1], #0x0001
184 strb r3, [r1], #0x0001
189 /* Word aligned insw */
194 ldr r3, [r0, #0x0002] /* take advantage of nonaligned
197 mov r3, r3, lsr #16 /* Put the two shorts together */
198 orr r3, r3, ip, lsl #16
199 str r3, [r1], #0x0004 /* Store */
200 subs r2, r2, #0x00000002 /* Next */
207 * Writes short ints (16 bits) from a block of memory to an I/O address
209 * r0 = address to write to (IO)
210 * r1 = address to read from (memory)
215 /* Make sure that we have a positive length */
219 /* If the destination address and the size is word aligned, do it fast */
222 tsteq r1, #0x00000003
225 /* Non aligned outsw */
228 ldrb r3, [r1], #0x0001
229 ldrb ip, [r1], #0x0001
230 subs r2, r2, #0x00000001 /* Loop test in load delay slot */
231 orr r3, r3, ip, lsl #8
232 orr r3, r3, r3, lsl #16
238 /* Word aligned outsw */
243 ldr r3, [r1], #0x0004 /* r3 = (H)(L) */
244 subs r2, r2, #0x00000002 /* Loop test in load delay slot */
246 eor ip, r3, r3, lsr #16 /* ip = (H)(H^L) */
247 eor r3, r3, ip, lsl #16 /* r3 = (H^H^L)(L) = (L)(L) */
248 eor ip, ip, r3, lsr #16 /* ip = (H)(H^L^L) = (H)(H) */
253 /* mov ip, r3, lsl #16
254 * orr ip, ip, ip, lsr #16
257 * mov ip, r3, lsr #16
258 * orr ip, ip, ip, lsl #16
268 * reads short ints (16 bits) from an I/O address into a block of memory
269 * with a length garenteed to be a multiple of 16 bytes
270 * with a word aligned destination address
272 * r0 = address to read from (IO)
273 * r1 = address to write to (memory)
278 /* Make sure that we have a positive length */
282 /* If the destination address is word aligned and the size suitably
283 aligned, do it fast */
286 tsteq r1, #0x00000003
290 /* Word aligned insw */
292 stmfd sp!, {r4,r5,lr}
295 ldr r3, [r0, #0x0002] /* take advantage of nonaligned
298 mov r3, r3, lsr #16 /* Put the two shorts together */
299 orr r3, r3, lr, lsl #16
301 ldr r4, [r0, #0x0002] /* take advantage of nonaligned
304 mov r4, r4, lsr #16 /* Put the two shorts together */
305 orr r4, r4, lr, lsl #16
307 ldr r5, [r0, #0x0002] /* take advantage of nonaligned
310 mov r5, r5, lsr #16 /* Put the two shorts together */
311 orr r5, r5, lr, lsl #16
313 ldr ip, [r0, #0x0002] /* take advantage of nonaligned
316 mov ip, ip, lsr #16 /* Put the two shorts together */
317 orr ip, ip, lr, lsl #16
319 stmia r1!, {r3-r5,ip}
320 subs r2, r2, #0x00000008 /* Next */
323 ldmfd sp!, {r4,r5,pc} /* Restore regs and go home */
327 * Writes short ints (16 bits) from a block of memory to an I/O address
329 * r0 = address to write to (IO)
330 * r1 = address to read from (memory)
335 /* Make sure that we have a positive length */
339 /* If the destination address is word aligned and the size suitably
340 aligned, do it fast */
343 tsteq r1, #0x00000003
347 /* Word aligned outsw */
349 stmfd sp!, {r4,r5,lr}
352 ldmia r1!, {r4,r5,ip,lr}
354 eor r3, r4, r4, lsl #16 /* r3 = (A^B)(B) */
355 eor r4, r4, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
356 eor r3, r3, r4, lsl #16 /* r3 = (A^B^A)(B) = (B)(B) */
360 /* mov r3, r4, lsl #16
361 * orr r3, r3, r3, lsr #16
364 * mov r3, r4, lsr #16
365 * orr r3, r3, r3, lsl #16
369 eor r3, r5, r5, lsl #16 /* r3 = (A^B)(B) */
370 eor r5, r5, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
371 eor r3, r3, r5, lsl #16 /* r3 = (A^B^A)(B) = (B)(B) */
375 eor r3, ip, ip, lsl #16 /* r3 = (A^B)(B) */
376 eor ip, ip, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
377 eor r3, r3, ip, lsl #16 /* r3 = (A^B^A)(B) = (B)(B) */
381 eor r3, lr, lr, lsl #16 /* r3 = (A^B)(B) */
382 eor lr, lr, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
383 eor r3, r3, lr, lsl #16 /* r3 = (A^B^A)(B) = (B)(B) */
387 subs r2, r2, #0x00000008
390 ldmfd sp!, {r4,r5,pc} /* and go home */
394 * reads short ints (16 bits) from an I/O address into a block of memory
395 * The I/O address is assumed to be mapped multiple times in a block of
397 * The destination address should be word aligned.
399 * r0 = address to read from (IO)
400 * r1 = address to write to (memory)
405 /* Make sure that we have a positive length */
409 /* If the destination address is word aligned and the size suitably
410 aligned, do it fast */
416 /* Word aligned insw */
418 stmfd sp!, {r4-r9,lr}
421 orr lr, lr, #0x00ff0000
430 orr r3, r3, r4, lsl #16
432 orr r4, r5, r6, lsl #16
434 orr r5, r7, r8, lsl #16
436 orr r6, r9, ip, lsl #16
440 subs r2, r2, #0x00000008 /* Next */
451 orr r3, r3, r4, lsl #16
453 orr r4, r5, r6, lsl #16
457 subs r2, r2, #0x00000004
467 orr r3, r3, r4, lsl #16
468 str r3, [r1], #0x0004
470 subs r2, r2, #0x00000002
478 subs r2, r2, #0x00000001 /* Test in load delay slot */
479 /* XXX, why don't we use result? */
481 strb r3, [r1], #0x0001
483 strb r3, [r1], #0x0001
487 ldmfd sp!, {r4-r9,pc} /* And go home */
491 * write short ints (16 bits) to an I/O address from a block of memory
492 * The I/O address is assumed to be mapped multiple times in a block of
494 * The source address should be word aligned.
496 * r0 = address to read to (IO)
497 * r1 = address to write from (memory)
502 /* Make sure that we have a positive length */
506 /* If the destination address is word aligned and the size suitably
507 aligned, do it fast */
513 /* Word aligned outsw */
515 stmfd sp!, {r4-r8,lr}
521 ldmia r1!, {r3,r5,r7,ip}
523 eor r4, r3, r3, lsr #16 /* r4 = (A)(A^B) */
524 eor r3, r3, r4, lsl #16 /* r3 = (A^A^B)(B) = (B)(B) */
525 eor r4, r4, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
527 eor r6, r5, r5, lsr #16 /* r6 = (A)(A^B) */
528 eor r5, r5, r6, lsl #16 /* r5 = (A^A^B)(B) = (B)(B) */
529 eor r6, r6, r5, lsr #16 /* r6 = (A)(B^A^B) = (A)(A) */
531 eor r8, r7, r7, lsr #16 /* r8 = (A)(A^B) */
532 eor r7, r7, r8, lsl #16 /* r7 = (A^A^B)(B) = (B)(B) */
533 eor r8, r8, r7, lsr #16 /* r8 = (A)(B^A^B) = (A)(A) */
535 eor lr, ip, ip, lsr #16 /* lr = (A)(A^B) */
536 eor ip, ip, lr, lsl #16 /* ip = (A^A^B)(B) = (B)(B) */
537 eor lr, lr, ip, lsr #16 /* lr = (A)(B^A^B) = (A)(A) */
539 stmia r0, {r3-r8,ip,lr}
541 subs r2, r2, #0x00000008 /* Next */
551 eor r6, r3, r3, lsr #16 /* r6 = (A)(A^B) */
552 eor r5, r3, r6, lsl #16 /* r5 = (A^A^B)(B) = (B)(B) */
553 eor r6, r6, r5, lsr #16 /* r6 = (A)(B^A^B) = (A)(A) */
555 eor r8, r4, r4, lsr #16 /* r8 = (A)(A^B) */
556 eor r7, r4, r8, lsl #16 /* r7 = (A^A^B)(B) = (B)(B) */
557 eor r8, r8, r7, lsr #16 /* r8 = (A)(B^A^B) = (A)(A) */
561 subs r2, r2, #0x00000004
568 ldr r3, [r1], #0x0004 /* r3 = (A)(B) */
569 subs r2, r2, #0x00000002 /* Done test in Load delay slot */
571 eor r5, r3, r3, lsr #16 /* r5 = (A)(A^B)*/
572 eor r4, r3, r5, lsl #16 /* r4 = (A^A^B)(B) = (B)(B) */
573 eor r5, r5, r4, lsr #16 /* r5 = (A)(B^A^B) = (A)(A) */
583 ldrb r3, [r1], #0x0001
584 ldrb r4, [r1], #0x0001
585 subs r2, r2, #0x00000001 /* Done test in load delay slot */
586 /* XXX This test isn't used? */
587 orr r3, r3, r4, lsl #8
588 orr r3, r3, r3, lsl #16
592 ldmfd sp!, {r4-r8,pc} /* And go home */