]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/bcopytest.c
3 #include <mach_vm_debug.h>
4 #include <db_machine_commands.h>
6 #include <kern/thread.h>
7 #include <mach/vm_attributes.h>
8 #include <mach/vm_param.h>
9 #include <vm/vm_kern.h>
10 #include <vm/vm_map.h>
11 #include <vm/vm_page.h>
14 #include <kern/misc_protos.h>
15 #include <ppc/exception.h>
16 #include <ppc/misc_protos.h>
17 #include <ppc/proc_reg.h>
23 #include <ppc/new_screen.h>
24 #include <ppc/Firmware.h>
25 #include <ppc/mappings.h>
26 #include <ddb/db_output.h>
28 #include <console/video_console.h> /* (TEST/DEBUG) */
34 void clrarea(unsigned int *source
, unsigned int *sink
);
35 int tstcopy(void *src
, void *snk
, unsigned int lgn
);
36 void clrarea2(unsigned int *source
, unsigned int *sink
);
37 int tstcopy2(void *src
, void *snk
, unsigned int lgn
);
38 int tstcopy3(void *src
, void *snk
, unsigned int lgn
);
39 int tstcopy4(void *src
, void *snk
, unsigned int lgn
);
40 int tstcopy5(void *src
, void *snk
, unsigned int lgn
);
41 int dumbcopy(void *src
, void *snk
, unsigned int lgn
);
44 unsigned int gtick(void);
48 void bcopytest(void) {
50 void *srcptr
, *snkptr
, *asrc
, *asnk
;
51 int bsrc
, bsnk
, size
, i
, ret
, n
;
53 unsigned int *sink
, *source
;
57 db_printf("bcopy test\n");
59 retr
= kmem_alloc_wired(kernel_map
, (vm_offset_t
*)&sink
, (1024*1024)+4096); /* Get sink area */
60 if(retr
!= KERN_SUCCESS
) { /* Did we find any memory at all? */
61 panic("bcopytest: Whoops... no memory for sink\n");
64 retr
= kmem_alloc_wired(kernel_map
, (vm_offset_t
*)&source
, (1024*1024)+4096); /* Get source area */
65 if(retr
!= KERN_SUCCESS
) { /* Did we find any memory at all? */
66 panic("bcopytest: Whoops... no memory for source\n");
69 db_printf("Source at %08X; Sink at %08X\n", source
, sink
);
71 srcptr
= (void *)&source
[0];
72 snkptr
= (void *)&sink
[0];
75 db_printf("Testing non-overlap case; source bndry = 0 to 7F; sink bndry = 0 - 7F; lgn = 1 to 256\n");
76 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step the source by 1 */
77 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step the sink by 1 */
78 for(size
= 1; size
<= 256; size
++) { /* Step the size by 1 */
80 clrarea(source
, sink
); /* Reset source and clear sink */
84 if(tstcopy((void *)((unsigned int)srcptr
+ bsrc
), (void *)((unsigned int)snkptr
+ bsnk
), size
)) {
85 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
86 db_printf("failed\n");
91 db_printf("Non-overlap test complete\n");
96 db_printf("Testing overlap\n");
97 for(bsrc
= 1; bsrc
< 128; bsrc
++) { /* Step the source by 1 */
98 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step the sink by 1 */
99 for(size
= 1; size
<= 256; size
++) { /* Step the size by 1 */
101 clrarea2(source
, sink
); /* Reset source and clear sink */
108 if(tstcopy2((void *)((unsigned int)srcptr
+ bsrc
), (void *)((unsigned int)srcptr
+ bsnk
), size
)) {
109 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
110 db_printf("failed\n");
115 db_printf("Overlap test complete\n");
119 db_printf("Starting exhaustive tests\n");
120 for(i
= 0; i
< 262144 * 4; i
++) { /* Set all 1MB of source and dest to known pattern */
121 ((unsigned char *)srcptr
)[i
] = i
% patper
; /* Make a non-power-of-two length pattern */
122 ((unsigned char *)snkptr
)[i
] = i
% patper
; /* Make a non-power-of-two length pattern */
125 db_printf("No overlap; source < sink, length = 0 to 1023\nSource =");
128 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
129 db_printf(" %3d", bsrc
); /* Show where we're at */
130 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
131 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
132 asrc
= (void *)((unsigned int)srcptr
+ bsrc
); /* Start byte address */
133 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ 2048); /* End byte address */
134 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
136 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
137 db_printf("failed\n");
145 db_printf("No overlap; source > sink, length = 0 to 1023\nSource =");
148 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
149 db_printf(" %3d", bsrc
); /* Show where we're at */
150 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
151 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
152 asrc
= (void *)((unsigned int)srcptr
+ bsrc
+ 2048); /* Start byte address */
153 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
154 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
156 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
157 db_printf("failed\n");
165 db_printf("Overlap; source = sink + N (N = 0 to 127), length = 0 to 1023\nN =");
168 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
169 db_printf(" %3d", n
); /* Show where we're at */
170 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
171 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
172 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
); /* Start byte address */
173 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
174 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
176 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
177 db_printf("failed\n");
185 db_printf("Overlap; source + N = sink (N = 0 to 127), length = 0 to 1023\nSource =");
188 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
189 db_printf(" %3d", bsrc
); /* Show where we're at */
190 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
191 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
192 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
193 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
); /* End byte address */
194 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
196 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
197 db_printf("failed\n");
206 db_printf("Overlap; source = sink + N + 128 (N = 0 to 127), length = 0 to 1023\nN =");
209 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
210 db_printf(" %3d", n
); /* Show where we're at */
211 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
212 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
213 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 128); /* Start byte address */
214 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
215 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
217 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
218 db_printf("failed\n");
226 db_printf("Overlap; source + N + 128 = sink (N = 0 to 127), length = 0 to 1023\nSource =");
229 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
230 db_printf(" %3d", bsrc
); /* Show where we're at */
231 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
232 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
233 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
234 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 128); /* End byte address */
235 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
237 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
238 db_printf("failed\n");
246 db_printf("Overlap; source = sink + N + 256 (N = 0 to 127), length = 0 to 1023\nSource =");
249 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
250 db_printf(" %3d", n
); /* Show where we're at */
251 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
252 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
253 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 256); /* Start byte address */
254 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
255 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
257 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
258 db_printf("failed\n");
266 db_printf("Overlap; source + N + 256 = sink (N = 0 to 127), length = 0 to 1023\nSource =");
268 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
269 db_printf(" %3d", bsrc
); /* Show where we're at */
270 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
271 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
272 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
273 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 256); /* End byte address */
274 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
276 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
277 db_printf("failed\n");
296 db_printf("Random test starting; iterations = %d\n", iterations
);
297 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
298 ((unsigned char *)srcptr
)[i
] = i
& 255;
301 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
302 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
303 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
304 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
305 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
306 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
307 size
= makerand
& 0x0007FFFF; /* Generate length */
309 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
310 ((unsigned int)srcptr
+ bsnk
), size
);
313 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
314 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
316 ret
= tstcopy3(asrc
, asnk
, size
);
319 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
320 db_printf("failed\n");
323 ticks
= timeout
- timein
; /* Get time in ticks for copy */
327 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
328 // rate = rate * (double)11250000.0; /* Bytes per second */
329 // rate = rate * (double)16500000.0; /* Bytes per second */
330 rate
= rate
* (double)tbfreq
; /* Bytes per second */
331 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
333 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
345 db_printf("Random test starting; iterations = %d\n", iterations
);
346 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
347 ((unsigned char *)srcptr
)[i
] = i
& 255;
350 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
351 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
352 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
353 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
354 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
355 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
356 size
= makerand
& 0x0007FFFF; /* Generate length */
358 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
359 ((unsigned int)srcptr
+ bsnk
), size
);
362 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
363 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
365 ret
= tstcopy4(asrc
, asnk
, size
);
368 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
369 db_printf("failed\n");
372 ticks
= timeout
- timein
; /* Get time in ticks for copy */
376 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
377 // rate = rate * (double)11250000.0; /* Bytes per second */
378 // rate = rate * (double)16500000.0; /* Bytes per second */
379 rate
= rate
* (double)tbfreq
; /* Bytes per second */
380 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
382 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
392 db_printf("Random test starting; iterations = %d\n", iterations
);
393 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
394 ((unsigned char *)srcptr
)[i
] = i
& 255;
397 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
398 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
399 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
400 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
401 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
402 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
403 size
= makerand
& 0x0007FFFF; /* Generate length */
405 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
406 ((unsigned int)srcptr
+ bsnk
), size
);
409 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
410 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
412 ret
= dumbcopy(asrc
, asnk
, size
);
415 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
416 db_printf("failed\n");
419 ticks
= timeout
- timein
; /* Get time in ticks for copy */
423 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
424 rate
= rate
* (double)tbfreq
; /* Bytes per second */
425 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
427 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
432 kmem_free(kernel_map
, (vm_offset_t
) sink
, (1024*1024)+4096); /* Release this mapping block */
433 kmem_free(kernel_map
, (vm_offset_t
) source
, (1024*1024)+4096); /* Release this mapping block */
435 if(dbg
== 22) db_printf("Gabbagoogoo\n");
439 void clrarea(unsigned int *source
, unsigned int *sink
) {
443 for(i
=0; i
< 1024; i
++) { /* Init source & sink */
444 source
[i
] = 0x55555555; /* Known pattern */
445 sink
[i
] = 0xAAAAAAAA; /* Known pattern */
451 clrarea2(unsigned int *source
, __unused
unsigned int *sink
)
456 ss
= (unsigned char *)&source
[0];
458 for(i
=0; i
< 1024 * 4; i
++) { /* Init source/sink */
459 ss
[i
] = i
& 0xFF; /* Known pattern */
464 int tstcopy(void *src
, void *snk
, unsigned int lgn
) {
466 unsigned int i
, crap
;
468 bcopy(src
, snk
, lgn
);
470 for(i
= 0; i
< lgn
; i
++) {
471 if(((unsigned char *)snk
)[i
] != 0x55) {
472 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
473 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
477 if(((unsigned char *)snk
)[lgn
] != 0xAA) { /* Is it right? */
478 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
479 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
486 int tstcopy2(void *src
, void *snk
, unsigned int lgn
) {
488 unsigned int i
, crap
;
489 unsigned char ic
, ec
;
491 ic
= ((unsigned char *)src
)[0];
492 ec
= ((unsigned char *)snk
)[lgn
];
494 bcopy(src
, snk
, lgn
);
496 for(i
= 0; i
< lgn
; i
++) {
497 if(((unsigned char *)snk
)[i
] != ic
) {
498 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
499 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
502 ic
= (ic
+ 1) & 0xFF;
505 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Is it right? */
506 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
507 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
514 int tstcopy3(void *src
, void *snk
, unsigned int lgn
) {
516 unsigned int i
, crap
;
517 unsigned char ic
, ec
, oic
;
519 oic
= ((unsigned char *)snk
)[0];
520 ic
= ((unsigned char *)src
)[0];
521 ec
= ((unsigned char *)snk
)[lgn
];
523 bcopy(src
, snk
, lgn
);
525 for(i
= 0; i
< lgn
; i
++) {
526 if(((unsigned char *)snk
)[i
] != ic
) {
527 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
528 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
531 ic
= (ic
+ 1) & 0xFF;
534 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Is it right? */
535 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
536 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
540 for(i
=0; i
< lgn
; i
++) { /* Restore pattern */
541 ((unsigned char *)snk
)[i
] = oic
;
542 oic
= (oic
+ 1) & 0xFF;
549 int tstcopy4(void *src
, void *snk
, unsigned int lgn
) {
551 bcopy(src
, snk
, lgn
);
556 int tstcopy5(void *src
, void *snk
, unsigned int lgn
) {
558 unsigned int i
= 0, crap
;
559 unsigned char ic
, ec
, oic
, pc
;
561 oic
= ((unsigned char *)snk
)[0]; /* Original first sink character */
562 ic
= ((unsigned char *)src
)[0]; /* Original first source character */
563 ec
= ((unsigned char *)snk
)[lgn
]; /* Original character just after last sink character */
564 pc
= ((unsigned char *)snk
)[-1]; /* Original character just before sink */
566 bcopy(src
, snk
, lgn
);
568 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Did we copy too far forward? */
569 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
570 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
574 if(((unsigned char *)snk
)[-1] != pc
) { /* Did we copy too far backward? */
575 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
576 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
580 for(i
= 0; i
< lgn
; i
++) { /* Check sink byte sequence */
581 if(((unsigned char *)snk
)[i
] != ic
) {
582 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
583 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
586 ic
= (ic
+ 1) % patper
;
589 for(i
=0; i
< lgn
; i
++) { /* Restore pattern */
590 ((unsigned char *)snk
)[i
] = oic
;
591 oic
= (oic
+ 1) % patper
;
598 int dumbcopy(void *src
, void *snk
, unsigned int lgn
) {
600 char *p
= (char *)snk
;
601 char *q
= (char *)src
;
603 for(i
= 0; i
< lgn
; i
++) {