From f0ffa8c904a7a99e115e926b4bf59d9749e86334 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 27 Oct 2011 20:21:19 +0800 Subject: [PATCH] Kernel/armv7 - Cleaing up mostly --- Kernel/arch/armv7/main.c | 4 ++-- Kernel/arch/armv7/mm_virt.c | 42 ++++++++++++++++++++++++++++--------- Kernel/arch/armv7/proc.c | 6 ++---- Kernel/arch/armv7/start.S | 8 +++---- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Kernel/arch/armv7/main.c b/Kernel/arch/armv7/main.c index b182e516..5ef567c8 100644 --- a/Kernel/arch/armv7/main.c +++ b/Kernel/arch/armv7/main.c @@ -4,7 +4,7 @@ * ARM7 Entrypoint * arch/arm7/main.c */ -#define DEBUG 1 +#define DEBUG 0 #include #include @@ -65,7 +65,7 @@ Uint32 ARMv7_int_HandleSyscalls(Uint32 Num, Uint32 *Args) switch(Num) { case 1: - Log_Debug("ARMv7", "__clear_cache(%p, %p)", Args[0], Args[1]); +// Log_Debug("ARMv7", "__clear_cache(%p, %p)", Args[0], Args[1]); // Align Args[0] &= ~0xFFF; Args[1] += 0xFFF; Args[1] &= ~0xFFF; diff --git a/Kernel/arch/armv7/mm_virt.c b/Kernel/arch/armv7/mm_virt.c index 3b4e5198..0c2f0438 100644 --- a/Kernel/arch/armv7/mm_virt.c +++ b/Kernel/arch/armv7/mm_virt.c @@ -161,6 +161,7 @@ int MM_int_SetPageInfo(tVAddr VAddr, tMM_PageInfo *pi) if( (*desc & 3) == 1 ) LEAVE_RET('i', 1); if( pi->PhysAddr == 0 ) { *desc = 0; + TLBIMVA(VAddr & 0xFFFFF000); LEAVE('i', 0); return 0; } @@ -403,7 +404,7 @@ int MM_Map(tVAddr VAddr, tPAddr PAddr) pi.AP = AP_KRW_ONLY; // Kernel Read/Write pi.bExecutable = 1; if( MM_int_SetPageInfo(VAddr, &pi) ) { - MM_DerefPhys(pi.PhysAddr); +// MM_DerefPhys(pi.PhysAddr); return 0; } return pi.PhysAddr; @@ -625,7 +626,7 @@ tPAddr MM_Clone(void) j = (sp / 0x1000) % 1024; num = MM_KSTACK_SIZE/0x1000; - Log("num = %i, sp = %p, j = %i", num, sp, j); +// Log("num = %i, sp = %p, j = %i", num, sp, j); // Copy stack pages for(; num--; j ++, sp += 0x1000) @@ -634,7 +635,7 @@ tPAddr MM_Clone(void) void *tmp_page; page = MM_AllocPhys(); - Log("page = %P", page); +// Log("page = %P", page); table[j] = page | 0x813; tmp_page = (void*)MM_MapTemp(page); @@ -660,7 +661,7 @@ void MM_ClearUser(void) // MM_DumpTables(0, 0x80000000); - Log("user_table_count = %i (as opposed to %i)", user_table_count, 0x800-4); +// Log("user_table_count = %i (as opposed to %i)", user_table_count, 0x800-4); for( i = 0; i < user_table_count; i ++ ) { @@ -723,8 +724,7 @@ void MM_ClearUser(void) } - MM_DumpTables(0, 0x80000000); -// Log_KernelPanic("MMVirt", "TODO: Implement MM_ClearUser"); +// MM_DumpTables(0, 0x80000000); } tVAddr MM_MapTemp(tPAddr PAddr) @@ -966,7 +966,28 @@ void MM_PageFault(Uint32 PC, Uint32 Addr, Uint32 DFSR, int bPrefetch) if( rv == 0 && pi.AP == AP_RO_BOTH ) { pi.AP = AP_RW_BOTH; - if( MM_GetRefCount(pi.PhysAddr) > 1 ) + if( giMM_ZeroPage && pi.PhysAddr == giMM_ZeroPage ) + { + tPAddr newpage; + newpage = MM_AllocPhys(); + if( !newpage ) { + Log_Error("MMVirt", "Unable to allocate new page for COW of ZERO"); + for(;;); + } + + Log_Notice("MMVirt", "COW %p caused by %p, ZERO duped to %P (RefCnt(%i)--)", Addr, PC, + newpage, MM_GetRefCount(pi.PhysAddr)); + + MM_DerefPhys(pi.PhysAddr); + pi.PhysAddr = newpage; + pi.AP = AP_RW_BOTH; + MM_int_SetPageInfo(Addr, &pi); + + memset( (void*)(Addr & ~(PAGE_SIZE-1)), 0, PAGE_SIZE ); + + return ; + } + else if( MM_GetRefCount(pi.PhysAddr) > 1 ) { // Duplicate the page tPAddr newpage; @@ -982,14 +1003,15 @@ void MM_PageFault(Uint32 PC, Uint32 Addr, Uint32 DFSR, int bPrefetch) memcpy( dst, src, PAGE_SIZE ); MM_FreeTemp( (tVAddr)dst ); - Log_Notice("MMVirt", "COW %p caused by %p, %P duped to %P", Addr, PC, - pi.PhysAddr, newpage); + Log_Notice("MMVirt", "COW %p caused by %p, %P duped to %P (RefCnt(%i)--)", Addr, PC, + pi.PhysAddr, newpage, MM_GetRefCount(pi.PhysAddr)); MM_DerefPhys(pi.PhysAddr); pi.PhysAddr = newpage; } else { - Log_Notice("MMVirt", "COW %p caused by %p, took last reference to %P", Addr, PC, pi.PhysAddr); + Log_Notice("MMVirt", "COW %p caused by %p, took last reference to %P", + Addr, PC, pi.PhysAddr); } // Unset COW pi.AP = AP_RW_BOTH; diff --git a/Kernel/arch/armv7/proc.c b/Kernel/arch/armv7/proc.c index 605b156c..0b4627a7 100644 --- a/Kernel/arch/armv7/proc.c +++ b/Kernel/arch/armv7/proc.c @@ -68,8 +68,8 @@ void Proc_StartUser(Uint Entrypoint, Uint Base, int ArgC, char **ArgV, int DataS char **envp; tVAddr delta; - Log_Debug("Proc", "Proc_StartUser: (Entrypoint=%p, Base=%p, ArgC=%i, ArgV=%p, DataSize=0x%x)", - Entrypoint, Base, ArgC, ArgV, DataSize); +// Log_Debug("Proc", "Proc_StartUser: (Entrypoint=%p, Base=%p, ArgC=%i, ArgV=%p, DataSize=0x%x)", +// Entrypoint, Base, ArgC, ArgV, DataSize); // Write data to the user's stack usr_sp = (void*)MM_NewUserStack(); @@ -79,12 +79,10 @@ void Proc_StartUser(Uint Entrypoint, Uint Base, int ArgC, char **ArgV, int DataS // Adjust user's copy of the arguments delta = (tVAddr)usr_sp - (tVAddr)ArgV; - Log("delta = %x", delta); ArgV = (void*)usr_sp; for(i = 0; ArgV[i]; i ++) ArgV[i] += delta; envp = &ArgV[i+1]; for(i = 0; envp[i]; i ++) envp[i] += delta; - Log("envp = %p", envp); *--usr_sp = (Uint32)envp; *--usr_sp = (Uint32)ArgV; diff --git a/Kernel/arch/armv7/start.S b/Kernel/arch/armv7/start.S index 589ef19b..da57360b 100644 --- a/Kernel/arch/armv7/start.S +++ b/Kernel/arch/armv7/start.S @@ -125,10 +125,10 @@ IRQHandler: PUSH_GPRS - ldr r0, =csIRQ_Tag - ldr r1, =csIRQ_Fmt - ldr r4, =Log_Debug - blx r4 +@ ldr r0, =csIRQ_Tag +@ ldr r1, =csIRQ_Fmt +@ ldr r4, =Log_Debug +@ blx r4 @ Call the registered handler ldr r0, gpIRQHandler -- 2.20.1