--- trunk/src/cpus/memory_ppc.c 2007/10/08 16:19:37 22 +++ trunk/src/cpus/memory_ppc.c 2007/10/08 16:20:58 32 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 Anders Gavare. All rights reserved. + * Copyright (C) 2005-2006 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: memory_ppc.c,v 1.22 2005/12/20 18:20:55 debug Exp $ + * $Id: memory_ppc.c,v 1.26 2006/09/30 05:57:08 debug Exp $ * * Included from cpu_ppc.c. */ @@ -41,7 +41,7 @@ * BAT translation. Returns -1 if there was no BAT hit, >= 0 for a hit. * (0 for access denied, 1 for read-only, and 2 for read-write access allowed.) */ -int ppc_bat(struct cpu *cpu, uint64_t vaddr, uint64_t *return_addr, int flags, +int ppc_bat(struct cpu *cpu, uint64_t vaddr, uint64_t *return_paddr, int flags, int user) { int i, istart = 0, iend = 8, pp; @@ -78,7 +78,7 @@ if ((vaddr & ~mask) != (ebs & ~mask)) continue; - *return_addr = (vaddr & mask) | (phys & ~mask); + *return_paddr = (vaddr & mask) | (phys & ~mask); pp = lower & BAT_PP; switch (pp) { @@ -107,8 +107,7 @@ static int get_pte_low(struct cpu *cpu, uint64_t pteg_select, uint32_t *lowp, uint32_t cmp) { - unsigned char *d = memory_paddr_to_hostaddr(cpu->mem, pteg_select, 1) - + (pteg_select & ((1 << BITS_PER_MEMBLOCK) - 1)); + unsigned char *d = memory_paddr_to_hostaddr(cpu->mem, pteg_select, 1); int i; for (i=0; i<8; i++) { @@ -139,7 +138,7 @@ * a permission violation. *resp is set to 0 for no access, 1 for read-only * access, or 2 for read/write access. */ -static int ppc_vtp32(struct cpu *cpu, uint32_t vaddr, uint64_t *return_addr, +static int ppc_vtp32(struct cpu *cpu, uint32_t vaddr, uint64_t *return_paddr, int *resp, uint64_t msr, int writeflag, int instr) { int srn = (vaddr >> 28) & 15, api = (vaddr >> 22) & PTE_API; @@ -186,7 +185,7 @@ return 1; access = lower_pte & PTE_PP; - *return_addr = (lower_pte & PTE_RPGN) | (vaddr & ~PTE_RPGN); + *return_paddr = (lower_pte & PTE_RPGN) | (vaddr & ~PTE_RPGN); key = (cpu->cd.ppc.sr[srn] & SR_PRKEY && msr & PPC_MSR_PR) || (cpu->cd.ppc.sr[srn] & SR_SUKEY && !(msr & PPC_MSR_PR)); @@ -212,17 +211,17 @@ /* - * ppc_translate_address(): + * ppc_translate_v2p(): * - * Don't call this function is userland_emul is non-NULL, or cpu is NULL. + * Don't call this function if userland_emul is non-NULL, or cpu is NULL. * * Return values: * 0 Failure * 1 Success, the page is readable only * 2 Success, the page is read/write */ -int ppc_translate_address(struct cpu *cpu, uint64_t vaddr, - uint64_t *return_addr, int flags) +int ppc_translate_v2p(struct cpu *cpu, uint64_t vaddr, + uint64_t *return_paddr, int flags) { int instr = flags & FLAG_INSTR, res = 0, match, user; int writeflag = flags & FLAG_WRITEFLAG? 1 : 0; @@ -235,18 +234,18 @@ vaddr &= 0xffffffff; if ((instr && !(msr & PPC_MSR_IR)) || (!instr && !(msr & PPC_MSR_DR))) { - *return_addr = vaddr; + *return_paddr = vaddr; return 2; } if (cpu->cd.ppc.cpu_type.flags & PPC_601) { - fatal("ppc_translate_address(): TODO: 601\n"); + fatal("ppc_translate_v2p(): TODO: 601\n"); exit(1); } /* Try the BATs first: */ if (cpu->cd.ppc.bits == 32) { - res = ppc_bat(cpu, vaddr, return_addr, flags, user); + res = ppc_bat(cpu, vaddr, return_paddr, flags, user); if (res > 0) return res; if (res == 0) { @@ -257,7 +256,7 @@ /* Virtual to physical translation: */ if (cpu->cd.ppc.bits == 32) { - match = ppc_vtp32(cpu, vaddr, return_addr, &res, msr, + match = ppc_vtp32(cpu, vaddr, return_paddr, &res, msr, writeflag, instr); if (match && res > 0) return res; @@ -279,9 +278,9 @@ return 0; if (!quiet_mode) - fatal("[ memory_ppc: exception! vaddr=0x%llx pc=0x%llx " - "instr=%i user=%i wf=%i ]\n", (long long)vaddr, - (long long)cpu->pc, instr, user, writeflag); + fatal("[ memory_ppc: exception! vaddr=0x%"PRIx64" pc=0x%"PRIx64 + " instr=%i user=%i wf=%i ]\n", (uint64_t) vaddr, + (uint64_t) cpu->pc, instr, user, writeflag); if (cpu->cd.ppc.cpu_type.flags & PPC_603) { cpu->cd.ppc.spr[instr? SPR_IMISS : SPR_DMISS] = vaddr;