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> 291de7afc9SPaolo Bonzini #include "qemu/osdep.h" 301de7afc9SPaolo Bonzini #include "qemu/queue.h" 31ce927ed9SAndreas Färber #ifndef CONFIG_USER_ONLY 32022c62cbSPaolo Bonzini #include "exec/hwaddr.h" 33ce927ed9SAndreas Färber #endif 34022c62cbSPaolo Bonzini 35022c62cbSPaolo Bonzini #ifndef TARGET_LONG_BITS 36022c62cbSPaolo Bonzini #error TARGET_LONG_BITS must be defined before including this header 37022c62cbSPaolo Bonzini #endif 38022c62cbSPaolo Bonzini 39022c62cbSPaolo Bonzini #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8) 40022c62cbSPaolo Bonzini 41022c62cbSPaolo Bonzini /* target_ulong is the type of a virtual address */ 42022c62cbSPaolo Bonzini #if TARGET_LONG_SIZE == 4 436cfd9b52SPaolo Bonzini typedef int32_t target_long; 446cfd9b52SPaolo Bonzini typedef uint32_t target_ulong; 45022c62cbSPaolo Bonzini #define TARGET_FMT_lx "%08x" 46022c62cbSPaolo Bonzini #define TARGET_FMT_ld "%d" 47022c62cbSPaolo Bonzini #define TARGET_FMT_lu "%u" 48022c62cbSPaolo Bonzini #elif TARGET_LONG_SIZE == 8 496cfd9b52SPaolo Bonzini typedef int64_t target_long; 506cfd9b52SPaolo Bonzini typedef uint64_t target_ulong; 51022c62cbSPaolo Bonzini #define TARGET_FMT_lx "%016" PRIx64 52022c62cbSPaolo Bonzini #define TARGET_FMT_ld "%" PRId64 53022c62cbSPaolo Bonzini #define TARGET_FMT_lu "%" PRIu64 54022c62cbSPaolo Bonzini #else 55022c62cbSPaolo Bonzini #error TARGET_LONG_SIZE undefined 56022c62cbSPaolo Bonzini #endif 57022c62cbSPaolo Bonzini 58022c62cbSPaolo Bonzini #define EXCP_INTERRUPT 0x10000 /* async interruption */ 59022c62cbSPaolo Bonzini #define EXCP_HLT 0x10001 /* hlt instruction reached */ 60022c62cbSPaolo Bonzini #define EXCP_DEBUG 0x10002 /* cpu stopped after a breakpoint or singlestep */ 61022c62cbSPaolo Bonzini #define EXCP_HALTED 0x10003 /* cpu is halted (waiting for external event) */ 62*72c1d3afSPeter Maydell #define EXCP_YIELD 0x10004 /* cpu wants to yield timeslice to another */ 63022c62cbSPaolo Bonzini 64022c62cbSPaolo Bonzini #define TB_JMP_CACHE_BITS 12 65022c62cbSPaolo Bonzini #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) 66022c62cbSPaolo Bonzini 67022c62cbSPaolo Bonzini /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for 68022c62cbSPaolo Bonzini addresses on the same page. The top bits are the same. This allows 69022c62cbSPaolo Bonzini TLB invalidation to quickly clear a subset of the hash table. */ 70022c62cbSPaolo Bonzini #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) 71022c62cbSPaolo Bonzini #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) 72022c62cbSPaolo Bonzini #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) 73022c62cbSPaolo Bonzini #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE) 74022c62cbSPaolo Bonzini 75022c62cbSPaolo Bonzini #if !defined(CONFIG_USER_ONLY) 76022c62cbSPaolo Bonzini #define CPU_TLB_BITS 8 77022c62cbSPaolo Bonzini #define CPU_TLB_SIZE (1 << CPU_TLB_BITS) 78022c62cbSPaolo Bonzini 79022c62cbSPaolo Bonzini #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32 80022c62cbSPaolo Bonzini #define CPU_TLB_ENTRY_BITS 4 81022c62cbSPaolo Bonzini #else 82022c62cbSPaolo Bonzini #define CPU_TLB_ENTRY_BITS 5 83022c62cbSPaolo Bonzini #endif 84022c62cbSPaolo Bonzini 85022c62cbSPaolo Bonzini typedef struct CPUTLBEntry { 86022c62cbSPaolo Bonzini /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address 87022c62cbSPaolo Bonzini bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not 88022c62cbSPaolo Bonzini go directly to ram. 89022c62cbSPaolo Bonzini bit 3 : indicates that the entry is invalid 90022c62cbSPaolo Bonzini bit 2..0 : zero 91022c62cbSPaolo Bonzini */ 92022c62cbSPaolo Bonzini target_ulong addr_read; 93022c62cbSPaolo Bonzini target_ulong addr_write; 94022c62cbSPaolo Bonzini target_ulong addr_code; 95022c62cbSPaolo Bonzini /* Addend to virtual address to get host address. IO accesses 96022c62cbSPaolo Bonzini use the corresponding iotlb value. */ 97022c62cbSPaolo Bonzini uintptr_t addend; 98022c62cbSPaolo Bonzini /* padding to get a power of two size */ 99022c62cbSPaolo Bonzini uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 100022c62cbSPaolo Bonzini (sizeof(target_ulong) * 3 + 101022c62cbSPaolo Bonzini ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) + 102022c62cbSPaolo Bonzini sizeof(uintptr_t))]; 103022c62cbSPaolo Bonzini } CPUTLBEntry; 104022c62cbSPaolo Bonzini 105e85ef538SRichard Henderson QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS)); 106022c62cbSPaolo Bonzini 107022c62cbSPaolo Bonzini #define CPU_COMMON_TLB \ 108022c62cbSPaolo Bonzini /* The meaning of the MMU modes is defined in the target code. */ \ 109022c62cbSPaolo Bonzini CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \ 110022c62cbSPaolo Bonzini hwaddr iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \ 111022c62cbSPaolo Bonzini target_ulong tlb_flush_addr; \ 112022c62cbSPaolo Bonzini target_ulong tlb_flush_mask; 113022c62cbSPaolo Bonzini 114022c62cbSPaolo Bonzini #else 115022c62cbSPaolo Bonzini 116022c62cbSPaolo Bonzini #define CPU_COMMON_TLB 117022c62cbSPaolo Bonzini 118022c62cbSPaolo Bonzini #endif 119022c62cbSPaolo Bonzini 120022c62cbSPaolo Bonzini 121022c62cbSPaolo Bonzini #ifdef HOST_WORDS_BIGENDIAN 122022c62cbSPaolo Bonzini typedef struct icount_decr_u16 { 123022c62cbSPaolo Bonzini uint16_t high; 124022c62cbSPaolo Bonzini uint16_t low; 125022c62cbSPaolo Bonzini } icount_decr_u16; 126022c62cbSPaolo Bonzini #else 127022c62cbSPaolo Bonzini typedef struct icount_decr_u16 { 128022c62cbSPaolo Bonzini uint16_t low; 129022c62cbSPaolo Bonzini uint16_t high; 130022c62cbSPaolo Bonzini } icount_decr_u16; 131022c62cbSPaolo Bonzini #endif 132022c62cbSPaolo Bonzini 133022c62cbSPaolo Bonzini typedef struct CPUBreakpoint { 134022c62cbSPaolo Bonzini target_ulong pc; 135022c62cbSPaolo Bonzini int flags; /* BP_* */ 136022c62cbSPaolo Bonzini QTAILQ_ENTRY(CPUBreakpoint) entry; 137022c62cbSPaolo Bonzini } CPUBreakpoint; 138022c62cbSPaolo Bonzini 139022c62cbSPaolo Bonzini typedef struct CPUWatchpoint { 140022c62cbSPaolo Bonzini target_ulong vaddr; 141022c62cbSPaolo Bonzini target_ulong len_mask; 142022c62cbSPaolo Bonzini int flags; /* BP_* */ 143022c62cbSPaolo Bonzini QTAILQ_ENTRY(CPUWatchpoint) entry; 144022c62cbSPaolo Bonzini } CPUWatchpoint; 145022c62cbSPaolo Bonzini 146022c62cbSPaolo Bonzini #define CPU_TEMP_BUF_NLONGS 128 147022c62cbSPaolo Bonzini #define CPU_COMMON \ 148022c62cbSPaolo Bonzini /* soft mmu support */ \ 149022c62cbSPaolo Bonzini /* in order to avoid passing too many arguments to the MMIO \ 150022c62cbSPaolo Bonzini helpers, we store some rarely used information in the CPU \ 151022c62cbSPaolo Bonzini context) */ \ 152022c62cbSPaolo Bonzini uintptr_t mem_io_pc; /* host pc at which the memory was \ 153022c62cbSPaolo Bonzini accessed */ \ 154022c62cbSPaolo Bonzini target_ulong mem_io_vaddr; /* target virtual addr at which the \ 155022c62cbSPaolo Bonzini memory was accessed */ \ 156022c62cbSPaolo Bonzini CPU_COMMON_TLB \ 157022c62cbSPaolo Bonzini struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \ 158022c62cbSPaolo Bonzini \ 159022c62cbSPaolo Bonzini int64_t icount_extra; /* Instructions until next timer event. */ \ 160022c62cbSPaolo Bonzini /* Number of cycles left, with interrupt flag in high bit. \ 161022c62cbSPaolo Bonzini This allows a single read-compare-cbranch-write sequence to test \ 162022c62cbSPaolo Bonzini for both decrementer underflow and exceptions. */ \ 163022c62cbSPaolo Bonzini union { \ 164022c62cbSPaolo Bonzini uint32_t u32; \ 165022c62cbSPaolo Bonzini icount_decr_u16 u16; \ 166022c62cbSPaolo Bonzini } icount_decr; \ 167022c62cbSPaolo Bonzini uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \ 168022c62cbSPaolo Bonzini \ 169022c62cbSPaolo Bonzini /* from this point: preserved by CPU reset */ \ 170022c62cbSPaolo Bonzini /* ice debug support */ \ 171022c62cbSPaolo Bonzini QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; \ 172022c62cbSPaolo Bonzini \ 173022c62cbSPaolo Bonzini QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \ 174022c62cbSPaolo Bonzini CPUWatchpoint *watchpoint_hit; \ 175022c62cbSPaolo Bonzini \ 176022c62cbSPaolo Bonzini /* Core interrupt code */ \ 1776ab7e546SPeter Maydell sigjmp_buf jmp_env; \ 178022c62cbSPaolo Bonzini int exception_index; \ 179022c62cbSPaolo Bonzini \ 180022c62cbSPaolo Bonzini /* user data */ \ 181022c62cbSPaolo Bonzini void *opaque; \ 182022c62cbSPaolo Bonzini 183022c62cbSPaolo Bonzini #endif 184