"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

sysprobe.c

Go to the documentation of this file.
00001 /*
00002  * sysprobe.c - host endian probe implementation
00003  *
00004  * This file is a part of the SimpleScalar tool suite written by
00005  * Todd M. Austin as a part of the Multiscalar Research Project.
00006  *  
00007  * The tool suite is currently maintained by Doug Burger and Todd M. Austin.
00008  * 
00009  * Copyright (C) 1994, 1995, 1996, 1997, 1998 by Todd M. Austin
00010  *
00011  * This source file is distributed "as is" in the hope that it will be
00012  * useful.  The tool set comes with no warranty, and no author or
00013  * distributor accepts any responsibility for the consequences of its
00014  * use. 
00015  * 
00016  * Everyone is granted permission to copy, modify and redistribute
00017  * this tool set under the following conditions:
00018  * 
00019  *    This source code is distributed for non-commercial use only. 
00020  *    Please contact the maintainer for restrictions applying to 
00021  *    commercial use.
00022  *
00023  *    Permission is granted to anyone to make or distribute copies
00024  *    of this source code, either as received or modified, in any
00025  *    medium, provided that all copyright notices, permission and
00026  *    nonwarranty notices are preserved, and that the distributor
00027  *    grants the recipient permission for further redistribution as
00028  *    permitted by this document.
00029  *
00030  *    Permission is granted to distribute this file in compiled
00031  *    or executable form under the same conditions that apply for
00032  *    source code, provided that either:
00033  *
00034  *    A. it is accompanied by the corresponding machine-readable
00035  *       source code,
00036  *    B. it is accompanied by a written offer, with no time limit,
00037  *       to give anyone a machine-readable copy of the corresponding
00038  *       source code in return for reimbursement of the cost of
00039  *       distribution.  This written offer must permit verbatim
00040  *       duplication by anyone, or
00041  *    C. it is distributed by someone who received only the
00042  *       executable form, and is accompanied by a copy of the
00043  *       written offer of source code that they received concurrently.
00044  *
00045  * In other words, you are welcome to use, share and improve this
00046  * source file.  You are forbidden to forbid anyone else to use, share
00047  * and improve what you give them.
00048  *
00049  * INTERNET: dburger@cs.wisc.edu
00050  * US Mail:  1210 W. Dayton Street, Madison, WI 53706
00051  *
00052  * $Id: sysprobe.c,v 1.1.1.1 2000/05/26 15:18:58 taustin Exp $
00053  *
00054  * $Log: sysprobe.c,v $
00055  * Revision 1.1.1.1  2000/05/26 15:18:58  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  * Revision 1.8  1999/12/31 18:54:24  taustin
00060  * Linux support updated
00061  *
00062  * Revision 1.7  1998/09/03 22:24:34  taustin
00063  * only locate first GZIP binary
00064  *
00065  * Revision 1.6  1998/08/31 17:11:36  taustin
00066  * ported to MS VC++
00067  *
00068  * Revision 1.5  1998/08/27 16:45:59  taustin
00069  * implemented host interface description in host.h
00070  * added target interface support
00071  * added gzopen() and gzclose() routines for reading and writing
00072  *       compressed files, updated sysprobe to search for GZIP, if found
00073  *       support is enabled
00074  * added support for fast shifts if host machine can successfully implement
00075  *       them, sysprobe tests if fast shifts work and then sets -DFAST_SRA and
00076  *       -DFAST_SRL accordingly
00077  * added "-t" option on sysprobe that probes sizes of various C data types
00078  *
00079  * Revision 1.4  1997/04/16  22:12:36  taustin
00080  * added standalone loader support
00081  *
00082  * Revision 1.3  1997/03/11  01:35:38  taustin
00083  * updated copyright
00084  * support added for portable SYMCAT()
00085  * -libs support added for portability
00086  * -flags support added for portability
00087  * various target supports added
00088  *
00089  * Revision 1.1  1996/12/05  18:52:32  taustin
00090  * Initial revision
00091  *
00092  *
00093  */
00094 
00095 #include <stdio.h>
00096 #include <stdlib.h>
00097 #ifndef _MSC_VER
00098 #include <unistd.h>
00099 #else /* _MSC_VER */
00100 #define access  _access
00101 #define X_OK    4
00102 #endif
00103 
00104 #include "host.h"
00105 #include "misc.h"
00106 
00107 char *gzip_paths[] =
00108 {
00109   "/bin/gzip",
00110   "/usr/bin/gzip",
00111   "/usr/local/bin/gzip",
00112   "/usr/intel/bin/gzip",
00113   "/usr/gnu/bin/gzip",
00114   "/usr/local/gnu/bin",
00115   NULL
00116 };
00117 
00118 #define HOST_ONLY
00119 #include "endian.c"
00120 
00121 #define CAT(a,b)        ab
00122 
00123 #define MSB             0x80000000
00124 int
00125 fast_SRL(void)
00126 {
00127   word_t ui;
00128 
00129   if (sizeof(ui) != 4)
00130     {
00131       /* fundamental size assumption broken - emulate SRL */
00132       return FALSE;
00133     }
00134 
00135   ui = (word_t)MSB;
00136   if (((ui >> 1) & MSB) != 0)
00137     {
00138       /* unsigned int does SRA - emulate SRL */
00139       return FALSE;
00140     }
00141   else
00142     {
00143       /* unsigned int does SRL - use fast native SRL */
00144       return TRUE;
00145     }
00146 }
00147 
00148 int
00149 fast_SRA(void)
00150 {
00151   sword_t si;
00152 
00153   if (sizeof(si) != 4)
00154     {
00155       /* fundamental size assumption broken - emulate SRA */
00156       return FALSE;
00157     }
00158 
00159   si = (sword_t)MSB;
00160   if ((si >> 1) & MSB)
00161     {
00162       /* signed int does SRA - use fast native SRA */
00163       return TRUE;
00164     }
00165   else
00166     {
00167       /* singned int does SRL - emulate SRA */
00168       return FALSE;
00169     }
00170 }
00171 
00172 int
00173 main(int argc, char **argv)
00174 {
00175   int little_bytes = 0, little_words = 0;
00176 
00177   if (argc == 2 && !strcmp(argv[1], "-s"))
00178     {
00179       switch (endian_host_byte_order())
00180         {
00181         case endian_big:
00182           fprintf(stdout, "big\n");
00183           break;
00184         case endian_little:
00185           fprintf(stdout, "little\n");
00186           break;
00187         case endian_unknown:
00188           fprintf(stderr, "\nerror: cannot determine byte order!\n");
00189           exit(1);
00190         default:
00191           abort();
00192         }
00193     }
00194   else if (argc == 2 && !strcmp(argv[1], "-libs"))
00195     {
00196 #ifdef BFD_LOADER
00197       fprintf(stdout, "-lbfd -liberty ");
00198 #endif /* BFD_LOADER */
00199 
00200 #ifdef linux
00201       /* nada... */
00202 #elif defined(__USLC__) || (defined(__svr4__) && defined(__i386__) && defined(__unix__))
00203       fprintf(stdout, "-L/usr/ucblib -lucb ");
00204 #else
00205       /* nada */
00206 #endif
00207       fprintf(stdout, " \n");
00208     }
00209   else if (argc == 1 || (argc == 2 && !strcmp(argv[1], "-flags")))
00210     {
00211       switch (endian_host_byte_order())
00212         {
00213         case endian_big:
00214           fprintf(stdout, "-DBYTES_BIG_ENDIAN ");
00215           break;
00216         case endian_little:
00217           fprintf(stdout, "-DBYTES_LITTLE_ENDIAN ");
00218           little_bytes = 1;
00219           break;
00220         case endian_unknown:
00221           fprintf(stderr, "\nerror: cannot determine byte order!\n");
00222           exit(1);
00223         default:
00224           abort();
00225         }
00226 
00227       switch (endian_host_word_order())
00228         {
00229         case endian_big:
00230           fprintf(stdout, "-DWORDS_BIG_ENDIAN ");
00231           break;
00232         case endian_little:
00233           fprintf(stdout, "-DWORDS_LITTLE_ENDIAN ");
00234           little_words = 1;
00235           break;
00236         case endian_unknown:
00237           fprintf(stderr, "\nerror: cannot determine word order!\n");
00238           exit(1);
00239         default:
00240           abort();
00241         }
00242 
00243 #ifdef _AIX
00244         fprintf(stdout, "-D_ALL_SOURCE ");
00245 #endif /* _AIX */
00246 
00247 #if (defined(hpux) || defined(__hpux)) && !defined(__GNUC__)
00248         fprintf(stdout, "-D_INCLUDE_HPUX_SOURCE -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_AES_SOURCE ");
00249 #endif /* hpux */
00250 
00251 #ifndef __GNUC__
00252       /* probe compiler approach needed to concatenate symbols in CPP,
00253          new style concatenation is always used with GNU GCC */
00254       {
00255         int i = 5, j;
00256 
00257         j = CAT(-,-i);
00258 
00259         if (j == 4)
00260           {
00261             /* old style symbol concatenation worked */
00262             fprintf(stdout, "-DOLD_SYMCAT ");
00263           }
00264         else if (j == 5)
00265           {
00266             /* old style symbol concatenation does not work, assume that
00267                new style symbol concatenation works */
00268             ;
00269           }
00270         else
00271           {
00272             /* huh!?!?! */
00273             fprintf(stderr, "\nerror: cannot grok symbol concat method!\n");
00274             exit(1);
00275           }
00276       }
00277 #endif /* __GNUC__ */
00278 
00279 #ifndef SLOW_SHIFTS
00280       /* probe host shift capabilities */
00281       if (fast_SRL())
00282         fprintf(stdout, "-DFAST_SRL ");
00283       if (fast_SRA())
00284         fprintf(stdout, "-DFAST_SRA ");
00285 #endif /* !SLOW_SHIFTS */
00286 
00287       /* locate GZIP */
00288 #ifndef GZIP_PATH
00289       {
00290         int i;
00291 
00292         for (i=0; gzip_paths[i] != NULL; i++)
00293           {
00294             if (access(gzip_paths[i], X_OK) == 0)
00295               {
00296                 fprintf(stdout, "-DGZIP_PATH=\"%s\" ", gzip_paths[i]);
00297                 break;
00298               }
00299           }
00300       }
00301 #endif /* !GZIP_PATH */
00302 
00303     }
00304   else if (argc == 2 && !strcmp(argv[1], "-t"))
00305     {
00306       fprintf(stdout, "sizeof(int) = %d\n", sizeof(int));
00307       fprintf(stdout, "sizeof(long) = %d\n", sizeof(long));
00308     }
00309 
00310 
00311   /* check for different byte/word endian-ness */
00312   if (little_bytes != little_words)
00313     {
00314       fprintf(stderr,
00315               "\nerror: opposite byte/word endian currently not supported!\n");
00316       exit(1);
00317     }
00318   exit(0);
00319   return 0;
00320 }
00321 


UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214