最近一直VS2005中DeviceEmulator的bsp。其中eboot中有一个地址转换问题:
#if defined(MIPS) || defined(SHx)
#define OALPAtoCA(pa) (VOID*)(((UINT32)(pa))|0x80000000)
#define OALPAtoUA(pa) (VOID*)(((UINT32)(pa))|0xA0000000)
#define OALPAtoVA(pa, c) (VOID*)((c)?(pa)|0x80000000:(pa)|0xA0000000)
#define OALVAtoPA(va) (((UINT32)(va))&~0xE0000000)
#else
#define OALPAtoCA(pa) OALPAtoVA(pa, TRUE)
#define OALPAtoUA(pa) OALPAtoVA(pa, FALSE)
VOID* OALPAtoVA(UINT32 pa, BOOL cached);
UINT32 OALVAtoPA(VOID *va);
#endif
自己分析觉得,eboot中应该是调用了VOID* OALPAtoVA(UINT32 pa, BOOL cached);然后跟踪下去。
发现:
VOID* OALPAtoVA(UINT32 pa, BOOL cached)
{
UINT32 offset;
UINT8 *va = NULL;
OALMSG(OAL_MEMORY&&OAL_FUNC, (L"+OALPAtoVA(0x%x, %d)/r/n", pa, cached));
offset = pa & (PAGE_SIZE - 1); //#define PAGE_SIZE 0x1000
pa &= ~(PAGE_SIZE - 1);
va = NKPhysToVirt( pa >> 8, cached );
va += offset;
// Indicate the virtual address
OALMSG(OAL_MEMORY&&OAL_FUNC, (L"-OALPAtoVA(va = 0x%08x)/r/n", va));
return va;
}
但是不知道NKPhysToVirt( pa >> 8, cached )的源代码是怎么实现的,找不到源码,查MSDN的话,只知道它是根据g_oalAddressTable表转化成虚拟地址的。但是究竟是怎么实现的呢。有没有高人能指点一下啊。。
g_oalAddressTable
DCD 0x80000000, 0x30000000, 64 ; 64 MB DRAM BANK 6
DCD 0x84000000, 0x10000000, 32 ; nGCS2: PCMCIA/PCCARD
DCD 0x86000000, 0x18000000, 32 ; 32 MB SROM(SRAM/ROM) BANK 3 (CS8900 netcard)
DCD 0x88000000, 0x00000000, 96 ; 96mb NOR flash
DCD 0x90800000, 0x48000000, 1 ; Memory control register
DCD 0x90900000, 0x49000000, 1 ; USB Host register
DCD 0x90A00000, 0x4A000000, 1 ; Interrupt Control register
DCD 0x90B00000, 0x4B000000, 1 ; DMA control register
DCD 0x90C00000, 0x4C000000, 1 ; Clock & Power register
DCD 0x90D00000, 0x4D000000, 1 ; LCD control register
DCD 0x90E00000, 0x4E000000, 1 ; NAND flash control register
DCD 0x91000000, 0x50000000, 1 ; UART control register
DCD 0x91100000, 0x51000000, 1 ; PWM timer register
DCD 0x91200000, 0x52000000, 1 ; USB device register
DCD 0x91300000, 0x53000000, 1 ; Watchdog Timer register
DCD 0x91400000, 0x54000000, 1 ; IIC control register
DCD 0x91500000, 0x55000000, 1 ; IIS control register
DCD 0x91600000, 0x56000000, 1 ; I/O Port register
DCD 0x91700000, 0x57000000, 1 ; RTC control register
DCD 0x91800000, 0x58000000, 1 ; A/D convert register
DCD 0x91900000, 0x59000000, 1 ; SPI register
DCD 0x91A00000, 0x5A000000, 1 ; SD Interface register
; 0x92000000, 0x00000000, 32 ; original location of 32MB of NOR flash
DCD 0x94000000, 0x34000000, 192 ; 192 MB bank 6&7 - Extended RAM
DCD 0x00000000, 0x00000000, 0 ; end of table
;------------------------------------------------------------------------------
END