1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth * OpenRISC virtual CPU header.
3fcf5ef2aSThomas Huth *
4fcf5ef2aSThomas Huth * Copyright (c) 2011-2012 Jia Liu <proljc@gmail.com>
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
9198a2d21SThomas 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 OPENRISC_CPU_H
21fcf5ef2aSThomas Huth #define OPENRISC_CPU_H
22fcf5ef2aSThomas Huth
23*2d8efe96SPhilippe Mathieu-Daudé #include "cpu-qom.h"
2474433bf0SRichard Henderson #include "exec/cpu-defs.h"
2569242e7eSMarc-André Lureau #include "fpu/softfloat-types.h"
26fcf5ef2aSThomas Huth
27fcf5ef2aSThomas Huth /**
28fcf5ef2aSThomas Huth * OpenRISCCPUClass:
29fcf5ef2aSThomas Huth * @parent_realize: The parent class' realize handler.
3004097504SPeter Maydell * @parent_phases: The parent class' reset phase handlers.
31fcf5ef2aSThomas Huth *
32fcf5ef2aSThomas Huth * A OpenRISC CPU model.
33fcf5ef2aSThomas Huth */
34db1015e9SEduardo Habkost struct OpenRISCCPUClass {
35fcf5ef2aSThomas Huth CPUClass parent_class;
36fcf5ef2aSThomas Huth
37fcf5ef2aSThomas Huth DeviceRealize parent_realize;
3804097504SPeter Maydell ResettablePhases parent_phases;
39db1015e9SEduardo Habkost };
40fcf5ef2aSThomas Huth
4124c32852SRichard Henderson #define TARGET_INSN_START_EXTRA_WORDS 1
42fcf5ef2aSThomas Huth
43fcf5ef2aSThomas Huth enum {
44fcf5ef2aSThomas Huth MMU_NOMMU_IDX = 0,
45fcf5ef2aSThomas Huth MMU_SUPERVISOR_IDX = 1,
46fcf5ef2aSThomas Huth MMU_USER_IDX = 2,
47fcf5ef2aSThomas Huth };
48fcf5ef2aSThomas Huth
49fcf5ef2aSThomas Huth #define SET_FP_CAUSE(reg, v) do {\
50fcf5ef2aSThomas Huth (reg) = ((reg) & ~(0x3f << 12)) | \
51fcf5ef2aSThomas Huth ((v & 0x3f) << 12);\
52fcf5ef2aSThomas Huth } while (0)
53fcf5ef2aSThomas Huth #define GET_FP_ENABLE(reg) (((reg) >> 7) & 0x1f)
54fcf5ef2aSThomas Huth #define UPDATE_FP_FLAGS(reg, v) do {\
55fcf5ef2aSThomas Huth (reg) |= ((v & 0x1f) << 2);\
56fcf5ef2aSThomas Huth } while (0)
57fcf5ef2aSThomas Huth
58fcf5ef2aSThomas Huth /* Interrupt */
59fcf5ef2aSThomas Huth #define NR_IRQS 32
60fcf5ef2aSThomas Huth
61fcf5ef2aSThomas Huth /* Unit presece register */
62fcf5ef2aSThomas Huth enum {
63fcf5ef2aSThomas Huth UPR_UP = (1 << 0),
64fcf5ef2aSThomas Huth UPR_DCP = (1 << 1),
65fcf5ef2aSThomas Huth UPR_ICP = (1 << 2),
66fcf5ef2aSThomas Huth UPR_DMP = (1 << 3),
67fcf5ef2aSThomas Huth UPR_IMP = (1 << 4),
68fcf5ef2aSThomas Huth UPR_MP = (1 << 5),
69fcf5ef2aSThomas Huth UPR_DUP = (1 << 6),
70fcf5ef2aSThomas Huth UPR_PCUR = (1 << 7),
71fcf5ef2aSThomas Huth UPR_PMP = (1 << 8),
72fcf5ef2aSThomas Huth UPR_PICP = (1 << 9),
73fcf5ef2aSThomas Huth UPR_TTP = (1 << 10),
74fcf5ef2aSThomas Huth UPR_CUP = (255 << 24),
75fcf5ef2aSThomas Huth };
76fcf5ef2aSThomas Huth
77fcf5ef2aSThomas Huth /* CPU configure register */
78fcf5ef2aSThomas Huth enum {
79fcf5ef2aSThomas Huth CPUCFGR_NSGF = (15 << 0),
80fcf5ef2aSThomas Huth CPUCFGR_CGF = (1 << 4),
81fcf5ef2aSThomas Huth CPUCFGR_OB32S = (1 << 5),
82fcf5ef2aSThomas Huth CPUCFGR_OB64S = (1 << 6),
83fcf5ef2aSThomas Huth CPUCFGR_OF32S = (1 << 7),
84fcf5ef2aSThomas Huth CPUCFGR_OF64S = (1 << 8),
85fcf5ef2aSThomas Huth CPUCFGR_OV64S = (1 << 9),
868bebf7d1SRichard Henderson CPUCFGR_ND = (1 << 10),
878bebf7d1SRichard Henderson CPUCFGR_AVRP = (1 << 11),
88356a2db3STim 'mithro' Ansell CPUCFGR_EVBARP = (1 << 12),
898bebf7d1SRichard Henderson CPUCFGR_ISRP = (1 << 13),
908bebf7d1SRichard Henderson CPUCFGR_AECSRP = (1 << 14),
918bebf7d1SRichard Henderson CPUCFGR_OF64A32S = (1 << 15),
92fcf5ef2aSThomas Huth };
93fcf5ef2aSThomas Huth
94fcf5ef2aSThomas Huth /* DMMU configure register */
95fcf5ef2aSThomas Huth enum {
96fcf5ef2aSThomas Huth DMMUCFGR_NTW = (3 << 0),
97fcf5ef2aSThomas Huth DMMUCFGR_NTS = (7 << 2),
98fcf5ef2aSThomas Huth DMMUCFGR_NAE = (7 << 5),
99fcf5ef2aSThomas Huth DMMUCFGR_CRI = (1 << 8),
100fcf5ef2aSThomas Huth DMMUCFGR_PRI = (1 << 9),
101fcf5ef2aSThomas Huth DMMUCFGR_TEIRI = (1 << 10),
102fcf5ef2aSThomas Huth DMMUCFGR_HTR = (1 << 11),
103fcf5ef2aSThomas Huth };
104fcf5ef2aSThomas Huth
105fcf5ef2aSThomas Huth /* IMMU configure register */
106fcf5ef2aSThomas Huth enum {
107fcf5ef2aSThomas Huth IMMUCFGR_NTW = (3 << 0),
108fcf5ef2aSThomas Huth IMMUCFGR_NTS = (7 << 2),
109fcf5ef2aSThomas Huth IMMUCFGR_NAE = (7 << 5),
110fcf5ef2aSThomas Huth IMMUCFGR_CRI = (1 << 8),
111fcf5ef2aSThomas Huth IMMUCFGR_PRI = (1 << 9),
112fcf5ef2aSThomas Huth IMMUCFGR_TEIRI = (1 << 10),
113fcf5ef2aSThomas Huth IMMUCFGR_HTR = (1 << 11),
114fcf5ef2aSThomas Huth };
115fcf5ef2aSThomas Huth
116f4d1414aSStafford Horne /* Power management register */
117f4d1414aSStafford Horne enum {
118f4d1414aSStafford Horne PMR_SDF = (15 << 0),
119f4d1414aSStafford Horne PMR_DME = (1 << 4),
120f4d1414aSStafford Horne PMR_SME = (1 << 5),
121f4d1414aSStafford Horne PMR_DCGE = (1 << 6),
122f4d1414aSStafford Horne PMR_SUME = (1 << 7),
123f4d1414aSStafford Horne };
124f4d1414aSStafford Horne
125fcf5ef2aSThomas Huth /* Float point control status register */
126fcf5ef2aSThomas Huth enum {
127fcf5ef2aSThomas Huth FPCSR_FPEE = 1,
128fcf5ef2aSThomas Huth FPCSR_RM = (3 << 1),
129fcf5ef2aSThomas Huth FPCSR_OVF = (1 << 3),
130fcf5ef2aSThomas Huth FPCSR_UNF = (1 << 4),
131fcf5ef2aSThomas Huth FPCSR_SNF = (1 << 5),
132fcf5ef2aSThomas Huth FPCSR_QNF = (1 << 6),
133fcf5ef2aSThomas Huth FPCSR_ZF = (1 << 7),
134fcf5ef2aSThomas Huth FPCSR_IXF = (1 << 8),
135fcf5ef2aSThomas Huth FPCSR_IVF = (1 << 9),
136fcf5ef2aSThomas Huth FPCSR_INF = (1 << 10),
137fcf5ef2aSThomas Huth FPCSR_DZF = (1 << 11),
138fcf5ef2aSThomas Huth };
139fcf5ef2aSThomas Huth
140fcf5ef2aSThomas Huth /* Exceptions indices */
141fcf5ef2aSThomas Huth enum {
142fcf5ef2aSThomas Huth EXCP_RESET = 0x1,
143fcf5ef2aSThomas Huth EXCP_BUSERR = 0x2,
144fcf5ef2aSThomas Huth EXCP_DPF = 0x3,
145fcf5ef2aSThomas Huth EXCP_IPF = 0x4,
146fcf5ef2aSThomas Huth EXCP_TICK = 0x5,
147fcf5ef2aSThomas Huth EXCP_ALIGN = 0x6,
148fcf5ef2aSThomas Huth EXCP_ILLEGAL = 0x7,
149fcf5ef2aSThomas Huth EXCP_INT = 0x8,
150fcf5ef2aSThomas Huth EXCP_DTLBMISS = 0x9,
151fcf5ef2aSThomas Huth EXCP_ITLBMISS = 0xa,
152fcf5ef2aSThomas Huth EXCP_RANGE = 0xb,
153fcf5ef2aSThomas Huth EXCP_SYSCALL = 0xc,
154fcf5ef2aSThomas Huth EXCP_FPE = 0xd,
155fcf5ef2aSThomas Huth EXCP_TRAP = 0xe,
156fcf5ef2aSThomas Huth EXCP_NR,
157fcf5ef2aSThomas Huth };
158fcf5ef2aSThomas Huth
159fcf5ef2aSThomas Huth /* Supervisor register */
160fcf5ef2aSThomas Huth enum {
161fcf5ef2aSThomas Huth SR_SM = (1 << 0),
162fcf5ef2aSThomas Huth SR_TEE = (1 << 1),
163fcf5ef2aSThomas Huth SR_IEE = (1 << 2),
164fcf5ef2aSThomas Huth SR_DCE = (1 << 3),
165fcf5ef2aSThomas Huth SR_ICE = (1 << 4),
166fcf5ef2aSThomas Huth SR_DME = (1 << 5),
167fcf5ef2aSThomas Huth SR_IME = (1 << 6),
168fcf5ef2aSThomas Huth SR_LEE = (1 << 7),
169fcf5ef2aSThomas Huth SR_CE = (1 << 8),
170fcf5ef2aSThomas Huth SR_F = (1 << 9),
171fcf5ef2aSThomas Huth SR_CY = (1 << 10),
172fcf5ef2aSThomas Huth SR_OV = (1 << 11),
173fcf5ef2aSThomas Huth SR_OVE = (1 << 12),
174fcf5ef2aSThomas Huth SR_DSX = (1 << 13),
175fcf5ef2aSThomas Huth SR_EPH = (1 << 14),
176fcf5ef2aSThomas Huth SR_FO = (1 << 15),
177fcf5ef2aSThomas Huth SR_SUMRA = (1 << 16),
178fcf5ef2aSThomas Huth SR_SCE = (1 << 17),
179fcf5ef2aSThomas Huth };
180fcf5ef2aSThomas Huth
181fcf5ef2aSThomas Huth /* Tick Timer Mode Register */
182fcf5ef2aSThomas Huth enum {
183fcf5ef2aSThomas Huth TTMR_TP = (0xfffffff),
184fcf5ef2aSThomas Huth TTMR_IP = (1 << 28),
185fcf5ef2aSThomas Huth TTMR_IE = (1 << 29),
186fcf5ef2aSThomas Huth TTMR_M = (3 << 30),
187fcf5ef2aSThomas Huth };
188fcf5ef2aSThomas Huth
189fcf5ef2aSThomas Huth /* Timer Mode */
190fcf5ef2aSThomas Huth enum {
191fcf5ef2aSThomas Huth TIMER_NONE = (0 << 30),
192fcf5ef2aSThomas Huth TIMER_INTR = (1 << 30),
193fcf5ef2aSThomas Huth TIMER_SHOT = (2 << 30),
194fcf5ef2aSThomas Huth TIMER_CONT = (3 << 30),
195fcf5ef2aSThomas Huth };
196fcf5ef2aSThomas Huth
197fcf5ef2aSThomas Huth /* TLB size */
198fcf5ef2aSThomas Huth enum {
1991cc9e5d8SRichard Henderson TLB_SIZE = 128,
20056c3a141SRichard Henderson TLB_MASK = TLB_SIZE - 1,
201fcf5ef2aSThomas Huth };
202fcf5ef2aSThomas Huth
203fcf5ef2aSThomas Huth /* TLB prot */
204fcf5ef2aSThomas Huth enum {
205fcf5ef2aSThomas Huth URE = (1 << 6),
206fcf5ef2aSThomas Huth UWE = (1 << 7),
207fcf5ef2aSThomas Huth SRE = (1 << 8),
208fcf5ef2aSThomas Huth SWE = (1 << 9),
209fcf5ef2aSThomas Huth
210fcf5ef2aSThomas Huth SXE = (1 << 6),
211fcf5ef2aSThomas Huth UXE = (1 << 7),
212fcf5ef2aSThomas Huth };
213fcf5ef2aSThomas Huth
214fcf5ef2aSThomas Huth typedef struct OpenRISCTLBEntry {
215fcf5ef2aSThomas Huth uint32_t mr;
216fcf5ef2aSThomas Huth uint32_t tr;
217fcf5ef2aSThomas Huth } OpenRISCTLBEntry;
218fcf5ef2aSThomas Huth
219fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
220fcf5ef2aSThomas Huth typedef struct CPUOpenRISCTLBContext {
22156c3a141SRichard Henderson OpenRISCTLBEntry itlb[TLB_SIZE];
22256c3a141SRichard Henderson OpenRISCTLBEntry dtlb[TLB_SIZE];
223fcf5ef2aSThomas Huth
22436861198SPhilippe Mathieu-Daudé int (*cpu_openrisc_map_address_code)(OpenRISCCPU *cpu,
225fcf5ef2aSThomas Huth hwaddr *physical,
226fcf5ef2aSThomas Huth int *prot,
227fcf5ef2aSThomas Huth target_ulong address, int rw);
22836861198SPhilippe Mathieu-Daudé int (*cpu_openrisc_map_address_data)(OpenRISCCPU *cpu,
229fcf5ef2aSThomas Huth hwaddr *physical,
230fcf5ef2aSThomas Huth int *prot,
231fcf5ef2aSThomas Huth target_ulong address, int rw);
232fcf5ef2aSThomas Huth } CPUOpenRISCTLBContext;
233fcf5ef2aSThomas Huth #endif
234fcf5ef2aSThomas Huth
2351ea4a06aSPhilippe Mathieu-Daudé typedef struct CPUArchState {
236d89e71e8SStafford Horne target_ulong shadow_gpr[16][32]; /* Shadow registers */
237d89e71e8SStafford Horne
238fcf5ef2aSThomas Huth target_ulong pc; /* Program counter */
239fcf5ef2aSThomas Huth target_ulong ppc; /* Prev PC */
240fcf5ef2aSThomas Huth target_ulong jmp_pc; /* Jump PC */
241fcf5ef2aSThomas Huth
2426f7332baSRichard Henderson uint64_t mac; /* Multiply registers MACHI:MACLO */
243fcf5ef2aSThomas Huth
244fcf5ef2aSThomas Huth target_ulong epcr; /* Exception PC register */
245fcf5ef2aSThomas Huth target_ulong eear; /* Exception EA register */
246fcf5ef2aSThomas Huth
24784775c43SRichard Henderson target_ulong sr_f; /* the SR_F bit, values 0, 1. */
24897458071SRichard Henderson target_ulong sr_cy; /* the SR_CY bit, values 0, 1. */
24997458071SRichard Henderson target_long sr_ov; /* the SR_OV bit (in the sign bit only) */
25097458071SRichard Henderson uint32_t sr; /* Supervisor register, without SR_{F,CY,OV} */
251fcf5ef2aSThomas Huth uint32_t esr; /* Exception supervisor register */
252356a2db3STim 'mithro' Ansell uint32_t evbar; /* Exception vector base address register */
253f4d1414aSStafford Horne uint32_t pmr; /* Power Management Register */
254fcf5ef2aSThomas Huth uint32_t fpcsr; /* Float register */
255fcf5ef2aSThomas Huth float_status fp_status;
256fcf5ef2aSThomas Huth
257930c3d00SRichard Henderson target_ulong lock_addr;
258930c3d00SRichard Henderson target_ulong lock_value;
259930c3d00SRichard Henderson
260a01deb36SRichard Henderson uint32_t dflag; /* In delay slot (boolean) */
261fcf5ef2aSThomas Huth
262455d45d2SRichard Henderson #ifndef CONFIG_USER_ONLY
263455d45d2SRichard Henderson CPUOpenRISCTLBContext tlb;
264455d45d2SRichard Henderson #endif
265455d45d2SRichard Henderson
2661f5c00cfSAlex Bennée /* Fields up to this point are cleared by a CPU reset */
2671f5c00cfSAlex Bennée struct {} end_reset_fields;
2681f5c00cfSAlex Bennée
269fcf5ef2aSThomas Huth /* Fields from here on are preserved across CPU reset. */
270c7efab4fSRichard Henderson uint32_t vr; /* Version register */
2718bebf7d1SRichard Henderson uint32_t vr2; /* Version register 2 */
2728bebf7d1SRichard Henderson uint32_t avr; /* Architecture version register */
273c7efab4fSRichard Henderson uint32_t upr; /* Unit presence register */
27448a1b62bSStafford Horne uint32_t cpucfgr; /* CPU configure register */
275c7efab4fSRichard Henderson uint32_t dmmucfgr; /* DMMU configure register */
276c7efab4fSRichard Henderson uint32_t immucfgr; /* IMMU configure register */
27748a1b62bSStafford Horne
278fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
279fcf5ef2aSThomas Huth QEMUTimer *timer;
280fcf5ef2aSThomas Huth uint32_t ttmr; /* Timer tick mode register */
2816b4bbd6aSStafford Horne int is_counting;
282fcf5ef2aSThomas Huth
283fcf5ef2aSThomas Huth uint32_t picmr; /* Interrupt mask register */
2848b81968cSMichael Tokarev uint32_t picsr; /* Interrupt control register */
285fcf5ef2aSThomas Huth #endif
286fcf5ef2aSThomas Huth } CPUOpenRISCState;
287fcf5ef2aSThomas Huth
288fcf5ef2aSThomas Huth /**
289fcf5ef2aSThomas Huth * OpenRISCCPU:
290fcf5ef2aSThomas Huth * @env: #CPUOpenRISCState
291fcf5ef2aSThomas Huth *
292fcf5ef2aSThomas Huth * A OpenRISC CPU.
293fcf5ef2aSThomas Huth */
294b36e239eSPhilippe Mathieu-Daudé struct ArchCPU {
295fcf5ef2aSThomas Huth CPUState parent_obj;
296fcf5ef2aSThomas Huth
297fcf5ef2aSThomas Huth CPUOpenRISCState env;
298db1015e9SEduardo Habkost };
299fcf5ef2aSThomas Huth
30090c84c56SMarkus Armbruster void openrisc_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
301a010bdbeSAlex Bennée int openrisc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
302fcf5ef2aSThomas Huth int openrisc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
303fcf5ef2aSThomas Huth void openrisc_translate_init(void);
304d5cabcceSRichard Henderson int print_insn_or1k(bfd_vma addr, disassemble_info *info);
305fcf5ef2aSThomas Huth
306fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
3076d2d454aSPhilippe Mathieu-Daudé hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
3086d2d454aSPhilippe Mathieu-Daudé
30912f0bc55SRichard Henderson bool openrisc_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
31012f0bc55SRichard Henderson MMUAccessType access_type, int mmu_idx,
31112f0bc55SRichard Henderson bool probe, uintptr_t retaddr);
31212f0bc55SRichard Henderson
3138a9358ccSMarkus Armbruster extern const VMStateDescription vmstate_openrisc_cpu;
314fcf5ef2aSThomas Huth
315250ae6dfSPhilippe Mathieu-Daudé void openrisc_cpu_do_interrupt(CPUState *cpu);
316250ae6dfSPhilippe Mathieu-Daudé bool openrisc_cpu_exec_interrupt(CPUState *cpu, int int_req);
317250ae6dfSPhilippe Mathieu-Daudé
318fcf5ef2aSThomas Huth /* hw/openrisc_pic.c */
319fcf5ef2aSThomas Huth void cpu_openrisc_pic_init(OpenRISCCPU *cpu);
320fcf5ef2aSThomas Huth
321fcf5ef2aSThomas Huth /* hw/openrisc_timer.c */
322fcf5ef2aSThomas Huth void cpu_openrisc_clock_init(OpenRISCCPU *cpu);
3236b4bbd6aSStafford Horne uint32_t cpu_openrisc_count_get(OpenRISCCPU *cpu);
3246b4bbd6aSStafford Horne void cpu_openrisc_count_set(OpenRISCCPU *cpu, uint32_t val);
325fcf5ef2aSThomas Huth void cpu_openrisc_count_update(OpenRISCCPU *cpu);
326fcf5ef2aSThomas Huth void cpu_openrisc_timer_update(OpenRISCCPU *cpu);
327fcf5ef2aSThomas Huth void cpu_openrisc_count_start(OpenRISCCPU *cpu);
328fcf5ef2aSThomas Huth void cpu_openrisc_count_stop(OpenRISCCPU *cpu);
329fcf5ef2aSThomas Huth #endif
330fcf5ef2aSThomas Huth
3310dacec87SIgor Mammedov #define CPU_RESOLVING_TYPE TYPE_OPENRISC_CPU
332a6772731SIgor Mammedov
333fcf5ef2aSThomas Huth #include "exec/cpu-all.h"
334fcf5ef2aSThomas Huth
335b9bed1b9SRichard Henderson #define TB_FLAGS_SM SR_SM
336b9bed1b9SRichard Henderson #define TB_FLAGS_DME SR_DME
337b9bed1b9SRichard Henderson #define TB_FLAGS_IME SR_IME
338a01deb36SRichard Henderson #define TB_FLAGS_OVE SR_OVE
339b9bed1b9SRichard Henderson #define TB_FLAGS_DFLAG 2 /* reuse SR_TEE */
340b9bed1b9SRichard Henderson #define TB_FLAGS_R0_0 4 /* reuse SR_IEE */
341a01deb36SRichard Henderson
cpu_get_gpr(const CPUOpenRISCState * env,int i)342d89e71e8SStafford Horne static inline uint32_t cpu_get_gpr(const CPUOpenRISCState *env, int i)
343d89e71e8SStafford Horne {
344d89e71e8SStafford Horne return env->shadow_gpr[0][i];
345d89e71e8SStafford Horne }
346d89e71e8SStafford Horne
cpu_set_gpr(CPUOpenRISCState * env,int i,uint32_t val)347d89e71e8SStafford Horne static inline void cpu_set_gpr(CPUOpenRISCState *env, int i, uint32_t val)
348d89e71e8SStafford Horne {
349d89e71e8SStafford Horne env->shadow_gpr[0][i] = val;
350d89e71e8SStafford Horne }
351d89e71e8SStafford Horne
cpu_get_tb_cpu_state(CPUOpenRISCState * env,vaddr * pc,uint64_t * cs_base,uint32_t * flags)352bb5de525SAnton Johansson static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env, vaddr *pc,
353bb5de525SAnton Johansson uint64_t *cs_base, uint32_t *flags)
354fcf5ef2aSThomas Huth {
355fcf5ef2aSThomas Huth *pc = env->pc;
356fcf5ef2aSThomas Huth *cs_base = 0;
357b9bed1b9SRichard Henderson *flags = (env->dflag ? TB_FLAGS_DFLAG : 0)
358b9bed1b9SRichard Henderson | (cpu_get_gpr(env, 0) ? 0 : TB_FLAGS_R0_0)
359b9bed1b9SRichard Henderson | (env->sr & (SR_SM | SR_DME | SR_IME | SR_OVE));
360fcf5ef2aSThomas Huth }
361fcf5ef2aSThomas Huth
cpu_get_sr(const CPUOpenRISCState * env)36284775c43SRichard Henderson static inline uint32_t cpu_get_sr(const CPUOpenRISCState *env)
36384775c43SRichard Henderson {
36497458071SRichard Henderson return (env->sr
36597458071SRichard Henderson + env->sr_f * SR_F
36697458071SRichard Henderson + env->sr_cy * SR_CY
36797458071SRichard Henderson + (env->sr_ov < 0) * SR_OV);
36884775c43SRichard Henderson }
36984775c43SRichard Henderson
cpu_set_sr(CPUOpenRISCState * env,uint32_t val)37084775c43SRichard Henderson static inline void cpu_set_sr(CPUOpenRISCState *env, uint32_t val)
37184775c43SRichard Henderson {
37284775c43SRichard Henderson env->sr_f = (val & SR_F) != 0;
37397458071SRichard Henderson env->sr_cy = (val & SR_CY) != 0;
37497458071SRichard Henderson env->sr_ov = (val & SR_OV ? -1 : 0);
37597458071SRichard Henderson env->sr = (val & ~(SR_F | SR_CY | SR_OV)) | SR_FO;
37684775c43SRichard Henderson }
37784775c43SRichard Henderson
378a465772eSRichard Henderson void cpu_set_fpcsr(CPUOpenRISCState *env, uint32_t val);
379a465772eSRichard Henderson
380fcf5ef2aSThomas Huth #define CPU_INTERRUPT_TIMER CPU_INTERRUPT_TGT_INT_0
381fcf5ef2aSThomas Huth
382fcf5ef2aSThomas Huth #endif /* OPENRISC_CPU_H */
383