1022c62cbSPaolo Bonzini /* 2022c62cbSPaolo Bonzini * common defines for all CPUs 3022c62cbSPaolo Bonzini * 4022c62cbSPaolo Bonzini * Copyright (c) 2003 Fabrice Bellard 5022c62cbSPaolo Bonzini * 6022c62cbSPaolo Bonzini * This library is free software; you can redistribute it and/or 7022c62cbSPaolo Bonzini * modify it under the terms of the GNU Lesser General Public 8022c62cbSPaolo Bonzini * License as published by the Free Software Foundation; either 9022c62cbSPaolo Bonzini * version 2 of the License, or (at your option) any later version. 10022c62cbSPaolo Bonzini * 11022c62cbSPaolo Bonzini * This library is distributed in the hope that it will be useful, 12022c62cbSPaolo Bonzini * but WITHOUT ANY WARRANTY; without even the implied warranty of 13022c62cbSPaolo Bonzini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14022c62cbSPaolo Bonzini * Lesser General Public License for more details. 15022c62cbSPaolo Bonzini * 16022c62cbSPaolo Bonzini * You should have received a copy of the GNU Lesser General Public 17022c62cbSPaolo Bonzini * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18022c62cbSPaolo Bonzini */ 19022c62cbSPaolo Bonzini #ifndef CPU_DEFS_H 20022c62cbSPaolo Bonzini #define CPU_DEFS_H 21022c62cbSPaolo Bonzini 22022c62cbSPaolo Bonzini #ifndef NEED_CPU_H 23022c62cbSPaolo Bonzini #error cpu.h included from common code 24022c62cbSPaolo Bonzini #endif 25022c62cbSPaolo Bonzini 26022c62cbSPaolo Bonzini #include "config.h" 27022c62cbSPaolo Bonzini #include <setjmp.h> 28022c62cbSPaolo Bonzini #include <inttypes.h> 29022c62cbSPaolo Bonzini #include <signal.h> 30*1de7afc9SPaolo Bonzini #include "qemu/osdep.h" 31*1de7afc9SPaolo Bonzini #include "qemu/queue.h" 32022c62cbSPaolo Bonzini #include "exec/hwaddr.h" 33022c62cbSPaolo Bonzini 34022c62cbSPaolo Bonzini #ifndef TARGET_LONG_BITS 35022c62cbSPaolo Bonzini #error TARGET_LONG_BITS must be defined before including this header 36022c62cbSPaolo Bonzini #endif 37022c62cbSPaolo Bonzini 38022c62cbSPaolo Bonzini #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8) 39022c62cbSPaolo Bonzini 40022c62cbSPaolo Bonzini typedef int16_t target_short __attribute__ ((aligned(TARGET_SHORT_ALIGNMENT))); 41022c62cbSPaolo Bonzini typedef uint16_t target_ushort __attribute__((aligned(TARGET_SHORT_ALIGNMENT))); 42022c62cbSPaolo Bonzini typedef int32_t target_int __attribute__((aligned(TARGET_INT_ALIGNMENT))); 43022c62cbSPaolo Bonzini typedef uint32_t target_uint __attribute__((aligned(TARGET_INT_ALIGNMENT))); 44022c62cbSPaolo Bonzini typedef int64_t target_llong __attribute__((aligned(TARGET_LLONG_ALIGNMENT))); 45022c62cbSPaolo Bonzini typedef uint64_t target_ullong __attribute__((aligned(TARGET_LLONG_ALIGNMENT))); 46022c62cbSPaolo Bonzini /* target_ulong is the type of a virtual address */ 47022c62cbSPaolo Bonzini #if TARGET_LONG_SIZE == 4 48022c62cbSPaolo Bonzini typedef int32_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT))); 49022c62cbSPaolo Bonzini typedef uint32_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT))); 50022c62cbSPaolo Bonzini #define TARGET_FMT_lx "%08x" 51022c62cbSPaolo Bonzini #define TARGET_FMT_ld "%d" 52022c62cbSPaolo Bonzini #define TARGET_FMT_lu "%u" 53022c62cbSPaolo Bonzini #elif TARGET_LONG_SIZE == 8 54022c62cbSPaolo Bonzini typedef int64_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT))); 55022c62cbSPaolo Bonzini typedef uint64_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT))); 56022c62cbSPaolo Bonzini #define TARGET_FMT_lx "%016" PRIx64 57022c62cbSPaolo Bonzini #define TARGET_FMT_ld "%" PRId64 58022c62cbSPaolo Bonzini #define TARGET_FMT_lu "%" PRIu64 59022c62cbSPaolo Bonzini #else 60022c62cbSPaolo Bonzini #error TARGET_LONG_SIZE undefined 61022c62cbSPaolo Bonzini #endif 62022c62cbSPaolo Bonzini 63022c62cbSPaolo Bonzini #define EXCP_INTERRUPT 0x10000 /* async interruption */ 64022c62cbSPaolo Bonzini #define EXCP_HLT 0x10001 /* hlt instruction reached */ 65022c62cbSPaolo Bonzini #define EXCP_DEBUG 0x10002 /* cpu stopped after a breakpoint or singlestep */ 66022c62cbSPaolo Bonzini #define EXCP_HALTED 0x10003 /* cpu is halted (waiting for external event) */ 67022c62cbSPaolo Bonzini 68022c62cbSPaolo Bonzini #define TB_JMP_CACHE_BITS 12 69022c62cbSPaolo Bonzini #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) 70022c62cbSPaolo Bonzini 71022c62cbSPaolo Bonzini /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for 72022c62cbSPaolo Bonzini addresses on the same page. The top bits are the same. This allows 73022c62cbSPaolo Bonzini TLB invalidation to quickly clear a subset of the hash table. */ 74022c62cbSPaolo Bonzini #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) 75022c62cbSPaolo Bonzini #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) 76022c62cbSPaolo Bonzini #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) 77022c62cbSPaolo Bonzini #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE) 78022c62cbSPaolo Bonzini 79022c62cbSPaolo Bonzini #if !defined(CONFIG_USER_ONLY) 80022c62cbSPaolo Bonzini #define CPU_TLB_BITS 8 81022c62cbSPaolo Bonzini #define CPU_TLB_SIZE (1 << CPU_TLB_BITS) 82022c62cbSPaolo Bonzini 83022c62cbSPaolo Bonzini #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32 84022c62cbSPaolo Bonzini #define CPU_TLB_ENTRY_BITS 4 85022c62cbSPaolo Bonzini #else 86022c62cbSPaolo Bonzini #define CPU_TLB_ENTRY_BITS 5 87022c62cbSPaolo Bonzini #endif 88022c62cbSPaolo Bonzini 89022c62cbSPaolo Bonzini typedef struct CPUTLBEntry { 90022c62cbSPaolo Bonzini /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address 91022c62cbSPaolo Bonzini bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not 92022c62cbSPaolo Bonzini go directly to ram. 93022c62cbSPaolo Bonzini bit 3 : indicates that the entry is invalid 94022c62cbSPaolo Bonzini bit 2..0 : zero 95022c62cbSPaolo Bonzini */ 96022c62cbSPaolo Bonzini target_ulong addr_read; 97022c62cbSPaolo Bonzini target_ulong addr_write; 98022c62cbSPaolo Bonzini target_ulong addr_code; 99022c62cbSPaolo Bonzini /* Addend to virtual address to get host address. IO accesses 100022c62cbSPaolo Bonzini use the corresponding iotlb value. */ 101022c62cbSPaolo Bonzini uintptr_t addend; 102022c62cbSPaolo Bonzini /* padding to get a power of two size */ 103022c62cbSPaolo Bonzini uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 104022c62cbSPaolo Bonzini (sizeof(target_ulong) * 3 + 105022c62cbSPaolo Bonzini ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) + 106022c62cbSPaolo Bonzini sizeof(uintptr_t))]; 107022c62cbSPaolo Bonzini } CPUTLBEntry; 108022c62cbSPaolo Bonzini 109022c62cbSPaolo Bonzini extern int CPUTLBEntry_wrong_size[sizeof(CPUTLBEntry) == (1 << CPU_TLB_ENTRY_BITS) ? 1 : -1]; 110022c62cbSPaolo Bonzini 111022c62cbSPaolo Bonzini #define CPU_COMMON_TLB \ 112022c62cbSPaolo Bonzini /* The meaning of the MMU modes is defined in the target code. */ \ 113022c62cbSPaolo Bonzini CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \ 114022c62cbSPaolo Bonzini hwaddr iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \ 115022c62cbSPaolo Bonzini target_ulong tlb_flush_addr; \ 116022c62cbSPaolo Bonzini target_ulong tlb_flush_mask; 117022c62cbSPaolo Bonzini 118022c62cbSPaolo Bonzini #else 119022c62cbSPaolo Bonzini 120022c62cbSPaolo Bonzini #define CPU_COMMON_TLB 121022c62cbSPaolo Bonzini 122022c62cbSPaolo Bonzini #endif 123022c62cbSPaolo Bonzini 124022c62cbSPaolo Bonzini 125022c62cbSPaolo Bonzini #ifdef HOST_WORDS_BIGENDIAN 126022c62cbSPaolo Bonzini typedef struct icount_decr_u16 { 127022c62cbSPaolo Bonzini uint16_t high; 128022c62cbSPaolo Bonzini uint16_t low; 129022c62cbSPaolo Bonzini } icount_decr_u16; 130022c62cbSPaolo Bonzini #else 131022c62cbSPaolo Bonzini typedef struct icount_decr_u16 { 132022c62cbSPaolo Bonzini uint16_t low; 133022c62cbSPaolo Bonzini uint16_t high; 134022c62cbSPaolo Bonzini } icount_decr_u16; 135022c62cbSPaolo Bonzini #endif 136022c62cbSPaolo Bonzini 137022c62cbSPaolo Bonzini struct kvm_run; 138022c62cbSPaolo Bonzini struct KVMState; 139022c62cbSPaolo Bonzini struct qemu_work_item; 140022c62cbSPaolo Bonzini 141022c62cbSPaolo Bonzini typedef struct CPUBreakpoint { 142022c62cbSPaolo Bonzini target_ulong pc; 143022c62cbSPaolo Bonzini int flags; /* BP_* */ 144022c62cbSPaolo Bonzini QTAILQ_ENTRY(CPUBreakpoint) entry; 145022c62cbSPaolo Bonzini } CPUBreakpoint; 146022c62cbSPaolo Bonzini 147022c62cbSPaolo Bonzini typedef struct CPUWatchpoint { 148022c62cbSPaolo Bonzini target_ulong vaddr; 149022c62cbSPaolo Bonzini target_ulong len_mask; 150022c62cbSPaolo Bonzini int flags; /* BP_* */ 151022c62cbSPaolo Bonzini QTAILQ_ENTRY(CPUWatchpoint) entry; 152022c62cbSPaolo Bonzini } CPUWatchpoint; 153022c62cbSPaolo Bonzini 154022c62cbSPaolo Bonzini #define CPU_TEMP_BUF_NLONGS 128 155022c62cbSPaolo Bonzini #define CPU_COMMON \ 156022c62cbSPaolo Bonzini struct TranslationBlock *current_tb; /* currently executing TB */ \ 157022c62cbSPaolo Bonzini /* soft mmu support */ \ 158022c62cbSPaolo Bonzini /* in order to avoid passing too many arguments to the MMIO \ 159022c62cbSPaolo Bonzini helpers, we store some rarely used information in the CPU \ 160022c62cbSPaolo Bonzini context) */ \ 161022c62cbSPaolo Bonzini uintptr_t mem_io_pc; /* host pc at which the memory was \ 162022c62cbSPaolo Bonzini accessed */ \ 163022c62cbSPaolo Bonzini target_ulong mem_io_vaddr; /* target virtual addr at which the \ 164022c62cbSPaolo Bonzini memory was accessed */ \ 165022c62cbSPaolo Bonzini uint32_t halted; /* Nonzero if the CPU is in suspend state */ \ 166022c62cbSPaolo Bonzini uint32_t interrupt_request; \ 167022c62cbSPaolo Bonzini volatile sig_atomic_t exit_request; \ 168022c62cbSPaolo Bonzini CPU_COMMON_TLB \ 169022c62cbSPaolo Bonzini struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \ 170022c62cbSPaolo Bonzini /* buffer for temporaries in the code generator */ \ 171022c62cbSPaolo Bonzini long temp_buf[CPU_TEMP_BUF_NLONGS]; \ 172022c62cbSPaolo Bonzini \ 173022c62cbSPaolo Bonzini int64_t icount_extra; /* Instructions until next timer event. */ \ 174022c62cbSPaolo Bonzini /* Number of cycles left, with interrupt flag in high bit. \ 175022c62cbSPaolo Bonzini This allows a single read-compare-cbranch-write sequence to test \ 176022c62cbSPaolo Bonzini for both decrementer underflow and exceptions. */ \ 177022c62cbSPaolo Bonzini union { \ 178022c62cbSPaolo Bonzini uint32_t u32; \ 179022c62cbSPaolo Bonzini icount_decr_u16 u16; \ 180022c62cbSPaolo Bonzini } icount_decr; \ 181022c62cbSPaolo Bonzini uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \ 182022c62cbSPaolo Bonzini \ 183022c62cbSPaolo Bonzini /* from this point: preserved by CPU reset */ \ 184022c62cbSPaolo Bonzini /* ice debug support */ \ 185022c62cbSPaolo Bonzini QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; \ 186022c62cbSPaolo Bonzini int singlestep_enabled; \ 187022c62cbSPaolo Bonzini \ 188022c62cbSPaolo Bonzini QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \ 189022c62cbSPaolo Bonzini CPUWatchpoint *watchpoint_hit; \ 190022c62cbSPaolo Bonzini \ 191022c62cbSPaolo Bonzini struct GDBRegisterState *gdb_regs; \ 192022c62cbSPaolo Bonzini \ 193022c62cbSPaolo Bonzini /* Core interrupt code */ \ 194022c62cbSPaolo Bonzini jmp_buf jmp_env; \ 195022c62cbSPaolo Bonzini int exception_index; \ 196022c62cbSPaolo Bonzini \ 197022c62cbSPaolo Bonzini CPUArchState *next_cpu; /* next CPU sharing TB cache */ \ 198022c62cbSPaolo Bonzini int cpu_index; /* CPU index (informative) */ \ 199022c62cbSPaolo Bonzini uint32_t host_tid; /* host thread ID */ \ 200022c62cbSPaolo Bonzini int numa_node; /* NUMA node this cpu is belonging to */ \ 201022c62cbSPaolo Bonzini int nr_cores; /* number of cores within this CPU package */ \ 202022c62cbSPaolo Bonzini int nr_threads;/* number of threads within this CPU */ \ 203022c62cbSPaolo Bonzini int running; /* Nonzero if cpu is currently running(usermode). */ \ 204022c62cbSPaolo Bonzini /* user data */ \ 205022c62cbSPaolo Bonzini void *opaque; \ 206022c62cbSPaolo Bonzini \ 207022c62cbSPaolo Bonzini const char *cpu_model_str; \ 208022c62cbSPaolo Bonzini struct KVMState *kvm_state; \ 209022c62cbSPaolo Bonzini struct kvm_run *kvm_run; \ 210022c62cbSPaolo Bonzini int kvm_fd; \ 211022c62cbSPaolo Bonzini int kvm_vcpu_dirty; 212022c62cbSPaolo Bonzini 213022c62cbSPaolo Bonzini #endif 214