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$");
56 * Read bytes from an I/O address into a block of memory
58 * r0 = address to read from (IO)
59 * r1 = address to write to (memory)
63 /* This code will look very familiar if you've read _memcpy(). */
66 stmfd sp!, {fp, ip, lr, pc}
68 subs r2, r2, #4 /* r2 = length - 4 */
69 blt .Lrm1_l4 /* less than 4 bytes */
71 beq .Lrm1_main /* aligned destination */
86 orr r3, r3, r12, lsl #8
88 orr r3, r3, r12, lsl #16
90 orr r3, r3, r12, lsl #24
95 adds r2, r2, #4 /* r2 = length again */
96 ldmdbeq fp, {fp, sp, pc}
105 ldmdb fp, {fp, sp, pc}
109 * Write bytes to an I/O address from a block of memory
111 * r0 = address to write to (IO)
112 * r1 = address to read from (memory)
116 /* This code will look very familiar if you've read _memcpy(). */
119 stmfd sp!, {fp, ip, lr, pc}
121 subs r2, r2, #4 /* r2 = length - 4 */
122 blt .Lwm1_l4 /* less than 4 bytes */
124 beq .Lwm1_main /* aligned source */
148 adds r2, r2, #4 /* r2 = length again */
149 ldmdbeq fp, {fp, sp, pc}
157 ldmdb fp, {fp, sp, pc}
161 * Reads short ints (16 bits) from an I/O address into a block of memory
163 * r0 = address to read from (IO)
164 * r1 = address to write to (memory)
169 /* Make sure that we have a positive length */
173 /* If the destination address and the size is word aligned, do it fast */
176 tsteq r1, #0x00000003
179 /* Non aligned insw */
183 subs r2, r2, #0x00000001 /* Loop test in load delay slot */
184 strb r3, [r1], #0x0001
186 strb r3, [r1], #0x0001
191 /* Word aligned insw */
196 ldr r3, [r0, #0x0002] /* take advantage of nonaligned
199 mov r3, r3, lsr #16 /* Put the two shorts together */
200 orr r3, r3, ip, lsl #16
201 str r3, [r1], #0x0004 /* Store */
202 subs r2, r2, #0x00000002 /* Next */
209 * Writes short ints (16 bits) from a block of memory to an I/O address
211 * r0 = address to write to (IO)
212 * r1 = address to read from (memory)
217 /* Make sure that we have a positive length */
221 /* If the destination address and the size is word aligned, do it fast */
224 tsteq r1, #0x00000003
227 /* Non aligned outsw */
230 ldrb r3, [r1], #0x0001
231 ldrb ip, [r1], #0x0001
232 subs r2, r2, #0x00000001 /* Loop test in load delay slot */
233 orr r3, r3, ip, lsl #8
234 orr r3, r3, r3, lsl #16
240 /* Word aligned outsw */
245 ldr r3, [r1], #0x0004 /* r3 = (H)(L) */
246 subs r2, r2, #0x00000002 /* Loop test in load delay slot */
248 eor ip, r3, r3, lsr #16 /* ip = (H)(H^L) */
249 eor r3, r3, ip, lsl #16 /* r3 = (H^H^L)(L) = (L)(L) */
250 eor ip, ip, r3, lsr #16 /* ip = (H)(H^L^L) = (H)(H) */
255 /* mov ip, r3, lsl #16
256 * orr ip, ip, ip, lsr #16
259 * mov ip, r3, lsr #16
260 * orr ip, ip, ip, lsl #16
270 * reads short ints (16 bits) from an I/O address into a block of memory
271 * with a length garenteed to be a multiple of 16 bytes
272 * with a word aligned destination address
274 * r0 = address to read from (IO)
275 * r1 = address to write to (memory)
280 /* Make sure that we have a positive length */
284 /* If the destination address is word aligned and the size suitably
285 aligned, do it fast */
288 tsteq r1, #0x00000003
292 /* Word aligned insw */
294 stmfd sp!, {r4,r5,lr}
297 ldr r3, [r0, #0x0002] /* take advantage of nonaligned
300 mov r3, r3, lsr #16 /* Put the two shorts together */
301 orr r3, r3, lr, lsl #16
303 ldr r4, [r0, #0x0002] /* take advantage of nonaligned
306 mov r4, r4, lsr #16 /* Put the two shorts together */
307 orr r4, r4, lr, lsl #16
309 ldr r5, [r0, #0x0002] /* take advantage of nonaligned
312 mov r5, r5, lsr #16 /* Put the two shorts together */
313 orr r5, r5, lr, lsl #16
315 ldr ip, [r0, #0x0002] /* take advantage of nonaligned
318 mov ip, ip, lsr #16 /* Put the two shorts together */
319 orr ip, ip, lr, lsl #16
321 stmia r1!, {r3-r5,ip}
322 subs r2, r2, #0x00000008 /* Next */
325 ldmfd sp!, {r4,r5,pc} /* Restore regs and go home */
329 * Writes short ints (16 bits) from a block of memory to an I/O address
331 * r0 = address to write to (IO)
332 * r1 = address to read from (memory)
337 /* Make sure that we have a positive length */
341 /* If the destination address is word aligned and the size suitably
342 aligned, do it fast */
345 tsteq r1, #0x00000003
349 /* Word aligned outsw */
351 stmfd sp!, {r4,r5,lr}
354 ldmia r1!, {r4,r5,ip,lr}
356 eor r3, r4, r4, lsl #16 /* r3 = (A^B)(B) */
357 eor r4, r4, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
358 eor r3, r3, r4, lsl #16 /* r3 = (A^B^A)(B) = (B)(B) */
362 /* mov r3, r4, lsl #16
363 * orr r3, r3, r3, lsr #16
366 * mov r3, r4, lsr #16
367 * orr r3, r3, r3, lsl #16
371 eor r3, r5, r5, lsl #16 /* r3 = (A^B)(B) */
372 eor r5, r5, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
373 eor r3, r3, r5, lsl #16 /* r3 = (A^B^A)(B) = (B)(B) */
377 eor r3, ip, ip, lsl #16 /* r3 = (A^B)(B) */
378 eor ip, ip, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
379 eor r3, r3, ip, lsl #16 /* r3 = (A^B^A)(B) = (B)(B) */
383 eor r3, lr, lr, lsl #16 /* r3 = (A^B)(B) */
384 eor lr, lr, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
385 eor r3, r3, lr, lsl #16 /* r3 = (A^B^A)(B) = (B)(B) */
389 subs r2, r2, #0x00000008
392 ldmfd sp!, {r4,r5,pc} /* and go home */
396 * reads short ints (16 bits) from an I/O address into a block of memory
397 * The I/O address is assumed to be mapped multiple times in a block of
399 * The destination address should be word aligned.
401 * r0 = address to read from (IO)
402 * r1 = address to write to (memory)
407 /* Make sure that we have a positive length */
411 /* If the destination address is word aligned and the size suitably
412 aligned, do it fast */
418 /* Word aligned insw */
420 stmfd sp!, {r4-r9,lr}
423 orr lr, lr, #0x00ff0000
432 orr r3, r3, r4, lsl #16
434 orr r4, r5, r6, lsl #16
436 orr r5, r7, r8, lsl #16
438 orr r6, r9, ip, lsl #16
442 subs r2, r2, #0x00000008 /* Next */
453 orr r3, r3, r4, lsl #16
455 orr r4, r5, r6, lsl #16
459 subs r2, r2, #0x00000004
469 orr r3, r3, r4, lsl #16
470 str r3, [r1], #0x0004
472 subs r2, r2, #0x00000002
480 subs r2, r2, #0x00000001 /* Test in load delay slot */
481 /* XXX, why don't we use result? */
483 strb r3, [r1], #0x0001
485 strb r3, [r1], #0x0001
489 ldmfd sp!, {r4-r9,pc} /* And go home */
493 * write short ints (16 bits) to an I/O address from a block of memory
494 * The I/O address is assumed to be mapped multiple times in a block of
496 * The source address should be word aligned.
498 * r0 = address to read to (IO)
499 * r1 = address to write from (memory)
504 /* Make sure that we have a positive length */
508 /* If the destination address is word aligned and the size suitably
509 aligned, do it fast */
515 /* Word aligned outsw */
517 stmfd sp!, {r4-r8,lr}
523 ldmia r1!, {r3,r5,r7,ip}
525 eor r4, r3, r3, lsr #16 /* r4 = (A)(A^B) */
526 eor r3, r3, r4, lsl #16 /* r3 = (A^A^B)(B) = (B)(B) */
527 eor r4, r4, r3, lsr #16 /* r4 = (A)(B^A^B) = (A)(A) */
529 eor r6, r5, r5, lsr #16 /* r6 = (A)(A^B) */
530 eor r5, r5, r6, lsl #16 /* r5 = (A^A^B)(B) = (B)(B) */
531 eor r6, r6, r5, lsr #16 /* r6 = (A)(B^A^B) = (A)(A) */
533 eor r8, r7, r7, lsr #16 /* r8 = (A)(A^B) */
534 eor r7, r7, r8, lsl #16 /* r7 = (A^A^B)(B) = (B)(B) */
535 eor r8, r8, r7, lsr #16 /* r8 = (A)(B^A^B) = (A)(A) */
537 eor lr, ip, ip, lsr #16 /* lr = (A)(A^B) */
538 eor ip, ip, lr, lsl #16 /* ip = (A^A^B)(B) = (B)(B) */
539 eor lr, lr, ip, lsr #16 /* lr = (A)(B^A^B) = (A)(A) */
541 stmia r0, {r3-r8,ip,lr}
543 subs r2, r2, #0x00000008 /* Next */
553 eor r6, r3, r3, lsr #16 /* r6 = (A)(A^B) */
554 eor r5, r3, r6, lsl #16 /* r5 = (A^A^B)(B) = (B)(B) */
555 eor r6, r6, r5, lsr #16 /* r6 = (A)(B^A^B) = (A)(A) */
557 eor r8, r4, r4, lsr #16 /* r8 = (A)(A^B) */
558 eor r7, r4, r8, lsl #16 /* r7 = (A^A^B)(B) = (B)(B) */
559 eor r8, r8, r7, lsr #16 /* r8 = (A)(B^A^B) = (A)(A) */
563 subs r2, r2, #0x00000004
570 ldr r3, [r1], #0x0004 /* r3 = (A)(B) */
571 subs r2, r2, #0x00000002 /* Done test in Load delay slot */
573 eor r5, r3, r3, lsr #16 /* r5 = (A)(A^B)*/
574 eor r4, r3, r5, lsl #16 /* r4 = (A^A^B)(B) = (B)(B) */
575 eor r5, r5, r4, lsr #16 /* r5 = (A)(B^A^B) = (A)(A) */
585 ldrb r3, [r1], #0x0001
586 ldrb r4, [r1], #0x0001
587 subs r2, r2, #0x00000001 /* Done test in load delay slot */
588 /* XXX This test isn't used? */
589 orr r3, r3, r4, lsl #8
590 orr r3, r3, r3, lsl #16
594 ldmfd sp!, {r4-r8,pc} /* And go home */