25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: memory_ppc.c,v 1.23 2006/03/30 19:41:51 debug Exp $ |
* $Id: memory_ppc.c,v 1.25 2006/07/14 16:33:28 debug Exp $ |
29 |
* |
* |
30 |
* Included from cpu_ppc.c. |
* Included from cpu_ppc.c. |
31 |
*/ |
*/ |
41 |
* BAT translation. Returns -1 if there was no BAT hit, >= 0 for a hit. |
* BAT translation. Returns -1 if there was no BAT hit, >= 0 for a hit. |
42 |
* (0 for access denied, 1 for read-only, and 2 for read-write access allowed.) |
* (0 for access denied, 1 for read-only, and 2 for read-write access allowed.) |
43 |
*/ |
*/ |
44 |
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, |
45 |
int user) |
int user) |
46 |
{ |
{ |
47 |
int i, istart = 0, iend = 8, pp; |
int i, istart = 0, iend = 8, pp; |
78 |
if ((vaddr & ~mask) != (ebs & ~mask)) |
if ((vaddr & ~mask) != (ebs & ~mask)) |
79 |
continue; |
continue; |
80 |
|
|
81 |
*return_addr = (vaddr & mask) | (phys & ~mask); |
*return_paddr = (vaddr & mask) | (phys & ~mask); |
82 |
|
|
83 |
pp = lower & BAT_PP; |
pp = lower & BAT_PP; |
84 |
switch (pp) { |
switch (pp) { |
107 |
static int get_pte_low(struct cpu *cpu, uint64_t pteg_select, |
static int get_pte_low(struct cpu *cpu, uint64_t pteg_select, |
108 |
uint32_t *lowp, uint32_t cmp) |
uint32_t *lowp, uint32_t cmp) |
109 |
{ |
{ |
110 |
unsigned char *d = memory_paddr_to_hostaddr(cpu->mem, pteg_select, 1) |
unsigned char *d = memory_paddr_to_hostaddr(cpu->mem, pteg_select, 1); |
|
+ (pteg_select & ((1 << BITS_PER_MEMBLOCK) - 1)); |
|
111 |
int i; |
int i; |
112 |
|
|
113 |
for (i=0; i<8; i++) { |
for (i=0; i<8; i++) { |
138 |
* a permission violation. *resp is set to 0 for no access, 1 for read-only |
* a permission violation. *resp is set to 0 for no access, 1 for read-only |
139 |
* access, or 2 for read/write access. |
* access, or 2 for read/write access. |
140 |
*/ |
*/ |
141 |
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, |
142 |
int *resp, uint64_t msr, int writeflag, int instr) |
int *resp, uint64_t msr, int writeflag, int instr) |
143 |
{ |
{ |
144 |
int srn = (vaddr >> 28) & 15, api = (vaddr >> 22) & PTE_API; |
int srn = (vaddr >> 28) & 15, api = (vaddr >> 22) & PTE_API; |
185 |
return 1; |
return 1; |
186 |
|
|
187 |
access = lower_pte & PTE_PP; |
access = lower_pte & PTE_PP; |
188 |
*return_addr = (lower_pte & PTE_RPGN) | (vaddr & ~PTE_RPGN); |
*return_paddr = (lower_pte & PTE_RPGN) | (vaddr & ~PTE_RPGN); |
189 |
|
|
190 |
key = (cpu->cd.ppc.sr[srn] & SR_PRKEY && msr & PPC_MSR_PR) || |
key = (cpu->cd.ppc.sr[srn] & SR_PRKEY && msr & PPC_MSR_PR) || |
191 |
(cpu->cd.ppc.sr[srn] & SR_SUKEY && !(msr & PPC_MSR_PR)); |
(cpu->cd.ppc.sr[srn] & SR_SUKEY && !(msr & PPC_MSR_PR)); |
211 |
|
|
212 |
|
|
213 |
/* |
/* |
214 |
* ppc_translate_address(): |
* ppc_translate_v2p(): |
215 |
* |
* |
216 |
* Don't call this function is userland_emul is non-NULL, or cpu is NULL. |
* Don't call this function is userland_emul is non-NULL, or cpu is NULL. |
217 |
* |
* |
220 |
* 1 Success, the page is readable only |
* 1 Success, the page is readable only |
221 |
* 2 Success, the page is read/write |
* 2 Success, the page is read/write |
222 |
*/ |
*/ |
223 |
int ppc_translate_address(struct cpu *cpu, uint64_t vaddr, |
int ppc_translate_v2p(struct cpu *cpu, uint64_t vaddr, |
224 |
uint64_t *return_addr, int flags) |
uint64_t *return_paddr, int flags) |
225 |
{ |
{ |
226 |
int instr = flags & FLAG_INSTR, res = 0, match, user; |
int instr = flags & FLAG_INSTR, res = 0, match, user; |
227 |
int writeflag = flags & FLAG_WRITEFLAG? 1 : 0; |
int writeflag = flags & FLAG_WRITEFLAG? 1 : 0; |
234 |
vaddr &= 0xffffffff; |
vaddr &= 0xffffffff; |
235 |
|
|
236 |
if ((instr && !(msr & PPC_MSR_IR)) || (!instr && !(msr & PPC_MSR_DR))) { |
if ((instr && !(msr & PPC_MSR_IR)) || (!instr && !(msr & PPC_MSR_DR))) { |
237 |
*return_addr = vaddr; |
*return_paddr = vaddr; |
238 |
return 2; |
return 2; |
239 |
} |
} |
240 |
|
|
241 |
if (cpu->cd.ppc.cpu_type.flags & PPC_601) { |
if (cpu->cd.ppc.cpu_type.flags & PPC_601) { |
242 |
fatal("ppc_translate_address(): TODO: 601\n"); |
fatal("ppc_translate_v2p(): TODO: 601\n"); |
243 |
exit(1); |
exit(1); |
244 |
} |
} |
245 |
|
|
246 |
/* Try the BATs first: */ |
/* Try the BATs first: */ |
247 |
if (cpu->cd.ppc.bits == 32) { |
if (cpu->cd.ppc.bits == 32) { |
248 |
res = ppc_bat(cpu, vaddr, return_addr, flags, user); |
res = ppc_bat(cpu, vaddr, return_paddr, flags, user); |
249 |
if (res > 0) |
if (res > 0) |
250 |
return res; |
return res; |
251 |
if (res == 0) { |
if (res == 0) { |
256 |
|
|
257 |
/* Virtual to physical translation: */ |
/* Virtual to physical translation: */ |
258 |
if (cpu->cd.ppc.bits == 32) { |
if (cpu->cd.ppc.bits == 32) { |
259 |
match = ppc_vtp32(cpu, vaddr, return_addr, &res, msr, |
match = ppc_vtp32(cpu, vaddr, return_paddr, &res, msr, |
260 |
writeflag, instr); |
writeflag, instr); |
261 |
if (match && res > 0) |
if (match && res > 0) |
262 |
return res; |
return res; |