public void Transfer(Dma.Direction Direction, int Size, DmaEnum Address, ref uint Value) { switch (Address) { case DmaEnum.KIRK_PATTERN: Value = 1; break; case DmaEnum.KIRK_COMMAND: TransferUtils.Transfer(Direction, ref KirkCommand, ref Value); break; case DmaEnum.KIRK_RESULT: TransferUtils.Transfer(Direction, ref KirkResult, ref Value); break; case DmaEnum.KIRK_SOURCE_ADDRESS: TransferUtils.Transfer(Direction, ref KirkSource, ref Value); break; case DmaEnum.KIRK_DESTINATION_ADDRESS: TransferUtils.Transfer(Direction, ref KirkDestination, ref Value); break; case DmaEnum.KIRK_START: if (KirkCommand != 1) throw(new NotImplementedException()); var SourcePtr = (byte *)Memory.PspAddressToPointerSafe(KirkSource); var DestinationPtr = (byte*)Memory.PspAddressToPointerSafe(KirkDestination); //var Out = new byte[10000]; //fixed (byte* OutPtr = Out) { //DestinationPtr = OutPtr; Console.WriteLine("Input:"); ArrayUtils.HexDump(PointerUtils.PointerToByteArray(SourcePtr, 0x200)); /* try { Kirk.kirk_CMD1(DestinationPtr, SourcePtr, -1, true); this.KirkResult = (uint)Kirk.ResultEnum.OK; } catch (Kirk.KirkException KirkException) { this.KirkResult = (uint)KirkException.Result; Console.Error.WriteLine("Kirk.KirkException : {0}", KirkException); } */ this.KirkResult = (uint)Kirk.sceUtilsBufferCopyWithRange(DestinationPtr, -1, SourcePtr, -1, 1); Console.WriteLine("Output:"); ArrayUtils.HexDump(PointerUtils.PointerToByteArray(DestinationPtr, 0x200)); Console.WriteLine("LOADADDR:{0:X8}", ((uint*)DestinationPtr)[0]); Console.WriteLine("BLOCKSIZE:{0:X8}", ((uint*)DestinationPtr)[1]); Console.WriteLine("ENTRY:{0:X8}", ((uint*)DestinationPtr)[2]); Console.WriteLine("CHECKSUM:{0:X8}", ((uint*)DestinationPtr)[3]); } //Thread.Sleep(4); break; } }
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); } }
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 void TransferDMA(Dma.Direction Direction, int Size, DmaEnum Address, ref uint Value) { if (false) { } /* else if ((uint)Address >= 0x1FD00000 && (uint)Address <= 0x1FD00000 + 0x1000) { TransferUtils.TransferToArray(Direction, Test, (int)(Address - 0x1FD00000), Size, ref Value); } */ else if (Address >= DmaEnum.GPIO && Address <= DmaEnum.GPIO__PORT_CLEAR) { LLEState.GPIO.Transfer(Direction, Size, (DmaEnum)Address, ref Value); return; } else if (Address >= DmaEnum.NAND__CONTROL && Address <= DmaEnum.NAND__READDATA) { LLEState.NAND.Transfer(Direction, Size, (DmaEnum)Address, ref Value); return; } else if (Address >= DmaEnum.NAND__DATA_PAGE_START && Address <= DmaEnum.NAND__DATA_EXTRA_END) { LLEState.NAND.Transfer(Direction, Size, (DmaEnum)Address, ref Value); return; } else if (Address >= DmaEnum.KIRK_SIGNATURE && Address <= DmaEnum.KIRK_UNK_50) { LLEState.LleKirk.Transfer(Direction, Size, (DmaEnum)Address, ref Value); return; } else { Console.WriteLine("Unprocessed LLEState.Memory:{0}", LLEState.Memory.MountedPreIpl); //Thread.Sleep(100); } }
public void Transfer(Dma.Direction Direction, int Size, DmaEnum Address, ref uint Value) { // Reading sector if ((Address >= DmaEnum.NAND__DATA_PAGE_START) && (Address < DmaEnum.NAND__DATA_PAGE_END)) { var Offset = (int)(Address - DmaEnum.NAND__DATA_PAGE_START); //Console.WriteLine("{0:X8}", (uint)Address); //Console.WriteLine("Transfer {0} / {1} [{2}]", Offset, Size, NandBlock.Length); TransferUtils.TransferToArray(Direction, NandBlock, Offset, Size, ref Value); return; } if ((Address >= DmaEnum.NAND__DATA_SPARE_BUF0_REG) && (Address < DmaEnum.NAND__DATA_EXTRA_END)) { var Offset = (int)(Address - DmaEnum.NAND__DATA_SPARE_BUF0_REG); TransferUtils.TransferToArray(Direction, NandBlock, 512 + Offset + 4, Size, ref Value); return; } switch (Address) { case DmaEnum.NAND__CONTROL: TransferUtils.Transfer(Direction, ref ControlRegister, ref Value); break; case DmaEnum.NAND__STATUS: TransferUtils.Transfer(Direction, ref Status, ref Value); //Thread.Sleep(200); break; case DmaEnum.NAND__COMMAND: TransferUtils.Transfer(Direction, ref Command, ref Value); // Reset if (Direction == Dma.Direction.Write) { switch ((EnumCommands)Value) { case EnumCommands.Reset: Status = EnumStatus.Ready; break; } } break; case DmaEnum.NAND__ADDRESS: TransferUtils.Transfer(Direction, ref Address, ref Value); break; case DmaEnum.NAND__RESET: if (Direction == Dma.Direction.Write) { Reset(); } break; case DmaEnum.NAND__DMA_ADDRESS: TransferUtils.Transfer(Direction, ref DmaAddress, ref Value); break; case DmaEnum.NAND__DMA_CONTROL: if (Direction == Dma.Direction.Write) { if (Value == 0x301) { //0x20000/2/512*(512+16) NandStream.Position = ((DmaAddress / 2 / 512) * (512 + 16)); NandBlock = NandStream.ReadBytes(512 + 16); Console.WriteLine("Read from NAND: 0x{0:X8}", DmaAddress); ArrayUtils.HexDump(NandBlock); //Thread.Sleep(TimeSpan.FromSeconds(0.5)); //Thread.Sleep(-1); } } else { Value = 0; } break; case DmaEnum.NAND__DMA_ERROR: Value = 0; break; } }
static void Main(string[] args) { var PspConfig = new PspConfig(); var PspEmulatorContext = new PspEmulatorContext(PspConfig); var DebugPspMemory = PspEmulatorContext.GetInstance<DebugPspMemory>(); PspEmulatorContext.SetInstance<PspMemory>(DebugPspMemory); var CpuProcessor = PspEmulatorContext.GetInstance<CpuProcessor>(); var CpuThreadState = new CpuThreadState(CpuProcessor); var Dma = new Dma(CpuThreadState); DebugPspMemory.CpuThreadState = CpuThreadState; DebugPspMemory.Dma = Dma; Console.SetWindowSize(120, 60); Console.SetBufferSize(120, 8000); PspConfig.MustLogWrites = true; var NandStream = File.OpenRead(NandPath); //DebugPspMemory.Write4(0xBFC00FFC, 0x20040420); // It doesn't start the ME //DebugPspMemory.Write4(0xBFC00FFC, 0xFFFFFFFF); #if false // PRE-IPL uint StartPC = 0x1FC00000; DebugPspMemory.WriteBytes(StartPC, File.ReadAllBytes(PreIplPath)); PspConfig.TraceJal = true; //PspConfig.TraceJIT = true; #else var IplReader = new IplReader(new NandReader(NandStream)); var Info = IplReader.LoadIplToMemory(new PspMemoryStream(DebugPspMemory)); uint StartPC = Info.EntryFunction; #endif /* ME: li $t0, 0x40EC19C jr $t0 nop */ //IplReader.WriteIplToFile(File.Open(NandPath + ".ipl.bin", FileMode.Create, FileAccess.Write)); var LLEState = new LLEState(); Dma.LLEState = LLEState; LLEState.GPIO = new LleGPIO(); LLEState.NAND = new LleNAND(NandStream); LLEState.Cpu = new LlePspCpu("CPU", PspEmulatorContext, CpuProcessor, StartPC); LLEState.Me = new LlePspCpu("ME", PspEmulatorContext, CpuProcessor, StartPC); LLEState.LleKirk = new LleKirk(DebugPspMemory); LLEState.Memory = DebugPspMemory; LLEState.Cpu.Start(); while (true) Thread.Sleep(int.MaxValue); }
public void LogDMA(Dma.Direction Direction, int Size, uint Address, ref uint Value) { var DmaAddress = (DmaEnum)Address; if ((DmaAddress >= DmaEnum.NAND__DATA_PAGE_START) && (DmaAddress < DmaEnum.NAND__DATA_PAGE_END)) return; Console.WriteLine("PC({0:X8}) {1}: {2} : 0x{3:X8}", CpuThreadState.PC, Direction, GetRegisterName(Address), Value); }