VirtualBox

source: vbox/trunk/src/recompiler/cpu-defs.h@ 36171

Last change on this file since 36171 was 36171, checked in by vboxsync, 14 years ago

rem: Merged in changes from the branches/stable_0_10 (r7249).

  • Property svn:eol-style set to native
File size: 9.7 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
19 */
20
21/*
22 * Oracle 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, Oracle 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
30#ifndef CPU_DEFS_H
31#define CPU_DEFS_H
32
33#ifndef NEED_CPU_H
34#error cpu.h included from common code
35#endif
36
37#include "config.h"
38#include <setjmp.h>
39#include <inttypes.h>
40#include "osdep.h"
41#include "sys-queue.h"
42
43#ifndef TARGET_LONG_BITS
44#error TARGET_LONG_BITS must be defined before including this header
45#endif
46
47#ifndef TARGET_PHYS_ADDR_BITS
48#if TARGET_LONG_BITS >= HOST_LONG_BITS
49#define TARGET_PHYS_ADDR_BITS TARGET_LONG_BITS
50#else
51#define TARGET_PHYS_ADDR_BITS HOST_LONG_BITS
52#endif
53#endif
54
55#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
56
57/* target_ulong is the type of a virtual address */
58#if TARGET_LONG_SIZE == 4
59typedef int32_t target_long;
60typedef uint32_t target_ulong;
61#define TARGET_FMT_lx "%08x"
62#define TARGET_FMT_ld "%d"
63#define TARGET_FMT_lu "%u"
64#elif TARGET_LONG_SIZE == 8
65typedef int64_t target_long;
66typedef uint64_t target_ulong;
67#define TARGET_FMT_lx "%016" PRIx64
68#define TARGET_FMT_ld "%" PRId64
69#define TARGET_FMT_lu "%" PRIu64
70#else
71#error TARGET_LONG_SIZE undefined
72#endif
73
74/* target_phys_addr_t is the type of a physical address (its size can
75 be different from 'target_ulong'). We have sizeof(target_phys_addr)
76 = max(sizeof(unsigned long),
77 sizeof(size_of_target_physical_address)) because we must pass a
78 host pointer to memory operations in some cases */
79
80#if TARGET_PHYS_ADDR_BITS == 32
81typedef uint32_t target_phys_addr_t;
82#define TARGET_FMT_plx "%08x"
83#elif TARGET_PHYS_ADDR_BITS == 64
84typedef uint64_t target_phys_addr_t;
85#define TARGET_FMT_plx "%016" PRIx64
86#else
87#error TARGET_PHYS_ADDR_BITS undefined
88#endif
89
90#define HOST_LONG_SIZE (HOST_LONG_BITS / 8)
91
92#define EXCP_INTERRUPT 0x10000 /* async interruption */
93#define EXCP_HLT 0x10001 /* hlt instruction reached */
94#define EXCP_DEBUG 0x10002 /* cpu stopped after a breakpoint or singlestep */
95#define EXCP_HALTED 0x10003 /* cpu is halted (waiting for external event) */
96#ifdef VBOX
97# define EXCP_EXECUTE_RAW 0x11024 /**< execute raw mode. */
98# define EXCP_EXECUTE_HWACC 0x11025 /**< execute hardware accelerated raw mode. */
99# define EXCP_SINGLE_INSTR 0x11026 /**< executed single instruction. */
100# define EXCP_RC 0x11027 /**< a EM rc was raised (VMR3Reset/Suspend/PowerOff). */
101#endif /* VBOX */
102
103#define TB_JMP_CACHE_BITS 12
104#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
105
106/* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
107 addresses on the same page. The top bits are the same. This allows
108 TLB invalidation to quickly clear a subset of the hash table. */
109#define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
110#define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
111#define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
112#define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
113
114#define CPU_TLB_BITS 8
115#define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
116
117#if TARGET_PHYS_ADDR_BITS == 32 && TARGET_LONG_BITS == 32
118#define CPU_TLB_ENTRY_BITS 4
119#else
120#define CPU_TLB_ENTRY_BITS 5
121#endif
122
123typedef struct CPUTLBEntry {
124 /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
125 bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not
126 go directly to ram.
127 bit 3 : indicates that the entry is invalid
128 bit 2..0 : zero
129 */
130 target_ulong addr_read;
131 target_ulong addr_write;
132 target_ulong addr_code;
133 /* Addend to virtual address to get physical address. IO accesses
134 use the corresponding iotlb value. */
135#if TARGET_PHYS_ADDR_BITS == 64
136 /* on i386 Linux make sure it is aligned */
137 target_phys_addr_t addend __attribute__((aligned(8)));
138#else
139 target_phys_addr_t addend;
140#endif
141 /* padding to get a power of two size */
142 uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) -
143 (sizeof(target_ulong) * 3 +
144 ((-sizeof(target_ulong) * 3) & (sizeof(target_phys_addr_t) - 1)) +
145 sizeof(target_phys_addr_t))];
146} CPUTLBEntry;
147
148#ifdef WORDS_BIGENDIAN
149typedef struct icount_decr_u16 {
150 uint16_t high;
151 uint16_t low;
152} icount_decr_u16;
153#else
154typedef struct icount_decr_u16 {
155 uint16_t low;
156 uint16_t high;
157} icount_decr_u16;
158#endif
159
160struct kvm_run;
161struct KVMState;
162
163typedef struct CPUBreakpoint {
164 target_ulong pc;
165 int flags; /* BP_* */
166 TAILQ_ENTRY(CPUBreakpoint) entry;
167} CPUBreakpoint;
168
169typedef struct CPUWatchpoint {
170 target_ulong vaddr;
171 target_ulong len_mask;
172 int flags; /* BP_* */
173 TAILQ_ENTRY(CPUWatchpoint) entry;
174} CPUWatchpoint;
175
176#define CPU_TEMP_BUF_NLONGS 128
177#define CPU_COMMON \
178 struct TranslationBlock *current_tb; /* currently executing TB */ \
179 /* soft mmu support */ \
180 /* in order to avoid passing too many arguments to the MMIO \
181 helpers, we store some rarely used information in the CPU \
182 context) */ \
183 unsigned long mem_io_pc; /* host pc at which the memory was \
184 accessed */ \
185 target_ulong mem_io_vaddr; /* target virtual addr at which the \
186 memory was accessed */ \
187 uint32_t halted; /* Nonzero if the CPU is in suspend state */ \
188 uint32_t interrupt_request; \
189 volatile /*sig_atomic_t - vbox*/ int32_t exit_request; \
190 /* The meaning of the MMU modes is defined in the target code. */ \
191 CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \
192 target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \
193 /** addends for HVA -> GPA translations */ \
194 VBOX_ONLY(target_phys_addr_t phys_addends[NB_MMU_MODES][CPU_TLB_SIZE]); \
195 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \
196 /* buffer for temporaries in the code generator */ \
197 long temp_buf[CPU_TEMP_BUF_NLONGS]; \
198 \
199 int64_t icount_extra; /* Instructions until next timer event. */ \
200 /* Number of cycles left, with interrupt flag in high bit. \
201 This allows a single read-compare-cbranch-write sequence to test \
202 for both decrementer underflow and exceptions. */ \
203 union { \
204 uint32_t u32; \
205 icount_decr_u16 u16; \
206 } icount_decr; \
207 uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \
208 \
209 /* from this point: preserved by CPU reset */ \
210 /* ice debug support */ \
211 TAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; \
212 int singlestep_enabled; \
213 \
214 TAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \
215 CPUWatchpoint *watchpoint_hit; \
216 \
217 struct GDBRegisterState *gdb_regs; \
218 \
219 /* Core interrupt code */ \
220 jmp_buf jmp_env; \
221 int exception_index; \
222 \
223 void *next_cpu; /* next CPU sharing TB cache */ \
224 int cpu_index; /* CPU index (informative) */ \
225 int running; /* Nonzero if cpu is currently running(usermode). */ \
226 /* user data */ \
227 void *opaque; \
228 \
229 const char *cpu_model_str; \
230 struct KVMState *kvm_state; \
231 struct kvm_run *kvm_run; \
232 int kvm_fd;
233
234#endif
Note: See TracBrowser for help on using the repository browser.

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