]>
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
, iterations
, i
, ret
, n
;
52 unsigned int makerand
, timein
, timeout
, ticks
;
54 unsigned int *sink
, *source
;
56 long long tottime
, totbytes
;
57 long long tottime2
, totbytes2
;
61 db_printf("bcopy test\n");
63 retr
= kmem_alloc_wired(kernel_map
, (vm_offset_t
*)&sink
, (1024*1024)+4096); /* Get sink area */
64 if(retr
!= KERN_SUCCESS
) { /* Did we find any memory at all? */
65 panic("bcopytest: Whoops... no memory for sink\n");
68 retr
= kmem_alloc_wired(kernel_map
, (vm_offset_t
*)&source
, (1024*1024)+4096); /* Get source area */
69 if(retr
!= KERN_SUCCESS
) { /* Did we find any memory at all? */
70 panic("bcopytest: Whoops... no memory for source\n");
73 db_printf("Source at %08X; Sink at %08X\n", source
, sink
);
75 srcptr
= (void *)&source
[0];
76 snkptr
= (void *)&sink
[0];
79 db_printf("Testing non-overlap case; source bndry = 0 to 7F; sink bndry = 0 - 7F; lgn = 1 to 256\n");
80 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step the source by 1 */
81 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step the sink by 1 */
82 for(size
= 1; size
<= 256; size
++) { /* Step the size by 1 */
84 clrarea(source
, sink
); /* Reset source and clear sink */
88 if(tstcopy((void *)((unsigned int)srcptr
+ bsrc
), (void *)((unsigned int)snkptr
+ bsnk
), size
)) {
89 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
90 db_printf("failed\n");
95 db_printf("Non-overlap test complete\n");
100 db_printf("Testing overlap\n");
101 for(bsrc
= 1; bsrc
< 128; bsrc
++) { /* Step the source by 1 */
102 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step the sink by 1 */
103 for(size
= 1; size
<= 256; size
++) { /* Step the size by 1 */
105 clrarea2(source
, sink
); /* Reset source and clear sink */
112 if(tstcopy2((void *)((unsigned int)srcptr
+ bsrc
), (void *)((unsigned int)srcptr
+ bsnk
), size
)) {
113 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
114 db_printf("failed\n");
119 db_printf("Overlap test complete\n");
123 db_printf("Starting exhaustive tests\n");
124 for(i
= 0; i
< 262144 * 4; i
++) { /* Set all 1MB of source and dest to known pattern */
125 ((unsigned char *)srcptr
)[i
] = i
% patper
; /* Make a non-power-of-two length pattern */
126 ((unsigned char *)snkptr
)[i
] = i
% patper
; /* Make a non-power-of-two length pattern */
129 db_printf("No overlap; source < sink, length = 0 to 1023\nSource =");
132 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
133 db_printf(" %3d", bsrc
); /* Show where we're at */
134 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
135 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
136 asrc
= (void *)((unsigned int)srcptr
+ bsrc
); /* Start byte address */
137 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ 2048); /* End byte address */
138 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
140 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
141 db_printf("failed\n");
149 db_printf("No overlap; source > sink, length = 0 to 1023\nSource =");
152 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
153 db_printf(" %3d", bsrc
); /* Show where we're at */
154 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
155 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
156 asrc
= (void *)((unsigned int)srcptr
+ bsrc
+ 2048); /* Start byte address */
157 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
158 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
160 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
161 db_printf("failed\n");
169 db_printf("Overlap; source = sink + N (N = 0 to 127), length = 0 to 1023\nN =");
172 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
173 db_printf(" %3d", n
); /* Show where we're at */
174 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
175 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
176 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
); /* Start byte address */
177 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
178 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
180 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
181 db_printf("failed\n");
189 db_printf("Overlap; source + N = sink (N = 0 to 127), length = 0 to 1023\nSource =");
192 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
193 db_printf(" %3d", bsrc
); /* Show where we're at */
194 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
195 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
196 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
197 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
); /* End byte address */
198 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
200 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
201 db_printf("failed\n");
210 db_printf("Overlap; source = sink + N + 128 (N = 0 to 127), length = 0 to 1023\nN =");
213 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
214 db_printf(" %3d", n
); /* Show where we're at */
215 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
216 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
217 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 128); /* Start byte address */
218 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
219 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
221 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
222 db_printf("failed\n");
230 db_printf("Overlap; source + N + 128 = sink (N = 0 to 127), length = 0 to 1023\nSource =");
233 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
234 db_printf(" %3d", bsrc
); /* Show where we're at */
235 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
236 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
237 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
238 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 128); /* End byte address */
239 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
241 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
242 db_printf("failed\n");
250 db_printf("Overlap; source = sink + N + 256 (N = 0 to 127), length = 0 to 1023\nSource =");
253 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
254 db_printf(" %3d", n
); /* Show where we're at */
255 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
256 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
257 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 256); /* Start byte address */
258 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
259 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
261 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
262 db_printf("failed\n");
270 db_printf("Overlap; source + N + 256 = sink (N = 0 to 127), length = 0 to 1023\nSource =");
272 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
273 db_printf(" %3d", bsrc
); /* Show where we're at */
274 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
275 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
276 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
277 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 256); /* End byte address */
278 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
280 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
281 db_printf("failed\n");
300 db_printf("Random test starting; iterations = %d\n", iterations
);
301 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
302 ((unsigned char *)srcptr
)[i
] = i
& 255;
305 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
306 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
307 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
308 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
309 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
310 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
311 size
= makerand
& 0x0007FFFF; /* Generate length */
313 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
314 ((unsigned int)srcptr
+ bsnk
), size
);
317 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
318 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
320 ret
= tstcopy3(asrc
, asnk
, size
);
323 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
324 db_printf("failed\n");
327 ticks
= timeout
- timein
; /* Get time in ticks for copy */
331 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
332 // rate = rate * (double)11250000.0; /* Bytes per second */
333 // rate = rate * (double)16500000.0; /* Bytes per second */
334 rate
= rate
* (double)tbfreq
; /* Bytes per second */
335 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
337 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
349 db_printf("Random test starting; iterations = %d\n", iterations
);
350 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
351 ((unsigned char *)srcptr
)[i
] = i
& 255;
354 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
355 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
356 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
357 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
358 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
359 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
360 size
= makerand
& 0x0007FFFF; /* Generate length */
362 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
363 ((unsigned int)srcptr
+ bsnk
), size
);
366 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
367 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
369 ret
= tstcopy4(asrc
, asnk
, size
);
372 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
373 db_printf("failed\n");
376 ticks
= timeout
- timein
; /* Get time in ticks for copy */
380 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
381 // rate = rate * (double)11250000.0; /* Bytes per second */
382 // rate = rate * (double)16500000.0; /* Bytes per second */
383 rate
= rate
* (double)tbfreq
; /* Bytes per second */
384 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
386 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
396 db_printf("Random test starting; iterations = %d\n", iterations
);
397 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
398 ((unsigned char *)srcptr
)[i
] = i
& 255;
401 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
402 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
403 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
404 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
405 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
406 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
407 size
= makerand
& 0x0007FFFF; /* Generate length */
409 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
410 ((unsigned int)srcptr
+ bsnk
), size
);
413 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
414 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
416 ret
= dumbcopy(asrc
, asnk
, size
);
419 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
420 db_printf("failed\n");
423 ticks
= timeout
- timein
; /* Get time in ticks for copy */
427 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
428 rate
= rate
* (double)tbfreq
; /* Bytes per second */
429 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
431 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
436 kmem_free(kernel_map
, (vm_offset_t
) sink
, (1024*1024)+4096); /* Release this mapping block */
437 kmem_free(kernel_map
, (vm_offset_t
) source
, (1024*1024)+4096); /* Release this mapping block */
439 if(dbg
== 22) db_printf("Gabbagoogoo\n");
443 void clrarea(unsigned int *source
, unsigned int *sink
) {
447 for(i
=0; i
< 1024; i
++) { /* Init source & sink */
448 source
[i
] = 0x55555555; /* Known pattern */
449 sink
[i
] = 0xAAAAAAAA; /* Known pattern */
454 void clrarea2(unsigned int *source
, unsigned int *sink
) {
459 ss
= (unsigned char *)&source
[0];
461 for(i
=0; i
< 1024 * 4; i
++) { /* Init source/sink */
462 ss
[i
] = i
& 0xFF; /* Known pattern */
467 int tstcopy(void *src
, void *snk
, unsigned int lgn
) {
469 unsigned int i
, crap
;
471 bcopy(src
, snk
, lgn
);
473 for(i
= 0; i
< lgn
; i
++) {
474 if(((unsigned char *)snk
)[i
] != 0x55) {
475 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
476 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
480 if(((unsigned char *)snk
)[lgn
] != 0xAA) { /* Is it right? */
481 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
482 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
489 int tstcopy2(void *src
, void *snk
, unsigned int lgn
) {
491 unsigned int i
, crap
;
492 unsigned char ic
, ec
;
494 ic
= ((unsigned char *)src
)[0];
495 ec
= ((unsigned char *)snk
)[lgn
];
497 bcopy(src
, snk
, lgn
);
499 for(i
= 0; i
< lgn
; i
++) {
500 if(((unsigned char *)snk
)[i
] != ic
) {
501 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
502 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
505 ic
= (ic
+ 1) & 0xFF;
508 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Is it right? */
509 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
510 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
517 int tstcopy3(void *src
, void *snk
, unsigned int lgn
) {
519 unsigned int i
, crap
;
520 unsigned char ic
, ec
, oic
;
522 oic
= ((unsigned char *)snk
)[0];
523 ic
= ((unsigned char *)src
)[0];
524 ec
= ((unsigned char *)snk
)[lgn
];
526 bcopy(src
, snk
, lgn
);
528 for(i
= 0; i
< lgn
; i
++) {
529 if(((unsigned char *)snk
)[i
] != ic
) {
530 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
531 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
534 ic
= (ic
+ 1) & 0xFF;
537 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Is it right? */
538 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
539 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
543 for(i
=0; i
< lgn
; i
++) { /* Restore pattern */
544 ((unsigned char *)snk
)[i
] = oic
;
545 oic
= (oic
+ 1) & 0xFF;
552 int tstcopy4(void *src
, void *snk
, unsigned int lgn
) {
554 bcopy(src
, snk
, lgn
);
559 int tstcopy5(void *src
, void *snk
, unsigned int lgn
) {
561 unsigned int i
, crap
;
562 unsigned char ic
, ec
, oic
, pc
;
564 oic
= ((unsigned char *)snk
)[0]; /* Original first sink character */
565 ic
= ((unsigned char *)src
)[0]; /* Original first source character */
566 ec
= ((unsigned char *)snk
)[lgn
]; /* Original character just after last sink character */
567 pc
= ((unsigned char *)snk
)[-1]; /* Original character just before sink */
569 bcopy(src
, snk
, lgn
);
571 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Did we copy too far forward? */
572 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
573 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
577 if(((unsigned char *)snk
)[-1] != pc
) { /* Did we copy too far backward? */
578 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
579 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
583 for(i
= 0; i
< lgn
; i
++) { /* Check sink byte sequence */
584 if(((unsigned char *)snk
)[i
] != ic
) {
585 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
586 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
589 ic
= (ic
+ 1) % patper
;
592 for(i
=0; i
< lgn
; i
++) { /* Restore pattern */
593 ((unsigned char *)snk
)[i
] = oic
;
594 oic
= (oic
+ 1) % patper
;
601 int dumbcopy(void *src
, void *snk
, unsigned int lgn
) {
603 char *p
= (char *)snk
;
604 char *q
= (char *)src
;
606 for(i
= 0; i
< lgn
; i
++) {