* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <sys/mman.h>
-
#include "exec.h"
#if defined (USE_OPEN_FIRMWARE)
#include <time.h>
//#define DEBUG_BATS
//#define DEBUG_EXCEPTIONS
-extern FILE *logfile, *stdout, *stderr;
-void exit (int);
-void abort (void);
-
-void cpu_loop_exit(void)
-{
- longjmp(env->jmp_env, 1);
-}
-
-void do_process_exceptions (void)
-{
- cpu_loop_exit();
-}
-
-int check_exception_state (CPUState *env)
-{
- int i;
-
- /* Process PPC exceptions */
- for (i = 1; i < EXCP_PPC_MAX; i++) {
- if (env->exceptions & (1 << i)) {
- switch (i) {
- case EXCP_EXTERNAL:
- case EXCP_DECR:
- if (msr_ee == 0)
- return 0;
- break;
- case EXCP_PROGRAM:
- if (env->errors[EXCP_PROGRAM] == EXCP_FP &&
- msr_fe0 == 0 && msr_fe1 == 0)
- return 0;
- break;
- default:
- break;
- }
- env->exception_index = i;
- env->error_code = env->errors[i];
- return 1;
- }
- }
-
- return 0;
-}
-
/*****************************************************************************/
/* PPC MMU emulation */
int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
((virtual & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) |
(virtual & 0x0001F000);
if (*BATl & 0x00000001)
- *prot = PROT_READ;
+ *prot = PAGE_READ;
if (*BATl & 0x00000002)
- *prot = PROT_WRITE | PROT_READ;
+ *prot = PAGE_WRITE | PAGE_READ;
#if defined (DEBUG_BATS)
if (loglevel > 0) {
fprintf(logfile, "BAT %d match: r 0x%08x prot=%c%c\n",
- i, *real, *prot & PROT_READ ? 'R' : '-',
- *prot & PROT_WRITE ? 'W' : '-');
+ i, *real, *prot & PAGE_READ ? 'R' : '-',
+ *prot & PAGE_WRITE ? 'W' : '-');
}
#endif
ret = 0;
*BATu, *BATl, BEPIu, BEPIl, bl);
}
#endif
- env->spr[DAR] = virtual;
}
/* No hit */
return ret;
int ret = -1; /* No entry found */
for (i = 0; i < 8; i++) {
- pte0 = ldl_raw((void *)((uint32_t)phys_ram_base + base + (i * 8)));
- pte1 = ldl_raw((void *)((uint32_t)phys_ram_base + base + (i * 8) + 4));
+ pte0 = ldl_raw(phys_ram_base + base + (i * 8));
+ pte1 = ldl_raw(phys_ram_base + base + (i * 8) + 4);
#if defined (DEBUG_MMU)
if (loglevel > 0) {
fprintf(logfile, "Load pte from 0x%08x => 0x%08x 0x%08x "
}
/* Check access rights */
if (key == 0) {
- access = PROT_READ;
+ access = PAGE_READ;
if ((pte1 & 0x00000003) != 0x3)
- access |= PROT_WRITE;
+ access |= PAGE_WRITE;
} else {
switch (pte1 & 0x00000003) {
case 0x0:
break;
case 0x1:
case 0x3:
- access = PROT_READ;
+ access = PAGE_READ;
break;
case 0x2:
- access = PROT_READ | PROT_WRITE;
+ access = PAGE_READ | PAGE_WRITE;
break;
}
}
if (ret < 0) {
- if ((rw == 0 && (access & PROT_READ)) ||
- (rw == 1 && (access & PROT_WRITE))) {
+ if ((rw == 0 && (access & PAGE_READ)) ||
+ (rw == 1 && (access & PAGE_WRITE))) {
#if defined (DEBUG_MMU)
if (loglevel > 0)
fprintf(logfile, "PTE access granted !\n");
store = 1;
} else {
/* Force page fault for first write access */
- *prot &= ~PROT_WRITE;
+ *prot &= ~PAGE_WRITE;
}
}
if (store) {
- stl_raw((void *)((uint32_t)phys_ram_base + base + (good * 8) + 4),
- keep);
+ stl_raw(phys_ram_base + base + (good * 8) + 4, keep);
}
}
uint32_t address, int rw, int access_type)
{
int ret;
-
+#if 0
if (loglevel > 0) {
fprintf(logfile, "%s\n", __func__);
}
-
- if ((access_type == ACCESS_CODE && msr_ir == 0) || msr_dr == 0) {
+#endif
+ if ((access_type == ACCESS_CODE && msr_ir == 0) ||
+ (access_type != ACCESS_CODE && msr_dr == 0)) {
/* No address translation */
*physical = address & ~0xFFF;
- *prot = PROT_READ | PROT_WRITE;
+ *prot = PAGE_READ | PAGE_WRITE;
ret = 0;
} else {
/* Try to find a BAT */
ret = get_segment(env, physical, prot, address, rw, access_type);
}
}
+#if 0
if (loglevel > 0) {
fprintf(logfile, "%s address %08x => %08x\n",
__func__, address, *physical);
}
-
+#endif
return ret;
}
tlb_addrr = env->tlb_read[is_user][index].address;
tlb_addrw = env->tlb_write[is_user][index].address;
#if 0
- printf("%s 1 %p %p idx=%d addr=0x%08lx tbl_addr=0x%08lx 0x%08lx "
+ if (loglevel) {
+ fprintf(logfile,
+ "%s 1 %p %p idx=%d addr=0x%08lx tbl_addr=0x%08lx 0x%08lx "
"(0x%08lx 0x%08lx)\n", __func__, env,
&env->tlb_read[is_user][index], index, addr,
tlb_addrr, tlb_addrw, addr & TARGET_PAGE_MASK,
tlb_addrr & (TARGET_PAGE_MASK | TLB_INVALID_MASK));
+ }
#endif
}
ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, is_user, 1);
cpu_restore_state(tb, env, pc, NULL);
}
}
- do_queue_exception_err(env->exception_index, env->error_code);
- do_process_exceptions();
+ do_raise_exception_err(env->exception_index, env->error_code);
}
{
unsigned long tlb_addrr, tlb_addrw;
access_type = env->access_type;
if (env->user_mode_only) {
/* user mode only emulation */
- ret = -1;
+ ret = -2;
goto do_fault;
}
/* NASTY BUG workaround */
if (access_type == ACCESS_CODE && rw) {
- // printf("%s: ERROR WRITE CODE ACCESS\n", __func__);
+ printf("%s: ERROR WRITE CODE ACCESS\n", __func__);
access_type = ACCESS_INT;
}
ret = get_physical_address(env, &physical, &prot,
void _store_msr (CPUState *env, uint32_t value)
{
- if (((T0 >> MSR_IR) & 0x01) != msr_ir ||
- ((T0 >> MSR_DR) & 0x01) != msr_dr) {
+#if 0 // TRY
+ if (((value >> MSR_IR) & 0x01) != msr_ir ||
+ ((value >> MSR_DR) & 0x01) != msr_dr)
+ {
/* Flush all tlb when changing translation mode or privilege level */
- do_tlbia();
+ tlb_flush(env, 1);
}
+#endif
msr_pow = (value >> MSR_POW) & 0x03;
msr_ile = (value >> MSR_ILE) & 0x01;
msr_ee = (value >> MSR_EE) & 0x01;
uint32_t msr;
int excp = env->exception_index;
- /* Dequeue PPC exceptions */
- if (excp < EXCP_PPC_MAX)
- env->exceptions &= ~(1 << excp);
msr = _load_msr(env);
#if defined (DEBUG_EXCEPTIONS)
if ((excp == EXCP_PROGRAM || excp == EXCP_DSI) && msr_pr == 1)
goto store_next;
case EXCP_MACHINE_CHECK:
if (msr_me == 0) {
- printf("Machine check exception while not allowed !\n");
- if (loglevel) {
- fprintf(logfile,
- "Machine check exception while not allowed !\n");
+ cpu_abort(env, "Machine check exception while not allowed\n");
}
- abort();
- }
msr_me = 0;
break;
case EXCP_DSI:
}
#endif
/* Requeue it */
- do_queue_exception(EXCP_EXTERNAL);
+ do_raise_exception(EXCP_EXTERNAL);
return;
}
goto store_next;
env->fpscr[7] |= 0x4;
break;
case EXCP_INVAL:
- printf("Invalid instruction at 0x%08x\n", env->nip);
+ // printf("Invalid instruction at 0x%08x\n", env->nip);
msr |= 0x00080000;
break;
case EXCP_PRIV:
case EXCP_DECR:
if (msr_ee == 0) {
/* Requeue it */
- do_queue_exception(EXCP_DECR);
+ do_raise_exception(EXCP_DECR);
return;
}
goto store_next;
env->nip = excp << 8;
env->exception_index = EXCP_NONE;
/* Invalidate all TLB as we may have changed translation mode */
- do_tlbia();
+ tlb_flush(env, 1);
/* ensure that no TB jump will be modified as
the program flow was changed */
#ifdef __sparc__
T0 = 0;
#endif
#endif
+ env->exception_index = -1;
}