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 (Semaphore.CurrentCount - Signal < 0)
            {
                //ThreadManager.Reschedule();
                CpuThreadState.Yield();
                throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_SEMA_ZERO));
            }
            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;
            }
            */
        }
Example #2
0
        public unsafe void CopyRegistersFrom(CpuThreadState that)
        {
            this.PC         = that.PC;
            this.BranchFlag = that.BranchFlag;
            this.Fcr31      = that.Fcr31;
            this.IC         = that.IC;
            this.LO         = that.LO;
            this.HI         = that.HI;
            fixed(float *ThisFPR = &this.FPR0)
            fixed(float *ThatFPR = &that.FPR0)
            fixed(uint *ThisGPR  = &this.GPR0)
            fixed(uint *ThatGPR  = &that.GPR0)
            {
                for (int n = 0; n < 32; n++)
                {
                    ThisFPR[n] = ThatFPR[n];
                    ThisGPR[n] = ThatGPR[n];
                }
            }

            fixed(float *ThisVFR = &this.VFR0)
            fixed(float *ThatVFR = &that.VFR0)
            {
                for (int n = 0; n < 128; n++)
                {
                    ThisVFR[n] = ThatVFR[n];
                }
            }
        }
Example #3
0
        public void SetArgumentsToCpuThreadState(CpuThreadState CpuThreadState)
        {
            int GprIndex = 4;
            //int FprIndex = 0;
            Action<int> GprAlign = (int Alignment) =>
            {
                GprIndex = (int)MathUtils.NextAligned((uint)GprIndex, Alignment);
            };
            foreach (var Argument in Arguments)
            {
                var ArgumentType = Argument.GetType();
                if (ArgumentType == typeof(uint))
                {
                    GprAlign(1);
                    CpuThreadState.GPR[GprIndex++] = (int)(uint)Argument;
                }
                else if (ArgumentType == typeof(int))
                {
                    GprAlign(1);
                    CpuThreadState.GPR[GprIndex++] = (int)Argument;
                }
                else
                {
                    throw(new NotImplementedException(String.Format("Can't handle type '{0}'", ArgumentType)));
                }
            }

            CpuThreadState.PC = Function;
            //Console.Error.WriteLine(CpuThreadState);
            //CpuThreadState.DumpRegisters(Console.Error);
        }
Example #4
0
 public LlePspCpu(string Name, InjectContext InjectContext, CpuProcessor CpuProcessor, uint EntryPoint = 0x1fc00000)
 {
     this.Name = Name;
     //this.CachedGetMethodCache = PspEmulatorContext.GetInstance<CachedGetMethodCache>();
     this.CpuThreadState = new CpuThreadState(CpuProcessor);
     this.EntryPoint = EntryPoint;
 }
Example #5
0
 public void waitThreadForever(CpuThreadState CpuThreadState)
 {
     var SleepThread = ThreadManager.Current;
     SleepThread.SetStatus(HleThread.Status.Waiting);
     SleepThread.CurrentWaitType = HleThread.WaitType.None;
     ThreadManager.Yield();
 }
Example #6
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));
            uint 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);
        }
        public uint sceKernelCreateThread(CpuThreadState CpuThreadState, string Name, uint /*SceKernelThreadEntry*/ EntryPoint, int InitPriority, int StackSize, PspThreadAttributes Attribute, SceKernelThreadOptParam* Option)
        {
            var Thread = HleState.ThreadManager.Create();
            Thread.Name = Name;
            Thread.Info.PriorityCurrent = InitPriority;
            Thread.Info.PriorityInitially = InitPriority;
            Thread.Attribute = Attribute;
            Thread.GP = CpuThreadState.GP;
            Thread.Info.EntryPoint = (SceKernelThreadEntry)EntryPoint;
            Thread.Stack = HleState.MemoryManager.GetPartition(HleMemoryManager.Partitions.User).Allocate(StackSize, MemoryPartition.Anchor.High, Alignment: 0x100);
            if (!Thread.Attribute.HasFlag(PspThreadAttributes.NoFillStack))
            {
                HleState.MemoryManager.Memory.WriteRepeated1(0xFF, Thread.Stack.Low, Thread.Stack.Size);
                //Console.Error.WriteLine("-------------------------------------------------");
                //Console.Error.WriteLine("'{0}', '{1}'", StackSize, Thread.Stack.Size);
                //Console.Error.WriteLine("-------------------------------------------------");
            }
            Thread.Info.StackPointer = Thread.Stack.High;
            Thread.Info.StackSize = StackSize;

            // Used K0 from parent thread.
            // @FAKE. K0 should be preserved between thread calls. Though probably not modified by user modules.
            Thread.CpuThreadState.CopyRegistersFrom(HleState.ThreadManager.Current.CpuThreadState);

            Thread.CpuThreadState.PC = (uint)EntryPoint;
            Thread.CpuThreadState.GP = (uint)CpuThreadState.GP;
            Thread.CpuThreadState.SP = (uint)(Thread.Stack.High);
            Thread.CpuThreadState.RA = (uint)HleEmulatorSpecialAddresses.CODE_PTR_EXIT_THREAD;
            Thread.CurrentStatus = HleThread.Status.Stopped;
            //Thread.CpuThreadState.RA = (uint)0;

            //Console.WriteLine("STACK: {0:X}", Thread.CpuThreadState.SP);

            return (uint)Thread.Id;
        }
