2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 64 bits in a Cray word
36 12345678901234567890123456789012
37 1234567890123456789012345678901234567890123456789012345678901234
38 ________________________________________________________________
39 < pid >< word-offset in file (same #) >< pid >
41 1234567890123456789012345678901234567890123456789012345678901234
42 ________________________________________________________________
43 < pid >< offset in file of this word >< pid >
46 8 bits to a bytes == character
51 #include <sys/param.h>
57 static char Errmsg[80];
59 #define LOWER16BITS(X) (X & 0177777)
60 #define LOWER32BITS(X) (X & 0xffffffff)
63 #define HIGHBITS(WRD, bits) ( (-1 << (64-bits)) & WRD)
64 #define LOWBITS(WRD, bits) ( (-1 >> (64-bits)) & WRD)
67 #define NBPBYTE 8 /* number bits per byte */
73 /***********************************************************************
76 * 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 15 bytes
77 * 1234567890123456789012345678901234567890123456789012345678901234 bits
78 * ________________________________________________________________ 1 word
79 * < pid >< offset in file of this word >< pid >
81 * the words are put together where offset zero is the start.
82 * thus, offset 16 is the start of the second full word
83 * Thus, offset 8 is in middle of word 1
84 ***********************************************************************/
86 datapidgen(pid, buffer, bsize, offset)
99 int woff; /* file offset for the word */
100 int boff; /* buffer offset or index */
103 num_full_words = bsize/NBPW;
106 if ( cnt=(offset % NBPW) ) { /* partial word */
110 printf("partial at beginning, cnt = %d, woff = %d\n", cnt, woff);
113 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
117 for (tmp=0; tmp<cnt; tmp++) { /* skip unused bytes */
121 for (; boff<(NBPW-cnt) && boff<bsize; boff++, chr++) {
130 num_full_words = (bsize-boff)/NBPW;
134 for (cnt=0; cnt<num_full_words; woff += NBPW, cnt++ ) {
136 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
139 for(tmp=0; tmp<NBPW; tmp++, chr++) {
140 buffer[boff++] = *chr;
142 /****** Only if wptr is a word ellined
143 wptr = (long *)&buffer[boff];
151 * partial word at end of buffer
154 if ( cnt=((bsize-boff) % NBPW) ) {
156 printf("partial at end\n");
158 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
162 for (tmp=0; tmp<cnt && boff<bsize; tmp++, chr++) {
163 buffer[boff++] = *chr;
170 return -1; /* not support on non-64 bits word machines */
176 /***********************************************************************
179 ***********************************************************************/
181 datapidchk(pid, buffer, bsize, offset, errmsg)
195 int woff; /* file offset for the word */
196 int boff; /* buffer offset or index */
200 if ( errmsg != NULL ) {
205 num_full_words = bsize/NBPW;
208 if ( cnt=(offset % NBPW) ) { /* partial word */
210 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
214 for (tmp=0; tmp<cnt; tmp++) { /* skip unused bytes */
218 for (; boff<(NBPW-cnt) && boff<bsize; boff++, chr++) {
219 if (buffer[boff] != *chr) {
220 sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
221 offset+boff, *chr, buffer[boff]);
231 num_full_words = (bsize-boff)/NBPW;
235 for (cnt=0; cnt<num_full_words; woff += NBPW, cnt++ ) {
236 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
239 for(tmp=0; tmp<NBPW; tmp++, boff++, chr++) {
240 if ( buffer[boff] != *chr ) {
241 sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
242 woff, *chr, buffer[boff]);
247 /****** only if a word elined
248 wptr = (long *)&buffer[boff];
249 if ( *wptr != word ) {
250 sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
259 * partial word at end of buffer
262 if ( cnt=((bsize-boff) % NBPW) ) {
264 printf("partial at end\n");
266 word = ((LOWER16BITS(pid) << 48) | (LOWER32BITS(woff) << 16) | LOWER16BITS(pid));
271 for (tmp=0; tmp<cnt && boff<bsize; boff++, tmp++, chr++) {
272 if ( buffer[boff] != *chr ) {
273 sprintf(Errmsg, "Data mismatch at offset %d, exp:%#o, act:%#o",
274 offset+boff, *chr, buffer[boff]);
280 sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
281 return -1; /* buffer is ok */
285 if ( errmsg != NULL ) {
288 sprintf(Errmsg, "Not supported on this OS.");
294 } /* end of datapidchk */
298 /***********************************************************************
299 * main for doing unit testing
300 ***********************************************************************/
312 if ((buffer=(char *)malloc(size)) == NULL ) {
318 datapidgen(-1, buffer, size, 3);
321 fwrite(buffer, size, 1, stdout);
322 fwrite("\n", 1, 1, stdout);
325 printf("datapidgen(-1, buffer, size, 3)\n");
327 ret=datapidchk(-1, buffer, size, 3, &errmsg);
328 printf("datapidchk(-1, buffer, %d, 3, &errmsg) returned %d %s\n",
330 ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
331 printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
332 size-1, ret, errmsg);
338 printf("changing char 25-28\n");
340 ret=datapidchk(-1, &buffer[1], size-1, 4, &errmsg);
341 printf("datapidchk(-1, &buffer[1], %d, 4, &errmsg) returned %d %s\n",
342 size-1, ret, errmsg);
344 printf("------------------------------------------\n");
346 datapidgen(getpid(), buffer, size, 5);
349 fwrite(buffer, size, 1, stdout);
350 fwrite("\n", 1, 1, stdout);
353 printf("\ndatapidgen(getpid(), buffer, size, 5)\n");
355 ret=datapidchk(getpid(), buffer, size, 5, &errmsg);
356 printf("datapidchk(getpid(), buffer, %d, 5, &errmsg) returned %d %s\n",
359 ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
360 printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
361 size-1, ret, errmsg);
364 printf("changing char 25\n");
366 ret=datapidchk(getpid(), &buffer[1], size-1, 6, &errmsg);
367 printf("datapidchk(getpid(), &buffer[1], %d, 6, &errmsg) returned %d %s\n",
368 size-1, ret, errmsg);