]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/bcopytest.c
e27d13eebb17074e29061f02efc11563d3eaae84
4 #include <mach_vm_debug.h>
5 #include <db_machine_commands.h>
7 #include <kern/thread.h>
8 #include <kern/thread_act.h>
9 #include <mach/vm_attributes.h>
10 #include <mach/vm_param.h>
11 #include <vm/vm_kern.h>
12 #include <vm/vm_map.h>
13 #include <vm/vm_page.h>
16 #include <kern/misc_protos.h>
17 #include <ppc/exception.h>
18 #include <ppc/misc_protos.h>
19 #include <ppc/proc_reg.h>
25 #include <ppc/new_screen.h>
26 #include <ppc/Firmware.h>
27 #include <ppc/mappings.h>
28 #include <ddb/db_output.h>
30 #include <ppc/POWERMAC/video_console.h> /* (TEST/DEBUG) */
36 void clrarea(unsigned int *source
, unsigned int *sink
);
37 int tstcopy(void *src
, void *snk
, unsigned int lgn
);
38 void clrarea2(unsigned int *source
, unsigned int *sink
);
39 int tstcopy2(void *src
, void *snk
, unsigned int lgn
);
40 int tstcopy3(void *src
, void *snk
, unsigned int lgn
);
41 int tstcopy4(void *src
, void *snk
, unsigned int lgn
);
42 int tstcopy5(void *src
, void *snk
, unsigned int lgn
);
43 int dumbcopy(void *src
, void *snk
, unsigned int lgn
);
46 unsigned int gtick(void);
50 void bcopytest(void) {
52 void *srcptr
, *snkptr
, *asrc
, *asnk
;
53 int bsrc
, bsnk
, size
, iterations
, i
, ret
, n
;
54 unsigned int makerand
, timein
, timeout
, ticks
;
56 unsigned int *sink
, *source
;
58 long long tottime
, totbytes
;
59 long long tottime2
, totbytes2
;
63 db_printf("bcopy test\n");
65 retr
= kmem_alloc_wired(kernel_map
, (vm_offset_t
*)&sink
, (1024*1024)+4096); /* Get sink area */
66 if(retr
!= KERN_SUCCESS
) { /* Did we find any memory at all? */
67 panic("bcopytest: Whoops... no memory for sink\n");
70 retr
= kmem_alloc_wired(kernel_map
, (vm_offset_t
*)&source
, (1024*1024)+4096); /* Get source area */
71 if(retr
!= KERN_SUCCESS
) { /* Did we find any memory at all? */
72 panic("bcopytest: Whoops... no memory for source\n");
75 db_printf("Source at %08X; Sink at %08X\n", source
, sink
);
77 srcptr
= (void *)&source
[0];
78 snkptr
= (void *)&sink
[0];
81 db_printf("Testing non-overlap case; source bndry = 0 to 7F; sink bndry = 0 - 7F; lgn = 1 to 256\n");
82 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step the source by 1 */
83 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step the sink by 1 */
84 for(size
= 1; size
<= 256; size
++) { /* Step the size by 1 */
86 clrarea(source
, sink
); /* Reset source and clear sink */
90 if(tstcopy((void *)((unsigned int)srcptr
+ bsrc
), (void *)((unsigned int)snkptr
+ bsnk
), size
)) {
91 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
92 db_printf("failed\n");
97 db_printf("Non-overlap test complete\n");
102 db_printf("Testing overlap\n");
103 for(bsrc
= 1; bsrc
< 128; bsrc
++) { /* Step the source by 1 */
104 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step the sink by 1 */
105 for(size
= 1; size
<= 256; size
++) { /* Step the size by 1 */
107 clrarea2(source
, sink
); /* Reset source and clear sink */
114 if(tstcopy2((void *)((unsigned int)srcptr
+ bsrc
), (void *)((unsigned int)srcptr
+ bsnk
), size
)) {
115 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
116 db_printf("failed\n");
121 db_printf("Overlap test complete\n");
125 db_printf("Starting exhaustive tests\n");
126 for(i
= 0; i
< 262144 * 4; i
++) { /* Set all 1MB of source and dest to known pattern */
127 ((unsigned char *)srcptr
)[i
] = i
% patper
; /* Make a non-power-of-two length pattern */
128 ((unsigned char *)snkptr
)[i
] = i
% patper
; /* Make a non-power-of-two length pattern */
131 db_printf("No overlap; source < sink, length = 0 to 1023\nSource =");
134 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
135 db_printf(" %3d", bsrc
); /* Show where we're at */
136 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
137 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
138 asrc
= (void *)((unsigned int)srcptr
+ bsrc
); /* Start byte address */
139 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ 2048); /* End byte address */
140 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
142 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
143 db_printf("failed\n");
151 db_printf("No overlap; source > sink, length = 0 to 1023\nSource =");
154 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
155 db_printf(" %3d", bsrc
); /* Show where we're at */
156 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
157 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
158 asrc
= (void *)((unsigned int)srcptr
+ bsrc
+ 2048); /* Start byte address */
159 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
160 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
162 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
163 db_printf("failed\n");
171 db_printf("Overlap; source = sink + N (N = 0 to 127), length = 0 to 1023\nN =");
174 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
175 db_printf(" %3d", n
); /* Show where we're at */
176 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
177 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
178 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
); /* Start byte address */
179 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
180 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
182 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
183 db_printf("failed\n");
191 db_printf("Overlap; source + N = sink (N = 0 to 127), length = 0 to 1023\nSource =");
194 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
195 db_printf(" %3d", bsrc
); /* Show where we're at */
196 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
197 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
198 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
199 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
); /* End byte address */
200 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
202 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
203 db_printf("failed\n");
212 db_printf("Overlap; source = sink + N + 128 (N = 0 to 127), length = 0 to 1023\nN =");
215 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
216 db_printf(" %3d", n
); /* Show where we're at */
217 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
218 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
219 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 128); /* Start byte address */
220 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
221 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
223 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
224 db_printf("failed\n");
232 db_printf("Overlap; source + N + 128 = sink (N = 0 to 127), length = 0 to 1023\nSource =");
235 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
236 db_printf(" %3d", bsrc
); /* Show where we're at */
237 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
238 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
239 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
240 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 128); /* End byte address */
241 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
243 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
244 db_printf("failed\n");
252 db_printf("Overlap; source = sink + N + 256 (N = 0 to 127), length = 0 to 1023\nSource =");
255 for(n
= 0; n
< 128; n
++) { /* Step n by 1 */
256 db_printf(" %3d", n
); /* Show where we're at */
257 for(bsnk
= 0; bsnk
< 128; bsnk
++) { /* Step sink by 1 */
258 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
259 asrc
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 256); /* Start byte address */
260 asnk
= (void *)((unsigned int)srcptr
+ bsnk
); /* End byte address */
261 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
263 db_printf("\nTest failed - source = %3d, sink = %3d size = %d\n", bsrc
, bsnk
, size
);
264 db_printf("failed\n");
272 db_printf("Overlap; source + N + 256 = sink (N = 0 to 127), length = 0 to 1023\nSource =");
274 for(bsrc
= 0; bsrc
< 128; bsrc
++) { /* Step source by 1 */
275 db_printf(" %3d", bsrc
); /* Show where we're at */
276 for(n
= 0; n
< 128; n
++) { /* Step N by 1 */
277 for(size
= 0; size
< 1025; size
++) { /* Step size from 0 to 1023 */
278 asrc
= (void *)((unsigned int)srcptr
+ bsnk
); /* Start byte address */
279 asnk
= (void *)((unsigned int)srcptr
+ bsnk
+ n
+ 256); /* End byte address */
280 ret
= tstcopy5(asrc
, asnk
, size
); /* Copy and validate */
282 db_printf("\nTest failed - source = %3d, n = %3d size = %d\n", bsrc
, n
, size
);
283 db_printf("failed\n");
302 db_printf("Random test starting; iterations = %d\n", iterations
);
303 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
304 ((unsigned char *)srcptr
)[i
] = i
& 255;
307 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
308 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
309 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
310 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
311 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
312 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
313 size
= makerand
& 0x0007FFFF; /* Generate length */
315 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
316 ((unsigned int)srcptr
+ bsnk
), size
);
319 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
320 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
322 ret
= tstcopy3(asrc
, asnk
, size
);
325 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
326 db_printf("failed\n");
329 ticks
= timeout
- timein
; /* Get time in ticks for copy */
333 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
334 // rate = rate * (double)11250000.0; /* Bytes per second */
335 // rate = rate * (double)16500000.0; /* Bytes per second */
336 rate
= rate
* (double)tbfreq
; /* Bytes per second */
337 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
339 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
351 db_printf("Random test starting; iterations = %d\n", iterations
);
352 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
353 ((unsigned char *)srcptr
)[i
] = i
& 255;
356 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
357 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
358 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
359 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
360 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
361 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
362 size
= makerand
& 0x0007FFFF; /* Generate length */
364 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
365 ((unsigned int)srcptr
+ bsnk
), size
);
368 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
369 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
371 ret
= tstcopy4(asrc
, asnk
, size
);
374 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
375 db_printf("failed\n");
378 ticks
= timeout
- timein
; /* Get time in ticks for copy */
382 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
383 // rate = rate * (double)11250000.0; /* Bytes per second */
384 // rate = rate * (double)16500000.0; /* Bytes per second */
385 rate
= rate
* (double)tbfreq
; /* Bytes per second */
386 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
388 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
398 db_printf("Random test starting; iterations = %d\n", iterations
);
399 for(i
= 0; i
< 262144 * 4; i
++) { /* Clear all 2MB of source (and dest for this test) */
400 ((unsigned char *)srcptr
)[i
] = i
& 255;
403 for(i
= 0; i
< iterations
; i
++) { /* Test until we are done */
404 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
405 bsrc
= makerand
& 0x0007FFFF; /* Generate source */
406 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
407 bsnk
= makerand
& 0x0007FFFF; /* Generate sink */
408 makerand
= rand() << 16 | (rand() & 0x0000FFFF);
409 size
= makerand
& 0x0007FFFF; /* Generate length */
411 db_printf("rt %7d: src = %08X; sink = %08X; length = %7d\n", i
, ((unsigned int)srcptr
+ bsrc
),
412 ((unsigned int)srcptr
+ bsnk
), size
);
415 asrc
= (void *)((unsigned int)srcptr
+ bsrc
);
416 asnk
= (void *)((unsigned int)srcptr
+ bsnk
);
418 ret
= dumbcopy(asrc
, asnk
, size
);
421 db_printf("Test failed; source = %02X; sink = %02X; length = %d\n", bsrc
, bsnk
, size
);
422 db_printf("failed\n");
425 ticks
= timeout
- timein
; /* Get time in ticks for copy */
429 rate
= (double) totbytes
/ (double)tottime
; /* Get bytes per tick */
430 rate
= rate
* (double)tbfreq
; /* Bytes per second */
431 rate
= rate
/ (double)1000000.0; /* Get number of MBs */
433 db_printf("Total bytes = %lld; total time = %lld; rate = %f10\n", totbytes
, tottime
, rate
);
438 kmem_free(kernel_map
, (vm_offset_t
) sink
, (1024*1024)+4096); /* Release this mapping block */
439 kmem_free(kernel_map
, (vm_offset_t
) source
, (1024*1024)+4096); /* Release this mapping block */
441 if(dbg
== 22) db_printf("Gabbagoogoo\n");
445 void clrarea(unsigned int *source
, unsigned int *sink
) {
449 for(i
=0; i
< 1024; i
++) { /* Init source & sink */
450 source
[i
] = 0x55555555; /* Known pattern */
451 sink
[i
] = 0xAAAAAAAA; /* Known pattern */
456 void clrarea2(unsigned int *source
, unsigned int *sink
) {
461 ss
= (unsigned char *)&source
[0];
463 for(i
=0; i
< 1024 * 4; i
++) { /* Init source/sink */
464 ss
[i
] = i
& 0xFF; /* Known pattern */
469 int tstcopy(void *src
, void *snk
, unsigned int lgn
) {
471 unsigned int i
, crap
;
473 bcopy(src
, snk
, lgn
);
475 for(i
= 0; i
< lgn
; i
++) {
476 if(((unsigned char *)snk
)[i
] != 0x55) {
477 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
478 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
482 if(((unsigned char *)snk
)[lgn
] != 0xAA) { /* Is it right? */
483 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
484 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
491 int tstcopy2(void *src
, void *snk
, unsigned int lgn
) {
493 unsigned int i
, crap
;
494 unsigned char ic
, ec
;
496 ic
= ((unsigned char *)src
)[0];
497 ec
= ((unsigned char *)snk
)[lgn
];
499 bcopy(src
, snk
, lgn
);
501 for(i
= 0; i
< lgn
; i
++) {
502 if(((unsigned char *)snk
)[i
] != ic
) {
503 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
504 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
507 ic
= (ic
+ 1) & 0xFF;
510 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Is it right? */
511 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
512 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
519 int tstcopy3(void *src
, void *snk
, unsigned int lgn
) {
521 unsigned int i
, crap
;
522 unsigned char ic
, ec
, oic
;
524 oic
= ((unsigned char *)snk
)[0];
525 ic
= ((unsigned char *)src
)[0];
526 ec
= ((unsigned char *)snk
)[lgn
];
528 bcopy(src
, snk
, lgn
);
530 for(i
= 0; i
< lgn
; i
++) {
531 if(((unsigned char *)snk
)[i
] != ic
) {
532 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
533 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
536 ic
= (ic
+ 1) & 0xFF;
539 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Is it right? */
540 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
541 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
545 for(i
=0; i
< lgn
; i
++) { /* Restore pattern */
546 ((unsigned char *)snk
)[i
] = oic
;
547 oic
= (oic
+ 1) & 0xFF;
554 int tstcopy4(void *src
, void *snk
, unsigned int lgn
) {
556 bcopy(src
, snk
, lgn
);
561 int tstcopy5(void *src
, void *snk
, unsigned int lgn
) {
563 unsigned int i
, crap
;
564 unsigned char ic
, ec
, oic
, pc
;
566 oic
= ((unsigned char *)snk
)[0]; /* Original first sink character */
567 ic
= ((unsigned char *)src
)[0]; /* Original first source character */
568 ec
= ((unsigned char *)snk
)[lgn
]; /* Original character just after last sink character */
569 pc
= ((unsigned char *)snk
)[-1]; /* Original character just before sink */
571 bcopy(src
, snk
, lgn
);
573 if(((unsigned char *)snk
)[lgn
] != ec
) { /* Did we copy too far forward? */
574 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
575 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
579 if(((unsigned char *)snk
)[-1] != pc
) { /* Did we copy too far backward? */
580 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
581 db_printf("Copied too far at sink[%d] (%08X) it is %02X\n", i
, crap
, ((unsigned char *)snk
)[lgn
]);
585 for(i
= 0; i
< lgn
; i
++) { /* Check sink byte sequence */
586 if(((unsigned char *)snk
)[i
] != ic
) {
587 crap
= (unsigned int)&((unsigned char *)snk
)[i
];
588 db_printf("bad copy at sink[%d] (%08X) it is %02X\n", i
,crap
, ((unsigned char *)snk
)[i
]);
591 ic
= (ic
+ 1) % patper
;
594 for(i
=0; i
< lgn
; i
++) { /* Restore pattern */
595 ((unsigned char *)snk
)[i
] = oic
;
596 oic
= (oic
+ 1) % patper
;
603 int dumbcopy(void *src
, void *snk
, unsigned int lgn
) {
605 char *p
= (char *)snk
;
606 char *q
= (char *)src
;
608 for(i
= 0; i
< lgn
; i
++) {