* gencode.c (process_instructions): Generate word64 and uword64
[binutils-gdb.git] / sim / mips / support.h
1 /*> support.h <*/
2 /* Support for the MIPS architecture simulator.
3
4 This file is part of the MIPS sim
5
6 THIS SOFTWARE IS NOT COPYRIGHTED
7
8 Cygnus offers the following for use in the public domain. Cygnus
9 makes no warranty with regard to the software or it's performance
10 and the user accepts the software "AS IS" with all faults.
11
12 CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
13 THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15
16 $Revision$
17 $Author$
18 $Date$
19 */
20
21 #ifndef __support_h
22 #define __support_h
23
24 /* For 64bit values either use the GCC "long long" feature, or have a
25 structure made from two 32bit values. We can then have macros for
26 accessing the LO and HI parts of the value. Also we can provide
27 macros for the basic operations we want to perform on 64bit values
28 (i.e. ADD64,SUB64,SHIFTLEFT64, etc.). This means we should be able
29 to host the simulator on non-GCC compilers, and 32bit only
30 architectures if desired. */
31
32 /* Control via a build boolean for the moment */
33 #if defined(__GNUC__) || defined(__WIN32__)
34
35 #ifdef __WIN32__
36 typedef signed __int64 word64;
37 typedef unsigned __int64 uword64;
38 #else
39 typedef long long word64;
40 typedef unsigned long long uword64;
41 #endif
42
43 #define WORD64LO(t) (unsigned int)((t)&0xFFFFFFFF)
44 #define WORD64HI(t) (unsigned int)(((uword64)(t))>>32)
45 #define SET64LO(t) (((uword64)(t))&0xFFFFFFFF)
46 #define SET64HI(t) (((uword64)(t))<<32)
47
48 /* Sign-extend the given value (e) as a value (b) bits long. We cannot
49 assume the HI32bits of the operand are zero, so we must perform a
50 mask to ensure we can use the simple subtraction to sign-extend. */
51 #define SIGNEXTEND(e,b) (((e) & ((uword64)1 << ((b) - 1))) ? (((e) & (((uword64)1 << (b)) - 1)) - ((uword64)1 << (b))) : (e))
52
53 /* Check if a value will fit within a word (unsigned int): */
54 #define NOTWORDVALUE(v) ((((((uword64)(v)>>32) == 0) && !((v) & ((unsigned)1 << 31))) || ((((uword64)(v)>>32) == 0xFFFFFFFF) && ((v) & ((unsigned)1 << 31)))) ? (1 == 0) : (1 == 1))
55
56 /* Check if a value will fit within a halfword: */
57 #define NOTHALFWORDVALUE(v) ((((((uword64)(v)>>16) == 0) && !((v) & ((unsigned)1 << 15))) || (((((uword64)(v)>>32) == 0xFFFFFFFF) && ((((uword64)(v)>>16) & 0xFFFF) == 0xFFFF)) && ((v) & ((unsigned)1 << 15)))) ? (1 == 0) : (1 == 1))
58
59 /* The following should be executed once at the start of day in the
60 main emulator control function. The simulator assumes char is
61 8bits, and from this: */
62 #define CHECKSIM() {\
63 if (sizeof(int) != (4 * sizeof(char)))\
64 SignalException(SimulatorFault,"sizeof(int) != 4");\
65 if (sizeof(word64) != (8 * sizeof(char)))\
66 SignalException(SimulatorFault,"sizeof(word64) != 8");\
67 }
68
69 #else /* non-GCC build */
70
71 #error "non-GCC build to be completed" /* avoid using long long */
72
73 typedef struct uword64 {
74 unsigned int lo;
75 unsigned int hi;
76 } uword64;
77
78 #define WORD64LO(t) (unsigned int)(t.lo)
79 #define WORD64HI(t) (unsigned int)(t.hi)
80 #define SET64LO(t) (..TODO..) /* need structure into which value will be placed */
81 #define SET64HI(t) (..TODO..) /* need structure into which value will be placed */
82
83 /* TODO: Update these to manipulate the split structure values */
84 #define SIGNEXTEND(e,b) /* TODO */
85 #define NOTWORDVALUE(v) /* TODO */
86 #define NOTHALFWORDVALUE(v) /* TODO */
87
88 /* The following should be executed once at the start of day in the
89 main emulator control function. The simulator assumes char is
90 8bits, and from this: */
91 #define CHECKSIM() {\
92 if (sizeof(int) != (4 * sizeof(char)))\
93 SignalException(SimulatorFault,"sizeof(int) != 4");\
94 }
95
96 #endif /* non-GCC build */
97
98 #endif /* __support_h */
99
100 /*> EOF support.h <*/