2 * MicroBlaze helper routines.
4 * Copyright (c) 2009 Edgar E. Iglesias <edgar.iglesias@gmail.com>
5 * Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "host-utils.h"
27 #if defined(CONFIG_USER_ONLY)
29 void do_interrupt (CPUMBState
*env
)
31 env
->exception_index
= -1;
32 env
->regs
[14] = env
->sregs
[SR_PC
];
35 int cpu_mb_handle_mmu_fault(CPUMBState
* env
, target_ulong address
, int rw
,
38 env
->exception_index
= 0xaa;
39 cpu_dump_state(env
, stderr
, fprintf
, 0);
43 #else /* !CONFIG_USER_ONLY */
45 int cpu_mb_handle_mmu_fault (CPUMBState
*env
, target_ulong address
, int rw
,
49 unsigned int mmu_available
;
54 if (env
->pvr
.regs
[0] & PVR0_USE_MMU
) {
56 if ((env
->pvr
.regs
[0] & PVR0_PVR_FULL_MASK
)
57 && (env
->pvr
.regs
[11] & PVR11_USE_MMU
) != PVR11_USE_MMU
) {
62 /* Translate if the MMU is available and enabled. */
63 if (mmu_available
&& (env
->sregs
[SR_MSR
] & MSR_VM
)) {
64 target_ulong vaddr
, paddr
;
65 struct microblaze_mmu_lookup lu
;
67 hit
= mmu_translate(&env
->mmu
, &lu
, address
, rw
, mmu_idx
);
69 vaddr
= address
& TARGET_PAGE_MASK
;
70 paddr
= lu
.paddr
+ vaddr
- lu
.vaddr
;
72 DMMU(qemu_log("MMU map mmu=%d v=%x p=%x prot=%x\n",
73 mmu_idx
, vaddr
, paddr
, lu
.prot
));
74 tlb_set_page(env
, vaddr
, paddr
, lu
.prot
, mmu_idx
, TARGET_PAGE_SIZE
);
77 env
->sregs
[SR_EAR
] = address
;
78 DMMU(qemu_log("mmu=%d miss v=%x\n", mmu_idx
, address
));
82 env
->sregs
[SR_ESR
] = rw
== 2 ? 17 : 16;
83 env
->sregs
[SR_ESR
] |= (rw
== 1) << 10;
86 env
->sregs
[SR_ESR
] = rw
== 2 ? 19 : 18;
87 env
->sregs
[SR_ESR
] |= (rw
== 1) << 10;
94 if (env
->exception_index
== EXCP_MMU
) {
95 cpu_abort(env
, "recursive faults\n");
99 env
->exception_index
= EXCP_MMU
;
102 /* MMU disabled or not available. */
103 address
&= TARGET_PAGE_MASK
;
105 tlb_set_page(env
, address
, address
, prot
, mmu_idx
, TARGET_PAGE_SIZE
);
111 void do_interrupt(CPUMBState
*env
)
115 /* IMM flag cannot propagate across a branch and into the dslot. */
116 assert(!((env
->iflags
& D_FLAG
) && (env
->iflags
& IMM_FLAG
)));
117 assert(!(env
->iflags
& (DRTI_FLAG
| DRTE_FLAG
| DRTB_FLAG
)));
118 /* assert(env->sregs[SR_MSR] & (MSR_EE)); Only for HW exceptions. */
119 switch (env
->exception_index
) {
121 if (!(env
->pvr
.regs
[0] & PVR0_USE_EXC_MASK
)) {
122 qemu_log("Exception raised on system without exceptions!\n");
126 env
->regs
[17] = env
->sregs
[SR_PC
] + 4;
127 env
->sregs
[SR_ESR
] &= ~(1 << 12);
129 /* Exception breaks branch + dslot sequence? */
130 if (env
->iflags
& D_FLAG
) {
131 env
->sregs
[SR_ESR
] |= 1 << 12 ;
132 env
->sregs
[SR_BTR
] = env
->btarget
;
135 /* Disable the MMU. */
136 t
= (env
->sregs
[SR_MSR
] & (MSR_VM
| MSR_UM
)) << 1;
137 env
->sregs
[SR_MSR
] &= ~(MSR_VMS
| MSR_UMS
| MSR_VM
| MSR_UM
);
138 env
->sregs
[SR_MSR
] |= t
;
139 /* Exception in progress. */
140 env
->sregs
[SR_MSR
] |= MSR_EIP
;
142 qemu_log_mask(CPU_LOG_INT
,
143 "hw exception at pc=%x ear=%x esr=%x iflags=%x\n",
144 env
->sregs
[SR_PC
], env
->sregs
[SR_EAR
],
145 env
->sregs
[SR_ESR
], env
->iflags
);
146 log_cpu_state_mask(CPU_LOG_INT
, env
, 0);
147 env
->iflags
&= ~(IMM_FLAG
| D_FLAG
);
148 env
->sregs
[SR_PC
] = 0x20;
152 env
->regs
[17] = env
->sregs
[SR_PC
];
154 env
->sregs
[SR_ESR
] &= ~(1 << 12);
155 /* Exception breaks branch + dslot sequence? */
156 if (env
->iflags
& D_FLAG
) {
157 D(qemu_log("D_FLAG set at exception bimm=%d\n", env
->bimm
));
158 env
->sregs
[SR_ESR
] |= 1 << 12 ;
159 env
->sregs
[SR_BTR
] = env
->btarget
;
161 /* Reexecute the branch. */
163 /* was the branch immprefixed?. */
165 qemu_log_mask(CPU_LOG_INT
,
166 "bimm exception at pc=%x iflags=%x\n",
167 env
->sregs
[SR_PC
], env
->iflags
);
169 log_cpu_state_mask(CPU_LOG_INT
, env
, 0);
171 } else if (env
->iflags
& IMM_FLAG
) {
172 D(qemu_log("IMM_FLAG set at exception\n"));
176 /* Disable the MMU. */
177 t
= (env
->sregs
[SR_MSR
] & (MSR_VM
| MSR_UM
)) << 1;
178 env
->sregs
[SR_MSR
] &= ~(MSR_VMS
| MSR_UMS
| MSR_VM
| MSR_UM
);
179 env
->sregs
[SR_MSR
] |= t
;
180 /* Exception in progress. */
181 env
->sregs
[SR_MSR
] |= MSR_EIP
;
183 qemu_log_mask(CPU_LOG_INT
,
184 "exception at pc=%x ear=%x iflags=%x\n",
185 env
->sregs
[SR_PC
], env
->sregs
[SR_EAR
], env
->iflags
);
186 log_cpu_state_mask(CPU_LOG_INT
, env
, 0);
187 env
->iflags
&= ~(IMM_FLAG
| D_FLAG
);
188 env
->sregs
[SR_PC
] = 0x20;
192 assert(!(env
->sregs
[SR_MSR
] & (MSR_EIP
| MSR_BIP
)));
193 assert(env
->sregs
[SR_MSR
] & MSR_IE
);
194 assert(!(env
->iflags
& D_FLAG
));
196 t
= (env
->sregs
[SR_MSR
] & (MSR_VM
| MSR_UM
)) << 1;
201 /* Useful instrumentation when debugging interrupt issues in either
202 the models or in sw. */
206 sym
= lookup_symbol(env
->sregs
[SR_PC
]);
208 && (!strcmp("netif_rx", sym
)
209 || !strcmp("process_backlog", sym
))) {
212 "interrupt at pc=%x msr=%x %x iflags=%x sym=%s\n",
213 env
->sregs
[SR_PC
], env
->sregs
[SR_MSR
], t
, env
->iflags
,
216 log_cpu_state(env
, 0);
220 qemu_log_mask(CPU_LOG_INT
,
221 "interrupt at pc=%x msr=%x %x iflags=%x\n",
222 env
->sregs
[SR_PC
], env
->sregs
[SR_MSR
], t
, env
->iflags
);
224 env
->sregs
[SR_MSR
] &= ~(MSR_VMS
| MSR_UMS
| MSR_VM \
226 env
->sregs
[SR_MSR
] |= t
;
228 env
->regs
[14] = env
->sregs
[SR_PC
];
229 env
->sregs
[SR_PC
] = 0x10;
230 //log_cpu_state_mask(CPU_LOG_INT, env, 0);
235 assert(!(env
->iflags
& IMM_FLAG
));
236 assert(!(env
->iflags
& D_FLAG
));
237 t
= (env
->sregs
[SR_MSR
] & (MSR_VM
| MSR_UM
)) << 1;
238 qemu_log_mask(CPU_LOG_INT
,
239 "break at pc=%x msr=%x %x iflags=%x\n",
240 env
->sregs
[SR_PC
], env
->sregs
[SR_MSR
], t
, env
->iflags
);
241 log_cpu_state_mask(CPU_LOG_INT
, env
, 0);
242 env
->sregs
[SR_MSR
] &= ~(MSR_VMS
| MSR_UMS
| MSR_VM
| MSR_UM
);
243 env
->sregs
[SR_MSR
] |= t
;
244 env
->sregs
[SR_MSR
] |= MSR_BIP
;
245 if (env
->exception_index
== EXCP_HW_BREAK
) {
246 env
->regs
[16] = env
->sregs
[SR_PC
];
247 env
->sregs
[SR_MSR
] |= MSR_BIP
;
248 env
->sregs
[SR_PC
] = 0x18;
250 env
->sregs
[SR_PC
] = env
->btarget
;
253 cpu_abort(env
, "unhandled exception type=%d\n",
254 env
->exception_index
);
259 target_phys_addr_t
cpu_get_phys_page_debug(CPUMBState
* env
, target_ulong addr
)
261 target_ulong vaddr
, paddr
= 0;
262 struct microblaze_mmu_lookup lu
;
265 if (env
->sregs
[SR_MSR
] & MSR_VM
) {
266 hit
= mmu_translate(&env
->mmu
, &lu
, addr
, 0, 0);
268 vaddr
= addr
& TARGET_PAGE_MASK
;
269 paddr
= lu
.paddr
+ vaddr
- lu
.vaddr
;
271 paddr
= 0; /* ???. */
273 paddr
= addr
& TARGET_PAGE_MASK
;