1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth * SH4 emulation
3fcf5ef2aSThomas Huth *
4fcf5ef2aSThomas Huth * Copyright (c) 2005 Samuel Tardieu
5fcf5ef2aSThomas Huth *
6fcf5ef2aSThomas Huth * This library is free software; you can redistribute it and/or
7fcf5ef2aSThomas Huth * modify it under the terms of the GNU Lesser General Public
8fcf5ef2aSThomas Huth * License as published by the Free Software Foundation; either
96faf2b6cSThomas Huth * version 2.1 of the License, or (at your option) any later version.
10fcf5ef2aSThomas Huth *
11fcf5ef2aSThomas Huth * This library is distributed in the hope that it will be useful,
12fcf5ef2aSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fcf5ef2aSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14fcf5ef2aSThomas Huth * Lesser General Public License for more details.
15fcf5ef2aSThomas Huth *
16fcf5ef2aSThomas Huth * You should have received a copy of the GNU Lesser General Public
17fcf5ef2aSThomas Huth * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18fcf5ef2aSThomas Huth */
19fcf5ef2aSThomas Huth
20fcf5ef2aSThomas Huth #ifndef SH4_CPU_H
21fcf5ef2aSThomas Huth #define SH4_CPU_H
22fcf5ef2aSThomas Huth
23fcf5ef2aSThomas Huth #include "cpu-qom.h"
2474433bf0SRichard Henderson #include "exec/cpu-defs.h"
2569242e7eSMarc-André Lureau #include "qemu/cpu-float.h"
26fcf5ef2aSThomas Huth
27fcf5ef2aSThomas Huth /* CPU Subtypes */
28fcf5ef2aSThomas Huth #define SH_CPU_SH7750 (1 << 0)
29fcf5ef2aSThomas Huth #define SH_CPU_SH7750S (1 << 1)
30fcf5ef2aSThomas Huth #define SH_CPU_SH7750R (1 << 2)
31fcf5ef2aSThomas Huth #define SH_CPU_SH7751 (1 << 3)
32fcf5ef2aSThomas Huth #define SH_CPU_SH7751R (1 << 4)
33fcf5ef2aSThomas Huth #define SH_CPU_SH7785 (1 << 5)
34fcf5ef2aSThomas Huth #define SH_CPU_SH7750_ALL (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7750R)
35fcf5ef2aSThomas Huth #define SH_CPU_SH7751_ALL (SH_CPU_SH7751 | SH_CPU_SH7751R)
36fcf5ef2aSThomas Huth
37fcf5ef2aSThomas Huth #define SR_MD 30
38fcf5ef2aSThomas Huth #define SR_RB 29
39fcf5ef2aSThomas Huth #define SR_BL 28
40fcf5ef2aSThomas Huth #define SR_FD 15
41fcf5ef2aSThomas Huth #define SR_M 9
42fcf5ef2aSThomas Huth #define SR_Q 8
43fcf5ef2aSThomas Huth #define SR_I3 7
44fcf5ef2aSThomas Huth #define SR_I2 6
45fcf5ef2aSThomas Huth #define SR_I1 5
46fcf5ef2aSThomas Huth #define SR_I0 4
47fcf5ef2aSThomas Huth #define SR_S 1
48fcf5ef2aSThomas Huth #define SR_T 0
49fcf5ef2aSThomas Huth
50fcf5ef2aSThomas Huth #define FPSCR_MASK (0x003fffff)
51fcf5ef2aSThomas Huth #define FPSCR_FR (1 << 21)
52fcf5ef2aSThomas Huth #define FPSCR_SZ (1 << 20)
53fcf5ef2aSThomas Huth #define FPSCR_PR (1 << 19)
54fcf5ef2aSThomas Huth #define FPSCR_DN (1 << 18)
55fcf5ef2aSThomas Huth #define FPSCR_CAUSE_MASK (0x3f << 12)
56fcf5ef2aSThomas Huth #define FPSCR_CAUSE_SHIFT (12)
57fcf5ef2aSThomas Huth #define FPSCR_CAUSE_E (1 << 17)
58fcf5ef2aSThomas Huth #define FPSCR_CAUSE_V (1 << 16)
59fcf5ef2aSThomas Huth #define FPSCR_CAUSE_Z (1 << 15)
60fcf5ef2aSThomas Huth #define FPSCR_CAUSE_O (1 << 14)
61fcf5ef2aSThomas Huth #define FPSCR_CAUSE_U (1 << 13)
62fcf5ef2aSThomas Huth #define FPSCR_CAUSE_I (1 << 12)
63fcf5ef2aSThomas Huth #define FPSCR_ENABLE_MASK (0x1f << 7)
64fcf5ef2aSThomas Huth #define FPSCR_ENABLE_SHIFT (7)
65fcf5ef2aSThomas Huth #define FPSCR_ENABLE_V (1 << 11)
66fcf5ef2aSThomas Huth #define FPSCR_ENABLE_Z (1 << 10)
67fcf5ef2aSThomas Huth #define FPSCR_ENABLE_O (1 << 9)
68fcf5ef2aSThomas Huth #define FPSCR_ENABLE_U (1 << 8)
69fcf5ef2aSThomas Huth #define FPSCR_ENABLE_I (1 << 7)
70fcf5ef2aSThomas Huth #define FPSCR_FLAG_MASK (0x1f << 2)
71fcf5ef2aSThomas Huth #define FPSCR_FLAG_SHIFT (2)
72fcf5ef2aSThomas Huth #define FPSCR_FLAG_V (1 << 6)
73fcf5ef2aSThomas Huth #define FPSCR_FLAG_Z (1 << 5)
74fcf5ef2aSThomas Huth #define FPSCR_FLAG_O (1 << 4)
75fcf5ef2aSThomas Huth #define FPSCR_FLAG_U (1 << 3)
76fcf5ef2aSThomas Huth #define FPSCR_FLAG_I (1 << 2)
77fcf5ef2aSThomas Huth #define FPSCR_RM_MASK (0x03 << 0)
78fcf5ef2aSThomas Huth #define FPSCR_RM_NEAREST (0 << 0)
79fcf5ef2aSThomas Huth #define FPSCR_RM_ZERO (1 << 0)
80fcf5ef2aSThomas Huth
81ab419fd8SRichard Henderson #define TB_FLAG_DELAY_SLOT (1 << 0)
82ab419fd8SRichard Henderson #define TB_FLAG_DELAY_SLOT_COND (1 << 1)
83ab419fd8SRichard Henderson #define TB_FLAG_DELAY_SLOT_RTE (1 << 2)
841516184dSRichard Henderson #define TB_FLAG_PENDING_MOVCA (1 << 3)
85ab419fd8SRichard Henderson #define TB_FLAG_GUSA_SHIFT 4 /* [11:4] */
86ab419fd8SRichard Henderson #define TB_FLAG_GUSA_EXCLUSIVE (1 << 12)
87ab419fd8SRichard Henderson #define TB_FLAG_UNALIGN (1 << 13)
88ab419fd8SRichard Henderson #define TB_FLAG_SR_FD (1 << SR_FD) /* 15 */
89ab419fd8SRichard Henderson #define TB_FLAG_FPSCR_PR FPSCR_PR /* 19 */
90ab419fd8SRichard Henderson #define TB_FLAG_FPSCR_SZ FPSCR_SZ /* 20 */
91ab419fd8SRichard Henderson #define TB_FLAG_FPSCR_FR FPSCR_FR /* 21 */
92ab419fd8SRichard Henderson #define TB_FLAG_SR_RB (1 << SR_RB) /* 29 */
93ab419fd8SRichard Henderson #define TB_FLAG_SR_MD (1 << SR_MD) /* 30 */
941516184dSRichard Henderson
95ab419fd8SRichard Henderson #define TB_FLAG_DELAY_SLOT_MASK (TB_FLAG_DELAY_SLOT | \
96ab419fd8SRichard Henderson TB_FLAG_DELAY_SLOT_COND | \
97ab419fd8SRichard Henderson TB_FLAG_DELAY_SLOT_RTE)
98ab419fd8SRichard Henderson #define TB_FLAG_GUSA_MASK ((0xff << TB_FLAG_GUSA_SHIFT) | \
99ab419fd8SRichard Henderson TB_FLAG_GUSA_EXCLUSIVE)
100ab419fd8SRichard Henderson #define TB_FLAG_FPSCR_MASK (TB_FLAG_FPSCR_PR | \
101ab419fd8SRichard Henderson TB_FLAG_FPSCR_SZ | \
102ab419fd8SRichard Henderson TB_FLAG_FPSCR_FR)
103ab419fd8SRichard Henderson #define TB_FLAG_SR_MASK (TB_FLAG_SR_FD | \
104ab419fd8SRichard Henderson TB_FLAG_SR_RB | \
105ab419fd8SRichard Henderson TB_FLAG_SR_MD)
106ab419fd8SRichard Henderson #define TB_FLAG_ENVFLAGS_MASK (TB_FLAG_DELAY_SLOT_MASK | \
107ab419fd8SRichard Henderson TB_FLAG_GUSA_MASK)
108e1933d14SRichard Henderson
109fcf5ef2aSThomas Huth typedef struct tlb_t {
110fcf5ef2aSThomas Huth uint32_t vpn; /* virtual page number */
111fcf5ef2aSThomas Huth uint32_t ppn; /* physical page number */
112fcf5ef2aSThomas Huth uint32_t size; /* mapped page size in bytes */
113fcf5ef2aSThomas Huth uint8_t asid; /* address space identifier */
114fcf5ef2aSThomas Huth uint8_t v:1; /* validity */
115fcf5ef2aSThomas Huth uint8_t sz:2; /* page size */
116fcf5ef2aSThomas Huth uint8_t sh:1; /* share status */
117fcf5ef2aSThomas Huth uint8_t c:1; /* cacheability */
118fcf5ef2aSThomas Huth uint8_t pr:2; /* protection key */
119fcf5ef2aSThomas Huth uint8_t d:1; /* dirty */
120fcf5ef2aSThomas Huth uint8_t wt:1; /* write through */
121fcf5ef2aSThomas Huth uint8_t sa:3; /* space attribute (PCMCIA) */
122fcf5ef2aSThomas Huth uint8_t tc:1; /* timing control */
123fcf5ef2aSThomas Huth } tlb_t;
124fcf5ef2aSThomas Huth
125fcf5ef2aSThomas Huth #define UTLB_SIZE 64
126fcf5ef2aSThomas Huth #define ITLB_SIZE 4
127fcf5ef2aSThomas Huth
128fcf5ef2aSThomas Huth #define TARGET_INSN_START_EXTRA_WORDS 1
129fcf5ef2aSThomas Huth
130fcf5ef2aSThomas Huth enum sh_features {
131fcf5ef2aSThomas Huth SH_FEATURE_SH4A = 1,
132fcf5ef2aSThomas Huth SH_FEATURE_BCR3_AND_BCR4 = 2,
133fcf5ef2aSThomas Huth };
134fcf5ef2aSThomas Huth
135fcf5ef2aSThomas Huth typedef struct memory_content {
136fcf5ef2aSThomas Huth uint32_t address;
137fcf5ef2aSThomas Huth uint32_t value;
138fcf5ef2aSThomas Huth struct memory_content *next;
139fcf5ef2aSThomas Huth } memory_content;
140fcf5ef2aSThomas Huth
1411ea4a06aSPhilippe Mathieu-Daudé typedef struct CPUArchState {
142fcf5ef2aSThomas Huth uint32_t flags; /* general execution flags */
143fcf5ef2aSThomas Huth uint32_t gregs[24]; /* general registers */
144fcf5ef2aSThomas Huth float32 fregs[32]; /* floating point registers */
145fcf5ef2aSThomas Huth uint32_t sr; /* status register (with T split out) */
146fcf5ef2aSThomas Huth uint32_t sr_m; /* M bit of status register */
147fcf5ef2aSThomas Huth uint32_t sr_q; /* Q bit of status register */
148fcf5ef2aSThomas Huth uint32_t sr_t; /* T bit of status register */
149fcf5ef2aSThomas Huth uint32_t ssr; /* saved status register */
150fcf5ef2aSThomas Huth uint32_t spc; /* saved program counter */
151fcf5ef2aSThomas Huth uint32_t gbr; /* global base register */
152fcf5ef2aSThomas Huth uint32_t vbr; /* vector base register */
153fcf5ef2aSThomas Huth uint32_t sgr; /* saved global register 15 */
154fcf5ef2aSThomas Huth uint32_t dbr; /* debug base register */
155fcf5ef2aSThomas Huth uint32_t pc; /* program counter */
15647b9f4d5SAurelien Jarno uint32_t delayed_pc; /* target of delayed branch */
15747b9f4d5SAurelien Jarno uint32_t delayed_cond; /* condition of delayed branch */
158fcf5ef2aSThomas Huth uint32_t pr; /* procedure register */
159fcf5ef2aSThomas Huth uint32_t fpscr; /* floating point status/control register */
160fcf5ef2aSThomas Huth uint32_t fpul; /* floating point communication register */
161fcf5ef2aSThomas Huth
162*7d95db5eSRichard Henderson /* multiply and accumulate: high, low and combined. */
163*7d95db5eSRichard Henderson union {
164*7d95db5eSRichard Henderson uint64_t mac;
165*7d95db5eSRichard Henderson struct {
166*7d95db5eSRichard Henderson #if HOST_BIG_ENDIAN
167*7d95db5eSRichard Henderson uint32_t mach, macl;
168*7d95db5eSRichard Henderson #else
169*7d95db5eSRichard Henderson uint32_t macl, mach;
170*7d95db5eSRichard Henderson #endif
171*7d95db5eSRichard Henderson };
172*7d95db5eSRichard Henderson };
173*7d95db5eSRichard Henderson
174fcf5ef2aSThomas Huth /* float point status register */
175fcf5ef2aSThomas Huth float_status fp_status;
176fcf5ef2aSThomas Huth
177fcf5ef2aSThomas Huth /* Those belong to the specific unit (SH7750) but are handled here */
178fcf5ef2aSThomas Huth uint32_t mmucr; /* MMU control register */
179fcf5ef2aSThomas Huth uint32_t pteh; /* page table entry high register */
180fcf5ef2aSThomas Huth uint32_t ptel; /* page table entry low register */
181fcf5ef2aSThomas Huth uint32_t ptea; /* page table entry assistance register */
18223b5d9faSLichang Zhao uint32_t ttb; /* translation table base register */
183fcf5ef2aSThomas Huth uint32_t tea; /* TLB exception address register */
184fcf5ef2aSThomas Huth uint32_t tra; /* TRAPA exception register */
185fcf5ef2aSThomas Huth uint32_t expevt; /* exception event register */
186fcf5ef2aSThomas Huth uint32_t intevt; /* interrupt event register */
187fcf5ef2aSThomas Huth
188fcf5ef2aSThomas Huth tlb_t itlb[ITLB_SIZE]; /* instruction translation table */
189fcf5ef2aSThomas Huth tlb_t utlb[UTLB_SIZE]; /* unified translation table */
190fcf5ef2aSThomas Huth
191f85da308SRichard Henderson /* LDST = LOCK_ADDR != -1. */
192f85da308SRichard Henderson uint32_t lock_addr;
193f85da308SRichard Henderson uint32_t lock_value;
194fcf5ef2aSThomas Huth
1951f5c00cfSAlex Bennée /* Fields up to this point are cleared by a CPU reset */
1961f5c00cfSAlex Bennée struct {} end_reset_fields;
1971f5c00cfSAlex Bennée
198fcf5ef2aSThomas Huth /* Fields from here on are preserved over CPU reset. */
199fcf5ef2aSThomas Huth int id; /* CPU model */
200fcf5ef2aSThomas Huth
201fcf5ef2aSThomas Huth /* The features that we should emulate. See sh_features above. */
202fcf5ef2aSThomas Huth uint32_t features;
203fcf5ef2aSThomas Huth
204fcf5ef2aSThomas Huth void *intc_handle;
205fcf5ef2aSThomas Huth int in_sleep; /* SR_BL ignored during sleep */
206fcf5ef2aSThomas Huth memory_content *movcal_backup;
207fcf5ef2aSThomas Huth memory_content **movcal_backup_tail;
208fcf5ef2aSThomas Huth } CPUSH4State;
209fcf5ef2aSThomas Huth
210fcf5ef2aSThomas Huth /**
211fcf5ef2aSThomas Huth * SuperHCPU:
212fcf5ef2aSThomas Huth * @env: #CPUSH4State
213fcf5ef2aSThomas Huth *
214fcf5ef2aSThomas Huth * A SuperH CPU.
215fcf5ef2aSThomas Huth */
216b36e239eSPhilippe Mathieu-Daudé struct ArchCPU {
217fcf5ef2aSThomas Huth CPUState parent_obj;
218fcf5ef2aSThomas Huth
219fcf5ef2aSThomas Huth CPUSH4State env;
220fcf5ef2aSThomas Huth };
221fcf5ef2aSThomas Huth
2229348028eSPhilippe Mathieu-Daudé /**
2239348028eSPhilippe Mathieu-Daudé * SuperHCPUClass:
2249348028eSPhilippe Mathieu-Daudé * @parent_realize: The parent class' realize handler.
2259348028eSPhilippe Mathieu-Daudé * @parent_phases: The parent class' reset phase handlers.
2269348028eSPhilippe Mathieu-Daudé * @pvr: Processor Version Register
2279348028eSPhilippe Mathieu-Daudé * @prr: Processor Revision Register
2289348028eSPhilippe Mathieu-Daudé * @cvr: Cache Version Register
2299348028eSPhilippe Mathieu-Daudé *
2309348028eSPhilippe Mathieu-Daudé * A SuperH CPU model.
2319348028eSPhilippe Mathieu-Daudé */
2329348028eSPhilippe Mathieu-Daudé struct SuperHCPUClass {
2339348028eSPhilippe Mathieu-Daudé CPUClass parent_class;
2349348028eSPhilippe Mathieu-Daudé
2359348028eSPhilippe Mathieu-Daudé DeviceRealize parent_realize;
2369348028eSPhilippe Mathieu-Daudé ResettablePhases parent_phases;
2379348028eSPhilippe Mathieu-Daudé
2389348028eSPhilippe Mathieu-Daudé uint32_t pvr;
2399348028eSPhilippe Mathieu-Daudé uint32_t prr;
2409348028eSPhilippe Mathieu-Daudé uint32_t cvr;
2419348028eSPhilippe Mathieu-Daudé };
242fcf5ef2aSThomas Huth
24390c84c56SMarkus Armbruster void superh_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
244a010bdbeSAlex Bennée int superh_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
245fcf5ef2aSThomas Huth int superh_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
2468905770bSMarc-André Lureau G_NORETURN void superh_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
247fa947a66SRichard Henderson MMUAccessType access_type, int mmu_idx,
2488905770bSMarc-André Lureau uintptr_t retaddr);
249fcf5ef2aSThomas Huth
250fcf5ef2aSThomas Huth void sh4_translate_init(void);
251cac720ecSRichard Henderson
252cac720ecSRichard Henderson #if !defined(CONFIG_USER_ONLY)
2536d2d454aSPhilippe Mathieu-Daudé hwaddr superh_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
254f98bce2bSRichard Henderson bool superh_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
255f98bce2bSRichard Henderson MMUAccessType access_type, int mmu_idx,
256f98bce2bSRichard Henderson bool probe, uintptr_t retaddr);
25773166ca3SPhilippe Mathieu-Daudé void superh_cpu_do_interrupt(CPUState *cpu);
25873166ca3SPhilippe Mathieu-Daudé bool superh_cpu_exec_interrupt(CPUState *cpu, int int_req);
259fcf5ef2aSThomas Huth void cpu_sh4_invalidate_tlb(CPUSH4State *s);
260fcf5ef2aSThomas Huth uint32_t cpu_sh4_read_mmaped_itlb_addr(CPUSH4State *s,
261fcf5ef2aSThomas Huth hwaddr addr);
262fcf5ef2aSThomas Huth void cpu_sh4_write_mmaped_itlb_addr(CPUSH4State *s, hwaddr addr,
263fcf5ef2aSThomas Huth uint32_t mem_value);
264fcf5ef2aSThomas Huth uint32_t cpu_sh4_read_mmaped_itlb_data(CPUSH4State *s,
265fcf5ef2aSThomas Huth hwaddr addr);
266fcf5ef2aSThomas Huth void cpu_sh4_write_mmaped_itlb_data(CPUSH4State *s, hwaddr addr,
267fcf5ef2aSThomas Huth uint32_t mem_value);
268fcf5ef2aSThomas Huth uint32_t cpu_sh4_read_mmaped_utlb_addr(CPUSH4State *s,
269fcf5ef2aSThomas Huth hwaddr addr);
270fcf5ef2aSThomas Huth void cpu_sh4_write_mmaped_utlb_addr(CPUSH4State *s, hwaddr addr,
271fcf5ef2aSThomas Huth uint32_t mem_value);
272fcf5ef2aSThomas Huth uint32_t cpu_sh4_read_mmaped_utlb_data(CPUSH4State *s,
273fcf5ef2aSThomas Huth hwaddr addr);
274fcf5ef2aSThomas Huth void cpu_sh4_write_mmaped_utlb_data(CPUSH4State *s, hwaddr addr,
275fcf5ef2aSThomas Huth uint32_t mem_value);
276fcf5ef2aSThomas Huth #endif
277fcf5ef2aSThomas Huth
278fcf5ef2aSThomas Huth int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr);
279fcf5ef2aSThomas Huth
280fcf5ef2aSThomas Huth void cpu_load_tlb(CPUSH4State * env);
281fcf5ef2aSThomas Huth
2820dacec87SIgor Mammedov #define CPU_RESOLVING_TYPE TYPE_SUPERH_CPU
283974e58d2SIgor Mammedov
284fcf5ef2aSThomas Huth /* MMU modes definitions */
285fcf5ef2aSThomas Huth #define MMU_USER_IDX 1
286fcf5ef2aSThomas Huth
287fcf5ef2aSThomas Huth #include "exec/cpu-all.h"
288fcf5ef2aSThomas Huth
289fcf5ef2aSThomas Huth /* MMU control register */
290fcf5ef2aSThomas Huth #define MMUCR 0x1F000010
291fcf5ef2aSThomas Huth #define MMUCR_AT (1<<0)
292fcf5ef2aSThomas Huth #define MMUCR_TI (1<<2)
293fcf5ef2aSThomas Huth #define MMUCR_SV (1<<8)
294fcf5ef2aSThomas Huth #define MMUCR_URC_BITS (6)
295fcf5ef2aSThomas Huth #define MMUCR_URC_OFFSET (10)
296fcf5ef2aSThomas Huth #define MMUCR_URC_SIZE (1 << MMUCR_URC_BITS)
297fcf5ef2aSThomas Huth #define MMUCR_URC_MASK (((MMUCR_URC_SIZE) - 1) << MMUCR_URC_OFFSET)
cpu_mmucr_urc(uint32_t mmucr)298fcf5ef2aSThomas Huth static inline int cpu_mmucr_urc (uint32_t mmucr)
299fcf5ef2aSThomas Huth {
300fcf5ef2aSThomas Huth return ((mmucr & MMUCR_URC_MASK) >> MMUCR_URC_OFFSET);
301fcf5ef2aSThomas Huth }
302fcf5ef2aSThomas Huth
303fcf5ef2aSThomas Huth /* PTEH : Page Translation Entry High register */
304fcf5ef2aSThomas Huth #define PTEH_ASID_BITS (8)
305fcf5ef2aSThomas Huth #define PTEH_ASID_SIZE (1 << PTEH_ASID_BITS)
306fcf5ef2aSThomas Huth #define PTEH_ASID_MASK (PTEH_ASID_SIZE - 1)
307fcf5ef2aSThomas Huth #define cpu_pteh_asid(pteh) ((pteh) & PTEH_ASID_MASK)
308fcf5ef2aSThomas Huth #define PTEH_VPN_BITS (22)
309fcf5ef2aSThomas Huth #define PTEH_VPN_OFFSET (10)
310fcf5ef2aSThomas Huth #define PTEH_VPN_SIZE (1 << PTEH_VPN_BITS)
311fcf5ef2aSThomas Huth #define PTEH_VPN_MASK (((PTEH_VPN_SIZE) - 1) << PTEH_VPN_OFFSET)
cpu_pteh_vpn(uint32_t pteh)312fcf5ef2aSThomas Huth static inline int cpu_pteh_vpn (uint32_t pteh)
313fcf5ef2aSThomas Huth {
314fcf5ef2aSThomas Huth return ((pteh & PTEH_VPN_MASK) >> PTEH_VPN_OFFSET);
315fcf5ef2aSThomas Huth }
316fcf5ef2aSThomas Huth
317fcf5ef2aSThomas Huth /* PTEL : Page Translation Entry Low register */
318fcf5ef2aSThomas Huth #define PTEL_V (1 << 8)
319fcf5ef2aSThomas Huth #define cpu_ptel_v(ptel) (((ptel) & PTEL_V) >> 8)
320fcf5ef2aSThomas Huth #define PTEL_C (1 << 3)
321fcf5ef2aSThomas Huth #define cpu_ptel_c(ptel) (((ptel) & PTEL_C) >> 3)
322fcf5ef2aSThomas Huth #define PTEL_D (1 << 2)
323fcf5ef2aSThomas Huth #define cpu_ptel_d(ptel) (((ptel) & PTEL_D) >> 2)
324fcf5ef2aSThomas Huth #define PTEL_SH (1 << 1)
325fcf5ef2aSThomas Huth #define cpu_ptel_sh(ptel)(((ptel) & PTEL_SH) >> 1)
326fcf5ef2aSThomas Huth #define PTEL_WT (1 << 0)
327fcf5ef2aSThomas Huth #define cpu_ptel_wt(ptel) ((ptel) & PTEL_WT)
328fcf5ef2aSThomas Huth
329fcf5ef2aSThomas Huth #define PTEL_SZ_HIGH_OFFSET (7)
330fcf5ef2aSThomas Huth #define PTEL_SZ_HIGH (1 << PTEL_SZ_HIGH_OFFSET)
331fcf5ef2aSThomas Huth #define PTEL_SZ_LOW_OFFSET (4)
332fcf5ef2aSThomas Huth #define PTEL_SZ_LOW (1 << PTEL_SZ_LOW_OFFSET)
cpu_ptel_sz(uint32_t ptel)333fcf5ef2aSThomas Huth static inline int cpu_ptel_sz (uint32_t ptel)
334fcf5ef2aSThomas Huth {
335fcf5ef2aSThomas Huth int sz;
336fcf5ef2aSThomas Huth sz = (ptel & PTEL_SZ_HIGH) >> PTEL_SZ_HIGH_OFFSET;
337fcf5ef2aSThomas Huth sz <<= 1;
338fcf5ef2aSThomas Huth sz |= (ptel & PTEL_SZ_LOW) >> PTEL_SZ_LOW_OFFSET;
339fcf5ef2aSThomas Huth return sz;
340fcf5ef2aSThomas Huth }
341fcf5ef2aSThomas Huth
342fcf5ef2aSThomas Huth #define PTEL_PPN_BITS (19)
343fcf5ef2aSThomas Huth #define PTEL_PPN_OFFSET (10)
344fcf5ef2aSThomas Huth #define PTEL_PPN_SIZE (1 << PTEL_PPN_BITS)
345fcf5ef2aSThomas Huth #define PTEL_PPN_MASK (((PTEL_PPN_SIZE) - 1) << PTEL_PPN_OFFSET)
cpu_ptel_ppn(uint32_t ptel)346fcf5ef2aSThomas Huth static inline int cpu_ptel_ppn (uint32_t ptel)
347fcf5ef2aSThomas Huth {
348fcf5ef2aSThomas Huth return ((ptel & PTEL_PPN_MASK) >> PTEL_PPN_OFFSET);
349fcf5ef2aSThomas Huth }
350fcf5ef2aSThomas Huth
351fcf5ef2aSThomas Huth #define PTEL_PR_BITS (2)
352fcf5ef2aSThomas Huth #define PTEL_PR_OFFSET (5)
353fcf5ef2aSThomas Huth #define PTEL_PR_SIZE (1 << PTEL_PR_BITS)
354fcf5ef2aSThomas Huth #define PTEL_PR_MASK (((PTEL_PR_SIZE) - 1) << PTEL_PR_OFFSET)
cpu_ptel_pr(uint32_t ptel)355fcf5ef2aSThomas Huth static inline int cpu_ptel_pr (uint32_t ptel)
356fcf5ef2aSThomas Huth {
357fcf5ef2aSThomas Huth return ((ptel & PTEL_PR_MASK) >> PTEL_PR_OFFSET);
358fcf5ef2aSThomas Huth }
359fcf5ef2aSThomas Huth
360fcf5ef2aSThomas Huth /* PTEA : Page Translation Entry Assistance register */
361fcf5ef2aSThomas Huth #define PTEA_SA_BITS (3)
362fcf5ef2aSThomas Huth #define PTEA_SA_SIZE (1 << PTEA_SA_BITS)
363fcf5ef2aSThomas Huth #define PTEA_SA_MASK (PTEA_SA_SIZE - 1)
364fcf5ef2aSThomas Huth #define cpu_ptea_sa(ptea) ((ptea) & PTEA_SA_MASK)
365fcf5ef2aSThomas Huth #define PTEA_TC (1 << 3)
366fcf5ef2aSThomas Huth #define cpu_ptea_tc(ptea) (((ptea) & PTEA_TC) >> 3)
367fcf5ef2aSThomas Huth
cpu_read_sr(CPUSH4State * env)368fcf5ef2aSThomas Huth static inline target_ulong cpu_read_sr(CPUSH4State *env)
369fcf5ef2aSThomas Huth {
370fcf5ef2aSThomas Huth return env->sr | (env->sr_m << SR_M) |
371fcf5ef2aSThomas Huth (env->sr_q << SR_Q) |
372fcf5ef2aSThomas Huth (env->sr_t << SR_T);
373fcf5ef2aSThomas Huth }
374fcf5ef2aSThomas Huth
cpu_write_sr(CPUSH4State * env,target_ulong sr)375fcf5ef2aSThomas Huth static inline void cpu_write_sr(CPUSH4State *env, target_ulong sr)
376fcf5ef2aSThomas Huth {
377fcf5ef2aSThomas Huth env->sr_m = (sr >> SR_M) & 1;
378fcf5ef2aSThomas Huth env->sr_q = (sr >> SR_Q) & 1;
379fcf5ef2aSThomas Huth env->sr_t = (sr >> SR_T) & 1;
380fcf5ef2aSThomas Huth env->sr = sr & ~((1u << SR_M) | (1u << SR_Q) | (1u << SR_T));
381fcf5ef2aSThomas Huth }
382fcf5ef2aSThomas Huth
cpu_get_tb_cpu_state(CPUSH4State * env,vaddr * pc,uint64_t * cs_base,uint32_t * flags)383bb5de525SAnton Johansson static inline void cpu_get_tb_cpu_state(CPUSH4State *env, vaddr *pc,
384bb5de525SAnton Johansson uint64_t *cs_base, uint32_t *flags)
385fcf5ef2aSThomas Huth {
386fcf5ef2aSThomas Huth *pc = env->pc;
3874bfa602bSRichard Henderson /* For a gUSA region, notice the end of the region. */
388ab419fd8SRichard Henderson *cs_base = env->flags & TB_FLAG_GUSA_MASK ? env->gregs[0] : 0;
389ab419fd8SRichard Henderson *flags = env->flags
390ab419fd8SRichard Henderson | (env->fpscr & TB_FLAG_FPSCR_MASK)
391ab419fd8SRichard Henderson | (env->sr & TB_FLAG_SR_MASK)
3921516184dSRichard Henderson | (env->movcal_backup ? TB_FLAG_PENDING_MOVCA : 0); /* Bit 3 */
3934da06fb3SRichard Henderson #ifdef CONFIG_USER_ONLY
3944da06fb3SRichard Henderson *flags |= TB_FLAG_UNALIGN * !env_cpu(env)->prctl_unalign_sigbus;
3954da06fb3SRichard Henderson #endif
396fcf5ef2aSThomas Huth }
397fcf5ef2aSThomas Huth
398fcf5ef2aSThomas Huth #endif /* SH4_CPU_H */
399