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" 31022c62cbSPaolo Bonzini #include "exec/hwaddr.h" 32ab93bbe2Sbellard 3335b66fc4Sbellard #ifndef TARGET_LONG_BITS 3435b66fc4Sbellard #error TARGET_LONG_BITS must be defined before including this header 3535b66fc4Sbellard #endif 3635b66fc4Sbellard 3735b66fc4Sbellard #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8) 3835b66fc4Sbellard 39c2e3dee6SLaurent Vivier typedef int64_t target_llong __attribute__((aligned(TARGET_LLONG_ALIGNMENT))); 40c2e3dee6SLaurent Vivier typedef uint64_t target_ullong __attribute__((aligned(TARGET_LLONG_ALIGNMENT))); 41ab6d960fSbellard /* target_ulong is the type of a virtual address */ 4235b66fc4Sbellard #if TARGET_LONG_SIZE == 4 43*6cfd9b52SPaolo Bonzini typedef int32_t target_long; 44*6cfd9b52SPaolo 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 49*6cfd9b52SPaolo Bonzini typedef int64_t target_long; 50*6cfd9b52SPaolo 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) */ 62ab93bbe2Sbellard 63a316d335Sbellard #define TB_JMP_CACHE_BITS 12 64a316d335Sbellard #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) 65a316d335Sbellard 66b362e5e0Spbrook /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for 67b362e5e0Spbrook addresses on the same page. The top bits are the same. This allows 68b362e5e0Spbrook TLB invalidation to quickly clear a subset of the hash table. */ 69b362e5e0Spbrook #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2) 70b362e5e0Spbrook #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS) 71b362e5e0Spbrook #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1) 72b362e5e0Spbrook #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE) 73b362e5e0Spbrook 7420cb400dSPaul Brook #if !defined(CONFIG_USER_ONLY) 7584b7b8e7Sbellard #define CPU_TLB_BITS 8 7684b7b8e7Sbellard #define CPU_TLB_SIZE (1 << CPU_TLB_BITS) 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 104355b1943SPaul Brook extern int CPUTLBEntry_wrong_size[sizeof(CPUTLBEntry) == (1 << CPU_TLB_ENTRY_BITS) ? 1 : -1]; 105355b1943SPaul Brook 10620cb400dSPaul Brook #define CPU_COMMON_TLB \ 10720cb400dSPaul Brook /* The meaning of the MMU modes is defined in the target code. */ \ 10820cb400dSPaul Brook CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \ 109a8170e5eSAvi Kivity hwaddr iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \ 110d4c430a8SPaul Brook target_ulong tlb_flush_addr; \ 111d4c430a8SPaul Brook target_ulong tlb_flush_mask; 11220cb400dSPaul Brook 11320cb400dSPaul Brook #else 11420cb400dSPaul Brook 11520cb400dSPaul Brook #define CPU_COMMON_TLB 11620cb400dSPaul Brook 11720cb400dSPaul Brook #endif 11820cb400dSPaul Brook 11920cb400dSPaul Brook 120e2542fe2SJuan Quintela #ifdef HOST_WORDS_BIGENDIAN 1212e70f6efSpbrook typedef struct icount_decr_u16 { 1222e70f6efSpbrook uint16_t high; 1232e70f6efSpbrook uint16_t low; 1242e70f6efSpbrook } icount_decr_u16; 1252e70f6efSpbrook #else 1262e70f6efSpbrook typedef struct icount_decr_u16 { 1272e70f6efSpbrook uint16_t low; 1282e70f6efSpbrook uint16_t high; 1292e70f6efSpbrook } icount_decr_u16; 1302e70f6efSpbrook #endif 1312e70f6efSpbrook 132a1d1bb31Saliguori typedef struct CPUBreakpoint { 133a1d1bb31Saliguori target_ulong pc; 134a1d1bb31Saliguori int flags; /* BP_* */ 13572cf2d4fSBlue Swirl QTAILQ_ENTRY(CPUBreakpoint) entry; 136a1d1bb31Saliguori } CPUBreakpoint; 137a1d1bb31Saliguori 138a1d1bb31Saliguori typedef struct CPUWatchpoint { 139a1d1bb31Saliguori target_ulong vaddr; 140a1d1bb31Saliguori target_ulong len_mask; 141a1d1bb31Saliguori int flags; /* BP_* */ 14272cf2d4fSBlue Swirl QTAILQ_ENTRY(CPUWatchpoint) entry; 143a1d1bb31Saliguori } CPUWatchpoint; 144a1d1bb31Saliguori 145a20e31dcSblueswir1 #define CPU_TEMP_BUF_NLONGS 128 146a316d335Sbellard #define CPU_COMMON \ 147a316d335Sbellard /* soft mmu support */ \ 1482e70f6efSpbrook /* in order to avoid passing too many arguments to the MMIO \ 1492e70f6efSpbrook helpers, we store some rarely used information in the CPU \ 150a316d335Sbellard context) */ \ 15120503968SBlue Swirl uintptr_t mem_io_pc; /* host pc at which the memory was \ 1522e70f6efSpbrook accessed */ \ 1532e70f6efSpbrook target_ulong mem_io_vaddr; /* target virtual addr at which the \ 1542e70f6efSpbrook memory was accessed */ \ 15520cb400dSPaul Brook CPU_COMMON_TLB \ 156a316d335Sbellard struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \ 157a20e31dcSblueswir1 /* buffer for temporaries in the code generator */ \ 158a20e31dcSblueswir1 long temp_buf[CPU_TEMP_BUF_NLONGS]; \ 159a316d335Sbellard \ 1602e70f6efSpbrook int64_t icount_extra; /* Instructions until next timer event. */ \ 1612e70f6efSpbrook /* Number of cycles left, with interrupt flag in high bit. \ 1622e70f6efSpbrook This allows a single read-compare-cbranch-write sequence to test \ 1632e70f6efSpbrook for both decrementer underflow and exceptions. */ \ 1642e70f6efSpbrook union { \ 1652e70f6efSpbrook uint32_t u32; \ 1662e70f6efSpbrook icount_decr_u16 u16; \ 1672e70f6efSpbrook } icount_decr; \ 1682e70f6efSpbrook uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \ 1692e70f6efSpbrook \ 170a316d335Sbellard /* from this point: preserved by CPU reset */ \ 171a316d335Sbellard /* ice debug support */ \ 17272cf2d4fSBlue Swirl QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; \ 173a316d335Sbellard int singlestep_enabled; \ 174a316d335Sbellard \ 17572cf2d4fSBlue Swirl QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \ 176a1d1bb31Saliguori CPUWatchpoint *watchpoint_hit; \ 1776658ffb8Spbrook \ 17856aebc89Spbrook struct GDBRegisterState *gdb_regs; \ 17956aebc89Spbrook \ 1809133e39bSbellard /* Core interrupt code */ \ 1816ab7e546SPeter Maydell sigjmp_buf jmp_env; \ 182acb6685fSAnthony Liguori int exception_index; \ 1839133e39bSbellard \ 1849349b4f9SAndreas Färber CPUArchState *next_cpu; /* next CPU sharing TB cache */ \ 185a316d335Sbellard /* user data */ \ 18601ba9816Sths void *opaque; \ 18701ba9816Sths \ 188f7575c96SAndreas Färber const char *cpu_model_str; 189a316d335Sbellard 190ab93bbe2Sbellard #endif 191