root / cpu-defs.h @ f46f15bc
History | View | Annotate | Download (8.8 kB)
1 | ab93bbe2 | bellard | /*
|
---|---|---|---|
2 | ab93bbe2 | bellard | * common defines for all CPUs
|
3 | 5fafdf24 | ths | *
|
4 | ab93bbe2 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | ab93bbe2 | bellard | *
|
6 | ab93bbe2 | bellard | * This library is free software; you can redistribute it and/or
|
7 | ab93bbe2 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | ab93bbe2 | bellard | * License as published by the Free Software Foundation; either
|
9 | ab93bbe2 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | ab93bbe2 | bellard | *
|
11 | ab93bbe2 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | ab93bbe2 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | ab93bbe2 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | ab93bbe2 | bellard | * Lesser General Public License for more details.
|
15 | ab93bbe2 | bellard | *
|
16 | ab93bbe2 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | ab93bbe2 | bellard | * License along with this library; if not, write to the Free Software
|
18 | ab93bbe2 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | ab93bbe2 | bellard | */
|
20 | ab93bbe2 | bellard | #ifndef CPU_DEFS_H
|
21 | ab93bbe2 | bellard | #define CPU_DEFS_H
|
22 | ab93bbe2 | bellard | |
23 | 87ecb68b | pbrook | #ifndef NEED_CPU_H
|
24 | 87ecb68b | pbrook | #error cpu.h included from common code
|
25 | 87ecb68b | pbrook | #endif
|
26 | 87ecb68b | pbrook | |
27 | ab93bbe2 | bellard | #include "config.h" |
28 | ab93bbe2 | bellard | #include <setjmp.h> |
29 | ed1c0bcb | bellard | #include <inttypes.h> |
30 | ed1c0bcb | bellard | #include "osdep.h" |
31 | c0ce998e | aliguori | #include "sys-queue.h" |
32 | ab93bbe2 | bellard | |
33 | 35b66fc4 | bellard | #ifndef TARGET_LONG_BITS
|
34 | 35b66fc4 | bellard | #error TARGET_LONG_BITS must be defined before including this header
|
35 | 35b66fc4 | bellard | #endif
|
36 | 35b66fc4 | bellard | |
37 | 5fafdf24 | ths | #ifndef TARGET_PHYS_ADDR_BITS
|
38 | 4f2ac237 | bellard | #if TARGET_LONG_BITS >= HOST_LONG_BITS
|
39 | ab6d960f | bellard | #define TARGET_PHYS_ADDR_BITS TARGET_LONG_BITS
|
40 | 4f2ac237 | bellard | #else
|
41 | 4f2ac237 | bellard | #define TARGET_PHYS_ADDR_BITS HOST_LONG_BITS
|
42 | 4f2ac237 | bellard | #endif
|
43 | ab6d960f | bellard | #endif
|
44 | ab6d960f | bellard | |
45 | 35b66fc4 | bellard | #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8) |
46 | 35b66fc4 | bellard | |
47 | ab6d960f | bellard | /* target_ulong is the type of a virtual address */
|
48 | 35b66fc4 | bellard | #if TARGET_LONG_SIZE == 4 |
49 | 35b66fc4 | bellard | typedef int32_t target_long;
|
50 | 35b66fc4 | bellard | typedef uint32_t target_ulong;
|
51 | c27004ec | bellard | #define TARGET_FMT_lx "%08x" |
52 | b62b461b | j_mayer | #define TARGET_FMT_ld "%d" |
53 | 71c8b8fd | j_mayer | #define TARGET_FMT_lu "%u" |
54 | 35b66fc4 | bellard | #elif TARGET_LONG_SIZE == 8 |
55 | 35b66fc4 | bellard | typedef int64_t target_long;
|
56 | 35b66fc4 | bellard | typedef uint64_t target_ulong;
|
57 | 26a76461 | bellard | #define TARGET_FMT_lx "%016" PRIx64 |
58 | b62b461b | j_mayer | #define TARGET_FMT_ld "%" PRId64 |
59 | 71c8b8fd | j_mayer | #define TARGET_FMT_lu "%" PRIu64 |
60 | 35b66fc4 | bellard | #else
|
61 | 35b66fc4 | bellard | #error TARGET_LONG_SIZE undefined
|
62 | 35b66fc4 | bellard | #endif
|
63 | 35b66fc4 | bellard | |
64 | ab6d960f | bellard | /* target_phys_addr_t is the type of a physical address (its size can
|
65 | 4f2ac237 | bellard | be different from 'target_ulong'). We have sizeof(target_phys_addr)
|
66 | 4f2ac237 | bellard | = max(sizeof(unsigned long),
|
67 | 4f2ac237 | bellard | sizeof(size_of_target_physical_address)) because we must pass a
|
68 | 4f2ac237 | bellard | host pointer to memory operations in some cases */
|
69 | 4f2ac237 | bellard | |
70 | ab6d960f | bellard | #if TARGET_PHYS_ADDR_BITS == 32 |
71 | ab6d960f | bellard | typedef uint32_t target_phys_addr_t;
|
72 | ba13c432 | j_mayer | #define TARGET_FMT_plx "%08x" |
73 | ab6d960f | bellard | #elif TARGET_PHYS_ADDR_BITS == 64 |
74 | ab6d960f | bellard | typedef uint64_t target_phys_addr_t;
|
75 | ba13c432 | j_mayer | #define TARGET_FMT_plx "%016" PRIx64 |
76 | ab6d960f | bellard | #else
|
77 | ab6d960f | bellard | #error TARGET_PHYS_ADDR_BITS undefined
|
78 | ab6d960f | bellard | #endif
|
79 | ab6d960f | bellard | |
80 | f193c797 | bellard | #define HOST_LONG_SIZE (HOST_LONG_BITS / 8) |
81 | f193c797 | bellard | |
82 | 2be0071f | bellard | #define EXCP_INTERRUPT 0x10000 /* async interruption */ |
83 | 2be0071f | bellard | #define EXCP_HLT 0x10001 /* hlt instruction reached */ |
84 | 2be0071f | bellard | #define EXCP_DEBUG 0x10002 /* cpu stopped after a breakpoint or singlestep */ |
85 | 5a1e3cfc | bellard | #define EXCP_HALTED 0x10003 /* cpu is halted (waiting for external event) */ |
86 | ab93bbe2 | bellard | |
87 | a316d335 | bellard | #define TB_JMP_CACHE_BITS 12 |
88 | a316d335 | bellard | #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) |
89 | a316d335 | bellard | |
90 | b362e5e0 | pbrook | /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
|
91 | b362e5e0 | pbrook | addresses on the same page. The top bits are the same. This allows
|
92 | b362e5e0 | pbrook | TLB invalidation to quickly clear a subset of the hash table. */
|
93 | b362e5e0 | pbrook | #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) |
94 | b362e5e0 | pbrook | #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) |
95 | b362e5e0 | pbrook | #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) |
96 | b362e5e0 | pbrook | #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
|
97 | b362e5e0 | pbrook | |
98 | 84b7b8e7 | bellard | #define CPU_TLB_BITS 8 |
99 | 84b7b8e7 | bellard | #define CPU_TLB_SIZE (1 << CPU_TLB_BITS) |
100 | ab93bbe2 | bellard | |
101 | d656469f | bellard | #if TARGET_PHYS_ADDR_BITS == 32 && TARGET_LONG_BITS == 32 |
102 | d656469f | bellard | #define CPU_TLB_ENTRY_BITS 4 |
103 | d656469f | bellard | #else
|
104 | d656469f | bellard | #define CPU_TLB_ENTRY_BITS 5 |
105 | d656469f | bellard | #endif
|
106 | d656469f | bellard | |
107 | ab93bbe2 | bellard | typedef struct CPUTLBEntry { |
108 | 0f459d16 | pbrook | /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
|
109 | 0f459d16 | pbrook | bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not
|
110 | 0f459d16 | pbrook | go directly to ram.
|
111 | db8d7466 | bellard | bit 3 : indicates that the entry is invalid
|
112 | db8d7466 | bellard | bit 2..0 : zero
|
113 | db8d7466 | bellard | */
|
114 | 5fafdf24 | ths | target_ulong addr_read; |
115 | 5fafdf24 | ths | target_ulong addr_write; |
116 | 5fafdf24 | ths | target_ulong addr_code; |
117 | 0f459d16 | pbrook | /* Addend to virtual address to get physical address. IO accesses
|
118 | ee50add9 | pbrook | use the corresponding iotlb value. */
|
119 | d656469f | bellard | #if TARGET_PHYS_ADDR_BITS == 64 |
120 | d656469f | bellard | /* on i386 Linux make sure it is aligned */
|
121 | d656469f | bellard | target_phys_addr_t addend __attribute__((aligned(8)));
|
122 | d656469f | bellard | #else
|
123 | 5fafdf24 | ths | target_phys_addr_t addend; |
124 | d656469f | bellard | #endif
|
125 | d656469f | bellard | /* padding to get a power of two size */
|
126 | d656469f | bellard | uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) -
|
127 | d656469f | bellard | (sizeof(target_ulong) * 3 + |
128 | d656469f | bellard | ((-sizeof(target_ulong) * 3) & (sizeof(target_phys_addr_t) - 1)) + |
129 | d656469f | bellard | sizeof(target_phys_addr_t))];
|
130 | ab93bbe2 | bellard | } CPUTLBEntry; |
131 | ab93bbe2 | bellard | |
132 | 2e70f6ef | pbrook | #ifdef WORDS_BIGENDIAN
|
133 | 2e70f6ef | pbrook | typedef struct icount_decr_u16 { |
134 | 2e70f6ef | pbrook | uint16_t high; |
135 | 2e70f6ef | pbrook | uint16_t low; |
136 | 2e70f6ef | pbrook | } icount_decr_u16; |
137 | 2e70f6ef | pbrook | #else
|
138 | 2e70f6ef | pbrook | typedef struct icount_decr_u16 { |
139 | 2e70f6ef | pbrook | uint16_t low; |
140 | 2e70f6ef | pbrook | uint16_t high; |
141 | 2e70f6ef | pbrook | } icount_decr_u16; |
142 | 2e70f6ef | pbrook | #endif
|
143 | 2e70f6ef | pbrook | |
144 | 7ba1e619 | aliguori | struct kvm_run;
|
145 | 7ba1e619 | aliguori | struct KVMState;
|
146 | 7ba1e619 | aliguori | |
147 | a1d1bb31 | aliguori | typedef struct CPUBreakpoint { |
148 | a1d1bb31 | aliguori | target_ulong pc; |
149 | a1d1bb31 | aliguori | int flags; /* BP_* */ |
150 | c0ce998e | aliguori | TAILQ_ENTRY(CPUBreakpoint) entry; |
151 | a1d1bb31 | aliguori | } CPUBreakpoint; |
152 | a1d1bb31 | aliguori | |
153 | a1d1bb31 | aliguori | typedef struct CPUWatchpoint { |
154 | a1d1bb31 | aliguori | target_ulong vaddr; |
155 | a1d1bb31 | aliguori | target_ulong len_mask; |
156 | a1d1bb31 | aliguori | int flags; /* BP_* */ |
157 | c0ce998e | aliguori | TAILQ_ENTRY(CPUWatchpoint) entry; |
158 | a1d1bb31 | aliguori | } CPUWatchpoint; |
159 | a1d1bb31 | aliguori | |
160 | a20e31dc | blueswir1 | #define CPU_TEMP_BUF_NLONGS 128 |
161 | a316d335 | bellard | #define CPU_COMMON \
|
162 | a316d335 | bellard | struct TranslationBlock *current_tb; /* currently executing TB */ \ |
163 | a316d335 | bellard | /* soft mmu support */ \
|
164 | 2e70f6ef | pbrook | /* in order to avoid passing too many arguments to the MMIO \
|
165 | 2e70f6ef | pbrook | helpers, we store some rarely used information in the CPU \
|
166 | a316d335 | bellard | context) */ \
|
167 | 2e70f6ef | pbrook | unsigned long mem_io_pc; /* host pc at which the memory was \ |
168 | 2e70f6ef | pbrook | accessed */ \
|
169 | 2e70f6ef | pbrook | target_ulong mem_io_vaddr; /* target virtual addr at which the \
|
170 | 2e70f6ef | pbrook | memory was accessed */ \
|
171 | 9656f324 | pbrook | uint32_t halted; /* Nonzero if the CPU is in suspend state */ \
|
172 | 9656f324 | pbrook | uint32_t interrupt_request; \ |
173 | 623a930e | ths | /* The meaning of the MMU modes is defined in the target code. */ \
|
174 | 6fa4cea9 | j_mayer | CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \ |
175 | 0f459d16 | pbrook | target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \ |
176 | a316d335 | bellard | struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \
|
177 | a20e31dc | blueswir1 | /* buffer for temporaries in the code generator */ \
|
178 | a20e31dc | blueswir1 | long temp_buf[CPU_TEMP_BUF_NLONGS]; \
|
179 | a316d335 | bellard | \ |
180 | 2e70f6ef | pbrook | int64_t icount_extra; /* Instructions until next timer event. */ \
|
181 | 2e70f6ef | pbrook | /* Number of cycles left, with interrupt flag in high bit. \
|
182 | 2e70f6ef | pbrook | This allows a single read-compare-cbranch-write sequence to test \
|
183 | 2e70f6ef | pbrook | for both decrementer underflow and exceptions. */ \
|
184 | 2e70f6ef | pbrook | union { \
|
185 | 2e70f6ef | pbrook | uint32_t u32; \ |
186 | 2e70f6ef | pbrook | icount_decr_u16 u16; \ |
187 | 2e70f6ef | pbrook | } icount_decr; \ |
188 | 2e70f6ef | pbrook | uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \
|
189 | 2e70f6ef | pbrook | \ |
190 | a316d335 | bellard | /* from this point: preserved by CPU reset */ \
|
191 | a316d335 | bellard | /* ice debug support */ \
|
192 | c0ce998e | aliguori | TAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; \ |
193 | a316d335 | bellard | int singlestep_enabled; \
|
194 | a316d335 | bellard | \ |
195 | c0ce998e | aliguori | TAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \ |
196 | a1d1bb31 | aliguori | CPUWatchpoint *watchpoint_hit; \ |
197 | 56aebc89 | pbrook | \ |
198 | 56aebc89 | pbrook | struct GDBRegisterState *gdb_regs; \
|
199 | 6658ffb8 | pbrook | \ |
200 | 9133e39b | bellard | /* Core interrupt code */ \
|
201 | 9133e39b | bellard | jmp_buf jmp_env; \ |
202 | 9133e39b | bellard | int exception_index; \
|
203 | 9133e39b | bellard | \ |
204 | 9656f324 | pbrook | int user_mode_only; \
|
205 | 9656f324 | pbrook | \ |
206 | 6a00d601 | bellard | void *next_cpu; /* next CPU sharing TB cache */ \ |
207 | 6a00d601 | bellard | int cpu_index; /* CPU index (informative) */ \ |
208 | d5975363 | pbrook | int running; /* Nonzero if cpu is currently running(usermode). */ \ |
209 | a316d335 | bellard | /* user data */ \
|
210 | 01ba9816 | ths | void *opaque; \
|
211 | 01ba9816 | ths | \ |
212 | 7ba1e619 | aliguori | const char *cpu_model_str; \ |
213 | 7ba1e619 | aliguori | struct KVMState *kvm_state; \
|
214 | 7ba1e619 | aliguori | struct kvm_run *kvm_run; \
|
215 | 7ba1e619 | aliguori | int kvm_fd;
|
216 | a316d335 | bellard | |
217 | ab93bbe2 | bellard | #endif |