Calculating virtual address from physical address

Alexander Szekely alex at astech.at
Sat May 6 18:43:53 EST 2006


> How is a virtual address 
> calculated for a high address like 0x4F600000?

Add this to the MMU initialzation code (initial_mmu):

/* map leds - 1:1 phys=virt */
	lis	r3,0x4F600000 at h
	ori	r3,r3,0x4F600000 at l
	mr	r4,r3
	clrrwi	r4,r4,12
	ori	r4,r4,(TLB_WR|TLB_I|TLB_M|TLB_G)

	clrrwi	r3,r3,12
	ori	r3,r3,(TLB_VALID | TLB_PAGESZ(PAGESZ_4K))

	li	r0,0			/* TLB slot 0 */
	tlbwe	r4,r0,TLB_DATA
	tlbwe	r3,r0,TLB_TAG

Then you have a one to one mapping between physical and virtual memory, 
and you can access the LEDs at the same address after turning one the
MMU.

BTW, we had a similar problem, but the reason was not turning on the
MMU. The MMU is enabled by writing MSR_KERNEL the status register. This
also enables the machine state exception interrupt. 

Our hardware design produced PLB bus exceptions, which was unnoticed on
standalone applications. But this bus exceptions also trigger machine
state exceptions. So instead of jumping to start_here the processor
branched to 0x200 - unfortunatly the trap table is not set up at this
point in the boot process...

Alex 




More information about the Linuxppc-embedded mailing list