|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: File: diag.c
27:
28: Contains: Kernel diagnostics
29:
30: Copyright: 1997 by Apple Computer, Inc., all rights reserved
31:
32: File Ownership:
33:
34: DRI: Thomas Mason
35:
36: Other Contact: Brett Halle
37:
38: Technology: Kernel/IO
39:
40: Writers:
41:
42: (tjm) Thomas Mason
43:
44: Change History (most recent first):
45: */
46:
47: #include <machdep/ppc/exception.h>
48: #include <kern/thread.h>
49: #include <machdep/ppc/PseudoKernel.h>
50: #include <kern/ipc_tt.h>
51: #include <ipc/ipc_port.h>
52:
53: #define printf kprintf
54:
55: #if DEBUG
56:
57: /*
58: ** Profiling Counters
59: */
60: unsigned long shandler_cnt = 0;
61: unsigned long thandler_cnt = 0;
62: unsigned long ihandler_cnt = 0;
63: unsigned long gdbhandler_cnt = 0;
64: unsigned long fpu_switch_cnt = 0;
65:
66: #define TST_BCOPY_SIZE (256)
67: #define TST_MOVE_SIZE (TST_BCOPY_SIZE/2)
68: unsigned long sb[TST_BCOPY_SIZE]; /* source buffer */
69: unsigned long db[TST_BCOPY_SIZE]; /* destination buffer */
70:
71:
72: /*
73: **
74: ** test_bcopy()
75: **
76: ** Test the various configurations of bcopy for correctness
77: ** this does the table first, then cache aligned, the byte < 7
78: **
79: */
80: test_bcopy()
81: {
82: int i, j, k, l;
83: char *src, *dst, *cmpsrc, *cmpdst;
84: boolean_t succeeded;
85:
86:
87: cmpsrc = (char *)sb;
88: /* Initialize the source buffer */
89: for (i = 0; i < TST_BCOPY_SIZE; i++)
90: {
91: *cmpsrc++ = (char)i;
92: }
93:
94: /* test the variants */
95:
96: /* setup initial src and dst ptrs */
97: dst = (char *)db;
98: for (i = 0; i < 4; i++)
99: {
100: src = (char *)sb;
101: for (j = 0; j < 4; j++)
102: {
103: for (k = TST_MOVE_SIZE; k < TST_MOVE_SIZE+4; k++)
104: {
105: cmpdst = (char *)db;
106: /* jumble the destination buffer */
107: for (l = 0; l < TST_BCOPY_SIZE; l++)
108: {
109: *cmpdst++ = 0xA5;
110: }
111:
112: cmpsrc = src;
113: cmpdst = dst;
114: bcopy(src, dst, k);
115: succeeded = TRUE;
116: for (l = 0; l < k; l++)
117: {
118: if (*cmpsrc++ != *cmpdst++)
119: {
120: succeeded = FALSE;
121: }
122: }
123: printf("mm%ds%dc%d (src=0x%x,dst=0x%x,llen=%d) ",((int)dst&3),((int)src&3),(k&3),src, dst, k);
124: switch (succeeded) {
125: case FALSE:
126: printf("FAILED!\n");
127: break;
128: case TRUE:
129: printf("SUCCEEDED!\n");
130: break;
131: }
132: }
133: src++;
134: }
135: dst++;
136: }
137: /* update to original ptrs */
138: src = (char *)sb;
139: dst = (char *)db;
140:
141: /* do cache aligned */
142: cmpsrc = src;
143: cmpdst = dst;
144: bcopy(src, dst, TST_MOVE_SIZE);
145: succeeded = TRUE;
146: for (l = 0; l < TST_MOVE_SIZE; l++)
147: {
148: if (*cmpsrc++ != *cmpdst++)
149: {
150: succeeded = FALSE;
151: }
152: }
153: printf("cache aligned bcopy (src=0x%x,dst=0x%x,len=%d) ",src,dst,TST_MOVE_SIZE);
154: switch (succeeded) {
155: case FALSE:
156: printf("FAILED!\n");
157: break;
158: case TRUE:
159: printf("SUCCEEDED!\n");
160: break;
161: }
162:
163: /* do byte only */
164: cmpsrc = src;
165: cmpdst = dst;
166: bcopy(src, dst, 7);
167: succeeded = TRUE;
168: for (l = 0; l < 7; l++)
169: {
170: if (*cmpsrc++ != *cmpdst++)
171: {
172: succeeded = FALSE;
173: }
174: }
175: printf("byte only bcopy(src=0x%x,dst=0x%x,len=%d) ",src,dst,7);
176: switch (succeeded) {
177: case FALSE:
178: printf("FAILED!\n");
179: break;
180: case TRUE:
181: printf("SUCCEEDED!\n");
182: break;
183: }
184:
185: /* do copy in place */
186: cmpsrc = src;
187: cmpdst = dst+4;
188: bcopy(dst, dst+4, 7);
189: succeeded = TRUE;
190: for (l = 0; l < 7; l++)
191: {
192: if (*cmpsrc++ != *cmpdst++)
193: {
194: succeeded = FALSE;
195: }
196: }
197: printf("copy in place bcopy(src=0x%x,dst=0x%x,len=%d) ",dst,dst+4,7);
198: switch (succeeded) {
199: case FALSE:
200: printf("FAILED!\n");
201: break;
202: case TRUE:
203: printf("SUCCEEDED!\n");
204: break;
205: }
206: }
207:
208:
209: struct bcopy_callers {
210: int caller;
211: int count;
212: };
213:
214: typedef struct bcopy_callers bcopy_callers_t, *bcopy_callers_tPtr;
215:
216: bcopy_callers_t bcc[1024];
217: boolean_t bcc_inited = FALSE;
218:
219:
220: void bcopy_diag (
221: int caller
222: )
223: {
224: int i;
225:
226:
227: if (bcc_inited == FALSE)
228: {
229: for (i = 0; i < 1024; i++)
230: {
231: bcc[i].caller = 0;
232: bcc[i].count = 0;
233: bcc_inited = TRUE;
234: }
235: }
236: for (i = 0; i < 1024; i++)
237: {
238: if ( bcc[i].caller == caller )
239: {
240: bcc[i].count++;
241: return;
242: }
243: else if ((bcc[i].caller == 0) && (i < 1024))
244: {
245: bcc[i].caller = caller;
246: bcc[i].count = 1;
247: return;
248: }
249: }
250: }
251:
252: #endif /* DEBUG */
253:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.