VirtualBox

source: vbox/trunk/src/recompiler_new/cpu-defs.h@ 13357

Last change on this file since 13357 was 13357, checked in by vboxsync, 17 years ago

new codegen compiles, very unlikely works

  • Property svn:eol-style set to native
File size: 13.5 KB
Line 
1/*
2 * common defines for all CPUs
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
23 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
24 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
25 * a choice of LGPL license versions is made available with the language indicating
26 * that LGPLv2 or any later version may be used, or where a choice of which version
27 * of the LGPL is applied is otherwise unspecified.
28 */
29#ifndef CPU_DEFS_H
30#define CPU_DEFS_H
31
32#include "config.h"
33#include <setjmp.h>
34#include <inttypes.h>
35#include "osdep.h"
36
37#ifndef TARGET_LONG_BITS
38#error TARGET_LONG_BITS must be defined before including this header
39#endif
40
41#ifndef TARGET_PHYS_ADDR_BITS
42#if TARGET_LONG_BITS >= HOST_LONG_BITS
43#define TARGET_PHYS_ADDR_BITS TARGET_LONG_BITS
44#else
45#define TARGET_PHYS_ADDR_BITS HOST_LONG_BITS
46#endif
47#endif
48
49#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
50
51/* target_ulong is the type of a virtual address */
52#if TARGET_LONG_SIZE == 4
53typedef int32_t target_long;
54typedef uint32_t target_ulong;
55#define TARGET_FMT_lx "%08x"
56#define TARGET_FMT_ld "%d"
57#define TARGET_FMT_lu "%u"
58#elif TARGET_LONG_SIZE == 8
59typedef int64_t target_long;
60typedef uint64_t target_ulong;
61#define TARGET_FMT_lx "%016" PRIx64
62#define TARGET_FMT_ld "%" PRId64
63#define TARGET_FMT_lu "%" PRIu64
64#else
65#error TARGET_LONG_SIZE undefined
66#endif
67
68/* target_phys_addr_t is the type of a physical address (its size can
69 be different from 'target_ulong'). We have sizeof(target_phys_addr)
70 = max(sizeof(unsigned long),
71 sizeof(size_of_target_physical_address)) because we must pass a
72 host pointer to memory operations in some cases */
73
74#if TARGET_PHYS_ADDR_BITS == 32
75typedef uint32_t target_phys_addr_t;
76#define TARGET_FMT_plx "%08x"
77#elif TARGET_PHYS_ADDR_BITS == 64
78typedef uint64_t target_phys_addr_t;
79#define TARGET_FMT_plx "%016" PRIx64
80#else
81#error TARGET_PHYS_ADDR_BITS undefined
82#endif
83
84#define HOST_LONG_SIZE (HOST_LONG_BITS / 8)
85
86#define EXCP_INTERRUPT 0x10000 /* async interruption */
87#define EXCP_HLT 0x10001 /* hlt instruction reached */
88#define EXCP_DEBUG 0x10002 /* cpu stopped after a breakpoint or singlestep */
89#define EXCP_HALTED 0x10003 /* cpu is halted (waiting for external event) */
90#if defined(VBOX)
91#define EXCP_EXECUTE_RAW 0x11024 /* execute raw mode. */
92#define EXCP_EXECUTE_HWACC 0x11025 /* execute hardware accelerated raw mode. */
93#define EXCP_SINGLE_INSTR 0x11026 /* executed single instruction. */
94#define EXCP_RC 0x11027 /* a EM rc was raised (VMR3Reset/Suspend/PowerOff). */
95#endif /* VBOX */
96#define MAX_BREAKPOINTS 32
97#define MAX_WATCHPOINTS 32
98
99#define TB_JMP_CACHE_BITS 12
100#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
101
102/* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
103 addresses on the same page. The top bits are the same. This allows
104 TLB invalidation to quickly clear a subset of the hash table. */
105#define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
106#define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
107#define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
108#define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
109
110#define CPU_TLB_BITS 8
111#define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
112
113#if TARGET_PHYS_ADDR_BITS == 32 && TARGET_LONG_BITS == 32
114#define CPU_TLB_ENTRY_BITS 4
115#else
116#define CPU_TLB_ENTRY_BITS 5
117#endif
118
119typedef struct CPUTLBEntry {
120 /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
121 bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not
122 go directly to ram.
123 bit 3 : indicates that the entry is invalid
124 bit 2..0 : zero
125 */
126 target_ulong addr_read;
127 target_ulong addr_write;
128 target_ulong addr_code;
129 /* Addend to virtual address to get physical address. IO accesses
130 use the correcponding iotlb value. */
131#if TARGET_PHYS_ADDR_BITS == 64
132 /* on i386 Linux make sure it is aligned */
133 target_phys_addr_t addend __attribute__((aligned(8)));
134#else
135 target_phys_addr_t addend;
136#endif
137#ifndef VBOX
138 /* padding to get a power of two size */
139 uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) -
140 (sizeof(target_ulong) * 3 +
141 ((-sizeof(target_ulong) * 3) & (sizeof(target_phys_addr_t) - 1)) +
142 sizeof(target_phys_addr_t))];
143#endif
144} CPUTLBEntry;
145
146#ifdef WORDS_BIGENDIAN
147typedef struct icount_decr_u16 {
148 uint16_t high;
149 uint16_t low;
150} icount_decr_u16;
151#else
152typedef struct icount_decr_u16 {
153 uint16_t low;
154 uint16_t high;
155} icount_decr_u16;
156#endif
157
158
159#define CPU_TEMP_BUF_NLONGS 128
160#ifdef VBOX
161struct TCGContext;
162
163#define CPU_COMMON \
164 struct TranslationBlock *current_tb; /* currently executing TB */ \
165 /* soft mmu support */ \
166 /* in order to avoid passing too many arguments to the MMIO \
167 helpers, we store some rarely used information in the CPU \
168 context) */ \
169 unsigned long mem_io_pc; /* host pc at which the memory was \
170 accessed */ \
171 target_ulong mem_io_vaddr; /* target virtual addr at which the \
172 memory was accessed */ \
173 uint32_t halted; /* Nonzero if the CPU is in suspend state */ \
174 uint32_t interrupt_request; \
175 /* The meaning of the MMU modes is defined in the target code. */ \
176 CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \
177 target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \
178 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \
179 /* buffer for temporaries in the code generator */ \
180 long temp_buf[CPU_TEMP_BUF_NLONGS]; \
181 \
182 int64_t icount_extra; /* Instructions until next timer event. */ \
183 /* Number of cycles left, with interrupt flag in high bit. \
184 This allows a single read-compare-cbranch-write sequence to test \
185 for both decrementer underflow and exceptions. */ \
186 union { \
187 uint32_t u32; \
188 icount_decr_u16 u16; \
189 } icount_decr; \
190 uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \
191 \
192 /* from this point: preserved by CPU reset */ \
193 /* ice debug support */ \
194 target_ulong breakpoints[MAX_BREAKPOINTS]; \
195 int nb_breakpoints; \
196 int singlestep_enabled; \
197 \
198 struct { \
199 target_ulong vaddr; \
200 int type; /* PAGE_READ/PAGE_WRITE */ \
201 } watchpoint[MAX_WATCHPOINTS]; \
202 int nb_watchpoints; \
203 int watchpoint_hit; \
204 \
205 /* Core interrupt code */ \
206 jmp_buf jmp_env; \
207 int exception_index; \
208 \
209 int user_mode_only; \
210 \
211 void *next_cpu; /* next CPU sharing TB cache */ \
212 int cpu_index; /* CPU index (informative) */ \
213 int running; /* Nonzero if cpu is currently running(usermode). */ \
214 /* user data */ \
215 void *opaque; \
216 \
217 const char *cpu_model_str; \
218 /* Codegenerator context */ \
219 struct TCGContext *tcg_context;
220#else
221
222#define CPU_COMMON \
223 struct TranslationBlock *current_tb; /* currently executing TB */ \
224 /* soft mmu support */ \
225 /* in order to avoid passing too many arguments to the MMIO \
226 helpers, we store some rarely used information in the CPU \
227 context) */ \
228 unsigned long mem_io_pc; /* host pc at which the memory was \
229 accessed */ \
230 target_ulong mem_io_vaddr; /* target virtual addr at which the \
231 memory was accessed */ \
232 uint32_t halted; /* Nonzero if the CPU is in suspend state */ \
233 uint32_t interrupt_request; \
234 /* The meaning of the MMU modes is defined in the target code. */ \
235 CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \
236 target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \
237 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \
238 /* buffer for temporaries in the code generator */ \
239 long temp_buf[CPU_TEMP_BUF_NLONGS]; \
240 \
241 int64_t icount_extra; /* Instructions until next timer event. */ \
242 /* Number of cycles left, with interrupt flag in high bit. \
243 This allows a single read-compare-cbranch-write sequence to test \
244 for both decrementer underflow and exceptions. */ \
245 union { \
246 uint32_t u32; \
247 icount_decr_u16 u16; \
248 } icount_decr; \
249 uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \
250 \
251 /* from this point: preserved by CPU reset */ \
252 /* ice debug support */ \
253 target_ulong breakpoints[MAX_BREAKPOINTS]; \
254 int nb_breakpoints; \
255 int singlestep_enabled; \
256 \
257 struct { \
258 target_ulong vaddr; \
259 int type; /* PAGE_READ/PAGE_WRITE */ \
260 } watchpoint[MAX_WATCHPOINTS]; \
261 int nb_watchpoints; \
262 int watchpoint_hit; \
263 \
264 /* Core interrupt code */ \
265 jmp_buf jmp_env; \
266 int exception_index; \
267 \
268 int user_mode_only; \
269 \
270 void *next_cpu; /* next CPU sharing TB cache */ \
271 int cpu_index; /* CPU index (informative) */ \
272 int running; /* Nonzero if cpu is currently running(usermode). */ \
273 /* user data */ \
274 void *opaque; \
275 \
276 const char *cpu_model_str;
277#endif
278
279#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette