1ab93bbe2Sbellard /* 2ab93bbe2Sbellard * common defines for all CPUs 3ab93bbe2Sbellard * 4ab93bbe2Sbellard * Copyright (c) 2003 Fabrice Bellard 5ab93bbe2Sbellard * 6ab93bbe2Sbellard * This library is free software; you can redistribute it and/or 7ab93bbe2Sbellard * modify it under the terms of the GNU Lesser General Public 8ab93bbe2Sbellard * License as published by the Free Software Foundation; either 9ab93bbe2Sbellard * version 2 of the License, or (at your option) any later version. 10ab93bbe2Sbellard * 11ab93bbe2Sbellard * This library is distributed in the hope that it will be useful, 12ab93bbe2Sbellard * but WITHOUT ANY WARRANTY; without even the implied warranty of 13ab93bbe2Sbellard * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14ab93bbe2Sbellard * Lesser General Public License for more details. 15ab93bbe2Sbellard * 16ab93bbe2Sbellard * You should have received a copy of the GNU Lesser General Public 178167ee88SBlue Swirl * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18ab93bbe2Sbellard */ 19ab93bbe2Sbellard #ifndef CPU_DEFS_H 20ab93bbe2Sbellard #define CPU_DEFS_H 21ab93bbe2Sbellard 2287ecb68bSpbrook #ifndef NEED_CPU_H 2387ecb68bSpbrook #error cpu.h included from common code 2487ecb68bSpbrook #endif 2587ecb68bSpbrook 26ab93bbe2Sbellard #include "config.h" 27ed1c0bcbSbellard #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" 34ab93bbe2Sbellard 3535b66fc4Sbellard #ifndef TARGET_LONG_BITS 3635b66fc4Sbellard #error TARGET_LONG_BITS must be defined before including this header 3735b66fc4Sbellard #endif 3835b66fc4Sbellard 3935b66fc4Sbellard #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8) 4035b66fc4Sbellard 41ab6d960fSbellard /* target_ulong is the type of a virtual address */ 4235b66fc4Sbellard #if TARGET_LONG_SIZE == 4 436cfd9b52SPaolo Bonzini typedef int32_t target_long; 446cfd9b52SPaolo Bonzini typedef uint32_t target_ulong; 45c27004ecSbellard #define TARGET_FMT_lx "%08x" 46b62b461bSj_mayer #define TARGET_FMT_ld "%d" 4771c8b8fdSj_mayer #define TARGET_FMT_lu "%u" 4835b66fc4Sbellard #elif TARGET_LONG_SIZE == 8 496cfd9b52SPaolo Bonzini typedef int64_t target_long; 506cfd9b52SPaolo Bonzini typedef uint64_t target_ulong; 5126a76461Sbellard #define TARGET_FMT_lx "%016" PRIx64 52b62b461bSj_mayer #define TARGET_FMT_ld "%" PRId64 5371c8b8fdSj_mayer #define TARGET_FMT_lu "%" PRIu64 5435b66fc4Sbellard #else 5535b66fc4Sbellard #error TARGET_LONG_SIZE undefined 5635b66fc4Sbellard #endif 5735b66fc4Sbellard 582be0071fSbellard #define EXCP_INTERRUPT 0x10000 /* async interruption */ 592be0071fSbellard #define EXCP_HLT 0x10001 /* hlt instruction reached */ 602be0071fSbellard #define EXCP_DEBUG 0x10002 /* cpu stopped after a breakpoint or singlestep */ 615a1e3cfcSbellard #define EXCP_HALTED 0x10003 /* cpu is halted (waiting for external event) */ 6272c1d3afSPeter Maydell #define EXCP_YIELD 0x10004 /* cpu wants to yield timeslice to another */ 63ab93bbe2Sbellard 64b362e5e0Spbrook /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for 65b362e5e0Spbrook addresses on the same page. The top bits are the same. This allows 66b362e5e0Spbrook TLB invalidation to quickly clear a subset of the hash table. */ 67b362e5e0Spbrook #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) 68b362e5e0Spbrook #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) 69b362e5e0Spbrook #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) 70b362e5e0Spbrook #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE) 71b362e5e0Spbrook 7220cb400dSPaul Brook #if !defined(CONFIG_USER_ONLY) 7384b7b8e7Sbellard #define CPU_TLB_BITS 8 7484b7b8e7Sbellard #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 77ab93bbe2Sbellard 78355b1943SPaul Brook #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32 79d656469fSbellard #define CPU_TLB_ENTRY_BITS 4 80d656469fSbellard #else 81d656469fSbellard #define CPU_TLB_ENTRY_BITS 5 82d656469fSbellard #endif 83d656469fSbellard 84ab93bbe2Sbellard typedef struct CPUTLBEntry { 850f459d16Spbrook /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address 860f459d16Spbrook bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not 870f459d16Spbrook go directly to ram. 88db8d7466Sbellard bit 3 : indicates that the entry is invalid 89db8d7466Sbellard bit 2..0 : zero 90db8d7466Sbellard */ 9184b7b8e7Sbellard target_ulong addr_read; 9284b7b8e7Sbellard target_ulong addr_write; 9384b7b8e7Sbellard target_ulong addr_code; 94355b1943SPaul Brook /* Addend to virtual address to get host address. IO accesses 95ee50add9Spbrook use the corresponding iotlb value. */ 963b2992e4SStefan Weil uintptr_t addend; 97d656469fSbellard /* padding to get a power of two size */ 98d656469fSbellard uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 99d656469fSbellard (sizeof(target_ulong) * 3 + 1003b2992e4SStefan Weil ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) + 1013b2992e4SStefan Weil sizeof(uintptr_t))]; 102ab93bbe2Sbellard } CPUTLBEntry; 103ab93bbe2Sbellard 104e85ef538SRichard Henderson QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS)); 105355b1943SPaul Brook 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 11620cb400dSPaul Brook #define CPU_COMMON_TLB \ 11720cb400dSPaul Brook /* The meaning of the MMU modes is defined in the target code. */ \ 11820cb400dSPaul Brook 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]; \ 122d4c430a8SPaul Brook target_ulong tlb_flush_addr; \ 12388e89a57SXin Tong target_ulong tlb_flush_mask; \ 12488e89a57SXin Tong target_ulong vtlb_index; \ 12520cb400dSPaul Brook 12620cb400dSPaul Brook #else 12720cb400dSPaul Brook 12820cb400dSPaul Brook #define CPU_COMMON_TLB 12920cb400dSPaul Brook 13020cb400dSPaul Brook #endif 13120cb400dSPaul Brook 13220cb400dSPaul Brook 133a20e31dcSblueswir1 #define CPU_TEMP_BUF_NLONGS 128 134a316d335Sbellard #define CPU_COMMON \ 135a316d335Sbellard /* soft mmu support */ \ 13620cb400dSPaul Brook CPU_COMMON_TLB \ 137a316d335Sbellard 138ab93bbe2Sbellard #endif 139