Example #1
0
        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);
        }
 public static void Transfer <T>(Dma.Direction direction, ref T deviceValue, ref uint memoryValue)
 {
     if (direction == Dma.Direction.Read)
     {
         memoryValue = (uint)(object)deviceValue;
     }
     else
     {
         deviceValue = (T)(object)memoryValue;
     }
 }
        public static void TransferToArray(Dma.Direction direction, byte[] array, int offset, int size,
                                           ref uint memoryValue)
        {
            if (direction == Dma.Direction.Read)
            {
                switch (size)
                {
                case 4:
                    memoryValue = BitConverter.ToUInt32(array, offset);
                    break;

                case 2:
                    memoryValue = BitConverter.ToUInt16(array, offset);
                    break;

                case 1:
                    memoryValue = array[offset];
                    break;

                default: throw new NotImplementedException();
                }
            }
            else
            {
                byte[] bytes;
                switch (size)
                {
                case 4:
                    bytes = BitConverter.GetBytes(memoryValue);
                    break;

                case 2:
                    bytes = BitConverter.GetBytes((ushort)memoryValue);
                    break;

                case 1:
                    bytes = BitConverter.GetBytes((byte)memoryValue);
                    break;

                default: throw new NotImplementedException();
                }
                Buffer.BlockCopy(bytes, 0, array, offset, size);
            }
        }
Example #4
0
        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)
 {
 }
Example #6
0
        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;
            }
        }
Example #7
0
        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;
            }
        }