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 <inttypes.h> 281de7afc9SPaolo Bonzini #include "qemu/osdep.h" 291de7afc9SPaolo Bonzini #include "qemu/queue.h" 30ce927ed9SAndreas Färber #ifndef CONFIG_USER_ONLY 31022c62cbSPaolo Bonzini #include "exec/hwaddr.h" 32ce927ed9SAndreas Färber #endif 33*fadc1cbeSPeter Maydell #include "exec/memattrs.h" 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) */ 6272c1d3afSPeter Maydell #define EXCP_YIELD 0x10004 /* cpu wants to yield timeslice to another */ 63022c62cbSPaolo Bonzini 64022c62cbSPaolo Bonzini /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for 65022c62cbSPaolo Bonzini addresses on the same page. The top bits are the same. This allows 66022c62cbSPaolo Bonzini TLB invalidation to quickly clear a subset of the hash table. */ 67022c62cbSPaolo Bonzini #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) 68022c62cbSPaolo Bonzini #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) 69022c62cbSPaolo Bonzini #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) 70022c62cbSPaolo Bonzini #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE) 71022c62cbSPaolo Bonzini 72022c62cbSPaolo Bonzini #if !defined(CONFIG_USER_ONLY) 73022c62cbSPaolo Bonzini #define CPU_TLB_BITS 8 74022c62cbSPaolo Bonzini #define CPU_TLB_SIZE (1 << CPU_TLB_BITS) 7588e89a57SXin Tong /* use a fully associative victim tlb of 8 entries */ 7688e89a57SXin Tong #define CPU_VTLB_SIZE 8 77022c62cbSPaolo Bonzini 78022c62cbSPaolo Bonzini #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32 79022c62cbSPaolo Bonzini #define CPU_TLB_ENTRY_BITS 4 80022c62cbSPaolo Bonzini #else 81022c62cbSPaolo Bonzini #define CPU_TLB_ENTRY_BITS 5 82022c62cbSPaolo Bonzini #endif 83022c62cbSPaolo Bonzini 84022c62cbSPaolo Bonzini typedef struct CPUTLBEntry { 85022c62cbSPaolo Bonzini /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address 86022c62cbSPaolo Bonzini bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not 87022c62cbSPaolo Bonzini go directly to ram. 88022c62cbSPaolo Bonzini bit 3 : indicates that the entry is invalid 89022c62cbSPaolo Bonzini bit 2..0 : zero 90022c62cbSPaolo Bonzini */ 91022c62cbSPaolo Bonzini target_ulong addr_read; 92022c62cbSPaolo Bonzini target_ulong addr_write; 93022c62cbSPaolo Bonzini target_ulong addr_code; 94022c62cbSPaolo Bonzini /* Addend to virtual address to get host address. IO accesses 95022c62cbSPaolo Bonzini use the corresponding iotlb value. */ 96022c62cbSPaolo Bonzini uintptr_t addend; 97022c62cbSPaolo Bonzini /* padding to get a power of two size */ 98022c62cbSPaolo Bonzini uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 99022c62cbSPaolo Bonzini (sizeof(target_ulong) * 3 + 100022c62cbSPaolo Bonzini ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) + 101022c62cbSPaolo Bonzini sizeof(uintptr_t))]; 102022c62cbSPaolo Bonzini } CPUTLBEntry; 103022c62cbSPaolo Bonzini 104e85ef538SRichard Henderson QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS)); 105022c62cbSPaolo Bonzini 106e469b22fSPeter Maydell /* The IOTLB is not accessed directly inline by generated TCG code, 107e469b22fSPeter Maydell * so the CPUIOTLBEntry layout is not as critical as that of the 108e469b22fSPeter Maydell * CPUTLBEntry. (This is also why we don't want to combine the two 109e469b22fSPeter Maydell * structs into one.) 110e469b22fSPeter Maydell */ 111e469b22fSPeter Maydell typedef struct CPUIOTLBEntry { 112e469b22fSPeter Maydell hwaddr addr; 113*fadc1cbeSPeter Maydell MemTxAttrs attrs; 114e469b22fSPeter Maydell } CPUIOTLBEntry; 115e469b22fSPeter Maydell 116022c62cbSPaolo Bonzini #define CPU_COMMON_TLB \ 117022c62cbSPaolo Bonzini /* The meaning of the MMU modes is defined in the target code. */ \ 118022c62cbSPaolo Bonzini CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \ 11988e89a57SXin Tong CPUTLBEntry tlb_v_table[NB_MMU_MODES][CPU_VTLB_SIZE]; \ 120e469b22fSPeter Maydell CPUIOTLBEntry iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \ 121e469b22fSPeter Maydell CPUIOTLBEntry iotlb_v[NB_MMU_MODES][CPU_VTLB_SIZE]; \ 122022c62cbSPaolo Bonzini target_ulong tlb_flush_addr; \ 12388e89a57SXin Tong target_ulong tlb_flush_mask; \ 12488e89a57SXin Tong target_ulong vtlb_index; \ 125022c62cbSPaolo Bonzini 126022c62cbSPaolo Bonzini #else 127022c62cbSPaolo Bonzini 128022c62cbSPaolo Bonzini #define CPU_COMMON_TLB 129022c62cbSPaolo Bonzini 130022c62cbSPaolo Bonzini #endif 131022c62cbSPaolo Bonzini 132022c62cbSPaolo Bonzini 133022c62cbSPaolo Bonzini #define CPU_TEMP_BUF_NLONGS 128 134022c62cbSPaolo Bonzini #define CPU_COMMON \ 135022c62cbSPaolo Bonzini /* soft mmu support */ \ 136022c62cbSPaolo Bonzini CPU_COMMON_TLB \ 137022c62cbSPaolo Bonzini 138022c62cbSPaolo Bonzini #endif 139