Commit | Line | Data |
---|---|---|
8ad57737 | 1 | /*> support.h <*/ |
a647a859 JSC |
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 | */ | |
8ad57737 JSC |
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 */ | |
dbeec768 | 33 | #if defined(__GNUC__) || defined(_WIN32) |
8ad57737 | 34 | |
dbeec768 | 35 | #ifdef _WIN32 |
2902e8ab MA |
36 | #define SIGTRAP 5 |
37 | #define SIGQUIT 3 | |
4fa14cf7 SG |
38 | typedef signed __int64 word64; |
39 | typedef unsigned __int64 uword64; | |
40 | #else | |
8ad57737 JSC |
41 | typedef long long word64; |
42 | typedef unsigned long long uword64; | |
4fa14cf7 | 43 | #endif |
8ad57737 JSC |
44 | |
45 | #define WORD64LO(t) (unsigned int)((t)&0xFFFFFFFF) | |
a647a859 JSC |
46 | #define WORD64HI(t) (unsigned int)(((uword64)(t))>>32) |
47 | #define SET64LO(t) (((uword64)(t))&0xFFFFFFFF) | |
48 | #define SET64HI(t) (((uword64)(t))<<32) | |
276c2d7d GRK |
49 | #define WORD64(h,l) ((word64)((SET64HI(h)|SET64LO(l)))) |
50 | #define UWORD64(h,l) (SET64HI(h)|SET64LO(l)) | |
8ad57737 JSC |
51 | |
52 | /* Sign-extend the given value (e) as a value (b) bits long. We cannot | |
53 | assume the HI32bits of the operand are zero, so we must perform a | |
54 | mask to ensure we can use the simple subtraction to sign-extend. */ | |
149ee672 ILT |
55 | #define SIGNEXTEND(e,b) \ |
56 | (((e) & ((uword64) 1 << ((b) - 1))) \ | |
57 | ? (((e) & (((uword64) 1 << (b)) - 1)) - ((uword64)1 << (b))) \ | |
58 | : ((e) & (((((uword64) 1 << ((b) - 1)) - 1) << 1) | 1))) | |
8ad57737 JSC |
59 | |
60 | /* Check if a value will fit within a word (unsigned int): */ | |
4fa14cf7 | 61 | #define NOTWORDVALUE(v) ((((((uword64)(v)>>32) == 0) && !((v) & ((unsigned)1 << 31))) || ((((uword64)(v)>>32) == 0xFFFFFFFF) && ((v) & ((unsigned)1 << 31)))) ? (1 == 0) : (1 == 1)) |
8ad57737 JSC |
62 | |
63 | /* Check if a value will fit within a halfword: */ | |
4fa14cf7 | 64 | #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)) |
8ad57737 JSC |
65 | |
66 | /* The following should be executed once at the start of day in the | |
67 | main emulator control function. The simulator assumes char is | |
68 | 8bits, and from this: */ | |
69 | #define CHECKSIM() {\ | |
70 | if (sizeof(int) != (4 * sizeof(char)))\ | |
71 | SignalException(SimulatorFault,"sizeof(int) != 4");\ | |
4fa14cf7 SG |
72 | if (sizeof(word64) != (8 * sizeof(char)))\ |
73 | SignalException(SimulatorFault,"sizeof(word64) != 8");\ | |
8ad57737 JSC |
74 | } |
75 | ||
76 | #else /* non-GCC build */ | |
77 | ||
78 | #error "non-GCC build to be completed" /* avoid using long long */ | |
79 | ||
a647a859 | 80 | typedef struct uword64 { |
8ad57737 JSC |
81 | unsigned int lo; |
82 | unsigned int hi; | |
a647a859 | 83 | } uword64; |
8ad57737 JSC |
84 | |
85 | #define WORD64LO(t) (unsigned int)(t.lo) | |
86 | #define WORD64HI(t) (unsigned int)(t.hi) | |
a647a859 JSC |
87 | #define SET64LO(t) (..TODO..) /* need structure into which value will be placed */ |
88 | #define SET64HI(t) (..TODO..) /* need structure into which value will be placed */ | |
276c2d7d | 89 | #define WORD64(h,l) (SET64HI(h)|SET64LO(l)) |
8ad57737 JSC |
90 | |
91 | /* TODO: Update these to manipulate the split structure values */ | |
92 | #define SIGNEXTEND(e,b) /* TODO */ | |
93 | #define NOTWORDVALUE(v) /* TODO */ | |
94 | #define NOTHALFWORDVALUE(v) /* TODO */ | |
95 | ||
96 | /* The following should be executed once at the start of day in the | |
97 | main emulator control function. The simulator assumes char is | |
98 | 8bits, and from this: */ | |
99 | #define CHECKSIM() {\ | |
100 | if (sizeof(int) != (4 * sizeof(char)))\ | |
837d2893 | 101 | SignalException(SimulatorFault,"sizeof(int) != 4");\ |
8ad57737 JSC |
102 | } |
103 | ||
104 | #endif /* non-GCC build */ | |
105 | ||
106 | #endif /* __support_h */ | |
107 | ||
108 | /*> EOF support.h <*/ |