xref: /openbmc/qemu/target/microblaze/cpu.h (revision fd87be1dada5672f877e03c2ca8504458292c479)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  *  MicroBlaze virtual CPU header
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  *  Copyright (c) 2009 Edgar E. Iglesias
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
9ee452036SChetan Pant  * 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  * 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 MICROBLAZE_CPU_H
21fcf5ef2aSThomas Huth #define MICROBLAZE_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 
271ea4a06aSPhilippe Mathieu-Daudé typedef struct CPUArchState CPUMBState;
28fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
29fcf5ef2aSThomas Huth #include "mmu.h"
30fcf5ef2aSThomas Huth #endif
31fcf5ef2aSThomas Huth 
32fcf5ef2aSThomas Huth #define EXCP_MMU        1
33fcf5ef2aSThomas Huth #define EXCP_IRQ        2
34f5235314SRichard Henderson #define EXCP_SYSCALL    3  /* user-only */
35fcf5ef2aSThomas Huth #define EXCP_HW_BREAK   4
36fcf5ef2aSThomas Huth #define EXCP_HW_EXCP    5
37fcf5ef2aSThomas Huth 
38fcf5ef2aSThomas Huth /* MicroBlaze-specific interrupt pending bits.  */
39fcf5ef2aSThomas Huth #define CPU_INTERRUPT_NMI       CPU_INTERRUPT_TGT_EXT_3
40fcf5ef2aSThomas Huth 
41fcf5ef2aSThomas Huth /* Meanings of the MBCPU object's two inbound GPIO lines */
42fcf5ef2aSThomas Huth #define MB_CPU_IRQ 0
43fcf5ef2aSThomas Huth #define MB_CPU_FIR 1
44fcf5ef2aSThomas Huth 
45fcf5ef2aSThomas Huth /* Register aliases. R0 - R15 */
46fcf5ef2aSThomas Huth #define R_SP     1
47fcf5ef2aSThomas Huth #define SR_PC    0
48fcf5ef2aSThomas Huth #define SR_MSR   1
49fcf5ef2aSThomas Huth #define SR_EAR   3
50fcf5ef2aSThomas Huth #define SR_ESR   5
51fcf5ef2aSThomas Huth #define SR_FSR   7
52fcf5ef2aSThomas Huth #define SR_BTR   0xb
53fcf5ef2aSThomas Huth #define SR_EDR   0xd
54fcf5ef2aSThomas Huth 
55fcf5ef2aSThomas Huth /* MSR flags.  */
56fcf5ef2aSThomas Huth #define MSR_BE  (1<<0) /* 0x001 */
57fcf5ef2aSThomas Huth #define MSR_IE  (1<<1) /* 0x002 */
58fcf5ef2aSThomas Huth #define MSR_C   (1<<2) /* 0x004 */
59fcf5ef2aSThomas Huth #define MSR_BIP (1<<3) /* 0x008 */
60fcf5ef2aSThomas Huth #define MSR_FSL (1<<4) /* 0x010 */
61fcf5ef2aSThomas Huth #define MSR_ICE (1<<5) /* 0x020 */
62fcf5ef2aSThomas Huth #define MSR_DZ  (1<<6) /* 0x040 */
63fcf5ef2aSThomas Huth #define MSR_DCE (1<<7) /* 0x080 */
64fcf5ef2aSThomas Huth #define MSR_EE  (1<<8) /* 0x100 */
65fcf5ef2aSThomas Huth #define MSR_EIP (1<<9) /* 0x200 */
66fcf5ef2aSThomas Huth #define MSR_PVR (1<<10) /* 0x400 */
67fcf5ef2aSThomas Huth #define MSR_CC  (1<<31)
68fcf5ef2aSThomas Huth 
69fcf5ef2aSThomas Huth /* Machine State Register (MSR) Fields */
70fcf5ef2aSThomas Huth #define MSR_UM (1<<11) /* User Mode */
71fcf5ef2aSThomas Huth #define MSR_UMS        (1<<12) /* User Mode Save */
72fcf5ef2aSThomas Huth #define MSR_VM (1<<13) /* Virtual Mode */
73fcf5ef2aSThomas Huth #define MSR_VMS        (1<<14) /* Virtual Mode Save */
74fcf5ef2aSThomas Huth 
75fcf5ef2aSThomas Huth #define MSR_KERNEL      MSR_EE|MSR_VM
76fcf5ef2aSThomas Huth //#define MSR_USER     MSR_KERNEL|MSR_UM|MSR_IE
77fcf5ef2aSThomas Huth #define MSR_KERNEL_VMS  MSR_EE|MSR_VMS
78fcf5ef2aSThomas Huth //#define MSR_USER_VMS MSR_KERNEL_VMS|MSR_UMS|MSR_IE
79fcf5ef2aSThomas Huth 
80fcf5ef2aSThomas Huth /* Exception State Register (ESR) Fields */
81fcf5ef2aSThomas Huth #define          ESR_DIZ       (1<<11) /* Zone Protection */
82ab0c8d0fSRichard Henderson #define          ESR_W         (1<<11) /* Unaligned word access */
83fcf5ef2aSThomas Huth #define          ESR_S         (1<<10) /* Store instruction */
84fcf5ef2aSThomas Huth 
85fcf5ef2aSThomas Huth #define          ESR_ESS_FSL_OFFSET     5
86fcf5ef2aSThomas Huth 
87ab0c8d0fSRichard Henderson #define          ESR_ESS_MASK  (0x7f << 5)
88ab0c8d0fSRichard Henderson 
89fcf5ef2aSThomas Huth #define          ESR_EC_FSL             0
90fcf5ef2aSThomas Huth #define          ESR_EC_UNALIGNED_DATA  1
91fcf5ef2aSThomas Huth #define          ESR_EC_ILLEGAL_OP      2
92fcf5ef2aSThomas Huth #define          ESR_EC_INSN_BUS        3
93fcf5ef2aSThomas Huth #define          ESR_EC_DATA_BUS        4
94fcf5ef2aSThomas Huth #define          ESR_EC_DIVZERO         5
95fcf5ef2aSThomas Huth #define          ESR_EC_FPU             6
96fcf5ef2aSThomas Huth #define          ESR_EC_PRIVINSN        7
97fcf5ef2aSThomas Huth #define          ESR_EC_STACKPROT       7  /* Same as PRIVINSN.  */
98fcf5ef2aSThomas Huth #define          ESR_EC_DATA_STORAGE    8
99fcf5ef2aSThomas Huth #define          ESR_EC_INSN_STORAGE    9
100fcf5ef2aSThomas Huth #define          ESR_EC_DATA_TLB        10
101fcf5ef2aSThomas Huth #define          ESR_EC_INSN_TLB        11
102fcf5ef2aSThomas Huth #define          ESR_EC_MASK            31
103fcf5ef2aSThomas Huth 
104fcf5ef2aSThomas Huth /* Floating Point Status Register (FSR) Bits */
105fcf5ef2aSThomas Huth #define FSR_IO          (1<<4) /* Invalid operation */
106fcf5ef2aSThomas Huth #define FSR_DZ          (1<<3) /* Divide-by-zero */
107fcf5ef2aSThomas Huth #define FSR_OF          (1<<2) /* Overflow */
108fcf5ef2aSThomas Huth #define FSR_UF          (1<<1) /* Underflow */
109fcf5ef2aSThomas Huth #define FSR_DO          (1<<0) /* Denormalized operand error */
110fcf5ef2aSThomas Huth 
111fcf5ef2aSThomas Huth /* Version reg.  */
112fcf5ef2aSThomas Huth /* Basic PVR mask */
113fcf5ef2aSThomas Huth #define PVR0_PVR_FULL_MASK              0x80000000
114fcf5ef2aSThomas Huth #define PVR0_USE_BARREL_MASK            0x40000000
115fcf5ef2aSThomas Huth #define PVR0_USE_DIV_MASK               0x20000000
116fcf5ef2aSThomas Huth #define PVR0_USE_HW_MUL_MASK            0x10000000
117fcf5ef2aSThomas Huth #define PVR0_USE_FPU_MASK               0x08000000
118fcf5ef2aSThomas Huth #define PVR0_USE_EXC_MASK               0x04000000
119fcf5ef2aSThomas Huth #define PVR0_USE_ICACHE_MASK            0x02000000
120fcf5ef2aSThomas Huth #define PVR0_USE_DCACHE_MASK            0x01000000
121fcf5ef2aSThomas Huth #define PVR0_USE_MMU_MASK               0x00800000
122fcf5ef2aSThomas Huth #define PVR0_USE_BTC			0x00400000
123fcf5ef2aSThomas Huth #define PVR0_ENDI_MASK                  0x00200000
124fcf5ef2aSThomas Huth #define PVR0_FAULT			0x00100000
125fcf5ef2aSThomas Huth #define PVR0_VERSION_MASK               0x0000FF00
126fcf5ef2aSThomas Huth #define PVR0_USER1_MASK                 0x000000FF
127fcf5ef2aSThomas Huth #define PVR0_SPROT_MASK                 0x00000001
128fcf5ef2aSThomas Huth 
12979549c99SEdgar E. Iglesias #define PVR0_VERSION_SHIFT              8
13079549c99SEdgar E. Iglesias 
131fcf5ef2aSThomas Huth /* User 2 PVR mask */
132fcf5ef2aSThomas Huth #define PVR1_USER2_MASK                 0xFFFFFFFF
133fcf5ef2aSThomas Huth 
134fcf5ef2aSThomas Huth /* Configuration PVR masks */
135fcf5ef2aSThomas Huth #define PVR2_D_OPB_MASK                 0x80000000
136fcf5ef2aSThomas Huth #define PVR2_D_LMB_MASK                 0x40000000
137fcf5ef2aSThomas Huth #define PVR2_I_OPB_MASK                 0x20000000
138fcf5ef2aSThomas Huth #define PVR2_I_LMB_MASK                 0x10000000
139fcf5ef2aSThomas Huth #define PVR2_INTERRUPT_IS_EDGE_MASK     0x08000000
140fcf5ef2aSThomas Huth #define PVR2_EDGE_IS_POSITIVE_MASK      0x04000000
141fcf5ef2aSThomas Huth #define PVR2_D_PLB_MASK                 0x02000000      /* new */
142fcf5ef2aSThomas Huth #define PVR2_I_PLB_MASK                 0x01000000      /* new */
143fcf5ef2aSThomas Huth #define PVR2_INTERCONNECT               0x00800000      /* new */
144fcf5ef2aSThomas Huth #define PVR2_USE_EXTEND_FSL             0x00080000      /* new */
145fcf5ef2aSThomas Huth #define PVR2_USE_FSL_EXC                0x00040000      /* new */
146fcf5ef2aSThomas Huth #define PVR2_USE_MSR_INSTR              0x00020000
147fcf5ef2aSThomas Huth #define PVR2_USE_PCMP_INSTR             0x00010000
148fcf5ef2aSThomas Huth #define PVR2_AREA_OPTIMISED             0x00008000
149fcf5ef2aSThomas Huth #define PVR2_USE_BARREL_MASK            0x00004000
150fcf5ef2aSThomas Huth #define PVR2_USE_DIV_MASK               0x00002000
151fcf5ef2aSThomas Huth #define PVR2_USE_HW_MUL_MASK            0x00001000
152fcf5ef2aSThomas Huth #define PVR2_USE_FPU_MASK               0x00000800
153fcf5ef2aSThomas Huth #define PVR2_USE_MUL64_MASK             0x00000400
154fcf5ef2aSThomas Huth #define PVR2_USE_FPU2_MASK              0x00000200      /* new */
155fcf5ef2aSThomas Huth #define PVR2_USE_IPLBEXC                0x00000100
156fcf5ef2aSThomas Huth #define PVR2_USE_DPLBEXC                0x00000080
157fcf5ef2aSThomas Huth #define PVR2_OPCODE_0x0_ILL_MASK        0x00000040
158fcf5ef2aSThomas Huth #define PVR2_UNALIGNED_EXC_MASK         0x00000020
159fcf5ef2aSThomas Huth #define PVR2_ILL_OPCODE_EXC_MASK        0x00000010
160fcf5ef2aSThomas Huth #define PVR2_IOPB_BUS_EXC_MASK          0x00000008
161fcf5ef2aSThomas Huth #define PVR2_DOPB_BUS_EXC_MASK          0x00000004
162fcf5ef2aSThomas Huth #define PVR2_DIV_ZERO_EXC_MASK          0x00000002
163fcf5ef2aSThomas Huth #define PVR2_FPU_EXC_MASK               0x00000001
164fcf5ef2aSThomas Huth 
165fcf5ef2aSThomas Huth /* Debug and exception PVR masks */
166fcf5ef2aSThomas Huth #define PVR3_DEBUG_ENABLED_MASK         0x80000000
167fcf5ef2aSThomas Huth #define PVR3_NUMBER_OF_PC_BRK_MASK      0x1E000000
168fcf5ef2aSThomas Huth #define PVR3_NUMBER_OF_RD_ADDR_BRK_MASK 0x00380000
169fcf5ef2aSThomas Huth #define PVR3_NUMBER_OF_WR_ADDR_BRK_MASK 0x0000E000
170fcf5ef2aSThomas Huth #define PVR3_FSL_LINKS_MASK             0x00000380
171fcf5ef2aSThomas Huth 
172fcf5ef2aSThomas Huth /* ICache config PVR masks */
173fcf5ef2aSThomas Huth #define PVR4_USE_ICACHE_MASK            0x80000000
174fcf5ef2aSThomas Huth #define PVR4_ICACHE_ADDR_TAG_BITS_MASK  0x7C000000
175fcf5ef2aSThomas Huth #define PVR4_ICACHE_USE_FSL_MASK        0x02000000
176fcf5ef2aSThomas Huth #define PVR4_ICACHE_ALLOW_WR_MASK       0x01000000
177fcf5ef2aSThomas Huth #define PVR4_ICACHE_LINE_LEN_MASK       0x00E00000
178fcf5ef2aSThomas Huth #define PVR4_ICACHE_BYTE_SIZE_MASK      0x001F0000
179fcf5ef2aSThomas Huth 
180fcf5ef2aSThomas Huth /* DCache config PVR masks */
181fcf5ef2aSThomas Huth #define PVR5_USE_DCACHE_MASK            0x80000000
182fcf5ef2aSThomas Huth #define PVR5_DCACHE_ADDR_TAG_BITS_MASK  0x7C000000
183fcf5ef2aSThomas Huth #define PVR5_DCACHE_USE_FSL_MASK        0x02000000
184fcf5ef2aSThomas Huth #define PVR5_DCACHE_ALLOW_WR_MASK       0x01000000
185fcf5ef2aSThomas Huth #define PVR5_DCACHE_LINE_LEN_MASK       0x00E00000
186fcf5ef2aSThomas Huth #define PVR5_DCACHE_BYTE_SIZE_MASK      0x001F0000
187fcf5ef2aSThomas Huth #define PVR5_DCACHE_WRITEBACK_MASK      0x00004000
188fcf5ef2aSThomas Huth 
189fcf5ef2aSThomas Huth /* ICache base address PVR mask */
190fcf5ef2aSThomas Huth #define PVR6_ICACHE_BASEADDR_MASK       0xFFFFFFFF
191fcf5ef2aSThomas Huth 
192fcf5ef2aSThomas Huth /* ICache high address PVR mask */
193fcf5ef2aSThomas Huth #define PVR7_ICACHE_HIGHADDR_MASK       0xFFFFFFFF
194fcf5ef2aSThomas Huth 
195fcf5ef2aSThomas Huth /* DCache base address PVR mask */
196fcf5ef2aSThomas Huth #define PVR8_DCACHE_BASEADDR_MASK       0xFFFFFFFF
197fcf5ef2aSThomas Huth 
198fcf5ef2aSThomas Huth /* DCache high address PVR mask */
199fcf5ef2aSThomas Huth #define PVR9_DCACHE_HIGHADDR_MASK       0xFFFFFFFF
200fcf5ef2aSThomas Huth 
201fcf5ef2aSThomas Huth /* Target family PVR mask */
202fcf5ef2aSThomas Huth #define PVR10_TARGET_FAMILY_MASK        0xFF000000
203d248e1beSEdgar E. Iglesias #define PVR10_ASIZE_SHIFT               18
204fcf5ef2aSThomas Huth 
2058b81968cSMichael Tokarev /* MMU description */
206fcf5ef2aSThomas Huth #define PVR11_USE_MMU                   0xC0000000
207fcf5ef2aSThomas Huth #define PVR11_MMU_ITLB_SIZE             0x38000000
208fcf5ef2aSThomas Huth #define PVR11_MMU_DTLB_SIZE             0x07000000
209fcf5ef2aSThomas Huth #define PVR11_MMU_TLB_ACCESS            0x00C00000
210fcf5ef2aSThomas Huth #define PVR11_MMU_ZONES                 0x003E0000
211fcf5ef2aSThomas Huth /* MSR Reset value PVR mask */
212fcf5ef2aSThomas Huth #define PVR11_MSR_RESET_VALUE_MASK      0x000007FF
213fcf5ef2aSThomas Huth 
214fcf5ef2aSThomas Huth #define C_PVR_NONE                      0
215fcf5ef2aSThomas Huth #define C_PVR_BASIC                     1
216fcf5ef2aSThomas Huth #define C_PVR_FULL                      2
217fcf5ef2aSThomas Huth 
218fcf5ef2aSThomas Huth /* CPU flags.  */
219fcf5ef2aSThomas Huth 
220fcf5ef2aSThomas Huth /* Condition codes.  */
221fcf5ef2aSThomas Huth #define CC_GE  5
222fcf5ef2aSThomas Huth #define CC_GT  4
223fcf5ef2aSThomas Huth #define CC_LE  3
224fcf5ef2aSThomas Huth #define CC_LT  2
225fcf5ef2aSThomas Huth #define CC_NE  1
226fcf5ef2aSThomas Huth #define CC_EQ  0
227fcf5ef2aSThomas Huth 
228fcf5ef2aSThomas Huth #define STREAM_EXCEPTION (1 << 0)
229fcf5ef2aSThomas Huth #define STREAM_ATOMIC    (1 << 1)
230fcf5ef2aSThomas Huth #define STREAM_TEST      (1 << 2)
231fcf5ef2aSThomas Huth #define STREAM_CONTROL   (1 << 3)
232fcf5ef2aSThomas Huth #define STREAM_NONBLOCK  (1 << 4)
233fcf5ef2aSThomas Huth 
234683a247eSRichard Henderson #define TARGET_INSN_START_EXTRA_WORDS 1
235683a247eSRichard Henderson 
236ea2ccb65SJoe Komlodi /* use-non-secure property masks */
237ea2ccb65SJoe Komlodi #define USE_NON_SECURE_M_AXI_DP_MASK 0x1
238ea2ccb65SJoe Komlodi #define USE_NON_SECURE_M_AXI_IP_MASK 0x2
239ea2ccb65SJoe Komlodi #define USE_NON_SECURE_M_AXI_DC_MASK 0x4
240ea2ccb65SJoe Komlodi #define USE_NON_SECURE_M_AXI_IC_MASK 0x8
241ea2ccb65SJoe Komlodi 
2421ea4a06aSPhilippe Mathieu-Daudé struct CPUArchState {
243b9c58aabSRichard Henderson     uint32_t bvalue;   /* TCG temporary, only valid during a TB */
244b9c58aabSRichard Henderson     uint32_t btarget;  /* Full resolved branch destination */
245fcf5ef2aSThomas Huth 
246fcf5ef2aSThomas Huth     uint32_t imm;
2475c594ef3SEdgar E. Iglesias     uint32_t regs[32];
2480f96e96bSRichard Henderson     uint32_t pc;
2491074c0fbSRichard Henderson     uint32_t msr;    /* All bits of MSR except MSR[C] and MSR[CC] */
2501074c0fbSRichard Henderson     uint32_t msr_c;  /* MSR[C], in low bit; other bits must be 0 */
25119f27b6cSRichard Henderson     target_ulong ear;
2526efd5599SRichard Henderson     uint32_t esr;
25386017ccfSRichard Henderson     uint32_t fsr;
254ccf628b7SRichard Henderson     uint32_t btr;
25539db007eSRichard Henderson     uint32_t edr;
256fcf5ef2aSThomas Huth     float_status fp_status;
257fcf5ef2aSThomas Huth     /* Stack protectors. Yes, it's a hw feature.  */
258fcf5ef2aSThomas Huth     uint32_t slr, shr;
259fcf5ef2aSThomas Huth 
260fcf5ef2aSThomas Huth     /* lwx/swx reserved address */
261fcf5ef2aSThomas Huth #define RES_ADDR_NONE 0xffffffff /* Use 0xffffffff to indicate no reservation */
262403322eaSEdgar E. Iglesias     target_ulong res_addr;
263fcf5ef2aSThomas Huth     uint32_t res_val;
264fcf5ef2aSThomas Huth 
265fcf5ef2aSThomas Huth     /* Internal flags.  */
2667b34f45fSRichard Henderson #define IMM_FLAG        (1 << 0)
2677b34f45fSRichard Henderson #define BIMM_FLAG       (1 << 1)
268ab0c8d0fSRichard Henderson #define ESR_ESS_FLAG    (1 << 2)  /* indicates ESR_ESS_MASK is present */
269ab0c8d0fSRichard Henderson /* MSR_EE               (1 << 8)  -- these 3 are not in iflags but tb_flags */
2702c32179fSRichard Henderson /* MSR_UM               (1 << 11) */
2712c32179fSRichard Henderson /* MSR_VM               (1 << 13) */
272ab0c8d0fSRichard Henderson /* ESR_ESS_MASK         [11:5]    -- unwind into iflags for unaligned excp */
27364603d1eSRichard Henderson #define D_FLAG		(1 << 12)  /* Bit in ESR.  */
274fcf5ef2aSThomas Huth #define DRTI_FLAG	(1 << 16)
275fcf5ef2aSThomas Huth #define DRTE_FLAG	(1 << 17)
276fcf5ef2aSThomas Huth #define DRTB_FLAG	(1 << 18)
27731f163d3SRichard Henderson 
278fcf5ef2aSThomas Huth /* TB dependent CPUMBState.  */
27988e74b61SRichard Henderson #define IFLAGS_TB_MASK  (D_FLAG | BIMM_FLAG | IMM_FLAG | \
28088e74b61SRichard Henderson                          DRTI_FLAG | DRTE_FLAG | DRTB_FLAG)
28131f163d3SRichard Henderson #define MSR_TB_MASK     (MSR_UM | MSR_VM | MSR_EE)
28231f163d3SRichard Henderson 
283fcf5ef2aSThomas Huth     uint32_t iflags;
284fcf5ef2aSThomas Huth 
285fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
286fcf5ef2aSThomas Huth     /* Unified MMU.  */
2878ce97bc1SRichard Henderson     MicroBlazeMMU mmu;
288fcf5ef2aSThomas Huth #endif
289fcf5ef2aSThomas Huth 
2901f5c00cfSAlex Bennée     /* Fields up to this point are cleared by a CPU reset */
2911f5c00cfSAlex Bennée     struct {} end_reset_fields;
2921f5c00cfSAlex Bennée 
293fcf5ef2aSThomas Huth     /* These fields are preserved on reset.  */
294fcf5ef2aSThomas Huth };
295fcf5ef2aSThomas Huth 
29684bf3249SRichard Henderson /*
29784bf3249SRichard Henderson  * Microblaze Configuration Settings
298a0b2d16aSRichard Henderson  *
299a0b2d16aSRichard Henderson  * Note that the structure is sorted by type and size to minimize holes.
300fcf5ef2aSThomas Huth  */
30184bf3249SRichard Henderson typedef struct {
302a0b2d16aSRichard Henderson     char *version;
303a0b2d16aSRichard Henderson 
304de73ee1aSRichard Henderson     uint64_t addr_mask;
305de73ee1aSRichard Henderson 
306fcf5ef2aSThomas Huth     uint32_t base_vectors;
307a0b2d16aSRichard Henderson     uint32_t pvr_user2;
308a4bcfc33SRichard Henderson     uint32_t pvr_regs[13];
309a0b2d16aSRichard Henderson 
310d248e1beSEdgar E. Iglesias     uint8_t addr_size;
311fcf5ef2aSThomas Huth     uint8_t use_fpu;
3129b964318SEdgar E. Iglesias     uint8_t use_hw_mul;
313a0b2d16aSRichard Henderson     uint8_t pvr_user1;
314a0b2d16aSRichard Henderson     uint8_t pvr;
315de73ee1aSRichard Henderson     uint8_t mmu;
316de73ee1aSRichard Henderson     uint8_t mmu_tlb_access;
317de73ee1aSRichard Henderson     uint8_t mmu_zones;
318a0b2d16aSRichard Henderson 
319a0b2d16aSRichard Henderson     bool stackprot;
3207faa66aaSEdgar E. Iglesias     bool use_barrel;
32147709e4cSEdgar E. Iglesias     bool use_div;
32256837509SEdgar E. Iglesias     bool use_msr_instr;
3238fc5239eSEdgar E. Iglesias     bool use_pcmp_instr;
324fcf5ef2aSThomas Huth     bool use_mmu;
325ea2ccb65SJoe Komlodi     uint8_t use_non_secure;
326fcf5ef2aSThomas Huth     bool dcache_writeback;
327fcf5ef2aSThomas Huth     bool endi;
3282867a96fSEdgar E. Iglesias     bool dopb_bus_exception;
3292867a96fSEdgar E. Iglesias     bool iopb_bus_exception;
3305143fdf3SEdgar E. Iglesias     bool illegal_opcode_exception;
3311ee1bd28SEdgar E. Iglesias     bool opcode_0_illegal;
332622cc730SEdgar E. Iglesias     bool div_zero_exception;
3331507e5f6SEdgar E. Iglesias     bool unaligned_exceptions;
33484bf3249SRichard Henderson } MicroBlazeCPUConfig;
33584bf3249SRichard Henderson 
33684bf3249SRichard Henderson /**
33784bf3249SRichard Henderson  * MicroBlazeCPU:
33884bf3249SRichard Henderson  * @env: #CPUMBState
33984bf3249SRichard Henderson  *
34084bf3249SRichard Henderson  * A MicroBlaze CPU.
34184bf3249SRichard Henderson  */
342b36e239eSPhilippe Mathieu-Daudé struct ArchCPU {
34384bf3249SRichard Henderson     CPUState parent_obj;
3443b3d7df5SRichard Henderson 
3453b3d7df5SRichard Henderson     CPUMBState env;
3463b3d7df5SRichard Henderson 
347ea2ccb65SJoe Komlodi     bool ns_axi_dp;
348ea2ccb65SJoe Komlodi     bool ns_axi_ip;
349ea2ccb65SJoe Komlodi     bool ns_axi_dc;
350ea2ccb65SJoe Komlodi     bool ns_axi_ic;
35184bf3249SRichard Henderson 
35284bf3249SRichard Henderson     MicroBlazeCPUConfig cfg;
353fcf5ef2aSThomas Huth };
354fcf5ef2aSThomas Huth 
3559348028eSPhilippe Mathieu-Daudé /**
3569348028eSPhilippe Mathieu-Daudé  * MicroBlazeCPUClass:
3579348028eSPhilippe Mathieu-Daudé  * @parent_realize: The parent class' realize handler.
3589348028eSPhilippe Mathieu-Daudé  * @parent_phases: The parent class' reset phase handlers.
3599348028eSPhilippe Mathieu-Daudé  *
3609348028eSPhilippe Mathieu-Daudé  * A MicroBlaze CPU model.
3619348028eSPhilippe Mathieu-Daudé  */
3629348028eSPhilippe Mathieu-Daudé struct MicroBlazeCPUClass {
3639348028eSPhilippe Mathieu-Daudé     CPUClass parent_class;
3649348028eSPhilippe Mathieu-Daudé 
3659348028eSPhilippe Mathieu-Daudé     DeviceRealize parent_realize;
3669348028eSPhilippe Mathieu-Daudé     ResettablePhases parent_phases;
3679348028eSPhilippe Mathieu-Daudé };
368fcf5ef2aSThomas Huth 
369eb3ef313SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
370fcf5ef2aSThomas Huth void mb_cpu_do_interrupt(CPUState *cs);
371fcf5ef2aSThomas Huth bool mb_cpu_exec_interrupt(CPUState *cs, int int_req);
3726d2d454aSPhilippe Mathieu-Daudé hwaddr mb_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
3736d2d454aSPhilippe Mathieu-Daudé                                         MemTxAttrs *attrs);
374eb3ef313SPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
3758905770bSMarc-André Lureau G_NORETURN void mb_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,
376ab0c8d0fSRichard Henderson                                            MMUAccessType access_type,
3778905770bSMarc-André Lureau                                            int mmu_idx, uintptr_t retaddr);
37890c84c56SMarkus Armbruster void mb_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
379a010bdbeSAlex Bennée int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
380fcf5ef2aSThomas Huth int mb_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
381*66260159SAkihiko Odaki int mb_cpu_gdb_read_stack_protect(CPUState *cs, GByteArray *buf, int reg);
382*66260159SAkihiko Odaki int mb_cpu_gdb_write_stack_protect(CPUState *cs, uint8_t *buf, int reg);
383fcf5ef2aSThomas Huth 
mb_cpu_read_msr(const CPUMBState * env)3841074c0fbSRichard Henderson static inline uint32_t mb_cpu_read_msr(const CPUMBState *env)
3851074c0fbSRichard Henderson {
3861074c0fbSRichard Henderson     /* Replicate MSR[C] to MSR[CC]. */
3871074c0fbSRichard Henderson     return env->msr | (env->msr_c * (MSR_C | MSR_CC));
3881074c0fbSRichard Henderson }
3891074c0fbSRichard Henderson 
mb_cpu_write_msr(CPUMBState * env,uint32_t val)3901074c0fbSRichard Henderson static inline void mb_cpu_write_msr(CPUMBState *env, uint32_t val)
3911074c0fbSRichard Henderson {
3921074c0fbSRichard Henderson     env->msr_c = (val >> 2) & 1;
3931074c0fbSRichard Henderson     /*
3941074c0fbSRichard Henderson      * Clear both MSR[C] and MSR[CC] from the saved copy.
3951074c0fbSRichard Henderson      * MSR_PVR is not writable and is always clear.
3961074c0fbSRichard Henderson      */
3971074c0fbSRichard Henderson     env->msr = val & ~(MSR_C | MSR_CC | MSR_PVR);
3981074c0fbSRichard Henderson }
3991074c0fbSRichard Henderson 
400fcf5ef2aSThomas Huth void mb_tcg_init(void);
401fcf5ef2aSThomas Huth 
4020dacec87SIgor Mammedov #define CPU_RESOLVING_TYPE TYPE_MICROBLAZE_CPU
403fcf5ef2aSThomas Huth 
404fcf5ef2aSThomas Huth /* MMU modes definitions */
405fcf5ef2aSThomas Huth #define MMU_NOMMU_IDX   0
406fcf5ef2aSThomas Huth #define MMU_KERNEL_IDX  1
407fcf5ef2aSThomas Huth #define MMU_USER_IDX    2
408da876cc2SAnton Johansson /* See NB_MMU_MODES in cpu-defs.h. */
409fcf5ef2aSThomas Huth 
410fcf5ef2aSThomas Huth #include "exec/cpu-all.h"
411fcf5ef2aSThomas Huth 
41231f163d3SRichard Henderson /* Ensure there is no overlap between the two masks. */
41331f163d3SRichard Henderson QEMU_BUILD_BUG_ON(MSR_TB_MASK & IFLAGS_TB_MASK);
41431f163d3SRichard Henderson 
cpu_get_tb_cpu_state(CPUMBState * env,vaddr * pc,uint64_t * cs_base,uint32_t * flags)415bb5de525SAnton Johansson static inline void cpu_get_tb_cpu_state(CPUMBState *env, vaddr *pc,
416bb5de525SAnton Johansson                                         uint64_t *cs_base, uint32_t *flags)
417fcf5ef2aSThomas Huth {
41876e8187dSRichard Henderson     *pc = env->pc;
41931f163d3SRichard Henderson     *flags = (env->iflags & IFLAGS_TB_MASK) | (env->msr & MSR_TB_MASK);
420d7ecb757SRichard Henderson     *cs_base = (*flags & IMM_FLAG ? env->imm : 0);
421fcf5ef2aSThomas Huth }
422fcf5ef2aSThomas Huth 
423fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
424fd297732SRichard Henderson bool mb_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
425fd297732SRichard Henderson                      MMUAccessType access_type, int mmu_idx,
426fd297732SRichard Henderson                      bool probe, uintptr_t retaddr);
427fd297732SRichard Henderson 
428bdff8123SPeter Maydell void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
429bdff8123SPeter Maydell                                unsigned size, MMUAccessType access_type,
430bdff8123SPeter Maydell                                int mmu_idx, MemTxAttrs attrs,
431bdff8123SPeter Maydell                                MemTxResult response, uintptr_t retaddr);
432fcf5ef2aSThomas Huth #endif
433fcf5ef2aSThomas Huth 
43477f63e1dSRichard Henderson #ifndef CONFIG_USER_ONLY
43577f63e1dSRichard Henderson extern const VMStateDescription vmstate_mb_cpu;
43677f63e1dSRichard Henderson #endif
43777f63e1dSRichard Henderson 
438fcf5ef2aSThomas Huth #endif
439