📄 page.c
字号:
#include <windows.h>
#include <memorymap.h>
#define UNCACHED 0x00000000
#define WRITE_THROUGH 0x00000008
#define WRITE_BACK 0x0000000C
// Level one descriptors.
#define SECTION_HEADER 0x00000C12
#define COURSE_PAGETABLE 0x00000011
#define INVALID_DESCRIPTOR 0x00000000
// Level two descriptors.
#define SMALL_PAGE 0x00000FF2
/******************************************************************************
; PhysAddrStart = Physical start of memory to map.
; PhysAddrEnd = Physical end of memory to map.
; DescrAttr = Descriptor attributes.
; EntryReg = Register which is a pointer to the current page table entry
******************************************************************************/
DWORD CreateSectionEntry( DWORD PhysAddrStart, DWORD dwLen, DWORD DescrAttr , DWORD dwAddr)
{
DWORD * pAddr= (DWORD*) dwAddr;
DWORD i;
for( i=0; i< dwLen; i+=0x100000 , PhysAddrStart+= 0x100000 ){
*pAddr++=PhysAddrStart | DescrAttr;
}
return (DWORD) pAddr;
}
/*****************************************************************************
;
; Creates a entry for a small level 2 table.
;
; PhysAddrStart = Physical start of memory to map.
; PhysAddrEnd = Physical end of memory to map.
; DescrAttr = Descriptor attributes.
; EntryReg = Register which is a pointer to the current page table entry
;*****************************************************************************/
DWORD CreateCourseEntry( DWORD PhysAddrStart, DWORD dwLen, DWORD DescrAttr , DWORD dwAddr)
{
DWORD * pAddr= (DWORD*) dwAddr;
DWORD i;
for( i=0; i< dwLen; i+=0x1000, PhysAddrStart+= 0x1000 ){
*pAddr++=PhysAddrStart | DescrAttr;
}
return (DWORD) pAddr;
}
/*****************************************************************************
;
; The function to setup the MMU.
;
; r4 - Current Pagetable pointer. Virtual Address.
; r5 - Start of Pagetable (Physical Address)
; r6 - Level 2 Course Page Table.
;*****************************************************************************/
void PageTableSetup( DWORD dwPageStart )
{
DWORD dwAddress=dwPageStart ;
DWORD dwSize=0;
//a system must take at least one piece of SDRAM
dwAddress=CreateSectionEntry( PHYSICAL_ADDR_SDRAM_MAIN, SDRAM_MAIN_BLOCK_SIZE,
(SECTION_HEADER | WRITE_BACK) , dwAddress);
dwSize=SDRAM_MAIN_BLOCK_SIZE;
#if ( (SIZE_SDRAM_MAIN/SDRAM_MAIN_BLOCK_SIZE ) >1 )
dwAddress=CreateSectionEntry( PHYSICAL_ADDR_SDRAM_MAIN_BLOCK1, SDRAM_MAIN_BLOCK_SIZE,
(SECTION_HEADER | WRITE_BACK) , dwAddress);
dwSize +=SDRAM_MAIN_BLOCK_SIZE;
#endif
#if ( (SIZE_SDRAM_MAIN/SDRAM_MAIN_BLOCK_SIZE ) >2 )
dwAddress=CreateSectionEntry( PHYSICAL_ADDR_SDRAM_MAIN_BLOCK2, SDRAM_MAIN_BLOCK_SIZE,
(SECTION_HEADER | WRITE_BACK) , dwAddress);
dwSize +=SDRAM_MAIN_BLOCK_SIZE;
#endif
#if ( (SIZE_SDRAM_MAIN/SDRAM_MAIN_BLOCK_SIZE ) >3 )
dwAddress=CreateSectionEntry( PHYSICAL_ADDR_SDRAM_MAIN_BLOCK3, SDRAM_MAIN_BLOCK_SIZE,
(SECTION_HEADER | WRITE_BACK) , dwAddress);
dwSize +=SDRAM_MAIN_BLOCK_SIZE;
#endif
// mask from the end of the SDRAM to 0x10000000 as INVALID.
dwAddress=CreateSectionEntry( dwSize, 0x10000000- dwSize, (INVALID_DESCRIPTOR) , dwAddress);
dwAddress=CreateSectionEntry(0x10000000, 0xF0000000, (SECTION_HEADER | UNCACHED) , dwAddress);
// dwAddress=CreateSectionEntry( 0xC0000000, 0x02000000, (SECTION_HEADER | UNCACHED) , dwAddress);
// dwAddress=CreateSectionEntry( 0xC4000000, 0x02000000, (SECTION_HEADER | UNCACHED) , dwAddress);
// dwAddress=CreateSectionEntry( 0x04000000, 0x0C000000, (INVALID_DESCRIPTOR) , dwAddress);
// dwAddress=CreateSectionEntry(0x10000000, 0xF0000000, (SECTION_HEADER | UNCACHED) , dwAddress);
//dwAddress should be dwPageStart+0x400 here.
*(DWORD*)dwPageStart= (dwAddress) |COURSE_PAGETABLE;
//the first 1M bytes takes EBOOT codes, RAM and DRIVER GLOBAL,so create two level page table for these area.
dwAddress=CreateCourseEntry( PHYSICAL_ADDR_SDRAM_MAIN, 0x00040000,
(SMALL_PAGE | UNCACHED) , dwAddress); // 0x00000000, 0x0003FFFF
dwAddress=CreateCourseEntry( PHYSICAL_ADDR_SDRAM_MAIN+0x00040000, 0x00C00000,
(SMALL_PAGE | WRITE_BACK) , dwAddress); // 0x00000000, 0x000FFFFF
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -