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" 27ab93bbe2Sbellard #include <setjmp.h> 28ed1c0bcbSbellard #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 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) */ 62*72c1d3afSPeter Maydell #define EXCP_YIELD 0x10004 /* cpu wants to yield timeslice to another */ 63ab93bbe2Sbellard 64a316d335Sbellard #define TB_JMP_CACHE_BITS 12 65a316d335Sbellard #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) 66a316d335Sbellard 67b362e5e0Spbrook /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for 68b362e5e0Spbrook addresses on the same page. The top bits are the same. This allows 69b362e5e0Spbrook TLB invalidation to quickly clear a subset of the hash table. */ 70b362e5e0Spbrook #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) 71b362e5e0Spbrook #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) 72b362e5e0Spbrook #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) 73b362e5e0Spbrook #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE) 74b362e5e0Spbrook 7520cb400dSPaul Brook #if !defined(CONFIG_USER_ONLY) 7684b7b8e7Sbellard #define CPU_TLB_BITS 8 7784b7b8e7Sbellard #define CPU_TLB_SIZE (1 << CPU_TLB_BITS) 78ab93bbe2Sbellard 79355b1943SPaul Brook #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32 80d656469fSbellard #define CPU_TLB_ENTRY_BITS 4 81d656469fSbellard #else 82d656469fSbellard #define CPU_TLB_ENTRY_BITS 5 83d656469fSbellard #endif 84d656469fSbellard 85ab93bbe2Sbellard typedef struct CPUTLBEntry { 860f459d16Spbrook /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address 870f459d16Spbrook bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not 880f459d16Spbrook go directly to ram. 89db8d7466Sbellard bit 3 : indicates that the entry is invalid 90db8d7466Sbellard bit 2..0 : zero 91db8d7466Sbellard */ 9284b7b8e7Sbellard target_ulong addr_read; 9384b7b8e7Sbellard target_ulong addr_write; 9484b7b8e7Sbellard target_ulong addr_code; 95355b1943SPaul Brook /* Addend to virtual address to get host address. IO accesses 96ee50add9Spbrook use the corresponding iotlb value. */ 973b2992e4SStefan Weil uintptr_t addend; 98d656469fSbellard /* padding to get a power of two size */ 99d656469fSbellard uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 100d656469fSbellard (sizeof(target_ulong) * 3 + 1013b2992e4SStefan Weil ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) + 1023b2992e4SStefan Weil sizeof(uintptr_t))]; 103ab93bbe2Sbellard } CPUTLBEntry; 104ab93bbe2Sbellard 105e85ef538SRichard Henderson QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS)); 106355b1943SPaul Brook 10720cb400dSPaul Brook #define CPU_COMMON_TLB \ 10820cb400dSPaul Brook /* The meaning of the MMU modes is defined in the target code. */ \ 10920cb400dSPaul Brook CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \ 110a8170e5eSAvi Kivity hwaddr iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \ 111d4c430a8SPaul Brook target_ulong tlb_flush_addr; \ 112d4c430a8SPaul Brook target_ulong tlb_flush_mask; 11320cb400dSPaul Brook 11420cb400dSPaul Brook #else 11520cb400dSPaul Brook 11620cb400dSPaul Brook #define CPU_COMMON_TLB 11720cb400dSPaul Brook 11820cb400dSPaul Brook #endif 11920cb400dSPaul Brook 12020cb400dSPaul Brook 121e2542fe2SJuan Quintela #ifdef HOST_WORDS_BIGENDIAN 1222e70f6efSpbrook typedef struct icount_decr_u16 { 1232e70f6efSpbrook uint16_t high; 1242e70f6efSpbrook uint16_t low; 1252e70f6efSpbrook } icount_decr_u16; 1262e70f6efSpbrook #else 1272e70f6efSpbrook typedef struct icount_decr_u16 { 1282e70f6efSpbrook uint16_t low; 1292e70f6efSpbrook uint16_t high; 1302e70f6efSpbrook } icount_decr_u16; 1312e70f6efSpbrook #endif 1322e70f6efSpbrook 133a1d1bb31Saliguori typedef struct CPUBreakpoint { 134a1d1bb31Saliguori target_ulong pc; 135a1d1bb31Saliguori int flags; /* BP_* */ 13672cf2d4fSBlue Swirl QTAILQ_ENTRY(CPUBreakpoint) entry; 137a1d1bb31Saliguori } CPUBreakpoint; 138a1d1bb31Saliguori 139a1d1bb31Saliguori typedef struct CPUWatchpoint { 140a1d1bb31Saliguori target_ulong vaddr; 141a1d1bb31Saliguori target_ulong len_mask; 142a1d1bb31Saliguori int flags; /* BP_* */ 14372cf2d4fSBlue Swirl QTAILQ_ENTRY(CPUWatchpoint) entry; 144a1d1bb31Saliguori } CPUWatchpoint; 145a1d1bb31Saliguori 146a20e31dcSblueswir1 #define CPU_TEMP_BUF_NLONGS 128 147a316d335Sbellard #define CPU_COMMON \ 148a316d335Sbellard /* soft mmu support */ \ 1492e70f6efSpbrook /* in order to avoid passing too many arguments to the MMIO \ 1502e70f6efSpbrook helpers, we store some rarely used information in the CPU \ 151a316d335Sbellard context) */ \ 15220503968SBlue Swirl uintptr_t mem_io_pc; /* host pc at which the memory was \ 1532e70f6efSpbrook accessed */ \ 1542e70f6efSpbrook target_ulong mem_io_vaddr; /* target virtual addr at which the \ 1552e70f6efSpbrook memory was accessed */ \ 15620cb400dSPaul Brook CPU_COMMON_TLB \ 157a316d335Sbellard struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \ 158a316d335Sbellard \ 1592e70f6efSpbrook int64_t icount_extra; /* Instructions until next timer event. */ \ 1602e70f6efSpbrook /* Number of cycles left, with interrupt flag in high bit. \ 1612e70f6efSpbrook This allows a single read-compare-cbranch-write sequence to test \ 1622e70f6efSpbrook for both decrementer underflow and exceptions. */ \ 1632e70f6efSpbrook union { \ 1642e70f6efSpbrook uint32_t u32; \ 1652e70f6efSpbrook icount_decr_u16 u16; \ 1662e70f6efSpbrook } icount_decr; \ 1672e70f6efSpbrook uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \ 1682e70f6efSpbrook \ 169a316d335Sbellard /* from this point: preserved by CPU reset */ \ 170a316d335Sbellard /* ice debug support */ \ 17172cf2d4fSBlue Swirl QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; \ 172a316d335Sbellard \ 17372cf2d4fSBlue Swirl QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \ 174a1d1bb31Saliguori CPUWatchpoint *watchpoint_hit; \ 1756658ffb8Spbrook \ 1769133e39bSbellard /* Core interrupt code */ \ 1776ab7e546SPeter Maydell sigjmp_buf jmp_env; \ 178acb6685fSAnthony Liguori int exception_index; \ 1799133e39bSbellard \ 180a316d335Sbellard /* user data */ \ 18101ba9816Sths void *opaque; \ 182a316d335Sbellard 183ab93bbe2Sbellard #endif 184