2 * Altera Nios II virtual CPU header
4 * Copyright (c) 2012 Chris Wulff <crwulff@gmail.com>
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.1 of the License, or (at your option) any later version.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see
18 * <http://www.gnu.org/licenses/lgpl-2.1.html>
24 #include "exec/cpu-defs.h"
25 #include "hw/core/cpu.h"
26 #include "hw/registerfields.h"
27 #include "qom/object.h"
29 typedef struct CPUArchState CPUNios2State
;
30 #if !defined(CONFIG_USER_ONLY)
34 #define TYPE_NIOS2_CPU "nios2-cpu"
36 OBJECT_DECLARE_CPU_TYPE(Nios2CPU
, Nios2CPUClass
, NIOS2_CPU
)
40 * @parent_reset: The parent class' reset handler.
44 struct Nios2CPUClass
{
46 CPUClass parent_class
;
49 DeviceRealize parent_realize
;
50 DeviceReset parent_reset
;
53 #define TARGET_HAS_ICE 1
55 /* Configuration options for Nios II */
56 #define RESET_ADDRESS 0x00000000
57 #define EXCEPTION_ADDRESS 0x00000004
58 #define FAST_TLB_MISS_ADDRESS 0x00000008
60 #define NUM_GP_REGS 32
61 #define NUM_CR_REGS 32
63 /* General purpose register aliases */
81 /* Control register aliases */
84 FIELD(CR_STATUS
, PIE
, 0, 1)
85 FIELD(CR_STATUS
, U
, 1, 1)
86 FIELD(CR_STATUS
, EH
, 2, 1)
87 FIELD(CR_STATUS
, IH
, 3, 1)
88 FIELD(CR_STATUS
, IL
, 4, 6)
89 FIELD(CR_STATUS
, CRS
, 10, 6)
90 FIELD(CR_STATUS
, PRS
, 16, 6)
91 FIELD(CR_STATUS
, NMI
, 22, 1)
92 FIELD(CR_STATUS
, RSIE
, 23, 1)
94 #define CR_STATUS_PIE R_CR_STATUS_PIE_MASK
95 #define CR_STATUS_U R_CR_STATUS_U_MASK
96 #define CR_STATUS_EH R_CR_STATUS_EH_MASK
97 #define CR_STATUS_IH R_CR_STATUS_IH_MASK
98 #define CR_STATUS_NMI R_CR_STATUS_NMI_MASK
99 #define CR_STATUS_RSIE R_CR_STATUS_RSIE_MASK
104 #define CR_IPENDING 4
107 #define CR_EXCEPTION 7
109 FIELD(CR_EXCEPTION
, CAUSE
, 2, 5)
110 FIELD(CR_EXCEPTION
, ECCFTL
, 31, 1)
113 #define CR_PTEADDR_PTBASE_SHIFT 22
114 #define CR_PTEADDR_PTBASE_MASK (0x3FF << CR_PTEADDR_PTBASE_SHIFT)
115 #define CR_PTEADDR_VPN_SHIFT 2
116 #define CR_PTEADDR_VPN_MASK (0xFFFFF << CR_PTEADDR_VPN_SHIFT)
118 #define CR_TLBACC_IGN_SHIFT 25
119 #define CR_TLBACC_IGN_MASK (0x7F << CR_TLBACC_IGN_SHIFT)
120 #define CR_TLBACC_C (1 << 24)
121 #define CR_TLBACC_R (1 << 23)
122 #define CR_TLBACC_W (1 << 22)
123 #define CR_TLBACC_X (1 << 21)
124 #define CR_TLBACC_G (1 << 20)
125 #define CR_TLBACC_PFN_MASK 0x000FFFFF
126 #define CR_TLBMISC 10
127 #define CR_TLBMISC_WAY_SHIFT 20
128 #define CR_TLBMISC_WAY_MASK (0xF << CR_TLBMISC_WAY_SHIFT)
129 #define CR_TLBMISC_RD (1 << 19)
130 #define CR_TLBMISC_WR (1 << 18)
131 #define CR_TLBMISC_PID_SHIFT 4
132 #define CR_TLBMISC_PID_MASK (0x3FFF << CR_TLBMISC_PID_SHIFT)
133 #define CR_TLBMISC_DBL (1 << 3)
134 #define CR_TLBMISC_BAD (1 << 2)
135 #define CR_TLBMISC_PERM (1 << 1)
136 #define CR_TLBMISC_D (1 << 0)
138 #define CR_BADADDR 12
140 #define CR_MPUBASE 14
144 #define EXCP_BREAK 0x1000
146 #define EXCP_PRESET 1
149 #define EXCP_UNIMPL 4
150 #define EXCP_ILLEGAL 5
151 #define EXCP_UNALIGN 6
152 #define EXCP_UNALIGND 7
154 #define EXCP_SUPERA 9
155 #define EXCP_SUPERI 10
156 #define EXCP_SUPERD 11
164 #define CPU_INTERRUPT_NMI CPU_INTERRUPT_TGT_EXT_3
166 struct CPUArchState
{
167 uint32_t regs
[NUM_GP_REGS
];
168 uint32_t ctrl
[NUM_CR_REGS
];
171 #if !defined(CONFIG_USER_ONLY)
179 * @env: #CPUNios2State
188 CPUNegativeOffsetState neg
;
192 uint32_t pid_num_bits
;
193 uint32_t tlb_num_ways
;
194 uint32_t tlb_num_entries
;
196 /* Addresses that are hard-coded in the FPGA build settings */
198 uint32_t exception_addr
;
199 uint32_t fast_tlb_miss_addr
;
203 void nios2_tcg_init(void);
204 void nios2_cpu_do_interrupt(CPUState
*cs
);
205 void dump_mmu(CPUNios2State
*env
);
206 void nios2_cpu_dump_state(CPUState
*cpu
, FILE *f
, int flags
);
207 hwaddr
nios2_cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
);
208 G_NORETURN
void nios2_cpu_do_unaligned_access(CPUState
*cpu
, vaddr addr
,
209 MMUAccessType access_type
, int mmu_idx
,
212 void do_nios2_semihosting(CPUNios2State
*env
);
214 #define CPU_RESOLVING_TYPE TYPE_NIOS2_CPU
216 #define cpu_gen_code cpu_nios2_gen_code
218 #define CPU_SAVE_VERSION 1
220 /* MMU modes definitions */
221 #define MMU_SUPERVISOR_IDX 0
222 #define MMU_USER_IDX 1
224 static inline int cpu_mmu_index(CPUNios2State
*env
, bool ifetch
)
226 return (env
->ctrl
[CR_STATUS
] & CR_STATUS_U
) ? MMU_USER_IDX
:
230 #ifndef CONFIG_USER_ONLY
231 bool nios2_cpu_tlb_fill(CPUState
*cs
, vaddr address
, int size
,
232 MMUAccessType access_type
, int mmu_idx
,
233 bool probe
, uintptr_t retaddr
);
236 typedef CPUNios2State CPUArchState
;
237 typedef Nios2CPU ArchCPU
;
239 #include "exec/cpu-all.h"
241 static inline void cpu_get_tb_cpu_state(CPUNios2State
*env
, target_ulong
*pc
,
242 target_ulong
*cs_base
, uint32_t *flags
)
246 *flags
= env
->ctrl
[CR_STATUS
] & (CR_STATUS_EH
| CR_STATUS_U
);
249 #endif /* NIOS2_CPU_H */