2 * Copyright (c) 2000 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 64 bits in a Cray word
22 12345678901234567890123456789012
23 1234567890123456789012345678901234567890123456789012345678901234
24 ________________________________________________________________
25 < pid >< word-offset in file (same #) >< pid >
27 1234567890123456789012345678901234567890123456789012345678901234
28 ________________________________________________________________
29 < pid >< offset in file of this word >< pid >
32 8 bits to a bytes == character
37 #include <sys/param.h>
43 static char Errmsg[80];
45 #define LOWER16BITS(X) (X & 0177777)
46 #define LOWER32BITS(X) (X & 0xffffffff)
49 #define HIGHBITS(WRD, bits) ( (-1 << (64-bits)) & WRD)
50 #define LOWBITS(WRD, bits) ( (-1 >> (64-bits)) & WRD)
53 #define NBPBYTE 8 /* number bits per byte */
59 /***********************************************************************
62 * 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 15 bytes
63 * 1234567890123456789012345678901234567890123456789012345678901234 bits
64 * ________________________________________________________________ 1 word
65 * < pid >< offset in file of this word >< pid >
67 * the words are put together where offset zero is the start.
68 * thus, offset 16 is the start of the second full word
69 * Thus, offset 8 is in middle of word 1
70 ***********************************************************************/
72 datapidgen(pid, buffer, bsize, offset)
85 int woff; /* file offset for the word */
86 int boff; /* buffer offset or index */
89 num_full_words = bsize/NBPW;
92 if ( cnt=(offset % NBPW) ) { /* partial word */
96 printf("partial at beginning, cnt = %d, woff = %d\n", cnt, woff);
99 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
103 for (tmp=0; tmp<cnt; tmp++) { /* skip unused bytes */
107 for (; boff<(NBPW-cnt) && boff<bsize; boff++, chr++) {
116 num_full_words = (bsize-boff)/NBPW;
120 for (cnt=0; cnt<num_full_words; woff += NBPW, cnt++ ) {
122 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
125 for(tmp=0; tmp<NBPW; tmp++, chr++) {
126 buffer[boff++] = *chr;
128 /****** Only if wptr is a word ellined
129 wptr = (long *)&buffer[boff];
137 * partial word at end of buffer
140 if ( cnt=((bsize-boff) % NBPW) ) {
142 printf("partial at end\n");
144 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
148 for (tmp=0; tmp<cnt && boff<bsize; tmp++, chr++) {
149 buffer[boff++] = *chr;
156 return -1; /* not support on non-64 bits word machines */
162 /***********************************************************************
165 ***********************************************************************/
167 datapidchk(pid, buffer, bsize, offset, errmsg)
181 int woff; /* file offset for the word */
182 int boff; /* buffer offset or index */
186 if ( errmsg != NULL ) {
191 num_full_words = bsize/NBPW;
194 if ( cnt=(offset % NBPW) ) { /* partial word */
196 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
200 for (tmp=0; tmp<cnt; tmp++) { /* skip unused bytes */
204 for (; boff<(NBPW-cnt) && boff<bsize; boff++, chr++) {
205 if (buffer[boff] != *chr) {
206 sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
207 offset+boff, *chr, buffer[boff]);
217 num_full_words = (bsize-boff)/NBPW;
221 for (cnt=0; cnt<num_full_words; woff += NBPW, cnt++ ) {
222 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
225 for(tmp=0; tmp<NBPW; tmp++, boff++, chr++) {
226 if ( buffer[boff] != *chr ) {
227 sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
228 woff, *chr, buffer[boff]);
233 /****** only if a word elined
234 wptr = (long *)&buffer[boff];
235 if ( *wptr != word ) {
236 sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
245 * partial word at end of buffer
248 if ( cnt=((bsize-boff) % NBPW) ) {
250 printf("partial at end\n");
252 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
257 for (tmp=0; tmp<cnt && boff<bsize; boff++, tmp++, chr++) {
258 if ( buffer[boff] != *chr ) {
259 sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
260 offset+boff, *chr, buffer[boff]);
266 sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
267 return -1; /* buffer is ok */
271 if ( errmsg != NULL ) {
274 sprintf(Errmsg, "Not supported on this OS.");
280 } /* end of datapidchk */
284 /***********************************************************************
285 * main for doing unit testing
286 ***********************************************************************/
298 if ((buffer=(char *)malloc(size)) == NULL ) {
304 datapidgen(-1, buffer, size, 3);
307 fwrite(buffer, size, 1, stdout);
308 fwrite("\n", 1, 1, stdout);
311 printf("datapidgen(-1, buffer, size, 3)\n");
313 ret=datapidchk(-1, buffer, size, 3, &errmsg);
314 printf("datapidchk(-1, buffer, %d, 3, &errmsg) returned %d %s\n",
316 ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
317 printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
318 size-1, ret, errmsg);
324 printf("changing char 25-28\n");
326 ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
327 printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
328 size-1, ret, errmsg);
330 printf("------------------------------------------\n");
332 datapidgen(getpid(), buffer, size, 5);
335 fwrite(buffer, size, 1, stdout);
336 fwrite("\n", 1, 1, stdout);
339 printf("\ndatapidgen(getpid(), buffer, size, 5)\n");
341 ret=datapidchk(getpid(), buffer, size, 5, &errmsg);
342 printf("datapidchk(getpid(), buffer, %d, 5, &errmsg) returned %d %s\n",
345 ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
346 printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
347 size-1, ret, errmsg);
350 printf("changing char 25\n");
352 ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
353 printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
354 size-1, ret, errmsg);