]> git.proxmox.com Git - mirror_qemu.git/blame - include/exec/cpu-defs.h
rbd: Clean up after the previous commit
[mirror_qemu.git] / include / exec / cpu-defs.h
CommitLineData
ab93bbe2
FB
1/*
2 * common defines for all CPUs
5fafdf24 3 *
ab93bbe2
FB
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
8167ee88 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
ab93bbe2
FB
18 */
19#ifndef CPU_DEFS_H
20#define CPU_DEFS_H
21
87ecb68b
PB
22#ifndef NEED_CPU_H
23#error cpu.h included from common code
24#endif
25
87776ab7 26#include "qemu/host-utils.h"
1de7afc9 27#include "qemu/queue.h"
1de29aef 28#include "tcg-target.h"
ce927ed9 29#ifndef CONFIG_USER_ONLY
022c62cb 30#include "exec/hwaddr.h"
ce927ed9 31#endif
fadc1cbe 32#include "exec/memattrs.h"
ab93bbe2 33
35b66fc4
FB
34#ifndef TARGET_LONG_BITS
35#error TARGET_LONG_BITS must be defined before including this header
36#endif
37
38#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
39
ab6d960f 40/* target_ulong is the type of a virtual address */
35b66fc4 41#if TARGET_LONG_SIZE == 4
6cfd9b52
PB
42typedef int32_t target_long;
43typedef uint32_t target_ulong;
c27004ec 44#define TARGET_FMT_lx "%08x"
b62b461b 45#define TARGET_FMT_ld "%d"
71c8b8fd 46#define TARGET_FMT_lu "%u"
35b66fc4 47#elif TARGET_LONG_SIZE == 8
6cfd9b52
PB
48typedef int64_t target_long;
49typedef uint64_t target_ulong;
26a76461 50#define TARGET_FMT_lx "%016" PRIx64
b62b461b 51#define TARGET_FMT_ld "%" PRId64
71c8b8fd 52#define TARGET_FMT_lu "%" PRIu64
35b66fc4
FB
53#else
54#error TARGET_LONG_SIZE undefined
55#endif
56
20cb400d 57#if !defined(CONFIG_USER_ONLY)
88e89a57
XT
58/* use a fully associative victim tlb of 8 entries */
59#define CPU_VTLB_SIZE 8
ab93bbe2 60
355b1943 61#if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
d656469f
FB
62#define CPU_TLB_ENTRY_BITS 4
63#else
64#define CPU_TLB_ENTRY_BITS 5
65#endif
66
1de29aef
PB
67/* TCG_TARGET_TLB_DISPLACEMENT_BITS is used in CPU_TLB_BITS to ensure that
68 * the TLB is not unnecessarily small, but still small enough for the
69 * TLB lookup instruction sequence used by the TCG target.
70 *
71 * TCG will have to generate an operand as large as the distance between
72 * env and the tlb_table[NB_MMU_MODES - 1][0].addend. For simplicity,
73 * the TCG targets just round everything up to the next power of two, and
74 * count bits. This works because: 1) the size of each TLB is a largish
75 * power of two, 2) and because the limit of the displacement is really close
76 * to a power of two, 3) the offset of tlb_table[0][0] inside env is smaller
77 * than the size of a TLB.
78 *
79 * For example, the maximum displacement 0xFFF0 on PPC and MIPS, but TCG
80 * just says "the displacement is 16 bits". TCG_TARGET_TLB_DISPLACEMENT_BITS
81 * then ensures that tlb_table at least 0x8000 bytes large ("not unnecessarily
82 * small": 2^15). The operand then will come up smaller than 0xFFF0 without
83 * any particular care, because the TLB for a single MMU mode is larger than
84 * 0x10000-0xFFF0=16 bytes. In the end, the maximum value of the operand
85 * could be something like 0xC000 (the offset of the last TLB table) plus
86 * 0x18 (the offset of the addend field in each TLB entry) plus the offset
87 * of tlb_table inside env (which is non-trivial but not huge).
88 */
89#define CPU_TLB_BITS \
90 MIN(8, \
91 TCG_TARGET_TLB_DISPLACEMENT_BITS - CPU_TLB_ENTRY_BITS - \
92 (NB_MMU_MODES <= 1 ? 0 : \
93 NB_MMU_MODES <= 2 ? 1 : \
94 NB_MMU_MODES <= 4 ? 2 : \
95 NB_MMU_MODES <= 8 ? 3 : 4))
96
97#define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
98
ab93bbe2 99typedef struct CPUTLBEntry {
0f459d16
PB
100 /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
101 bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not
102 go directly to ram.
db8d7466
FB
103 bit 3 : indicates that the entry is invalid
104 bit 2..0 : zero
105 */
b4a4b8d0
PC
106 union {
107 struct {
108 target_ulong addr_read;
109 target_ulong addr_write;
110 target_ulong addr_code;
111 /* Addend to virtual address to get host address. IO accesses
112 use the corresponding iotlb value. */
113 uintptr_t addend;
114 };
115 /* padding to get a power of two size */
116 uint8_t dummy[1 << CPU_TLB_ENTRY_BITS];
117 };
ab93bbe2
FB
118} CPUTLBEntry;
119
e85ef538 120QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS));
355b1943 121
e469b22f
PM
122/* The IOTLB is not accessed directly inline by generated TCG code,
123 * so the CPUIOTLBEntry layout is not as critical as that of the
124 * CPUTLBEntry. (This is also why we don't want to combine the two
125 * structs into one.)
126 */
127typedef struct CPUIOTLBEntry {
128 hwaddr addr;
fadc1cbe 129 MemTxAttrs attrs;
e469b22f
PM
130} CPUIOTLBEntry;
131
20cb400d
PB
132#define CPU_COMMON_TLB \
133 /* The meaning of the MMU modes is defined in the target code. */ \
134 CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \
88e89a57 135 CPUTLBEntry tlb_v_table[NB_MMU_MODES][CPU_VTLB_SIZE]; \
e469b22f
PM
136 CPUIOTLBEntry iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \
137 CPUIOTLBEntry iotlb_v[NB_MMU_MODES][CPU_VTLB_SIZE]; \
d4c430a8 138 target_ulong tlb_flush_addr; \
88e89a57
XT
139 target_ulong tlb_flush_mask; \
140 target_ulong vtlb_index; \
20cb400d
PB
141
142#else
143
144#define CPU_COMMON_TLB
145
146#endif
147
148
a316d335 149#define CPU_COMMON \
a316d335 150 /* soft mmu support */ \
20cb400d 151 CPU_COMMON_TLB \
a316d335 152
ab93bbe2 153#endif