rPi MMU: Enhance debugging
* TRACE calls no longer need double '('
* Added CALLED trace function
* Add better debugging output
This commit is contained in:
@@ -28,11 +28,14 @@
|
|||||||
|
|
||||||
#define TRACE_MMU
|
#define TRACE_MMU
|
||||||
#ifdef TRACE_MMU
|
#ifdef TRACE_MMU
|
||||||
# define TRACE(x) dprintf x
|
# define TRACE(x...) dprintf("mmu: " x)
|
||||||
|
# define CALLED() dprintf("%s()\n", __func__)
|
||||||
#else
|
#else
|
||||||
# define TRACE(x) ;
|
# define TRACE(x) ;
|
||||||
|
# define CALLED() ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
#define TRACE_MEMORY_MAP
|
#define TRACE_MEMORY_MAP
|
||||||
// Define this to print the memory map to serial debug,
|
// Define this to print the memory map to serial debug,
|
||||||
@@ -210,6 +213,7 @@ get_next_physical_page(size_t pagesize)
|
|||||||
void
|
void
|
||||||
mmu_set_TTBR(uint32 ttb)
|
mmu_set_TTBR(uint32 ttb)
|
||||||
{
|
{
|
||||||
|
TRACE("%s: Set Translation Table Base to 0x%lx\n", __func__);
|
||||||
ttb &= 0xffffc000;
|
ttb &= 0xffffc000;
|
||||||
asm volatile("MRC p15, 0, %[adr], c2, c0, 0"::[adr] "r" (ttb));
|
asm volatile("MRC p15, 0, %[adr], c2, c0, 0"::[adr] "r" (ttb));
|
||||||
}
|
}
|
||||||
@@ -221,6 +225,7 @@ mmu_set_TTBR(uint32 ttb)
|
|||||||
void
|
void
|
||||||
mmu_flush_TLB()
|
mmu_flush_TLB()
|
||||||
{
|
{
|
||||||
|
TRACE("%s: TLB Flush\n", __func__);
|
||||||
uint32 value = 0;
|
uint32 value = 0;
|
||||||
asm volatile("MCR p15, 0, %[c8format], c8, c7, 0"::[c8format] "r" (value));
|
asm volatile("MCR p15, 0, %[c8format], c8, c7, 0"::[c8format] "r" (value));
|
||||||
}
|
}
|
||||||
@@ -251,6 +256,7 @@ mmu_write_C1(uint32 value)
|
|||||||
void
|
void
|
||||||
mmu_write_DACR(uint32 value)
|
mmu_write_DACR(uint32 value)
|
||||||
{
|
{
|
||||||
|
TRACE("%s: Set Domain Access Register to 0x%lx\n", __func__);
|
||||||
asm volatile("MCR p15, 0, %[c1in], c3, c0, 0"::[c1in] "r" (value));
|
asm volatile("MCR p15, 0, %[c1in], c3, c0, 0"::[c1in] "r" (value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,8 +264,9 @@ mmu_write_DACR(uint32 value)
|
|||||||
static uint32 *
|
static uint32 *
|
||||||
get_next_page_table(uint32 type)
|
get_next_page_table(uint32 type)
|
||||||
{
|
{
|
||||||
TRACE(("get_next_page_table, sNextPageTableAddress %p, kPageTableRegionEnd "
|
TRACE("%s: sNextPageTableAddress %p, kPageTableRegionEnd %p, type 0x%lx\n",
|
||||||
"%p, type 0x%lx\n", sNextPageTableAddress, kPageTableRegionEnd, type));
|
__func__, sNextPageTableAddress, kPageTableRegionEnd, type);
|
||||||
|
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case MMU_L1_TYPE_COARSEPAGETABLE:
|
case MMU_L1_TYPE_COARSEPAGETABLE:
|
||||||
@@ -272,7 +279,7 @@ get_next_page_table(uint32 type)
|
|||||||
|
|
||||||
addr_t address = sNextPageTableAddress;
|
addr_t address = sNextPageTableAddress;
|
||||||
if (address >= kPageTableRegionEnd) {
|
if (address >= kPageTableRegionEnd) {
|
||||||
TRACE(("outside of pagetableregion!\n"));
|
TRACE("%s: outside of pagetableregion!\n", __func__);
|
||||||
return (uint32 *)get_next_physical_address_alligned(size, 0xffffffc0);
|
return (uint32 *)get_next_physical_address_alligned(size, 0xffffffc0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +291,7 @@ get_next_page_table(uint32 type)
|
|||||||
void
|
void
|
||||||
init_page_directory()
|
init_page_directory()
|
||||||
{
|
{
|
||||||
TRACE(("init_page_directory\n"));
|
CALLED();
|
||||||
uint32 smalltype;
|
uint32 smalltype;
|
||||||
|
|
||||||
// see if subpages disabled
|
// see if subpages disabled
|
||||||
@@ -303,8 +310,8 @@ init_page_directory()
|
|||||||
for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP);i++) {
|
for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP);i++) {
|
||||||
|
|
||||||
pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
||||||
TRACE(("BLOCK: %s START: %lx END %lx\n", LOADER_MEMORYMAP[i].name,
|
TRACE("BLOCK: %s START: %lx END %lx\n", LOADER_MEMORYMAP[i].name,
|
||||||
LOADER_MEMORYMAP[i].start, LOADER_MEMORYMAP[i].end));
|
LOADER_MEMORYMAP[i].start, LOADER_MEMORYMAP[i].end);
|
||||||
addr_t pos = LOADER_MEMORYMAP[i].start;
|
addr_t pos = LOADER_MEMORYMAP[i].start;
|
||||||
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
@@ -328,19 +335,24 @@ init_page_directory()
|
|||||||
= (uint32)pageTable | MMU_L1_TYPE_COARSEPAGETABLE;
|
= (uint32)pageTable | MMU_L1_TYPE_COARSEPAGETABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TRACE("%s: Page table setup complete\n", __func__);
|
||||||
|
|
||||||
|
// TLB Flush
|
||||||
mmu_flush_TLB();
|
mmu_flush_TLB();
|
||||||
|
|
||||||
/* set up the translation table base */
|
// Set Translation Table Base
|
||||||
mmu_set_TTBR((uint32)sPageDirectory);
|
mmu_set_TTBR((uint32)sPageDirectory);
|
||||||
|
|
||||||
|
// TLB Flush
|
||||||
mmu_flush_TLB();
|
mmu_flush_TLB();
|
||||||
|
|
||||||
/* set up the domain access register */
|
// Set domain access register
|
||||||
mmu_write_DACR(0xFFFFFFFF);
|
mmu_write_DACR(0xFFFFFFFF);
|
||||||
|
|
||||||
/* turn on the mmu */
|
TRACE("%s: Enable MMU...\n", __func__);
|
||||||
mmu_write_C1(mmu_read_C1() | 0x1);
|
mmu_write_C1(mmu_read_C1() | 0x1);
|
||||||
|
|
||||||
|
TRACE("%s: Complete\n", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -348,7 +360,7 @@ init_page_directory()
|
|||||||
static void
|
static void
|
||||||
add_page_table(addr_t base)
|
add_page_table(addr_t base)
|
||||||
{
|
{
|
||||||
TRACE(("add_page_table(base = %p)\n", (void *)base));
|
TRACE("%s: base = %p\n", __func__, (void *)base);
|
||||||
|
|
||||||
// Get new page table and clear it out
|
// Get new page table and clear it out
|
||||||
uint32 *pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
uint32 *pageTable = get_next_page_table(MMU_L1_TYPE_COARSEPAGETABLE);
|
||||||
@@ -375,11 +387,11 @@ add_page_table(addr_t base)
|
|||||||
static void
|
static void
|
||||||
map_page(addr_t virtualAddress, addr_t physicalAddress, uint32 flags)
|
map_page(addr_t virtualAddress, addr_t physicalAddress, uint32 flags)
|
||||||
{
|
{
|
||||||
TRACE(("map_page: vaddr 0x%lx, paddr 0x%lx\n", virtualAddress,
|
TRACE("%s: vaddr 0x%lx, paddr 0x%lx\n", __func__, virtualAddress,
|
||||||
physicalAddress));
|
physicalAddress);
|
||||||
|
|
||||||
if (virtualAddress < KERNEL_BASE) {
|
if (virtualAddress < KERNEL_BASE) {
|
||||||
panic("map_page: asked to map invalid page %p!\n",
|
panic("%s: asked to map invalid page %p!\n", __func__,
|
||||||
(void *)virtualAddress);
|
(void *)virtualAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +401,7 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, uint32 flags)
|
|||||||
sMaxVirtualAddress += B_PAGE_SIZE * 256;
|
sMaxVirtualAddress += B_PAGE_SIZE * 256;
|
||||||
|
|
||||||
if (virtualAddress >= sMaxVirtualAddress) {
|
if (virtualAddress >= sMaxVirtualAddress) {
|
||||||
panic("map_page: asked to map a page to %p\n",
|
panic("%s: asked to map a page to %p\n", __func__,
|
||||||
(void *)virtualAddress);
|
(void *)virtualAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,8 +413,8 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, uint32 flags)
|
|||||||
= (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
= (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
|
||||||
& ARM_PDE_ADDRESS_MASK);
|
& ARM_PDE_ADDRESS_MASK);
|
||||||
|
|
||||||
TRACE(("map_page: pageTable 0x%lx\n",
|
TRACE("%s: pageTable 0x%lx\n", __func__,
|
||||||
sPageDirectory[VADDR_TO_PDENT(virtualAddress)] & ARM_PDE_ADDRESS_MASK));
|
sPageDirectory[VADDR_TO_PDENT(virtualAddress)] & ARM_PDE_ADDRESS_MASK);
|
||||||
|
|
||||||
if (pageTable == NULL) {
|
if (pageTable == NULL) {
|
||||||
add_page_table(virtualAddress);
|
add_page_table(virtualAddress);
|
||||||
@@ -412,14 +424,14 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, uint32 flags)
|
|||||||
|
|
||||||
uint32 tableEntry = VADDR_TO_PTENT(virtualAddress);
|
uint32 tableEntry = VADDR_TO_PTENT(virtualAddress);
|
||||||
|
|
||||||
TRACE(("map_page: inserting pageTable %p, tableEntry %ld, physicalAddress "
|
TRACE("%s: inserting pageTable %p, tableEntry %ld, physicalAddress %p\n",
|
||||||
"%p\n", pageTable, tableEntry, physicalAddress));
|
__func__, pageTable, tableEntry, physicalAddress);
|
||||||
|
|
||||||
pageTable[tableEntry] = physicalAddress | flags;
|
pageTable[tableEntry] = physicalAddress | flags;
|
||||||
|
|
||||||
mmu_flush_TLB();
|
mmu_flush_TLB();
|
||||||
|
|
||||||
TRACE(("map_page: done\n"));
|
TRACE("%s: done\n", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -446,10 +458,10 @@ mmu_map_physical_memory(addr_t physicalAddress, size_t size, uint32 flags)
|
|||||||
static void
|
static void
|
||||||
unmap_page(addr_t virtualAddress)
|
unmap_page(addr_t virtualAddress)
|
||||||
{
|
{
|
||||||
TRACE(("unmap_page(virtualAddress = %p)\n", (void *)virtualAddress));
|
TRACE("%s: virtualAddress = %p\n", __func__, (void *)virtualAddress);
|
||||||
|
|
||||||
if (virtualAddress < KERNEL_BASE) {
|
if (virtualAddress < KERNEL_BASE) {
|
||||||
panic("unmap_page: asked to unmap invalid page %p!\n",
|
panic("%s: asked to unmap invalid page %p!\n", __func__,
|
||||||
(void *)virtualAddress);
|
(void *)virtualAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,8 +479,8 @@ unmap_page(addr_t virtualAddress)
|
|||||||
extern "C" void *
|
extern "C" void *
|
||||||
mmu_allocate(void *virtualAddress, size_t size)
|
mmu_allocate(void *virtualAddress, size_t size)
|
||||||
{
|
{
|
||||||
TRACE(("mmu_allocate: requested vaddr: %p, next free vaddr: 0x%lx, size: "
|
TRACE("%s: requested vaddr: %p, next free vaddr: 0x%lx, size: %ld\n",
|
||||||
"%ld\n", virtualAddress, sNextVirtualAddress, size));
|
__func__, virtualAddress, sNextVirtualAddress, size);
|
||||||
|
|
||||||
size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
|
size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
|
||||||
// get number of pages to map
|
// get number of pages to map
|
||||||
@@ -484,10 +496,10 @@ mmu_allocate(void *virtualAddress, size_t size)
|
|||||||
// is the address within the valid range?
|
// is the address within the valid range?
|
||||||
if (address < KERNEL_BASE
|
if (address < KERNEL_BASE
|
||||||
|| address + size >= KERNEL_BASE + kMaxKernelSize) {
|
|| address + size >= KERNEL_BASE + kMaxKernelSize) {
|
||||||
TRACE(("mmu_allocate in illegal range\n address: %lx"
|
TRACE("mmu_allocate in illegal range\n address: %lx"
|
||||||
" KERNELBASE: %lx KERNEL_BASE + kMaxKernelSize: %lx"
|
" KERNELBASE: %lx KERNEL_BASE + kMaxKernelSize: %lx"
|
||||||
" address + size : %lx \n", (uint32)address, KERNEL_BASE,
|
" address + size : %lx \n", (uint32)address, KERNEL_BASE,
|
||||||
KERNEL_BASE + kMaxKernelSize, (uint32)(address + size)));
|
KERNEL_BASE + kMaxKernelSize, (uint32)(address + size));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (uint32 i = 0; i < size; i++) {
|
for (uint32 i = 0; i < size; i++) {
|
||||||
@@ -517,7 +529,8 @@ mmu_allocate(void *virtualAddress, size_t size)
|
|||||||
extern "C" void
|
extern "C" void
|
||||||
mmu_free(void *virtualAddress, size_t size)
|
mmu_free(void *virtualAddress, size_t size)
|
||||||
{
|
{
|
||||||
TRACE(("mmu_free(virtualAddress = %p, size: %ld)\n", virtualAddress, size));
|
TRACE("%s: virtualAddress = %p, size: %ld\n", __func__,
|
||||||
|
virtualAddress, size);
|
||||||
|
|
||||||
addr_t address = (addr_t)virtualAddress;
|
addr_t address = (addr_t)virtualAddress;
|
||||||
size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
|
size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
|
||||||
@@ -526,8 +539,8 @@ mmu_free(void *virtualAddress, size_t size)
|
|||||||
// is the address within the valid range?
|
// is the address within the valid range?
|
||||||
if (address < KERNEL_BASE
|
if (address < KERNEL_BASE
|
||||||
|| address + size >= KERNEL_BASE + kMaxKernelSize) {
|
|| address + size >= KERNEL_BASE + kMaxKernelSize) {
|
||||||
panic("mmu_free: asked to unmap out of range region (%p, size %lx)\n",
|
panic("%s: asked to unmap out of range region (%p, size %lx)\n",
|
||||||
(void *)address, size);
|
__func__, (void *)address, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmap all pages within the range
|
// unmap all pages within the range
|
||||||
@@ -551,7 +564,7 @@ mmu_free(void *virtualAddress, size_t size)
|
|||||||
extern "C" void
|
extern "C" void
|
||||||
mmu_init_for_kernel(void)
|
mmu_init_for_kernel(void)
|
||||||
{
|
{
|
||||||
TRACE(("mmu_init_for_kernel\n"));
|
CALLED();
|
||||||
|
|
||||||
// save the memory we've physically allocated
|
// save the memory we've physically allocated
|
||||||
gKernelArgs.physical_allocated_range[0].size
|
gKernelArgs.physical_allocated_range[0].size
|
||||||
@@ -596,7 +609,7 @@ mmu_init_for_kernel(void)
|
|||||||
extern "C" void
|
extern "C" void
|
||||||
mmu_init(void)
|
mmu_init(void)
|
||||||
{
|
{
|
||||||
TRACE(("mmu_init\n"));
|
CALLED();
|
||||||
|
|
||||||
mmu_write_C1(mmu_read_C1() & ~((1<<29)|(1<<28)|(1<<0)));
|
mmu_write_C1(mmu_read_C1() & ~((1<<29)|(1<<28)|(1<<0)));
|
||||||
// access flag disabled, TEX remap disabled, mmu disabled
|
// access flag disabled, TEX remap disabled, mmu disabled
|
||||||
@@ -642,8 +655,8 @@ mmu_init(void)
|
|||||||
gKernelArgs.cpu_kstack[0].size = KERNEL_STACK_SIZE
|
gKernelArgs.cpu_kstack[0].size = KERNEL_STACK_SIZE
|
||||||
+ KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE;
|
+ KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE;
|
||||||
|
|
||||||
TRACE(("kernel stack at 0x%lx to 0x%lx\n", gKernelArgs.cpu_kstack[0].start,
|
TRACE("kernel stack at 0x%lx to 0x%lx\n", gKernelArgs.cpu_kstack[0].start,
|
||||||
gKernelArgs.cpu_kstack[0].start + gKernelArgs.cpu_kstack[0].size));
|
gKernelArgs.cpu_kstack[0].start + gKernelArgs.cpu_kstack[0].size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user