From: John Hodge Date: Fri, 14 Oct 2011 07:48:58 +0000 (+0800) Subject: Kernel/armv7 - Implemetned Hivecs, fixing bugs X-Git-Tag: rel0.13~71 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b1e74a3e843f44c09c9c88b42db0efba99facb13;p=tpg%2Facess2.git Kernel/armv7 - Implemetned Hivecs, fixing bugs --- diff --git a/Kernel/arch/armv7/mm_virt.c b/Kernel/arch/armv7/mm_virt.c index 4a8a1fa3..1f10cd5c 100644 --- a/Kernel/arch/armv7/mm_virt.c +++ b/Kernel/arch/armv7/mm_virt.c @@ -32,7 +32,7 @@ typedef struct //#define FRACTAL(table1, addr) ((table1)[ (0xFF8/4*1024) + ((addr)>>20)]) #define FRACTAL(table1, addr) ((table1)[ (0xFF8/4*1024) + ((addr)>>22)]) -#define USRFRACTAL(table1, addr) ((table1)[ (0x7F8/4*1024) + ((addr)>>22)]) +#define USRFRACTAL(addr) (*((Uint32*)(0x7FDFF000) + ((addr)>>22))) #define TLBIALL() __asm__ __volatile__ ("mcr p15, 0, %0, c8, c7, 0" : : "r" (0)) #define TLBIMVA(addr) __asm__ __volatile__ ("mcr p15, 0, %0, c8, c7, 1" : : "r" (addr)) @@ -111,7 +111,14 @@ int MM_int_AllocateCoarse(tVAddr VAddr, int Domain) desc[2] = desc[0] + 0x800; desc[3] = desc[0] + 0xC00; - FRACTAL(table1, VAddr) = paddr | 3; + if( VAddr < 0x80000000 ) { +// Log("USRFRACTAL(%p) = %p", VAddr, &USRFRACTAL(VAddr)); + USRFRACTAL(VAddr) = paddr | 3; + } + else { +// Log("FRACTAL(%p) = %p", VAddr, &FRACTAL(table1, VAddr)); + FRACTAL(table1, VAddr) = paddr | 3; + } // TLBIALL TLBIALL(); @@ -470,8 +477,7 @@ tPAddr MM_Clone(void) new_lvl1_1 = (void*)MM_MapTemp(ret); new_lvl1_2 = (void*)MM_MapTemp(ret+0x1000); tmp_map = new_lvl1_1; - new_lvl1_1[0] = 0x8202; // Section mapping the first meg for exception vectors (K-RO) - for( i = 1; i < 0x800-4; i ++ ) + for( i = 0; i < 0x800-4; i ++ ) { // Log("i = %i", i); if( i == 0x400 ) @@ -498,7 +504,7 @@ tPAddr MM_Clone(void) Uint32 *table = (void*)MM_MapTemp(tmp); Uint32 sp; register Uint32 __SP asm("sp"); - Log("new_lvl1_2 = %p, &new_lvl1_2[0x3FC] = %p", new_lvl1_2, &new_lvl1_2[0x3FC]); + // Map table to last 4MiB of user space new_lvl1_2[0x3FC] = tmp + 0*0x400 + 1; new_lvl1_2[0x3FD] = tmp + 1*0x400 + 1; @@ -521,7 +527,7 @@ tPAddr MM_Clone(void) // Fractal table[j++] = (ret + 0x0000) | 0x813; table[j++] = (ret + 0x1000) | 0x813; - Log("table[%i] = %x, table[%i] = %x", j-2, table[j-2], j-1, table[j-1]); + // Nuke the rest for( ; j < 1024; j ++ ) table[j] = 0; @@ -529,7 +535,6 @@ tPAddr MM_Clone(void) sp = __SP & ~(MM_KSTACK_SIZE-1); j = (sp / 0x1000) % 1024; num = MM_KSTACK_SIZE/0x1000; - Log("sp = %p, j = %i", sp, j); // Copy stack pages for(; num--; j ++, sp += 0x1000) @@ -545,20 +550,12 @@ tPAddr MM_Clone(void) MM_FreeTemp( (tVAddr) tmp_page ); } -// Debug_HexDump("MMVirt - last table", table, 0x1000); - MM_FreeTemp( (tVAddr)table ); } -// Debug_HexDump("MMVirt - Return page 1", new_lvl1_1, 0x1000); -// Debug_HexDump("MMVirt - Return page 2", new_lvl1_2, 0x1000); - MM_FreeTemp( (tVAddr)new_lvl1_1 ); MM_FreeTemp( (tVAddr)new_lvl1_2 ); -// Log("Table dump"); -// MM_DumpTables(0, -1); - return ret; } @@ -733,5 +730,6 @@ void MM_DumpTables(tVAddr Start, tVAddr End) } if(inRange) MM_int_DumpTableEnt(range_start, addr - range_start, &pi); + Log("Done"); } diff --git a/Kernel/arch/armv7/proc.S b/Kernel/arch/armv7/proc.S index 37f9650a..d1bb091f 100644 --- a/Kernel/arch/armv7/proc.S +++ b/Kernel/arch/armv7/proc.S @@ -82,7 +82,8 @@ Proc_CloneInt_new: cps #18 mov r0, #0 - mov r1, #0x80000000 + mov r1, #0 + sub r1, #1 bl MM_DumpTables @ ldr r0, =csProc_CloneInt_NewTaskMessage diff --git a/Kernel/arch/armv7/proc.c b/Kernel/arch/armv7/proc.c index e3696489..ffc4b570 100644 --- a/Kernel/arch/armv7/proc.c +++ b/Kernel/arch/armv7/proc.c @@ -61,6 +61,7 @@ void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char ** { Log_Debug("Proc", "Proc_StartUser: (Entrypoint=%p, Bases=%p, ArgC=%i, ...)", Entrypoint, Bases, ArgC); + Log_Error("Proc", "TODO: Implement Proc_StartUser"); } tTID Proc_Clone(Uint Flags) diff --git a/Kernel/arch/armv7/start.S b/Kernel/arch/armv7/start.S index fb3ecd08..089ead5d 100644 --- a/Kernel/arch/armv7/start.S +++ b/Kernel/arch/armv7/start.S @@ -28,17 +28,33 @@ _start: mov r0, #3 mcr p15, 0, r0, c3, c0, 0 @ Set Domain 0 to Manager + @ Enable VMSA mrc p15, 0, r0, c1, c0, 0 orr r0, r0, #1 orr r0, r0, #1 << 23 mcr p15, 0, r0, c1, c0, 0 + @ + @ Check for security extensions + @ + mrc p15, 0, r0, c0, c1, 1 + and r0, #0xF0 + @ - Present + ldrne r0,=KERNEL_BASE + mcrne p15, 0, r0, c12, c0, 0 @ Set the VBAR (brings exceptions into high memory) + @ - Absent + mrceq p15, 0, r0, c1, c0, 0 @ Set SCTLR.V + orreq r0, #0x2000 + mcreq p15, 0, r0, c1, c0, 0 + + @ Prepare for interrupts cps #18 @ IRQ Mode ldr sp, =irqstack+0x1000 @ Set up stack + cps #23 @ Abort Mode + ldr sp, =abortstack+0x1000 cps #19 -@ ldr sp, =stack+0x10000 @ Set up stack ldr sp, =0x80000000-4 @ Set up stack (top of user range) ldr r0, =kmain mov pc, r0 @@ -47,6 +63,7 @@ _ptr_kmain: .long kmain .comm irqstack, 0x1000 @ ; 4KiB Stack +.comm abortstack, 0x1000 @ ; 4KiB Stack SyscallHandler: b . @@ -81,8 +98,8 @@ IRQHandler: .globl DataAbort DataAbort: sub lr, #8 @ Adjust LR to the correct value - srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD) - cpsid ifa, #19 +@ srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD) +@ cpsid ifa, #19 @ PUSH_GPRS mrc p15, 0, r4, c5, c0, 0 @ Read DFSR (Data Fault Address Register) to stack @@ -95,16 +112,16 @@ DataAbort: blx r4 b . - POP_GPRS - rfeia sp! @ Pop state (actually RFEFD) +@ POP_GPRS +@ rfeia sp! @ Pop state (actually RFEFD) bx lr .globl PrefetchAbort PrefetchAbort: sub lr, #4 @ Adjust LR to the correct value - srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD) - cpsid ifa, #19 - PUSH_GPRS +@ srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD) +@ cpsid ifa, #19 +@ PUSH_GPRS ldr r0, =csAbort_Tag ldr r1, =csPrefetchAbort_Fmt @@ -178,9 +195,10 @@ kernel_table0: .long kernel_table1_map + 0x400 - KERNEL_BASE + 1 .long kernel_table1_map + 0x800 - KERNEL_BASE + 1 .long kernel_table1_map + 0xC00 - KERNEL_BASE + 1 - .rept 0x1000 - 0xFFC - .long 0 - .endr + .long kernel_exception_map + 0x000 - KERNEL_BASE + 1 + .long kernel_exception_map + 0x400 - KERNEL_BASE + 1 + .long kernel_exception_map + 0x800 - KERNEL_BASE + 1 + .long kernel_exception_map + 0xC00 - KERNEL_BASE + 1 @ PID0 user table .globl user_table1_map @@ -213,7 +231,7 @@ kernel_table1_map: @ Size = 4KiB .long 0 .endr .long kernel_table1_map - KERNEL_BASE + (1 << 4) + 3 - .long 0 + .long kernel_exception_map - KERNEL_BASE + 0x13 @ Hardware mappings .globl hwmap_table_0 @@ -222,6 +240,20 @@ hwmap_table_0: .rept 1024 - 1 .long 0 .endr +.globl kernel_exception_map +kernel_exception_map: + @ Padding + .rept 1024-256 + .long 0 + .endr + @ Align to nearly the end + .rept 256-16 + .long 0 + .endr + .long 0x213 @ Map first page for exceptions (Kernel RO) + .rept 15 + .long 0 + .endr .section .padata stack: diff --git a/Kernel/binary.c b/Kernel/binary.c index 8b7e7448..7e271ed7 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -179,10 +179,10 @@ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP) } /** - * \fn tVAddr Binary_Load(char *Path, tVAddr *EntryPoint) * \brief Load a binary into the current address space * \param Path Path to binary to load * \param EntryPoint Pointer for exectuable entry point + * \return Virtual address where the binary has been loaded */ tVAddr Binary_Load(const char *Path, tVAddr *EntryPoint) { @@ -217,6 +217,7 @@ tVAddr Binary_Load(const char *Path, tVAddr *EntryPoint) VFS_Close(fd); mount_id = info.mount; inode = info.inode; + LOG("mount_id = %i, inode = %i", mount_id, inode); } // TODO: Also get modifcation time?