Example #8
0
			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 void TestMethod1()
        {
            var Config = new PspConfig();
            var PspEmulatorContext = new PspEmulatorContext(Config);
            PspEmulatorContext.SetInstanceType<PspMemory, LazyPspMemory>();

            var PspMemory = PspEmulatorContext.GetInstance<PspMemory>();
            var PspMemoryStream = new PspMemoryStream(PspMemory);
            var MipsAssembler = new MipsAssembler(PspMemoryStream);
            var DynarecFunctionCompilerTask = PspEmulatorContext.GetInstance<DynarecFunctionCompilerTask>();
            var CpuProcessor = PspEmulatorContext.GetInstance<CpuProcessor>();
            var CpuThreadState = new CpuThreadState(CpuProcessor);

            MipsAssembler.Assemble(@"
                .code 0x08000000
                addi r1, r1, 1
                jr r31
                nop
            ");

            var DynarecFunction = DynarecFunctionCompilerTask.GetFunctionForAddress(PspMemory.MainSegment.Low);

            Assert.AreEqual(0, CpuThreadState.GPR[1]);
            DynarecFunction.Delegate(CpuThreadState);
            Assert.AreEqual(1, CpuThreadState.GPR[1]);
        }
Example #10
0
 public void waitThreadForever(CpuThreadState CpuThreadState)
 {
     var SleepThread = HleState.ThreadManager.Current;
     SleepThread.CurrentStatus = HleThread.Status.Waiting;
     SleepThread.CurrentWaitType = HleThread.WaitType.None;
     CpuThreadState.Yield();
 }
Example #11
0
 public void ExecuteInterrupt(CpuThreadState CpuThreadState)
 {
     if (InterruptEnabled && InterruptFlag)
     {
         IInterruptManager.Interrupt(CpuThreadState);
     }
 }
 public int sceKernelChangeThreadPriority(CpuThreadState CpuThreadState, int ThreadId, int Priority)
 {
     GetThreadById(ThreadId).PriorityValue = Priority;
     HleState.ThreadManager.Reschedule();
     CpuThreadState.Yield();
     //throw(new NotImplementedException());
     return 0;
 }
Example #13
0
        public void Kprintf(string Format, CpuThreadState CpuThreadState)
        {
            var Arguments = new ArgumentReader(CpuThreadState);
            Arguments.LoadInteger(); // Skips format

            ConsoleUtils.SaveRestoreConsoleColor(ConsoleColor.Blue, () =>
            {
                Console.Error.Write("{0}", CStringFormater.Sprintf(Format, Arguments));
            });
        }
		public int sceKernelSignalSema(CpuThreadState CpuThreadState, SemaphoreId SemaphoreId, int Signal)
		{
			//Console.Error.WriteLine("sceKernelSignalSema!");
			var HleSemaphore = GetSemaphoreById(SemaphoreId);
			if (HleSemaphore.IncrementCount(Signal) > 0)
			{
				CpuThreadState.Yield();
			}
			return 0;
		}
Example #15
0
 public static void DebugCurrentThread(CpuThreadState CpuThreadState)
 {
     var CpuProcessor = CpuThreadState.CpuProcessor;
     Console.Error.WriteLine("*******************************************");
     Console.Error.WriteLine("* DebugCurrentThread **********************");
     Console.Error.WriteLine("*******************************************");
     CpuProcessor.DebugCurrentThreadEvent();
     Console.Error.WriteLine("*******************************************");
     CpuThreadState.DumpRegisters();
     Console.Error.WriteLine("*******************************************");
 }
        public int sceKernelDeleteSema(CpuThreadState CpuThreadState, SemaphoreId SemaphoreId)
        {
            var HleSemaphore = GetSemaphoreById(SemaphoreId);
            SemaphoreManager.Semaphores.Remove((int)SemaphoreId);
            if (HleSemaphore.IncrementCount(HleSemaphore.SceKernelSemaInfo.MaximumCount) > 0)
            {
                CpuThreadState.Yield();
            }

            return 0;
        }
Example #17
0
        public static void DebugCurrentThread(CpuThreadState cpuThreadState)
        {
            var cpuProcessor = cpuThreadState.CpuProcessor;

            Console.Error.WriteLine("*******************************************");
            Console.Error.WriteLine("* DebugCurrentThread **********************");
            Console.Error.WriteLine("*******************************************");
            cpuProcessor.DebugCurrentThreadEvent();
            Console.Error.WriteLine("*******************************************");
            cpuThreadState.DumpRegisters();
            Console.Error.WriteLine("*******************************************");
        }
Example #18
0
 public void Syscall(int Code, CpuThreadState CpuThreadState)
 {
     Action<int, CpuThreadState> Callback;
     if (RegisteredNativeSyscalls.TryGetValue(Code, out Callback))
     {
         Callback(Code, CpuThreadState);
     }
     else
     {
         Console.WriteLine("Undefined syscall: %06X at 0x%08X".Sprintf(Code, CpuThreadState.PC));
     }
 }
Example #19
0
		public void Syscall(int Code, CpuThreadState CpuThreadState)
		{
			Action<CpuThreadState, int> Callback;
			if ((Callback = GetSyscall(Code)) != null)
			{
				Callback(CpuThreadState, Code);
			}
			else
			{
				Console.WriteLine("Undefined syscall: {0:X6} at 0x{1:X8}", Code, CpuThreadState.PC);
			}
		}
Example #20
0
        public void Syscall(int Code, CpuThreadState CpuThreadState)
        {
            Action <int, CpuThreadState> Callback;

            if (RegisteredNativeSyscalls.TryGetValue(Code, out Callback))
            {
                Callback(Code, CpuThreadState);
            }
            else
            {
                Console.WriteLine("Undefined syscall: %06X at 0x%08X".Sprintf(Code, CpuThreadState.PC));
            }
        }
Example #21
0
        public void Syscall(int code, CpuThreadState cpuThreadState)
        {
            Action <CpuThreadState, int> callback;

            if ((callback = GetSyscall(code)) != null)
            {
                callback(cpuThreadState, code);
            }
            else
            {
                Console.WriteLine("Undefined syscall: {0:X6} at 0x{1:X8}", code, cpuThreadState.Pc);
            }
        }
Example #22
0
		public int ExecuteQueued(CpuThreadState CpuThreadState, bool MustReschedule)
		{
			int ExecutedCount = 0;

			//Console.WriteLine("ExecuteQueued");
			if (HasScheduledCallbacks)
			{
				//Console.WriteLine("ExecuteQueued.HasScheduledCallbacks!");
				//Console.Error.WriteLine("STARTED CALLBACKS");
				while (HasScheduledCallbacks)
				{
					var HleCallback = DequeueScheduledCallback();

					/*
					var FakeCpuThreadState = new CpuThreadState(CpuProcessor);
					FakeCpuThreadState.CopyRegistersFrom(CpuThreadState);
					HleCallback.SetArgumentsToCpuThreadState(FakeCpuThreadState);

					if (FakeCpuThreadState.PC == 0x88040E0) FakeCpuThreadState.PC = 0x880416C;
					*/
					//Console.WriteLine("ExecuteCallback: PC=0x{0:X}", FakeCpuThreadState.PC);
					//Console.WriteLine("               : A0=0x{0:X}", FakeCpuThreadState.GPR[4]);
					//Console.WriteLine("               : A1=0x{0:X}", FakeCpuThreadState.GPR[5]);
					try
					{
						HleInterop.ExecuteFunctionNow(HleCallback.Function, HleCallback.Arguments);
					}
					catch (Exception Exception)
					{
						Console.Error.WriteLine(Exception);
					}
					finally
					{
						//Console.WriteLine("               : PC=0x{0:X}", FakeCpuThreadState.PC);
						ExecutedCount++;
					}

					//Console.Error.WriteLine("  CALLBACK ENDED : " + HleCallback);
					if (MustReschedule)
					{
						//Console.Error.WriteLine("    RESCHEDULE");
						break;
					}
				}

				ExecutedCount += HleInterop.ExecuteAllQueuedFunctionsNow();
				//Console.Error.WriteLine("ENDED CALLBACKS");
			}

			return ExecutedCount;
		}
Example #23
0
        public static string ToNormalizedTypeString(Type ParameterType, CpuThreadState CpuThreadState, uint Int4, float Float4)
        {
            if (ParameterType == typeof(void))
            {
                return "void";
            }

            if (ParameterType == typeof(string))
            {
                return String.Format("'{0}'", StringFromAddress(CpuThreadState, Int4));
            }

            if (ParameterType == typeof(int))
            {
                return String.Format("{0}", (int)Int4);
            }

            if (ParameterType.IsEnum)
            {
                var Name = ParameterType.GetEnumName(Int4);
                if (Name == null || Name.Length == 0) Name = Int4.ToString();
                return Name;
            }

            if (ParameterType.IsPointer)
            {
                try
                {
                    return "0x%08X".Sprintf(CpuThreadState.CpuProcessor.Memory.PointerToPspAddress((void*)Int4));
                }
                catch (Exception)
                {
                    return String.Format("0x{0:X}", CpuThreadState.CpuProcessor.Memory.PointerToPspAddress((void*)Int4));
                }
            }

            if (ParameterType == typeof(float))
            {
                return String.Format("{0}", Float4);
            }

            try
            {
                return "0x%08X".Sprintf(Int4);
            }
            catch (Exception)
            {
                return String.Format("0x{0:X}", Int4);
            }
        }
Example #24
0
			public bool TryAllocate(CpuThreadState CpuThreadState, int Size, PspPointer* AddressPointer)
			{
				if (Size > Info.PoolSize) throw(new SceKernelException((SceKernelErrors)(-1)));
				try
				{
					var AllocatedSegment = MemoryPartition.Allocate(Size, InternalMemoryAnchor);
					AddressPointer->Address = AllocatedSegment.GetAnchoredAddress(InternalMemoryAnchor);
					return true;
				}
				catch (MemoryPartitionNoMemoryException)
				{
					//AddressPointer->Address = 0;
					return false;
				}
			}
			public void Unlock(CpuThreadState CurrentCpuThreadState, int UpdateCountValue)
			{
				if (UpdateCountValue == 0) throw(new SceKernelException(SceKernelErrors.ERROR_KERNEL_MUTEX_UNLOCKED));
				if (this.CurrentCountValue - UpdateCountValue < 0) throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_MUTEX_UNLOCK_UNDERFLOW));
				//Console.Error.WriteLine("Unlock : {0}", ThreadManager.Current.Id);
				//Console.Error.WriteLine(" {0} -> {1}", this.CurrentCountValue, this.CurrentCountValue - UpdateCountValue);
				CurrentCountValue -= UpdateCountValue;
				if (CurrentCountValue == 0)
				{
					//Console.Error.WriteLine("Release!");
					if (WakeUpList.Any())
					{
						var Action = WakeUpList.Dequeue();
						Action();
					}
				}
			}
        public void TestMethod1()
        {
            var CpuProcessor = CpuUtils.CreateCpuProcessor();

            var DynarecFunction = CpuProcessor.DynarecFunctionCompiler.CreateFunction(
                new InstructionArrayReader(MipsAssembler.StaticAssembleInstructions(@"
                    addi r1, r1, 1
                    jr r31
                    nop
                ").Instructions),
                 0
            );

            var CpuThreadState = new CpuThreadState(CpuProcessor);
            Assert.AreEqual(0, CpuThreadState.GPR[1]);
            DynarecFunction.Delegate(CpuThreadState);
            Assert.AreEqual(1, CpuThreadState.GPR[1]);
        }
Example #27
0
 public void CreateDelegateTest()
 {
     var PspConfig = new PspConfig();
     var PspEmulatorContext = new PspEmulatorContext(PspConfig);
     PspEmulatorContext.SetInstanceType<PspMemory, LazyPspMemory>();
     var Memory = PspEmulatorContext.GetInstance<PspMemory>();
     var Processor = PspEmulatorContext.GetInstance<CpuProcessor>();
     var CpuThreadState = new CpuThreadState(Processor);
     var MipsEmiter = new MipsMethodEmiter(new MipsEmiter(), Processor, 0);
     CpuThreadState.GPR[1] = 1;
     CpuThreadState.GPR[2] = 2;
     CpuThreadState.GPR[3] = 3;
     MipsEmiter.OP_3REG_Unsigned(1, 2, 2, () => { MipsEmiter.SafeILGenerator.BinaryOperation(SafeBinaryOperator.AdditionSigned); });
     MipsEmiter.OP_3REG_Unsigned(0, 2, 2, () => { MipsEmiter.SafeILGenerator.BinaryOperation(SafeBinaryOperator.AdditionSigned); });
     MipsEmiter.OP_2REG_IMM_Signed(10, 0, 1000, () => { MipsEmiter.SafeILGenerator.BinaryOperation(SafeBinaryOperator.AdditionSigned); });
     MipsEmiter.CreateDelegate()(CpuThreadState);
     Assert.AreEqual(4, CpuThreadState.GPR[1]);
     Assert.AreEqual(0, CpuThreadState.GPR[0]);
     Assert.AreEqual(1000, CpuThreadState.GPR[10]);
 }
Example #28
0
        public HleThread Execute(CpuThreadState FakeCpuThreadState)
        {
            var CurrentFakeHleThread = CurrentFakeHleThreads.Value;

            CurrentFakeHleThread.CpuThreadState.CopyRegistersFrom(FakeCpuThreadState);
            //HleCallback.SetArgumentsToCpuThreadState(CurrentFake.CpuThreadState);

            //CurrentFake.CpuThreadState.PC = HleCallback.Function;
            CurrentFakeHleThread.CpuThreadState.RA = HleEmulatorSpecialAddresses.CODE_PTR_FINALIZE_CALLBACK;
            //Current.CpuThreadState.RA = 0;

            CpuProcessor.RunningCallback = true;
            while (CpuProcessor.RunningCallback)
            {
                //Console.WriteLine("AAAAAAA {0:X}", CurrentFake.CpuThreadState.PC);
                CurrentFakeHleThread.Step();
            }

            return CurrentFakeHleThread;
        }
Example #29
0
		private int _waitVblankCB(CpuThreadState CpuThreadState, bool HandleCallbacks, int CycleCount)
		{
			if (PspConfig.VerticalSynchronization && LastVblankCount != PspDisplay.VblankCount)
			{
				var SleepThread = ThreadManager.Current;

				SleepThread.SetWaitAndPrepareWakeUp(HleThread.WaitType.Display, "sceDisplayWaitVblankStart", null, (WakeUpCallbackDelegate) =>
				{
#if true
					PspRtc.RegisterTimerInOnce(TimeSpan.FromMilliseconds(1000 / 60), () =>
					{
						WakeUpCallbackDelegate();
					});
#else
					if (LastWaitVblankStart == DateTime.MinValue)
					{
						LastWaitVblankStart = PspRtc.UpdatedCurrentDateTime;
					}
					PspRtc.RegisterTimerAtOnce(LastWaitVblankStart + TimeSpan.FromMilliseconds(1000 / 60), () =>
					{
						WakeUpCallbackDelegate();
					});
					LastWaitVblankStart = PspRtc.UpdatedCurrentDateTime;
#endif
				}, HandleCallbacks: HandleCallbacks);

				/*
				SleepThread.SetWaitAndPrepareWakeUp(HleThread.WaitType.Display, "sceDisplayWaitVblankStart", (WakeUpCallbackDelegate) =>
				{
					//PspDisplay.VBlankEvent
					PspDisplay.VBlankEvent.CallbackOnStateOnce(() =>
					{
						LastVblankCount = PspDisplay.VblankCount;
						WakeUpCallbackDelegate();
					});
				});
				*/
			}

			return 0;
		}
			public void Lock(CpuThreadState CurrentCpuThreadState, int UpdateCountValue, uint* Timeout)
			{
				if (Timeout != null)
				{
					Console.Error.WriteLine("PspMutex.Lock with Timeout not implemented!!");
					//throw (new NotImplementedException());
				}
				if (UpdateCountValue <= 0) throw (new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_COUNT));
				//Console.Error.WriteLine("Lock : {0}", ThreadManager.Current.Id);
				if (!TryLock(CurrentCpuThreadState, UpdateCountValue))
				{
					//ThreadManager.Current.
					ThreadManForUser.ThreadManager.Current.SetWaitAndPrepareWakeUp(HleThread.WaitType.Mutex, "sceKernelLockMutex", this, (WakeUp) =>
					{
						WakeUpList.Enqueue(() =>
						{
							WakeUp();
						});
					}, HandleCallbacks: false);
				}
			}
Example #31
0
        public void Execute(CpuThreadState FakeCpuThreadState)
        {
            var CpuProcessor = FakeCpuThreadState.CpuProcessor;
            if (CurrentFake == null)
            {
                CurrentFake = new HleThread(new CpuThreadState(CpuProcessor));
            }

            CurrentFake.CpuThreadState.CopyRegistersFrom(FakeCpuThreadState);
            //HleCallback.SetArgumentsToCpuThreadState(CurrentFake.CpuThreadState);

            //CurrentFake.CpuThreadState.PC = HleCallback.Function;
            CurrentFake.CpuThreadState.RA = HleEmulatorSpecialAddresses.CODE_PTR_FINALIZE_CALLBACK;
            //Current.CpuThreadState.RA = 0;

            CpuProcessor.RunningCallback = true;
            while (CpuProcessor.RunningCallback)
            {
                //Console.WriteLine("AAAAAAA {0:X}", CurrentFake.CpuThreadState.PC);
                CurrentFake.Step();
            }
        }
		public void TestMethod1()
		{
			var Config = new PspConfig();
			var PspEmulatorContext = new PspEmulatorContext(Config);
			PspEmulatorContext.SetInstanceType<PspMemory, LazyPspMemory>();

			var DynarecFunctionCompiler = PspEmulatorContext.GetInstance<DynarecFunctionCompiler>();
			var CpuProcessor = PspEmulatorContext.GetInstance<CpuProcessor>();
			var CpuThreadState = new CpuThreadState(CpuProcessor);
			
			var DynarecFunction = DynarecFunctionCompiler.CreateFunction(
				new InstructionArrayReader(MipsAssembler.StaticAssembleInstructions(@"
					addi r1, r1, 1
					jr r31
					nop
				")),
				 0
			);

			Assert.AreEqual(0, CpuThreadState.GPR[1]);
			DynarecFunction.Delegate(CpuThreadState);
			Assert.AreEqual(1, CpuThreadState.GPR[1]);
		}
Example #33
0
        public int ExecuteQueued(CpuThreadState CpuThreadState, bool MustReschedule)
        {
            int ExecutedCount = 0;

            if (HasScheduledCallbacks)
            {
                //Console.Error.WriteLine("STARTED CALLBACKS");
                while (HasScheduledCallbacks)
                {
                    var HleCallback = DequeueScheduledCallback();

                    var FakeCpuThreadState = new CpuThreadState(CpuProcessor);
                    FakeCpuThreadState.CopyRegistersFrom(CpuThreadState);
                    HleCallback.SetArgumentsToCpuThreadState(FakeCpuThreadState);

                    try
                    {
                        HleInterop.Execute(FakeCpuThreadState);
                    }
                    finally
                    {
                        ExecutedCount++;
                    }

                    //Console.Error.WriteLine("  CALLBACK ENDED : " + HleCallback);
                    if (MustReschedule)
                    {
                        //Console.Error.WriteLine("    RESCHEDULE");
                        break;
                    }
                }
                //Console.Error.WriteLine("ENDED CALLBACKS");
            }

            return ExecutedCount;
        }
 public void SetArgumentsToCpuThreadState(CpuThreadState CpuThreadState)
 {
     HleInterop.SetArgumentsToCpuThreadState(CpuThreadState, Function, Arguments);
 }
Example #35
0
 static public void ExecuteAssembly(this CpuThreadState CpuThreadState, String Assembly, bool BreakPoint = false)
 {
     CpuThreadState.CpuProcessor.CreateDelegateForString(Assembly, BreakPoint)(CpuThreadState);
 }