X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Farch%2Fx86_64%2Fproc.c;h=50b5054894d8987eab5d9f46bbba4143b5d1ced6;hb=d7dcea0e5a8df0f479e99f168a10b9a9535c7ad6;hp=48504a8bd82fab615951f9a80f9eae0ba9244d2b;hpb=1b0dcb8f9628a06caa880f10a5c82bf82676fab7;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/arch/x86_64/proc.c b/KernelLand/Kernel/arch/x86_64/proc.c index 48504a8b..50b50548 100644 --- a/KernelLand/Kernel/arch/x86_64/proc.c +++ b/KernelLand/Kernel/arch/x86_64/proc.c @@ -37,7 +37,7 @@ extern void APStartup(void); // 16-bit AP startup code extern Uint GetRIP(void); // start.asm extern Uint SaveState(Uint *RSP, Uint *Regs); -extern Uint Proc_CloneInt(Uint *RSP, Uint *CR3); +extern Uint Proc_CloneInt(Uint *RSP, Uint *CR3, int bCopyUserVM); extern void NewTaskHeader(void); // Actually takes cdecl args extern void Proc_InitialiseSSE(void); extern void Proc_SaveSSE(Uint DestPtr); @@ -75,6 +75,7 @@ void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP) NO //void Proc_DumpThreadCPUState(tThread *Thread); //void Proc_Reschedule(void); void Proc_Scheduler(int CPU, Uint RSP, Uint RIP); +Uint Proc_int_SetIRQIP(Uint RIP); // === GLOBALS === //!\brief Used by desctab.asm in SyscallStub @@ -323,7 +324,7 @@ void ArchThreads_Init(void) outb(0x40, (PIT_TIMER_DIVISOR>>8)&0xFF); // High Byte // Create Per-Process Data Block - if( !MM_Allocate(MM_PPD_CFG) ) + if( !MM_Allocate( (void*)MM_PPD_CFG ) ) { Warning("Oh, hell, Unable to allocate PPD for Thread#0"); } @@ -457,9 +458,8 @@ void Proc_ClearThread(tThread *Thread) tTID Proc_NewKThread(void (*Fcn)(void*), void *Data) { Uint rsp; - tThread *newThread, *cur; + tThread *newThread; - cur = Proc_GetCurThread(); newThread = Threads_CloneTCB(0); if(!newThread) return -1; @@ -507,7 +507,7 @@ tTID Proc_Clone(Uint Flags) if(!newThread) return -1; // Save core machine state - rip = Proc_CloneInt(&newThread->SavedState.RSP, &newThread->Process->MemState.CR3); + rip = Proc_CloneInt(&newThread->SavedState.RSP, &newThread->Process->MemState.CR3, !!(Flags & CLONE_NOUSER)); if(rip == 0) return 0; // Child newThread->KernelStack = cur->KernelStack; newThread->SavedState.RIP = rip; @@ -536,11 +536,9 @@ tTID Proc_Clone(Uint Flags) */ tThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data) { - tThread *new, *cur; + tThread *new; Uint stack_contents[3]; - cur = Proc_GetCurThread(); - // Create new thread new = Threads_CloneThreadZero(); if(!new) { @@ -575,39 +573,39 @@ tThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data) */ Uint Proc_MakeUserStack(void) { - int i; - Uint base = USER_STACK_TOP - USER_STACK_SZ; + tPage *base = (void*)(USER_STACK_TOP - USER_STACK_SZ); // Check Prospective Space - for( i = USER_STACK_SZ >> 12; i--; ) + for( int i = USER_STACK_SZ/PAGE_SIZE; i--; ) { - if( MM_GetPhysAddr( (void*)(base + (i<<12)) ) != 0 ) - break; + if( MM_GetPhysAddr( base + i ) != 0 ) + { + return 0; + } } - if(i != -1) return 0; - // Allocate Stack - Allocate incrementally to clean up MM_Dump output // - Most of the user stack is the zero page - for( i = 0; i < (USER_STACK_SZ-USER_STACK_PREALLOC)/0x1000; i++ ) + int i = 0; + for( ; i < (USER_STACK_SZ-USER_STACK_PREALLOC)/PAGE_SIZE; i++ ) { - MM_AllocateZero( base + (i<<12) ); + MM_AllocateZero( base + i ); } // - but the top USER_STACK_PREALLOC pages are actually allocated - for( ; i < USER_STACK_SZ/0x1000; i++ ) + for( ; i < USER_STACK_SZ/PAGE_SIZE; i++ ) { - tPAddr alloc = MM_Allocate( base + (i<<12) ); + tPAddr alloc = MM_Allocate( base + i ); if( !alloc ) { // Error - Log_Error("Proc", "Unable to allocate user stack (%i pages requested)", USER_STACK_SZ/0x1000); + Log_Error("Proc", "Unable to allocate user stack (%i pages requested)", USER_STACK_SZ/PAGE_SIZE); while( i -- ) - MM_Deallocate( base + (i<<12) ); + MM_Deallocate( base + i ); return 0; } } - return base + USER_STACK_SZ; + return (tVAddr)( base + USER_STACK_SZ/PAGE_SIZE ); } void Proc_StartUser(Uint Entrypoint, Uint Base, int ArgC, const char **ArgV, int DataSize) @@ -725,7 +723,14 @@ void Proc_CallFaultHandler(tThread *Thread) void Proc_DumpThreadCPUState(tThread *Thread) { - Log(" At %04x:%016llx", Thread->SavedState.UserCS, Thread->SavedState.UserRIP); + if( Thread->CurCPU == GetCPUNum() ) { + // TODO: Backtrace to IRQ + Log(" IRQ %016llx", Thread->SavedState.UserRIP); + } + else { + Log(" At %016llx, SP=%016llx", Thread->SavedState.RIP, Thread->SavedState.RSP); + Log(" User %04x:%016llx", Thread->SavedState.UserCS, Thread->SavedState.UserRIP); + } } void Proc_Reschedule(void) @@ -758,7 +763,7 @@ void Proc_Reschedule(void) // Update CPU state gaCPUs[cpu].Current = nextthread; - gTSSs[cpu].RSP0 = nextthread->KernelStack-4; + gTSSs[cpu].RSP0 = nextthread->KernelStack-sizeof(void*); __asm__ __volatile__ ("mov %0, %%db0" : : "r" (nextthread)); if( curthread ) @@ -825,5 +830,14 @@ void Proc_Scheduler(int CPU, Uint RSP, Uint RIP) #endif } +Uint Proc_int_SetIRQIP(Uint RIP) +{ + int cpu = GetCPUNum(); + tThread *thread = gaCPUs[cpu].Current; + Uint rv = thread->SavedState.UserRIP; + thread->SavedState.UserRIP = RIP; + return rv; +} + // === EXPORTS === EXPORT(Proc_SpawnWorker);