public static void _lvr_svr_q(CpuThreadState cpuThreadState, bool save, float *r0, float *r1, float *r2, float *r3, uint address) { //Console.Error.WriteLine("+RRRRRRRRRRRRR {0:X8}", Address); int k = (int)(4 - ((address >> 2) & 3)); //Address &= unchecked((uint)~0xF); var r = stackalloc float *[4]; r[0] = r0; r[1] = r1; r[2] = r2; r[3] = r3; fixed(float *vfpr = &cpuThreadState.Vfr0) { for (var j = 0; j < k; j++, address += 4) { var ptr = r[j]; var memoryAddress = address; var memory = (float *)cpuThreadState.GetMemoryPtr(memoryAddress); //Console.Error.WriteLine("_lvl_svr_q({0}): {1:X8}: Reg({2:X8}) {3} Mem({4:X8})", j, memory_address, *(int*)ptr, Save ? "->" : "<-", *(int*)memory); LanguageUtils.Transfer(ref *memory, ref *ptr, save); //Console.Error.WriteLine("_lvl_svr_q({0}): {1:X8}: Reg({2:X8}) {3} Mem({4:X8})", j, memory_address, *(int*)ptr, Save ? "->" : "<-", *(int*)memory); } } //Console.Error.WriteLine("--------------"); }
public static int _vrndi(CpuThreadState cpuThreadState) { var data = new byte[4]; cpuThreadState.Random.NextBytes(data); return(BitConverter.ToInt32(data, 0)); }
public void Frintx_S(uint a, char roundMode, bool defaultNaN, uint result) { uint opcode = 0x1E274020; // FRINTX S0, S1 Vector128 <float> v1 = MakeVectorE0(a); int fpcrTemp = 0x0; switch (roundMode) { case 'N': fpcrTemp = 0x0; break; case 'P': fpcrTemp = 0x400000; break; case 'M': fpcrTemp = 0x800000; break; case 'Z': fpcrTemp = 0xC00000; break; } if (defaultNaN) { fpcrTemp |= 1 << 25; } CpuThreadState threadState = SingleOpcode(opcode, v1: v1, fpcr: fpcrTemp); Assert.That(GetVectorE0(threadState.V0), Is.EqualTo(result)); CompareAgainstUnicorn(); }
public void Frintx_V(uint opcode, ulong a, ulong b, char roundMode, bool defaultNaN, ulong result0, ulong result1) { Vector128 <float> v1 = MakeVectorE0E1(a, b); int fpcrTemp = 0x0; switch (roundMode) { case 'N': fpcrTemp = 0x0; break; case 'P': fpcrTemp = 0x400000; break; case 'M': fpcrTemp = 0x800000; break; case 'Z': fpcrTemp = 0xC00000; break; } if (defaultNaN) { fpcrTemp |= 1 << 25; } CpuThreadState threadState = SingleOpcode(opcode, v1: v1, fpcr: fpcrTemp); Assert.Multiple(() => { Assert.That(GetVectorE0(threadState.V0), Is.EqualTo(result0)); Assert.That(GetVectorE1(threadState.V0), Is.EqualTo(result1)); }); CompareAgainstUnicorn(); }
private void SvcSleepThread(CpuThreadState ThreadState) { long Timeout = (long)ThreadState.X0; Logger.PrintDebug(LogClass.KernelSvc, "Timeout = 0x" + Timeout.ToString("x16")); KThread CurrentThread = System.Scheduler.GetCurrentThread(); if (Timeout < 1) { switch (Timeout) { case 0: CurrentThread.Yield(); break; case -1: CurrentThread.YieldWithLoadBalancing(); break; case -2: CurrentThread.YieldAndWaitForLoadBalancing(); break; } } else { CurrentThread.Sleep(Timeout); ThreadState.X0 = 0; } }
private void SvcSetThreadPriority(CpuThreadState ThreadState) { int Handle = (int)ThreadState.X0; int Priority = (int)ThreadState.X1; Logger.PrintDebug(LogClass.KernelSvc, "Handle = 0x" + Handle.ToString("x8") + ", " + "Priority = 0x" + Priority.ToString("x8")); //TODO: NPDM check. KThread Thread = Process.HandleTable.GetKThread(Handle); if (Thread == null) { Logger.PrintWarning(LogClass.KernelSvc, $"Invalid thread handle 0x{Handle:x8}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle); return; } Thread.SetPriority(Priority); ThreadState.X0 = 0; }
public void Run() { var cpuThreadState = new CpuThreadState(CpuProcessor); var dma = new Dma(cpuThreadState); Console.SetWindowSize(120, 60); Console.SetBufferSize(120, 8000); var nandStream = File.OpenRead(NandPath); var iplReader = new IplReader(new NandReader(nandStream)); var info = iplReader.LoadIplToMemory(new PspMemoryStream(PspMemory)); var startPc = info.EntryFunction; var lleState = new LleState(); dma.LleState = lleState; lleState.Gpio = new LleGpio(); lleState.Nand = new LleNand(nandStream); lleState.Cpu = new LlePspCpu("CPU", InjectContext, CpuProcessor, startPc); lleState.Me = new LlePspCpu("ME", InjectContext, CpuProcessor, startPc); lleState.LleKirk = new LleKirk(PspMemory); lleState.Memory = PspMemory; lleState.Cpu.Start(); while (true) { Thread.Sleep(int.MaxValue); } }
/// <summary> /// /// </summary> /// <param name="CpuThreadState"></param> /// <param name="HandleCallbacks"></param> /// <returns></returns> private int _sceKernelSleepThreadCB(CpuThreadState CpuThreadState, bool HandleCallbacks) { var ThreadToSleep = HleState.ThreadManager.Current; ThreadToSleep.ChangeWakeUpCount(-1, null); return(0); }
public static void Blx(CpuThreadState state, MemoryManager memory, OpCode64 opCode, bool x) { A32OpCodeBImmAl op = (A32OpCodeBImmAl)opCode; if (IsConditionTrue(state, op.Cond)) { uint pc = GetPc(state); if (state.Thumb) { state.R14 = pc | 1; } else { state.R14 = pc - 4U; } if (x) { state.Thumb = !state.Thumb; } if (!state.Thumb) { pc &= ~3U; } BranchWritePc(state, pc + (uint)op.Imm); } }
public void Allocate(CpuThreadState CpuThreadState, int Size, PspPointer *AddressPointer, uint *Timeout, bool HandleCallbacks) { if (!TryAllocate(CpuThreadState, Size, AddressPointer)) { bool TimedOut = false; ThreadManForUser.ThreadManager.Current.SetWaitAndPrepareWakeUp(HleThread.WaitType.Semaphore, "_sceKernelAllocateVplCB", this, (WakeUp) => { ThreadManForUser.PspRtc.RegisterTimeout(Timeout, () => { TimedOut = true; WakeUp(); }); WaitList.Add(new WaitVariablePoolItem() { RequiredSize = Size, WakeUp = () => { WakeUp(); Allocate(CpuThreadState, Size, AddressPointer, Timeout, HandleCallbacks); }, }); }, HandleCallbacks: HandleCallbacks); if (TimedOut) { throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_WAIT_TIMEOUT)); } } }
public static void _lvr_svr_q(CpuThreadState CpuThreadState, uint m, uint i, uint address, bool dir, bool save) { uint k = 4 - ((address >> 2) & 3); for (uint j = 0; j < k; ++j) { fixed (float* VFPR = &CpuThreadState.VFR0) { float* ptr; if (dir) { ptr = &VFPR[VfpuUtils.GetCellIndex(m, i, j)]; } else { ptr = &VFPR[VfpuUtils.GetCellIndex(m, j, i)]; } if (save) { *(float*)CpuThreadState.GetMemoryPtr(address) = *ptr; } else { *ptr = *(float*)CpuThreadState.GetMemoryPtr(address); } } address += 4; } }
public static uint _mfvc_impl(CpuThreadState cpuThreadState, VfpuControlRegistersEnum vfpuControlRegister) { Console.Error.WriteLine("Warning: _mfvc_impl"); switch (vfpuControlRegister) { case VfpuControlRegistersEnum.VfpuPfxs: return(cpuThreadState.PrefixSource.Value); case VfpuControlRegistersEnum.VfpuPfxt: return(cpuThreadState.PrefixTarget.Value); case VfpuControlRegistersEnum.VfpuPfxd: return(cpuThreadState.PrefixDestination.Value); case VfpuControlRegistersEnum.VfpuCc: return(cpuThreadState.VfrCcValue); case VfpuControlRegistersEnum.VfpuRcx0: return((uint)MathFloat.ReinterpretFloatAsInt((float)(new Random().NextDouble()))); case VfpuControlRegistersEnum.VfpuRcx1: case VfpuControlRegistersEnum.VfpuRcx2: case VfpuControlRegistersEnum.VfpuRcx3: case VfpuControlRegistersEnum.VfpuRcx4: case VfpuControlRegistersEnum.VfpuRcx5: case VfpuControlRegistersEnum.VfpuRcx6: case VfpuControlRegistersEnum.VfpuRcx7: return((uint)MathFloat.ReinterpretFloatAsInt(1.0f)); default: throw (new NotImplementedException("_mfvc_impl: " + vfpuControlRegister)); } }
private int _sceDisplayWaitVblankStartCB(CpuThreadState CpuThreadState, bool HandleCallbacks) { if (PspConfig.VerticalSynchronization && LastVblankCount != PspDisplay.VblankCount) { var SleepThread = ThreadManager.Current; SleepThread.SetWaitAndPrepareWakeUp(HleThread.WaitType.Display, "sceDisplayWaitVblankStart", (WakeUpCallbackDelegate) => { PspRtc.RegisterTimerAtOnce(LastWaitVblankStart + TimeSpan.FromMilliseconds(1000 / 60), () => { WakeUpCallbackDelegate(); }); LastWaitVblankStart = PspRtc.UpdatedCurrentDateTime; }, HandleCallbacks: HandleCallbacks); /* * SleepThread.SetWaitAndPrepareWakeUp(HleThread.WaitType.Display, "sceDisplayWaitVblankStart", (WakeUpCallbackDelegate) => * { * //PspDisplay.VBlankEvent * HleState.PspDisplay.VBlankEvent.CallbackOnStateOnce(() => * { * LastVblankCount = HleState.PspDisplay.VblankCount; * WakeUpCallbackDelegate(); * }); * }); */ } return(0); }
public static void _lvr_svr_q(CpuThreadState CpuThreadState, uint m, uint i, uint address, bool dir, bool save) { uint k = 4 - ((address >> 2) & 3); for (uint j = 0; j < k; ++j) { fixed (float* VFPR = &CpuThreadState.VFR0) { float* ptr; if (dir) { ptr = &VFPR[m * 16 + i * 4 + j]; } else { ptr = &VFPR[m * 16 + j * 4 + i]; } if (save) { *(float*)CpuThreadState.GetMemoryPtr(address) = *ptr; } else { *ptr = *(float*)CpuThreadState.GetMemoryPtr(address); } } address += 4; } }
public static void _break_impl(CpuThreadState CpuThreadState) { Console.Error.WriteLine("-------------------------------------------------------------------"); Console.Error.WriteLine("-- BREAK ---------------------------------------------------------"); Console.Error.WriteLine("-------------------------------------------------------------------"); throw(new PspBreakException("Break!")); }
private TranslatedSub TranslateTier0(CpuThreadState state, MemoryManager memory, long position) { Block block = Decoder.DecodeBasicBlock(state, memory, position); Block[] graph = new Block[] { block }; string subName = GetSubroutineName(position); ILEmitterCtx context = new ILEmitterCtx(_cache, graph, block, subName); do { context.EmitOpCode(); }while (context.AdvanceOpCode()); TranslatedSub subroutine = context.GetSubroutine(); subroutine.SetType(TranslatedSubType.SubTier0); _cache.AddOrUpdate(position, subroutine, block.OpCodes.Count); OpCode64 lastOp = block.GetLastOp(); return(subroutine); }
//[HlePspNotImplemented] public int sceKernelPollSema(CpuThreadState CpuThreadState, SemaphoreId SemaphoreId, int Signal) { var Semaphore = GetSemaphoreById(SemaphoreId); if (Signal <= 0) { throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_COUNT)); } if (Signal > Semaphore.CurrentCount) { //ThreadManager.Reschedule(); //CpuThreadState.Yield(); throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_SEMA_ZERO)); //return 0; } Semaphore.IncrementCount(-Signal); //throw(new NotImplementedException()); return(0); /* * try { * PspSemaphore pspSemaphore = uniqueIdFactory.get!PspSemaphore(semaid); * * if (pspSemaphore.info.currentCount - signal < 0) return SceKernelErrors.ERROR_KERNEL_SEMA_ZERO; * * pspSemaphore.info.currentCount -= signal; * return 0; * } catch (UniqueIdNotFoundException) { * return SceKernelErrors.ERROR_KERNEL_NOT_FOUND_SEMAPHORE; * } */ }
private void SvcSetHeapSize(CpuThreadState threadState) { ulong size = threadState.X1; if ((size & 0xfffffffe001fffff) != 0) { Logger.PrintWarning(LogClass.KernelSvc, $"Heap size 0x{size:x16} is not aligned!"); threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidSize); return; } KernelResult result = _process.MemoryManager.SetHeapSize(size, out ulong position); threadState.X0 = (ulong)result; if (result == KernelResult.Success) { threadState.X1 = position; } else { Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error \"{result}\"."); } }
public static uint GetOrAllocIndexFromPoolHelper(CpuThreadState CpuThreadState, Type Type, IHleUidPoolClass Item) { //Console.Error.WriteLine("AllocIndexFromPoolHelper"); return((uint)CpuThreadState.CpuProcessor.InjectContext.GetInstance <HleUidPoolManager>() .GetOrAllocIndex(Type, Item)); }
public static object GetObjectFromPoolHelper(CpuThreadState CpuThreadState, Type Type, int Index, bool CanReturnNull) { //Console.Error.WriteLine("GetObjectFromPoolHelper"); return(CpuThreadState.CpuProcessor.InjectContext.GetInstance <HleUidPoolManager>() .Get(Type, Index, CanReturnNull: CanReturnNull)); }
private void SvcSignalToAddress(CpuThreadState ThreadState) { long Address = (long)ThreadState.X0; SignalType Type = (SignalType)ThreadState.X1; int Value = (int)ThreadState.X2; int Count = (int)ThreadState.X3; Logger.PrintDebug(LogClass.KernelSvc, "Address = 0x" + Address.ToString("x16") + ", " + "Type = " + Type.ToString() + ", " + "Value = 0x" + Value.ToString("x8") + ", " + "Count = 0x" + Count.ToString("x8")); if (IsPointingInsideKernel(Address)) { Logger.PrintWarning(LogClass.KernelSvc, $"Invalid address 0x{Address:x16}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm); return; } if (IsAddressNotWordAligned(Address)) { Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned address 0x{Address:x16}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress); return; } long Result; switch (Type) { case SignalType.Signal: Result = System.AddressArbiter.Signal(Address, Count); break; case SignalType.SignalAndIncrementIfEqual: Result = System.AddressArbiter.SignalAndIncrementIfEqual(Memory, Address, Value, Count); break; case SignalType.SignalAndModifyIfEqual: Result = System.AddressArbiter.SignalAndModifyIfEqual(Memory, Address, Value, Count); break; default: Result = MakeError(ErrorModule.Kernel, KernelErr.InvalidEnumValue); break; } if (Result != 0) { Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!"); } ThreadState.X0 = (ulong)Result; }
public int sceKernelRotateThreadReadyQueue(CpuThreadState CpuThreadState, int priority) { // @TODO! //throw(new NotImplementedException()); #if false //this is the converted code from JSPSP should be easy enough to implement lock (readyThreads) { foreach (SceKernelThreadInfo thread in readyThreads) { if (thread.currentPriority == priority) { // When rotating the ready queue of the current thread, // the current thread yields and is moved to the end of its // ready queue. if (priority == currentThread.currentPriority) { thread = currentThread; // The current thread will be moved to the front of the ready queue hleChangeThreadState(thread, PSP_THREAD_READY); } // Move the thread to the end of the ready queue removeFromReadyThreads(thread); addToReadyThreads(thread, false); hleRescheduleCurrentThread(); break; } } } #endif CpuThreadState.Yield(); //foreach (SceKernelThreadInfo thread in readyThreads) //{ // if (thread.currentPriority == priority) // { // // When rotating the ready queue of the current thread, // // the current thread yields and is moved to the end of its // // ready queue. // if (priority == currentThread.currentPriority) // { // thread = currentThread; // // The current thread will be moved to the front of the ready queue // hleChangeThreadState(thread, PSP_THREAD_READY); // } // // Move the thread to the end of the ready queue // removeFromReadyThreads(thread); // addToReadyThreads(thread, false); // hleRescheduleCurrentThread(); // break; // } //} return(0); }
private void SvcWaitForAddress(CpuThreadState ThreadState) { long Address = (long)ThreadState.X0; ArbitrationType Type = (ArbitrationType)ThreadState.X1; int Value = (int)ThreadState.X2; long Timeout = (long)ThreadState.X3; Logger.PrintDebug(LogClass.KernelSvc, "Address = 0x" + Address.ToString("x16") + ", " + "Type = " + Type.ToString() + ", " + "Value = 0x" + Value.ToString("x8") + ", " + "Timeout = 0x" + Timeout.ToString("x16")); if (IsPointingInsideKernel(Address)) { Logger.PrintWarning(LogClass.KernelSvc, $"Invalid address 0x{Address:x16}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm); return; } if (IsAddressNotWordAligned(Address)) { Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned address 0x{Address:x16}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress); return; } long Result; switch (Type) { case ArbitrationType.WaitIfLessThan: Result = System.AddressArbiter.WaitForAddressIfLessThan(Memory, Address, Value, false, Timeout); break; case ArbitrationType.DecrementAndWaitIfLessThan: Result = System.AddressArbiter.WaitForAddressIfLessThan(Memory, Address, Value, true, Timeout); break; case ArbitrationType.WaitIfEqual: Result = System.AddressArbiter.WaitForAddressIfEqual(Memory, Address, Value, Timeout); break; default: Result = MakeError(ErrorModule.Kernel, KernelErr.InvalidEnumValue); break; } if (Result != 0) { Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!"); } ThreadState.X0 = (ulong)Result; }
public HleThread(CpuThreadState CpuThreadState) { this.MethodCache = CpuThreadState.CpuProcessor.MethodCache; this.PspConfig = CpuThreadState.CpuProcessor.PspConfig; this.GreenThread = new GreenThread(); this.CpuThreadState = CpuThreadState; this.PrepareThread(); }
private void SvcSendSyncRequestWithUserBuffer(CpuThreadState threadState) { SendSyncRequest( threadState, (long)threadState.X0, (long)threadState.X1, (int)threadState.X2); }
public static void _swl_exec(CpuThreadState cpuThreadState, uint rs, int offset, uint rt) { var address = (uint)(rs + offset); var addressAlign = (uint)address & 3; var addressPointer = (uint *)cpuThreadState.GetMemoryPtr(address & 0xFFFFFFFC); *addressPointer = (rt >> SwlShift[addressAlign]) | (*addressPointer & SwlMask[addressAlign]); }
private void CreateEvent64(CpuThreadState state) { KernelResult result = CreateEvent(out int wEventHandle, out int rEventHandle); state.X0 = (ulong)result; state.X1 = (ulong)wEventHandle; state.X2 = (ulong)rEventHandle; }
public static string StringFromAddress(CpuThreadState CpuThreadState, uint Address) { if (Address == 0) { return(null); } return(PointerUtils.PtrToString((byte *)CpuThreadState.GetMemoryPtr(Address), Encoding.UTF8)); }
public static Block DecodeBasicBlock(CpuThreadState state, MemoryManager memory, long start) { Block block = new Block(start); FillBlock(state, memory, block); return(block); }
private void CreateEvent64(CpuThreadState State) { KernelResult Result = CreateEvent(out int WEventHandle, out int REventHandle); State.X0 = (ulong)Result; State.X1 = (ulong)WEventHandle; State.X2 = (ulong)REventHandle; }
public void waitThreadForever(CpuThreadState CpuThreadState) { var SleepThread = ThreadManager.Current; SleepThread.SetStatus(HleThread.Status.Waiting); SleepThread.CurrentWaitType = HleThread.WaitType.None; ThreadManager.Yield(); }
public void waitThreadForever(CpuThreadState CpuThreadState) { var SleepThread = HleState.ThreadManager.Current; SleepThread.CurrentStatus = HleThread.Status.Waiting; SleepThread.CurrentWaitType = HleThread.WaitType.None; CpuThreadState.Yield(); }
public LlePspCpu(string name, InjectContext injectContext, CpuProcessor cpuProcessor, uint entryPoint = 0x1fc00000) { _name = name; //this.CachedGetMethodCache = PspEmulatorContext.GetInstance<CachedGetMethodCache>(); CpuThreadState = new CpuThreadState(cpuProcessor); EntryPoint = entryPoint; }
public static void _ctc1_impl(CpuThreadState CpuThreadState, int RD, int RT) { switch (RD) { case 31: CpuThreadState.Fcr31.Value = (uint)CpuThreadState.GPR[RT]; break; default: throw (new Exception(String.Format("Unsupported CFC1(%d)", RD))); } }
public static void _cvt_w_s_impl(CpuThreadState CpuThreadState, int FD, int FS) { //Console.WriteLine("_cvt_w_s_impl: {0}", CpuThreadState.FPR[FS]); switch (CpuThreadState.Fcr31.RM) { case CpuThreadState.FCR31.TypeEnum.Rint: CpuThreadState.FPR_I[FD] = (int)MathFloat.Rint(CpuThreadState.FPR[FS]); break; case CpuThreadState.FCR31.TypeEnum.Cast: CpuThreadState.FPR_I[FD] = (int)CpuThreadState.FPR[FS]; break; case CpuThreadState.FCR31.TypeEnum.Ceil: CpuThreadState.FPR_I[FD] = (int)MathFloat.Ceil(CpuThreadState.FPR[FS]); break; case CpuThreadState.FCR31.TypeEnum.Floor: CpuThreadState.FPR_I[FD] = (int)MathFloat.Floor(CpuThreadState.FPR[FS]); break; } }
// CFC1 -- move Control word from/to floating point (C1) public static void _cfc1_impl(CpuThreadState CpuThreadState, int RD, int RT) { switch (RD) { case 0: // readonly? throw(new NotImplementedException()); case 31: CpuThreadState.GPR[RT] = (int)CpuThreadState.Fcr31.Value; break; default: throw(new Exception(String.Format("Unsupported CFC1(%d)", RD))); } }
///////////////////////////////////////////////////////////////////////////////////////////////// // DIVide (Unsigned). ///////////////////////////////////////////////////////////////////////////////////////////////// public static unsafe void _div_impl(CpuThreadState CpuThreadState, int Left, int Right) { if (Right == 0) { CpuThreadState.LO = 0; CpuThreadState.HI = 0; } else { CpuThreadState.LO = Left / Right; CpuThreadState.HI = Left % Right; } }
public unsafe static void _divu_impl(CpuThreadState CpuThreadState, uint Left, uint Right) { if (Right == 0) { CpuThreadState.LO = 0; CpuThreadState.HI = 0; } else { CpuThreadState.LO = unchecked((int)(Left / Right)); CpuThreadState.HI = unchecked((int)(Left % Right)); } }
public static void _comp_impl(CpuThreadState CpuThreadState, float s, float t, bool fc_unordererd, bool fc_equal, bool fc_less, bool fc_inv_qnan) { if (float.IsNaN(s) || float.IsNaN(t)) { CpuThreadState.Fcr31.CC = fc_unordererd; } else { bool cc = false; if (fc_equal) cc = cc || (s == t); if (fc_less) cc = cc || (s < t); CpuThreadState.Fcr31.CC = cc; } }
public unsafe static void _div_impl(CpuThreadState CpuThreadState, int Left, int Right) { if (Right == 0) { CpuThreadState.LO = 0; CpuThreadState.HI = 0; } if (Left == int.MinValue && Right == -1) { CpuThreadState.LO = int.MinValue; CpuThreadState.HI = 0; } else { CpuThreadState.LO = unchecked(Left / Right); CpuThreadState.HI = unchecked(Left % Right); } }
public static void _vcmp_end(CpuThreadState CpuThreadState, int VectorSize) { CpuThreadState.VFR_CC_4 = false; CpuThreadState.VFR_CC_5 = true; if (VectorSize >= 1) { CpuThreadState.VFR_CC_4 |= CpuThreadState.VFR_CC_0; CpuThreadState.VFR_CC_5 &= CpuThreadState.VFR_CC_0; } if (VectorSize >= 2) { CpuThreadState.VFR_CC_4 |= CpuThreadState.VFR_CC_1; CpuThreadState.VFR_CC_5 &= CpuThreadState.VFR_CC_1; } if (VectorSize >= 3) { CpuThreadState.VFR_CC_4 |= CpuThreadState.VFR_CC_2; CpuThreadState.VFR_CC_5 &= CpuThreadState.VFR_CC_2; } if (VectorSize >= 4) { CpuThreadState.VFR_CC_4 |= CpuThreadState.VFR_CC_3; CpuThreadState.VFR_CC_5 &= CpuThreadState.VFR_CC_3; } /* Console.Error.WriteLine( "{0}, {1}, {2}, {3}, {4}, {5}", CpuThreadState.VFR_CC_0, CpuThreadState.VFR_CC_1, CpuThreadState.VFR_CC_2, CpuThreadState.VFR_CC_3, CpuThreadState.VFR_CC_4, CpuThreadState.VFR_CC_5 ); */ }
public static AstNodeStm _vcmp_end(CpuThreadState CpuThreadState, int VectorSize) { throw (new NotImplementedException()); //CpuThreadState.VFR_CC_4 = false; //CpuThreadState.VFR_CC_5 = true; //if (VectorSize >= 1) { CpuThreadState.VFR_CC_4 |= CpuThreadState.VFR_CC_0; CpuThreadState.VFR_CC_5 &= CpuThreadState.VFR_CC_0; } //if (VectorSize >= 2) { CpuThreadState.VFR_CC_4 |= CpuThreadState.VFR_CC_1; CpuThreadState.VFR_CC_5 &= CpuThreadState.VFR_CC_1; } //if (VectorSize >= 3) { CpuThreadState.VFR_CC_4 |= CpuThreadState.VFR_CC_2; CpuThreadState.VFR_CC_5 &= CpuThreadState.VFR_CC_2; } //if (VectorSize >= 4) { CpuThreadState.VFR_CC_4 |= CpuThreadState.VFR_CC_3; CpuThreadState.VFR_CC_5 &= CpuThreadState.VFR_CC_3; } /* Console.Error.WriteLine( "{0}, {1}, {2}, {3}, {4}, {5}", CpuThreadState.VFR_CC_0, CpuThreadState.VFR_CC_1, CpuThreadState.VFR_CC_2, CpuThreadState.VFR_CC_3, CpuThreadState.VFR_CC_4, CpuThreadState.VFR_CC_5 ); */ }
public static uint _mfvc_impl(CpuThreadState CpuThreadState, VfpuControlRegistersEnum VfpuControlRegister) { throw(new NotImplementedException()); //switch (VfpuControlRegister) //{ // case VfpuControlRegistersEnum.VFPU_PFXS: return CpuThreadState.PrefixSource.Value; // case VfpuControlRegistersEnum.VFPU_PFXT: return CpuThreadState.PrefixTarget.Value; // case VfpuControlRegistersEnum.VFPU_PFXD: return CpuThreadState.PrefixDestination.Value; // case VfpuControlRegistersEnum.VFPU_CC: return CpuThreadState.VFR_CC_Value; // case VfpuControlRegistersEnum.VFPU_RCX0: return (uint)MathFloat.ReinterpretFloatAsInt((float)(new Random().NextDouble())); // case VfpuControlRegistersEnum.VFPU_RCX1: // case VfpuControlRegistersEnum.VFPU_RCX2: // case VfpuControlRegistersEnum.VFPU_RCX3: // case VfpuControlRegistersEnum.VFPU_RCX4: // case VfpuControlRegistersEnum.VFPU_RCX5: // case VfpuControlRegistersEnum.VFPU_RCX6: // case VfpuControlRegistersEnum.VFPU_RCX7: // return (uint)MathFloat.ReinterpretFloatAsInt(1.0f); // default: // throw (new NotImplementedException("_mfvc_impl: " + VfpuControlRegister)); //} }
public static void _vpfxs_impl(CpuThreadState CpuThreadState, uint Value) { CpuThreadState.PrefixSource.Value = Value; }
public static void _sync_impl(CpuThreadState CpuThreadState, uint PC, uint Value) { CpuThreadState.PC = PC; //Console.WriteLine("Not implemented 'sync' instruction at 0x{0:X8} with value 0x{1:X8}", PC, Value); }
static public bool _LoadFcr31CC(CpuThreadState CpuThreadState) { return CpuThreadState.Fcr31.CC; }
/// <summary> /// /// </summary> /// <param name="CpuThreadState"></param> //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void CallDelegate(CpuThreadState CpuThreadState) { FunctionDelegate(CpuThreadState); }
public static float _vrndf1(CpuThreadState CpuThreadState) { var Result = (float)(CpuThreadState.Random.NextDouble() * 2.0f); //Console.WriteLine(Result); return Result; }
public static void _comp_impl(CpuThreadState CpuThreadState, float s, float t, bool fc_unordererd, bool fc_equal, bool fc_less, bool fc_inv_qnan) { if (float.IsNaN(s) || float.IsNaN(t)) { CpuThreadState.Fcr31.CC = fc_unordererd; } else { //bool cc = false; //if (fc_equal) cc = cc || (s == t); //if (fc_less) cc = cc || (s < t); //return cc; bool equal = (fc_equal) && (s == t); bool less = (fc_less) && (s < t); CpuThreadState.Fcr31.CC = (less || equal); } }
public void _MethodCacheInfo_SetInternal(CpuThreadState CpuThreadState, MethodCacheInfo MethodCacheInfo, uint PC) { MethodCacheInfo.SetDynarecFunction(MethodCompilerThread.GetDynarecFunctionForPC(PC)); }
public static void _cache_impl(CpuThreadState CpuThreadState, uint Value) { //Console.Error.WriteLine("cache! : 0x{0:X}", Value); //CpuThreadState.CpuProcessor.sceKernelIcacheInvalidateAll(); }
public static float LogFloatResult(float Value, CpuThreadState CpuThreadState) { Console.Error.WriteLine("LogFloatResult: {0}", Value); //CpuThreadState.DumpVfpuRegisters(Console.Error); return Value; }
public static void _vpfxt_impl(CpuThreadState CpuThreadState, uint Value) { CpuThreadState.PrefixTarget.Value = Value; }
public static void _vpfxd_impl(CpuThreadState CpuThreadState, uint Value) { CpuThreadState.PrefixDestination.Value = Value; }
public static int _vrndi(CpuThreadState CpuThreadState) { byte[] Data = new byte[4]; CpuThreadState.Random.NextBytes(Data); return BitConverter.ToInt32(Data, 0); }
public static float _vrndf2(CpuThreadState CpuThreadState) { return (float)(CpuThreadState.Random.NextDouble() * 4.0f); }
public static void _vrnds(CpuThreadState CpuThreadState, int Seed) { CpuThreadState.Random = new Random(Seed); }
public void CallDelegate(CpuThreadState CpuThreadState) { //if (StaticField.Value == null) throw(new Exception(String.Format("Delegate not set! at 0x{0:X8}", EntryPC))); StaticField.Value(CpuThreadState); }
public static void _debug_vfpu(CpuThreadState CpuThreadState) { Console.Error.WriteLine(""); Console.Error.WriteLine("VPU DEBUG:"); fixed (float* FPR = &CpuThreadState.VFR0) { int Index = 0; for (int Matrix = 0; Matrix < 8; Matrix++) { Console.Error.WriteLine("Matrix {0}: ", Matrix); for (int Row = 0; Row < 4; Row++) { for (int Column = 0; Column < 4; Column++) { Console.Error.Write("{0},", FPR[Index]); Index++; } Console.Error.WriteLine(""); } Console.Error.WriteLine(""); } } }
public static unsafe void _divu_impl(CpuThreadState CpuThreadState, uint Left, uint Right) { CpuThreadState.LO = (int)(Left / Right); CpuThreadState.HI = (int)(Left % Right); }