2 * MicroBlaze helper routines.
4 * Copyright (c) 2009 Edgar E. Iglesias <edgar.iglesias@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 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 <http://www.gnu.org/licenses/>.
26 #include "host-utils.h"
31 #if defined(CONFIG_USER_ONLY)
33 void do_interrupt (CPUState
*env
)
35 env
->exception_index
= -1;
36 env
->regs
[14] = env
->sregs
[SR_PC
];
39 int cpu_mb_handle_mmu_fault(CPUState
* env
, target_ulong address
, int rw
,
42 env
->exception_index
= 0xaa;
43 cpu_dump_state(env
, stderr
, fprintf
, 0);
47 #else /* !CONFIG_USER_ONLY */
49 int cpu_mb_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
53 unsigned int mmu_available
;
58 if (env
->pvr
.regs
[0] & PVR0_USE_MMU
) {
60 if ((env
->pvr
.regs
[0] & PVR0_PVR_FULL_MASK
)
61 && (env
->pvr
.regs
[11] & PVR11_USE_MMU
) != PVR11_USE_MMU
) {
66 /* Translate if the MMU is available and enabled. */
67 if (mmu_available
&& (env
->sregs
[SR_MSR
] & MSR_VM
)) {
68 target_ulong vaddr
, paddr
;
69 struct microblaze_mmu_lookup lu
;
71 hit
= mmu_translate(&env
->mmu
, &lu
, address
, rw
, mmu_idx
);
73 vaddr
= address
& TARGET_PAGE_MASK
;
74 paddr
= lu
.paddr
+ vaddr
- lu
.vaddr
;
76 DMMU(qemu_log("MMU map mmu=%d v=%x p=%x prot=%x\n",
77 mmu_idx
, vaddr
, paddr
, lu
.prot
));
78 tlb_set_page(env
, vaddr
, paddr
, lu
.prot
, mmu_idx
, TARGET_PAGE_SIZE
);
81 env
->sregs
[SR_EAR
] = address
;
82 DMMU(qemu_log("mmu=%d miss v=%x\n", mmu_idx
, address
));
86 env
->sregs
[SR_ESR
] = rw
== 2 ? 17 : 16;
87 env
->sregs
[SR_ESR
] |= (rw
== 1) << 10;
90 env
->sregs
[SR_ESR
] = rw
== 2 ? 19 : 18;
91 env
->sregs
[SR_ESR
] |= (rw
== 1) << 10;
98 if (env
->exception_index
== EXCP_MMU
) {
99 cpu_abort(env
, "recursive faults\n");
103 env
->exception_index
= EXCP_MMU
;
106 /* MMU disabled or not available. */
107 address
&= TARGET_PAGE_MASK
;
109 tlb_set_page(env
, address
, address
, prot
, mmu_idx
, TARGET_PAGE_SIZE
);
115 void do_interrupt(CPUState
*env
)
119 /* IMM flag cannot propagate across a branch and into the dslot. */
120 assert(!((env
->iflags
& D_FLAG
) && (env
->iflags
& IMM_FLAG
)));
121 assert(!(env
->iflags
& (DRTI_FLAG
| DRTE_FLAG
| DRTB_FLAG
)));
122 /* assert(env->sregs[SR_MSR] & (MSR_EE)); Only for HW exceptions. */
123 switch (env
->exception_index
) {
125 if (!(env
->pvr
.regs
[0] & PVR0_USE_EXC_MASK
)) {
126 qemu_log("Exception raised on system without exceptions!\n");
130 env
->regs
[17] = env
->sregs
[SR_PC
] + 4;
131 env
->sregs
[SR_ESR
] &= ~(1 << 12);
133 /* Exception breaks branch + dslot sequence? */
134 if (env
->iflags
& D_FLAG
) {
135 env
->sregs
[SR_ESR
] |= 1 << 12 ;
136 env
->sregs
[SR_BTR
] = env
->btarget
;
139 /* Disable the MMU. */
140 t
= (env
->sregs
[SR_MSR
] & (MSR_VM
| MSR_UM
)) << 1;
141 env
->sregs
[SR_MSR
] &= ~(MSR_VMS
| MSR_UMS
| MSR_VM
| MSR_UM
);
142 env
->sregs
[SR_MSR
] |= t
;
143 /* Exception in progress. */
144 env
->sregs
[SR_MSR
] |= MSR_EIP
;
146 qemu_log_mask(CPU_LOG_INT
,
147 "hw exception at pc=%x ear=%x esr=%x iflags=%x\n",
148 env
->sregs
[SR_PC
], env
->sregs
[SR_EAR
],
149 env
->sregs
[SR_ESR
], env
->iflags
);
150 log_cpu_state_mask(CPU_LOG_INT
, env
, 0);
151 env
->iflags
&= ~(IMM_FLAG
| D_FLAG
);
152 env
->sregs
[SR_PC
] = 0x20;
156 env
->regs
[17] = env
->sregs
[SR_PC
];
158 env
->sregs
[SR_ESR
] &= ~(1 << 12);
159 /* Exception breaks branch + dslot sequence? */
160 if (env
->iflags
& D_FLAG
) {
161 D(qemu_log("D_FLAG set at exception bimm=%d\n", env
->bimm
));
162 env
->sregs
[SR_ESR
] |= 1 << 12 ;
163 env
->sregs
[SR_BTR
] = env
->btarget
;
165 /* Reexecute the branch. */
167 /* was the branch immprefixed?. */
169 qemu_log_mask(CPU_LOG_INT
,
170 "bimm exception at pc=%x iflags=%x\n",
171 env
->sregs
[SR_PC
], env
->iflags
);
173 log_cpu_state_mask(CPU_LOG_INT
, env
, 0);
175 } else if (env
->iflags
& IMM_FLAG
) {
176 D(qemu_log("IMM_FLAG set at exception\n"));
180 /* Disable the MMU. */
181 t
= (env
->sregs
[SR_MSR
] & (MSR_VM
| MSR_UM
)) << 1;
182 env
->sregs
[SR_MSR
] &= ~(MSR_VMS
| MSR_UMS
| MSR_VM
| MSR_UM
);
183 env
->sregs
[SR_MSR
] |= t
;
184 /* Exception in progress. */
185 env
->sregs
[SR_MSR
] |= MSR_EIP
;
187 qemu_log_mask(CPU_LOG_INT
,
188 "exception at pc=%x ear=%x iflags=%x\n",
189 env
->sregs
[SR_PC
], env
->sregs
[SR_EAR
], env
->iflags
);
190 log_cpu_state_mask(CPU_LOG_INT
, env
, 0);
191 env
->iflags
&= ~(IMM_FLAG
| D_FLAG
);
192 env
->sregs
[SR_PC
] = 0x20;
196 assert(!(env
->sregs
[SR_MSR
] & (MSR_EIP
| MSR_BIP
)));
197 assert(env
->sregs
[SR_MSR
] & MSR_IE
);
198 assert(!(env
->iflags
& D_FLAG
));
200 t
= (env
->sregs
[SR_MSR
] & (MSR_VM
| MSR_UM
)) << 1;
205 /* Useful instrumentation when debugging interrupt issues in either
206 the models or in sw. */
210 sym
= lookup_symbol(env
->sregs
[SR_PC
]);
212 && (!strcmp("netif_rx", sym
)
213 || !strcmp("process_backlog", sym
))) {
216 "interrupt at pc=%x msr=%x %x iflags=%x sym=%s\n",
217 env
->sregs
[SR_PC
], env
->sregs
[SR_MSR
], t
, env
->iflags
,
220 log_cpu_state(env
, 0);
224 qemu_log_mask(CPU_LOG_INT
,
225 "interrupt at pc=%x msr=%x %x iflags=%x\n",
226 env
->sregs
[SR_PC
], env
->sregs
[SR_MSR
], t
, env
->iflags
);
228 env
->sregs
[SR_MSR
] &= ~(MSR_VMS
| MSR_UMS
| MSR_VM \
230 env
->sregs
[SR_MSR
] |= t
;
232 env
->regs
[14] = env
->sregs
[SR_PC
];
233 env
->sregs
[SR_PC
] = 0x10;
234 //log_cpu_state_mask(CPU_LOG_INT, env, 0);
239 assert(!(env
->iflags
& IMM_FLAG
));
240 assert(!(env
->iflags
& D_FLAG
));
241 t
= (env
->sregs
[SR_MSR
] & (MSR_VM
| MSR_UM
)) << 1;
242 qemu_log_mask(CPU_LOG_INT
,
243 "break at pc=%x msr=%x %x iflags=%x\n",
244 env
->sregs
[SR_PC
], env
->sregs
[SR_MSR
], t
, env
->iflags
);
245 log_cpu_state_mask(CPU_LOG_INT
, env
, 0);
246 env
->sregs
[SR_MSR
] &= ~(MSR_VMS
| MSR_UMS
| MSR_VM
| MSR_UM
);
247 env
->sregs
[SR_MSR
] |= t
;
248 env
->sregs
[SR_MSR
] |= MSR_BIP
;
249 if (env
->exception_index
== EXCP_HW_BREAK
) {
250 env
->regs
[16] = env
->sregs
[SR_PC
];
251 env
->sregs
[SR_MSR
] |= MSR_BIP
;
252 env
->sregs
[SR_PC
] = 0x18;
254 env
->sregs
[SR_PC
] = env
->btarget
;
257 cpu_abort(env
, "unhandled exception type=%d\n",
258 env
->exception_index
);
263 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
* env
, target_ulong addr
)
265 target_ulong vaddr
, paddr
= 0;
266 struct microblaze_mmu_lookup lu
;
269 if (env
->sregs
[SR_MSR
] & MSR_VM
) {
270 hit
= mmu_translate(&env
->mmu
, &lu
, addr
, 0, 0);
272 vaddr
= addr
& TARGET_PAGE_MASK
;
273 paddr
= lu
.paddr
+ vaddr
- lu
.vaddr
;
275 paddr
= 0; /* ???. */
277 paddr
= addr
& TARGET_PAGE_MASK
;