Discussion:
[Pearpc-devel] Problem with emulated MMU
Jochen Becher
2007-03-26 22:19:31 UTC
Permalink
Hi,

in the current CVS source I replaced the main function with the
following code. This is a simple test that maps effective address
0xfff00000 to physical address 0x00800000. Then the code translates the
same effective address to the physical address - but the result is
0x07f00000. I debugged into that code - there is some calculation of a
vairable pte which defines what page is mapped to what physical address.
Unfortunatly the same pte is already stored in the same mmu page entry
mapping that page to 0x07f00000.

Is this a bug in the MMU emulation code?

Regards, Jochen



int main(int argc, char *argv[])
{
setvbuf(stdout, 0, _IONBF, 0);

if (!ppc_init_physical_memory(128 * 1024 * 1024)) {
ht_printf("cannot initialize memory.\n");
exit(1);
}

if (!ppc_cpu_init()) {
ht_printf("cpu_init failed! Out of memory?\n");
exit(1);
}

// initialize initial paging (for prom)
uint32 PAGE_TABLE_ADDR = 104857600;

// 256 Kbytes Pagetable, 2^15 Pages, 2^12 PTEGs
if (!ppc_prom_set_sdr1(PAGE_TABLE_ADDR+0x03, false)) {
ht_printf("internal error setting sdr1.\n");
return 1;
}

// clear pagetable
if (!ppc_dma_set(PAGE_TABLE_ADDR, 0, 256*1024)) {
ht_printf("cannot access page table.\n");
return 1;
}

prom_mem_init();

// turn on address translation
ppc_cpu_set_msr(0, MSR_IR | MSR_DR | MSR_FP);
if ((ppc_cpu_get_pvr(0) & 0xffff0000) == 0x000c0000) {
ppc_cpu_set_msr(0, MSR_IR | MSR_DR | MSR_FP | MSR_VEC);
}

// lock pagetable
for (uint32 pa = PAGE_TABLE_ADDR; pa < (PAGE_TABLE_ADDR + 256*1024); pa
+= 4096) {
if (!prom_claim_page(pa)) {
ht_printf("cannot claim page table memory.\n");
exit(1);
}
}

prom_claim_page(0x00800000);
ppc_prom_page_create(0xfff00000, 0x00800000);
uint32 ea;
ppc_effective_to_physical(0xfff00000, PPC_MMU_READ | PPC_MMU_CODE, ea);
ht_printf("ea = 0x%08lx\n",ea);

return 0;
}
Sebastian Biallas
2007-03-26 22:53:37 UTC
Permalink
Post by Jochen Becher
Hi,
in the current CVS source I replaced the main function with the
following code. This is a simple test that maps effective address
0xfff00000 to physical address 0x00800000. Then the code translates the
same effective address to the physical address - but the result is
0x07f00000. I debugged into that code - there is some calculation of a
vairable pte which defines what page is mapped to what physical address.
Unfortunatly the same pte is already stored in the same mmu page entry
mapping that page to 0x07f00000.
Is this a bug in the MMU emulation code?
No. But it's, uh, lack of documentation.
Post by Jochen Becher
prom_claim_page(0x00800000);
ppc_prom_page_create(0xfff00000, 0x00800000);
You are interfering with the prom memory.

If you call prom_init() the memory looks as follows:

The last 2 MiB (constant PROM_MEMORY_SIZE in io/prom/prommem.h) of the
physical memory is reserved for prom. Devicetree stuff etc is put there.
This is mapped to 0xffe0'0000 - 0xffff'ffff of the virtual address space.

So the 0xfff0'0000 mapping you're trying to create is without effect:
The already existing mapping created by prom_init() is matched first (I
don't know how well you know the PowerPC address translation algorithm.
It's not well defined -- you can have two matching PTEs)

So, the only bug here is that prom_page_create doesn't check whether the
already exists a matching PTE. But you don't check the return value
either :)

Also note that all functions which have "prom" in its name where never
designed to stay in pearpc's code. I wanted to scrap them once openbios
works with pearpc (or vice versa). Unfortunately the current code works
well enough, so there isn't much urge to convert to it.

Sebastian
Jochen Becher
2007-03-27 07:44:46 UTC
Permalink
Hi,

thank you for the explanation. To solve my problem I understand that I
should not use the prom interface at all but just create my own memory
layout, right?

Regards, Jochen
Post by Sebastian Biallas
Post by Jochen Becher
Hi,
in the current CVS source I replaced the main function with the
following code. This is a simple test that maps effective address
0xfff00000 to physical address 0x00800000. Then the code translates the
same effective address to the physical address - but the result is
0x07f00000. I debugged into that code - there is some calculation of a
vairable pte which defines what page is mapped to what physical address.
Unfortunatly the same pte is already stored in the same mmu page entry
mapping that page to 0x07f00000.
Is this a bug in the MMU emulation code?
No. But it's, uh, lack of documentation.
Post by Jochen Becher
prom_claim_page(0x00800000);
ppc_prom_page_create(0xfff00000, 0x00800000);
You are interfering with the prom memory.
The last 2 MiB (constant PROM_MEMORY_SIZE in io/prom/prommem.h) of the
physical memory is reserved for prom. Devicetree stuff etc is put there.
This is mapped to 0xffe0'0000 - 0xffff'ffff of the virtual address space.
The already existing mapping created by prom_init() is matched first (I
don't know how well you know the PowerPC address translation algorithm.
It's not well defined -- you can have two matching PTEs)
So, the only bug here is that prom_page_create doesn't check whether the
already exists a matching PTE. But you don't check the return value
either :)
Also note that all functions which have "prom" in its name where never
designed to stay in pearpc's code. I wanted to scrap them once openbios
works with pearpc (or vice versa). Unfortunately the current code works
well enough, so there isn't much urge to convert to it.
Sebastian
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Pearpc-devel mailing list
https://lists.sourceforge.net/lists/listinfo/pearpc-devel
Sebastian Biallas
2007-03-27 10:50:30 UTC
Permalink
Post by Jochen Becher
Hi,
thank you for the explanation. To solve my problem I understand that I
should not use the prom interface at all but just create my own memory
layout, right?
Right. But you can use the ppc_prom_page_create function (at least as a
template) to create PTEs.

Out of curiosity: What are you trying to do?

Sebastian
Jochen Becher
2007-03-27 20:24:11 UTC
Permalink
Post by Sebastian Biallas
Out of curiosity: What are you trying to do?
For now I just try to understand how PearPC works and if it makes sense
to use it to emulate other PPC hardware as well. If compiled some PPC
boot software that is placed at 0xfff0000 and tried to run it with
PearPC.

Jochen
Post by Sebastian Biallas
Sebastian
Loading...