"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  

endian.c

Go to the documentation of this file.
00001 /*
00002  * endian.c - host endian probes
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: endian.c,v 1.1.1.1 2000/05/26 15:18:57 taustin Exp $
00053  *
00054  * $Log: endian.c,v $
00055  * Revision 1.1.1.1  2000/05/26 15:18:57  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  * Revision 1.5  1998/08/27 08:23:44  taustin
00060  * implemented host interface description in host.h
00061  *
00062  * Revision 1.4  1997/03/11  01:10:18  taustin
00063  * updated copyright
00064  *
00065  * Revision 1.3  1997/01/06  15:58:32  taustin
00066  * comments updated
00067  *
00068  * Revision 1.1  1996/12/05  18:52:32  taustin
00069  * Initial revision
00070  *
00071  *
00072  */
00073 
00074 #include "endian.h"
00075 #ifndef HOST_ONLY
00076 #include "loader.h"
00077 #endif
00078 
00079 /* probe host (simulator) byte endian format */
00080 enum endian_t
00081 endian_host_byte_order(void)
00082 {
00083   int i = 1, *p;
00084 
00085   p = &i;
00086   if (*((char *)p) == 1)
00087     return endian_little;
00088   else if (*((char *)p) == 0)
00089     return endian_big;
00090   else
00091     return endian_unknown;
00092 }
00093 
00094 /* probe host (simulator) double word endian format */
00095 enum endian_t
00096 endian_host_word_order(void)
00097 {
00098   int *p;
00099   double x = 1.0;
00100 
00101   /* NOTE: this check assumes IEEE floating point format */
00102   p = (int *)&x;
00103   if (*p == 0)
00104     return endian_little;
00105   else if (*p == 0x3ff00000)
00106     return endian_big;
00107   else
00108     return endian_unknown;
00109 }
00110 
00111 #ifndef HOST_ONLY
00112 
00113 /* probe target (simulated program) byte endian format, only
00114    valid after program has been loaded */
00115 enum endian_t
00116 endian_target_byte_order(void)
00117 {
00118   return ld_target_big_endian ? endian_big : endian_little;
00119 }
00120 
00121 /* probe target (simulated program) double word endian format,
00122    only valid after program has been loaded */
00123 enum endian_t
00124 endian_target_word_order(void)
00125 {
00126   /* same as byte sex for SimpleScalar target */
00127   return endian_target_byte_order();
00128 }
00129 
00130 #endif /* !HOST_ONLY */


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