//#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))
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();
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 )
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;
// 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;
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)
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;
}
}
if(inRange)
MM_int_DumpTableEnt(range_start, addr - range_start, &pi);
+ Log("Done");
}
cps #18
mov r0, #0
- mov r1, #0x80000000
+ mov r1, #0
+ sub r1, #1
bl MM_DumpTables
@ ldr r0, =csProc_CloneInt_NewTaskMessage
{
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)
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
.long kmain
.comm irqstack, 0x1000 @ ; 4KiB Stack
+.comm abortstack, 0x1000 @ ; 4KiB Stack
SyscallHandler:
b .
.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
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
.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
.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
.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:
}
/**
- * \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)
{
VFS_Close(fd);
mount_id = info.mount;
inode = info.inode;
+ LOG("mount_id = %i, inode = %i", mount_id, inode);
}
// TODO: Also get modifcation time?