"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 File Reference

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "host.h"
#include "misc.h"
#include "endian.c"

Include dependency graph for sysprobe.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define CAT a,
     a/**/b
 

Definition at line 121 of file sysprobe.c.

Referenced by main().

#define HOST_ONLY
 

Definition at line 118 of file sysprobe.c.

#define MSB   0x80000000
 

Definition at line 123 of file sysprobe.c.

Referenced by fast_SRA(), and fast_SRL().


Function Documentation

int fast_SRA void   
 

Definition at line 149 of file sysprobe.c.

References FALSE, MSB, sword_t, and TRUE.

Referenced by main().

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 }

int fast_SRL void   
 

Definition at line 125 of file sysprobe.c.

References FALSE, MSB, TRUE, and word_t.

Referenced by main().

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 }

int main int    argc,
char **    argv
 

Definition at line 173 of file sysprobe.c.

References CAT, endian_big, endian_host_byte_order(), endian_host_word_order(), endian_little, endian_unknown, fast_SRA(), fast_SRL(), and gzip_paths.

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 }


Variable Documentation

char* gzip_paths[]
 

Initial value:

{
  "/bin/gzip",
  "/usr/bin/gzip",
  "/usr/local/bin/gzip",
  "/usr/intel/bin/gzip",
  "/usr/gnu/bin/gzip",
  "/usr/local/gnu/bin",
  NULL
}

Definition at line 107 of file sysprobe.c.

Referenced by main().



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