Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: basics.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | /* | |
24 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. | |
25 | * Use is subject to license terms. | |
26 | */ | |
27 | ||
28 | #ifndef _BASICS_H_ | |
29 | #define _BASICS_H_ | |
30 | ||
31 | #pragma ident "@(#)basics.h 1.22 07/03/19 SMI" | |
32 | ||
33 | #ifdef __cplusplus | |
34 | extern "C" { | |
35 | #endif | |
36 | ||
37 | #include <sys/int_limits.h> | |
38 | #include "hostos.h" | |
39 | #include "hostcpu.h" | |
40 | #include "options.h" | |
41 | #include "rotlog.h" | |
42 | ||
43 | /* | |
44 | * Generic typedefs | |
45 | * | |
46 | * ... these type defs are so that the | |
47 | * types can be used as pointers. The actual structure | |
48 | * definitions are elsewhere. | |
49 | */ | |
50 | ||
51 | typedef uint64_t simcycle_t; | |
52 | ||
53 | typedef struct SIMSTATUS simstatus_t; | |
54 | typedef struct SIMCPU simcpu_t; | |
55 | typedef struct EXEC_THREAD exec_thread_t; | |
56 | typedef struct PROC_DEBUG proc_debug_t; | |
57 | ||
58 | /* | |
59 | * Generic physical and virtual address types. | |
60 | * | |
61 | * Core design is 64 bit addressing, however some | |
62 | * chips & cores may use 32bits in which case the | |
63 | * bit widths should be explicit, but for the general | |
64 | * infrastructure types use these two. | |
65 | */ | |
66 | ||
67 | typedef uint64_t tpaddr_t; | |
68 | typedef uint64_t tvaddr_t; | |
69 | ||
70 | /* | |
71 | * Some simple debugging stuff | |
72 | */ | |
73 | ||
74 | #ifdef NDEBUG | |
75 | #define ASSERT(_t) do { } while (0) | |
76 | #else | |
77 | #include <assert.h> | |
78 | #define ASSERT(_t) assert(_t) | |
79 | #endif | |
80 | ||
81 | #ifdef NDEBUG | |
82 | #define SANITY(_t) do { } while (0) | |
83 | #else | |
84 | #define SANITY(_t) do { _t } while (0) | |
85 | #endif | |
86 | ||
87 | #ifdef NDEBUG | |
88 | #define DBG(s) do { } while (0) | |
89 | #define LOG_INIT() do { } while (0) | |
90 | #else | |
91 | extern uint64_t debug_bits; | |
92 | extern uint64_t debug_bits_xor; | |
93 | #define DBG_BASIC 0x1 | |
94 | #define DBG(s) do { if (debug_bits & DBG_BASIC) { s } } while (0) | |
95 | #define LOG_INIT() do { log_init(); } while (0) | |
96 | #endif | |
97 | ||
98 | /* | |
99 | * Global Data Structures exported simulator wide | |
100 | */ | |
101 | extern options_t options; | |
102 | extern simstatus_t simstatus; | |
103 | ||
104 | /* | |
105 | * All non-essential printing now goes through one of these macros | |
106 | * so that we can control what gets printed using the options.verbose | |
107 | * flag. | |
108 | */ | |
109 | #define PRINTF(_s) do { if (options.verbose) printf _s ; } while (0) | |
110 | #define FPRINTF(_s) do { if (options.verbose) fprintf _s ; } while (0) | |
111 | #define LPRINTF(_s) do { if (options.verbose) lprintf _s ; } while (0) | |
112 | #define WARNING(_s) do { if (options.verbose) warning _s ; } while (0) | |
113 | ||
114 | /* | |
115 | * Note: the following warnings are intended to be used as follows: | |
116 | * | |
117 | * FIXME_WARNING Indended for stuff yet to be done. This warning is emitted | |
118 | * by code either partially complete or functionality not yet | |
119 | * implemented. | |
120 | * IMPL_WARNING Intended for warnings triggered by particular chip | |
121 | * implementation. e.g. accesses to certain register bit fields | |
122 | * that may not be used/legal on a particular implementation. | |
123 | * EXEC_WARNING Intended for errors/warnings for illegal / unusual behaviour | |
124 | * of the code running on the simulator. Can be useful for | |
125 | * debugging the correct execution of code. | |
126 | */ | |
127 | ||
128 | #ifdef NDEBUG | |
129 | #define FIXME_WARNING(_s) do { } while (0) | |
130 | #define IMPL_WARNING(_s) do { } while (0) | |
131 | #define EXEC_WARNING(_s) do { } while (0) | |
132 | #else | |
133 | #define _ONCE(_s) do { static bool_t __once ; if (!__once) { __once = true; _s ; } } while (0) | |
134 | #define FIXME_WARNING(_s) _ONCE( FPRINTF((stderr, "FIXME: ")); WARNING( _s );) | |
135 | #define IMPL_WARNING(_s) _ONCE( FPRINTF((stderr, "implementation ")); WARNING( _s );) | |
136 | #define EXEC_WARNING(_s) do { FPRINTF((stderr, "execution ")); WARNING( _s ); } while (0) | |
137 | #endif | |
138 | /* | |
139 | * Macros used if simulator performance measurement is required | |
140 | */ | |
141 | ||
142 | #if PERFORMANCE_CHECK /* { */ | |
143 | #define PERFDEF(_s) _s | |
144 | #define PERF(_s) do { _s ; } while (0) | |
145 | #else /* } { */ | |
146 | #define PERFDEF(_s) | |
147 | #define PERF(_s) do { } while (0) | |
148 | #endif /* } */ | |
149 | ||
150 | /* | |
151 | * Some simple maths macros | |
152 | */ | |
153 | ||
154 | #define Sizeof(_s) ((unsigned)sizeof(_s)) | |
155 | ||
156 | #define INC_MOD(_val, _mod) (((_val)+1)==(_mod) ? 0 : ((_val)+1)) | |
157 | #define DEC_MOD(_val, _mod) ((_val)==0 ? ((_mod)-1) : ((_val)-1)) | |
158 | ||
159 | ||
160 | /* This macro creates a 64bit (uint64_t) mask for the high to low bits specified */ | |
161 | /* we could do this with just two shifts, but since most architectures have */ | |
162 | /* a single pipelined shifter this is faster than waiting two shift latencies */ | |
163 | /* Of course if constants are provided, then the compiler can do a better job */ | |
164 | /* This also evaluates both high and low only once */ | |
165 | ||
166 | #define MASK64( _high, _low ) ( ( (uint64_t)((~(uint64_t)0)>>(63-(_high))) ) & ( (uint64_t)( (~(uint64_t)0)<<(_low)) ) ) | |
167 | ||
168 | ||
169 | ||
170 | /* | |
171 | * Basic functions we expect to be able to use everywhere | |
172 | */ | |
173 | ||
174 | extern uint64_t sim_roundup(uint64_t value, uint64_t round); | |
175 | #define HRT_TO_SEC( _x ) ((_x) / NANOSEC) | |
176 | #define HRT_TO_MILLISEC( _x ) ((_x) / MICROSEC) | |
177 | ||
178 | /* | |
179 | * Sign extension - _bits is the significant bits in | |
180 | * integer _i. | |
181 | */ | |
182 | #define _SE_SHIFT(_i, _bits) ((sizeof(_i)*8)-(_bits)) | |
183 | #define SIGN_EXT(_i, _bits) ((_i) = (((_i) << _SE_SHIFT(_i, _bits)) \ | |
184 | >> _SE_SHIFT(_i, _bits))) | |
185 | ||
186 | ||
187 | #ifdef __cplusplus | |
188 | } | |
189 | #endif | |
190 | ||
191 | #endif /* _BASICS_H_ */ |