Uint16 Resvd, IOPB; // IO Permissions Bitmap
} __attribute__((packed)) tTSS;
+#define USER_MAX KERNEL_BASE
+
#endif
mov cr3, ecx
mov ecx, cr0
- or ecx, 0x80010000 ; PG and WP
+ or ecx, 0x80010000 ; PG and WP
mov cr0, ecx
mov WORD [0xB8002], 0x0763 ; 'c'
// Adjust Multiboot structure address
mbInfo = (void*)( (Uint)MbInfoPtr + KERNEL_BASE );
gsBootCmdLine = (char*)( (Uint)mbInfo->CommandLine + KERNEL_BASE);
- Log("gsBootCmdLine = '%s'", gsBootCmdLine);
-
MM_InitPhys_Multiboot( mbInfo ); // Set up physical memory manager
break;
default:
Heap_Install();
*(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'E';
- Log_Log("Arch", "Starting threading...");
Threads_Init();
Time_Setup();
*(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'F';
- Log_Log("Arch", "Starting VFS...");
// Load Virtual Filesystem
+ Log_Log("Arch", "Starting VFS...");
VFS_Init();
*(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'Z';
paddr = ent->Base;
}
- Log(" MM_InitPhys_Multiboot: paddr=0x%x, avail=%i", paddr, avail);
+ Log("MM_InitPhys_Multiboot: paddr=0x%x, avail=0x%x pg", paddr, avail);
// Map
while( todo && avail --)
return ;
}
// Fill block
- Log("Allocated references for %P-%P", page_base << 12, (page_base+pages_per_refpage-1)<<12);
+ Log("Allocated references for %P-%P", page_base << 12, (page_base+pages_per_refpage)<<12);
for( i = 0; i < pages_per_refpage; i ++ ) {
int pg = page_base + i;
gaiPageReferences[pg] = !!PAGE_ALLOC_TEST(pg);
// === CODE ===
void MM_InitVirt(void)
{
- Log_Debug("MMVirt", "&PAGEMAPLVL4(0) = %p", &PAGEMAPLVL4(0));
+// Log_Debug("MMVirt", "&PAGEMAPLVL4(0) = %p", &PAGEMAPLVL4(0));
// MM_DumpTables(0, -1L);
}
{
*Ent &= ~PF_COW;
*Ent |= PF_PRESENT|PF_WRITE;
+// Log_Debug("MMVirt", "COW ent at %p (%p) only %P", Ent, NextLevel, curpage);
}
else
{
if( TMPMAPLVL4(i) & 1 )
MM_RefPhys( TMPMAPLVL4(i) & PADDR_MASK );
}
+
+ // Mark Per-Process data as COW
+ TMPMAPLVL4(MM_PPD_BASE>>39) |= PF_COW;
+ TMPMAPLVL4(MM_PPD_BASE>>39) &= ~PF_WRITE;
// #5 Set fractal mapping
- TMPMAPLVL4(508) = ret | 3; // Main
- TMPMAPLVL4(509) = 0; // Temp
+ TMPMAPLVL4(MM_FRACTAL_BASE>>39) = ret | 3; // Main
+ TMPMAPLVL4(MM_TMPFRAC_BASE>>39) = 0; // Temp
// #6 Create kernel stack
// tThread->KernelStack is the top
// There is 1 guard page below the stack
kstackbase = Proc_GetCurThread()->KernelStack - KERNEL_STACK_SIZE;
- Log("MM_Clone: kstackbase = %p", kstackbase);
-
+ // Clone stack
TMPMAPLVL4(MM_KSTACK_BASE >> PML4_SHIFT) = 0;
for( i = 1; i < KERNEL_STACK_SIZE/0x1000; i ++ )
{
tVAddr tmpmapping;
MM_MapEx(kstackbase+i*0x1000, phys, 1, 0);
- Log_Debug("MM", "MM_Clone: Cloning stack page %p from %P to %P",
- kstackbase+i*0x1000, MM_GetPhysAddr( kstackbase+i*0x1000 ), phys
- );
tmpmapping = MM_MapTemp(phys);
if( MM_GetPhysAddr( kstackbase+i*0x1000 ) )
memcpy((void*)tmpmapping, (void*)(kstackbase+i*0x1000), 0x1000);
Uint64 * const table_bases[] = {&PAGETABLE(0), &PAGEDIR(0), &PAGEDIRPTR(0), &PAGEMAPLVL4(0)};
Uint64 *table = table_bases[(LevelBits-12)/9] + (VAddr >> LevelBits);
int i;
- Log("MM_int_ClearTableLevel: (VAddr=%p, LevelBits=%i, MaxEnts=%i)", VAddr, LevelBits, MaxEnts);
+// Log("MM_int_ClearTableLevel: (VAddr=%p, LevelBits=%i, MaxEnts=%i)", VAddr, LevelBits, MaxEnts);
for( i = 0; i < MaxEnts; i ++ )
{
// Skip non-present tables
#include <hal_proc.h>
// === FLAGS ===
-#define DEBUG_TRACE_SWITCH 1
+#define DEBUG_TRACE_SWITCH 0
#define BREAK_ON_SWITCH 0 // Break into bochs debugger on a task switch
// === CONSTANTS ===
__asm__ __volatile__("sti");
#endif
MM_FinishVirtualInit();
- Log("Multithreading started");
+ Log_Log("Proc", "Multithreading started");
}
/**
newThread->KernelStack = cur->KernelStack;
newThread->SavedState.RIP = rip;
- // DEBUG
+ // DEBUG
+ #if 0
Log("New (Clone) %p, rsp = %p, cr3 = %p", rip, newThread->SavedState.RSP, newThread->MemState.CR3);
{
Uint cr3;
__asm__ __volatile__ ("mov %%cr3, %0" : "=r" (cr3));
Log("Current CR3 = 0x%x, PADDR(RSP) = 0x%x", cr3, MM_GetPhysAddr(newThread->SavedState.RSP));
}
+ #endif
// /DEBUG
// Lock list and add to active
for( ; i < USER_STACK_SZ/0x1000; i++ )
{
tPAddr alloc = MM_Allocate( base + (i<<12) );
- Log_Debug("Proc", "Proc_MakeUserStack: alloc = %P", alloc);
if( !alloc )
{
// Error
CS, SS);
Threads_Exit(0, -1);
}
- Log("Proc_StartProcess: (SS=%x, Stack=%p, Flags=%x, CS=%x, IP=%p)",
- SS, Stack, Flags, CS, IP);
- MM_DumpTables(0, USER_MAX);
+// Log("Proc_StartProcess: (SS=%x, Stack=%p, Flags=%x, CS=%x, IP=%p)", SS, Stack, Flags, CS, IP);
+// MM_DumpTables(0, USER_MAX);
if(CS == 0x1B)
{
// 32-bit return
return ;
#if DEBUG_TRACE_SWITCH
- LogF("\nSwitching to task %i, CR3 = 0x%x, RIP = %p, RSP = %p, KStack = %p\n",
- nextthread->TID,
+ LogF("\nSwitching to task CR3 = 0x%x, RIP = %p, RSP = %p - %i (%s)\n",
nextthread->MemState.CR3,
nextthread->SavedState.RIP,
nextthread->SavedState.RSP,
- nextthread->KernelStack
+ nextthread->TID,
+ nextthread->ThreadName
);
#endif
; Enable paging
mov eax, cr0
- or eax, 0x80000000
+ or eax, 0x80010000 ; PG & WP
mov cr0, eax
; Load GDT
case SYS_CLONE:
// Call clone system call
ret = Proc_Clone(Regs->Arg1);
- Log("Proc_Clone returned %i", ret);
// Change user stack if a new stack address is passed
if(ret == 0 && Regs->Arg2)
Regs->StackPointer = Regs->Arg2;