+void Proc_DumpThreadCPUState(tThread *Thread)
+{
+ if( Thread->CurCPU > -1 )
+ {
+ int maxBacktraceDistance = 6;
+ tRegs *regs = NULL;
+ Uint32 *stack;
+
+ if( Thread->CurCPU != GetCPUNum() ) {
+ Log(" Currently running");
+ return ;
+ }
+
+ // Backtrace to find the IRQ entrypoint
+ // - This will usually only be called by an IRQ, so this should
+ // work
+ __asm__ __volatile__ ("mov %%ebp, %0" : "=r" (stack));
+ while( maxBacktraceDistance -- )
+ {
+ // [ebp] = oldEbp
+ // [ebp+4] = retaddr
+
+ if( stack[1] == (tVAddr)&IRQCommon_handled ) {
+ regs = (void*)stack[2];
+ break;
+ }
+
+ stack = (void*)stack[0];
+ }
+
+ if( !regs ) {
+ Log(" Unable to find IRQ Entry");
+ return ;
+ }
+
+ Log(" at %04x:%08x", regs->cs, regs->eip);
+ return ;
+ }
+
+ #if 1
+ tVAddr diffFromScheduler = Thread->SavedState.EIP - (tVAddr)Proc_Scheduler;
+ tVAddr diffFromClone = Thread->SavedState.EIP - (tVAddr)Proc_Clone;
+ tVAddr diffFromSpawn = Thread->SavedState.EIP - (tVAddr)Proc_SpawnWorker;
+
+ if( diffFromClone > 0 && diffFromClone < 512 ) // When I last checked, GetEIP was at .+0x183
+ {
+ Log(" Creating full thread");
+ return ;
+ }
+
+ if( diffFromSpawn > 0 && diffFromSpawn < 512 ) // When I last checked, GetEIP was at .+0x99
+ {
+ Log(" Creating worker thread");
+ return ;
+ }
+
+ if( diffFromScheduler > 0 && diffFromScheduler < 256 ) // When I last checked, GetEIP was at .+0x60
+ #else
+ Uint32 data[3];
+ MM_ReadFromAddrSpace(Thread->MemState.CR3, Thread->SavedState.EBP, data, 12);
+ if( data[1] == (Uint32)&IRQCommon + 25 )
+ {
+ tRegs *regs = (void *) data[2];
+ Log(" oldebp = 0x%08x, ret = 0x%08x, regs = 0x%x",
+ data[0], data[1], data[2]
+ );
+ // [EBP] = old EBP
+ // [EBP+0x04] = Return Addr
+ // [EBP+0x08] = Arg 1 (CPU Number)
+ // [EBP+0x0C] = Arg 2 (Thread)
+ // [EBP+0x10] = GS (start of tRegs)
+ Log(" IRQ%i from %02x:%08x", regs->int_num regs->cs, regs->eip);
+ }
+ if( stack[1] == (Uint32)&scheduler_return )
+ #endif
+ {
+ // Scheduled out
+ Log(" At %04x:%08x", Thread->SavedState.UserCS, Thread->SavedState.UserEIP);
+ return ;
+ }
+
+ Log(" Just created (unknow %p)", Thread->SavedState.EIP);
+}
+