bzero.S revision 1.1 1 1.1 christos /* $NetBSD: bzero.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 1995 Carnegie-Mellon University.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * Author: Trevor Blackwell
8 1.1 christos *
9 1.1 christos * Permission to use, copy, modify and distribute this software and
10 1.1 christos * its documentation is hereby granted, provided that both the copyright
11 1.1 christos * notice and this permission notice appear in all copies of the
12 1.1 christos * software, derivative works or modified versions, and any portions
13 1.1 christos * thereof, and that both notices appear in supporting documentation.
14 1.1 christos *
15 1.1 christos * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 christos * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 christos * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 christos *
19 1.1 christos * Carnegie Mellon requests users of this software to return to
20 1.1 christos *
21 1.1 christos * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 christos * School of Computer Science
23 1.1 christos * Carnegie Mellon University
24 1.1 christos * Pittsburgh PA 15213-3890
25 1.1 christos *
26 1.1 christos * any improvements or extensions that they make and grant Carnegie the
27 1.1 christos * rights to redistribute these changes.
28 1.1 christos */
29 1.1 christos
30 1.1 christos #include <machine/asm.h>
31 1.1 christos
32 1.1 christos LEAF(bzero,2)
33 1.1 christos ble a1,bzero_done
34 1.1 christos bic a1,63,t3 /* t3 is # bytes to do 64 bytes at a time */
35 1.1 christos
36 1.1 christos /* If nothing in first word, ignore it */
37 1.1 christos subq zero,a0,t0
38 1.1 christos and t0,7,t0 /* t0 = (0-size)%8 */
39 1.1 christos beq t0,bzero_nostart1
40 1.1 christos
41 1.1 christos cmpult a1,t0,t1 /* if size > size%8 goto noshort */
42 1.1 christos beq t1,bzero_noshort
43 1.1 christos
44 1.1 christos /*
45 1.1 christos * The whole thing is less than a word.
46 1.1 christos * Mask off 1..7 bytes, and finish.
47 1.1 christos */
48 1.1 christos ldq_u t2,0(a0)
49 1.1 christos lda t0,-1(zero) /* t0=-1 */
50 1.1 christos mskql t0,a1,t0 /* Get ff in bytes (a0%8)..((a0+a1-1)%8) */
51 1.1 christos insql t0,a0,t0
52 1.1 christos bic t2,t0,t2 /* zero those bytes in word */
53 1.1 christos stq_u t2,0(a0)
54 1.1 christos RET
55 1.1 christos
56 1.1 christos bzero_noshort:
57 1.1 christos /* Handle the first partial word */
58 1.1 christos ldq_u t2,0(a0)
59 1.1 christos subq a1,t0,a1
60 1.1 christos mskql t2,a0,t2 /* zero bytes (a0%8)..7 in word */
61 1.1 christos stq_u t2,0(a0)
62 1.1 christos
63 1.1 christos addq a0,t0,a0 /* round a0 up to next word */
64 1.1 christos bic a1,63,t3 /* recalc t3 (# bytes to do 64 bytes at a
65 1.1 christos time) */
66 1.1 christos
67 1.1 christos bzero_nostart1:
68 1.1 christos /*
69 1.1 christos * Loop, zeroing 64 bytes at a time
70 1.1 christos */
71 1.1 christos beq t3,bzero_lp_done
72 1.1 christos bzero_lp:
73 1.1 christos stq zero,0(a0)
74 1.1 christos stq zero,8(a0)
75 1.1 christos stq zero,16(a0)
76 1.1 christos stq zero,24(a0)
77 1.1 christos subq t3,64,t3
78 1.1 christos stq zero,32(a0)
79 1.1 christos stq zero,40(a0)
80 1.1 christos stq zero,48(a0)
81 1.1 christos stq zero,56(a0)
82 1.1 christos addq a0,64,a0
83 1.1 christos bne t3,bzero_lp
84 1.1 christos
85 1.1 christos bzero_lp_done:
86 1.1 christos /*
87 1.1 christos * Handle the last 0..7 words.
88 1.1 christos * We mask off the low bits, so we don't need an extra
89 1.1 christos * compare instruction for the loop (just a bne. heh-heh)
90 1.1 christos */
91 1.1 christos and a1,0x38,t4
92 1.1 christos beq t4,bzero_finish_lp_done
93 1.1 christos bzero_finish_lp:
94 1.1 christos stq zero,0(a0)
95 1.1 christos subq t4,8,t4
96 1.1 christos addq a0,8,a0
97 1.1 christos bne t4,bzero_finish_lp
98 1.1 christos
99 1.1 christos /* Do the last partial word */
100 1.1 christos bzero_finish_lp_done:
101 1.1 christos and a1,7,t5 /* 0..7 bytes left */
102 1.1 christos beq t5,bzero_done /* mskqh won't change t0 if t5==0, but I
103 1.1 christos don't want to touch, say, a new VM page */
104 1.1 christos ldq t0,0(a0)
105 1.1 christos mskqh t0,t5,t0
106 1.1 christos stq t0,0(a0)
107 1.1 christos bzero_done:
108 1.1 christos RET
109 1.1 christos
110 1.1 christos END(bzero)
111