Exemple #1
0
 /// <summary>
 /// Simutrace comes with an integrated aggressive, but fast
 /// compressor for memory traces. To utilize the compressor, the
 /// stream must use one of the types returned by this method and
 /// employ the \c simtrace storage format (see StSessionCreateStore()).
 /// </summary>
 /// <param name="size">Architecture size of the simulated
 ///     system.</param>
 /// <param name="accessType">Type of memory operations that the new
 ///     stream should hold.</param>
 /// <param name="addressType">The semantic of the address
 ///     field.</param>
 /// <param name="hasData">Indicates if the memory entry will contain
 ///     the data read or written with the memory entry.</param>
 /// <returns>Stream descriptor identifying the desired memory entry
 ///     type. Do not modify the returned stream descriptor.</returns>
 public static StreamTypeDescriptor StStreamFindMemoryType(
     ArchitectureSize size, MemoryAccessType accessType,
     MemoryAddressType addressType, bool hasData)
 {
     return(NativeMethods.StStreamFindMemoryType(size, accessType,
                                                 addressType, hasData));
 }
Exemple #2
0
        public StoreRegisterToAddressOpcode(uint[] blocks)
        {
            BitWidth        = (BitWidthType)GetNibble(blocks[0], 2);
            SourceRegister  = GetNibble(blocks[0], 3);
            AddressRegister = GetNibble(blocks[0], 4);
            IncrementFlag   = GetNibble(blocks[0], 5) == 1;
            OffsetType      = GetNibble(blocks[0], 6);
            switch (OffsetType)
            {
            case 1:
                OffsetRegister = GetNibble(blocks[0], 7);
                break;

            case 2:
                RelativeAddress = ((UInt64)(blocks[0] & 0xF) << 32) + blocks[1];
                break;

            case 3:
                MemType = (MemoryAccessType)GetNibble(blocks[0], 7);
                break;

            case 4:
                MemType         = (MemoryAccessType)GetNibble(blocks[0], 7);
                RelativeAddress = ((UInt64)(blocks[0] & 0xF) << 32) + blocks[1];
                break;

            case 5:
                MemType         = (MemoryAccessType)GetNibble(blocks[0], 7);
                RelativeAddress = ((UInt64)(blocks[0] & 0xF) << 32) + blocks[1];
                break;
            }
        }
Exemple #3
0
 public StoreStaticOpcode(UInt32[] blocks)
 {
     BitWidth        = (BitWidthType)GetNibble(blocks[0], 2);
     MemType         = (MemoryAccessType)GetNibble(blocks[0], 3);
     OffsetRegister  = GetNibble(blocks[0], 4);
     RelativeAddress = blocks[1];
     if (BitWidth == BitWidthType.q)
     {
         Value = ((UInt64)blocks[2] << 32) | blocks[3];
     }
     else
     {
         Value = blocks[2];
     }
 }
Exemple #4
0
 public LoadRegisterMemoryOpcode(uint[] blocks)
 {
     BitWidth      = (BitWidthType)GetNibble(blocks[0], 2);
     MemType       = (MemoryAccessType)GetNibble(blocks[0], 3);
     RegisterIndex = GetNibble(blocks[0], 4);
     UseReg        = GetNibble(blocks[0], 5) == 1;
     if (UseReg)
     {
         Immediate = ((UInt64)(blocks[0] & 0xFF) << 32) + blocks[1];
     }
     else
     {
         Immediate = blocks[1];
     }
 }
        public ConditionalOpcode(uint[] blocks)
        {
            BitWidth  = (BitWidthType)GetNibble(blocks[0], 2);
            MemType   = (MemoryAccessType)GetNibble(blocks[0], 3);
            Condition = (ConditionalComparisonType)GetNibble(blocks[0], 4);
            Immediate = ((UInt64)(blocks[0] & 0xFF) << 32) + blocks[1];

            if (BitWidth == BitWidthType.q)
            {
                Value = ((UInt64)blocks[2] << 32) + blocks[3];
            }
            else
            {
                Value = blocks[2];
            }
        }
Exemple #6
0
        public ExProcess(Process process, MemoryAccessType memoryAccessType)
        {
            Process = process;

            Handle = Kernel32.OpenProcess(ProcessAccessFlags.AllAccess, false, process.Id);
            Handle.Validate(true);

            switch (memoryAccessType)
            {
            case MemoryAccessType.Local:
                Memory = new ProcessMemoryLocal(Handle);
                break;

            case MemoryAccessType.Remote:
                Memory = new ProcessMemoryRemote(Handle);
                break;

            default: throw new NotSupportedException();
            }

            Process.EnableRaisingEvents = true;
            Process.Exited += (s, e) => ProcessExited?.Invoke(this);
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new <see cref="Breakpoint"/> instance with the given parameters.
 /// </summary>
 /// <param name="id">A unique ID used to lookup the breakpoint.</param>
 /// <param name="address">The memory address to break at.</param>
 /// <param name="accessType">The access type that triggers the breakpoint.</param>
 public Breakpoint(int id, uint address, MemoryAccessType accessType)
     : this(id, BreakpointType.MemoryAccess)
 {
     this.AccessType = accessType;
     this.Address    = address;
 }
Exemple #8
0
        public RegisterConditionalOpcode(uint[] blocks)
        {
            /* C0TcSX## */
            /* C0TcS0Ma aaaaaaaa */
            /* C0TcS1Mr */
            /* C0TcS2Ra aaaaaaaa */
            /* C0TcS3Rr */
            /* C0TcS400 VVVVVVVV (VVVVVVVV) */
            /* C0 = opcode 0xC0 */
            /* T = bit width */
            /* c = condition type. */
            /* S = source register. */
            /* X = value operand type, 0 = main/heap with relative offset, 1 = main/heap with offset register, */
            /*     2 = register with relative offset, 3 = register with offset register, 4 = static value. */
            /* M = memory type. */
            /* a = relative address. */
            /* r = offset register. */
            /* V = value */

            BitWidth       = (BitWidthType)GetNibble(blocks[0], 3);
            Condition      = (ConditionalComparisonType)GetNibble(blocks[0], 4);
            SourceRegister = GetNibble(blocks[0], 5);
            OperandType    = GetNibble(blocks[0], 6);
            switch (OperandType)
            {
            case 0:
                MemType         = (MemoryAccessType)GetNibble(blocks[0], 7);
                RelativeAddress = ((ulong)(blocks[0] & 0xF) << 32) | blocks[1];
                break;

            case 1:
                MemType        = (MemoryAccessType)GetNibble(blocks[0], 7);
                OffsetRegister = GetNibble(blocks[0], 8);
                break;

            case 2:
                AddressRegister = GetNibble(blocks[0], 7);
                RelativeAddress = ((ulong)(blocks[0] & 0xF) << 32) | blocks[1];
                break;

            case 3:
                AddressRegister = GetNibble(blocks[0], 7);
                OffsetRegister  = GetNibble(blocks[0], 8);
                break;

            case 4:
                if (BitWidth == BitWidthType.q)
                {
                    Value = (((ulong)blocks[1]) << 32) | blocks[2];
                }
                else
                {
                    Value = blocks[1];
                }
                break;

            case 5:
                OtherRegister = GetNibble(blocks[0], 7);
                break;
            }
        }
Exemple #9
0
 private void LOR(MemoryAccessType mat, Word pos, byte b)
 {
     CurrentExecutingOpcode.MemoryAccessType = mat;
     CurrentExecutingOpcode.Address          = pos;
     CurrentExecutingOpcode.Data             = b;
 }
Exemple #10
0
        private void Access(uint addr, int size, ref byte[] buf, MemoryAccessType access)
        {
            uint offset = 0;

            while (size > 0) {
                int chunksize = Math.Min (size, (int)(MemoryConstants.PAGE_SIZE - addr.GetDisplacement ()));
                this.AccessPageBoundary (addr, chunksize, ref buf, offset, access);

                size -= chunksize;
                offset += (uint)chunksize;
                addr += (uint)chunksize;
            }
        }
Exemple #11
0
 public static extern StreamTypeDescriptor StStreamFindMemoryType(
     ArchitectureSize size, MemoryAccessType accessType,
     MemoryAddressType addressType,
     [MarshalAs(UnmanagedType.I1)] bool hasData);
Exemple #12
0
 /// <summary>
 /// Initializes a new <see cref="Breakpoint"/> instance with the given parameters.
 /// </summary>
 /// <param name="id">A unique ID used to lookup the breakpoint.</param>
 /// <param name="address">The memory address to break at.</param>
 /// <param name="accessType">The access type that triggers the breakpoint.</param>
 public Breakpoint( int id, uint address, MemoryAccessType accessType )
     : this(id, BreakpointType.MemoryAccess)
 {
     this.AccessType = accessType;
     this.Address = address;
 }
Exemple #13
0
 public MemoryPage(uint tag, MemoryAccessType permission)
 {
     this.Tag = tag;
     this.Permission = permission;
     this.Data = new byte[MemoryConstants.PAGE_SIZE];
     this.Next = null;
 }
Exemple #14
0
        private MemoryPage AddPage(uint addr, MemoryAccessType permission)
        {
            MemoryPage page = new MemoryPage (addr.GetTag (), permission);

            page.Next = this[addr.GetIndex ()];
            this[addr.GetIndex ()] = page;
            this.mappedSpace += MemoryConstants.PAGE_SIZE;
            this.maxMappedSpace = Math.Max (this.maxMappedSpace, this.mappedSpace);

            return page;
        }
Exemple #15
0
        private void AccessPageBoundary(uint addr, int size, ref byte[] buf, uint offset, MemoryAccessType access)
        {
            MemoryPage page = this.GetPage (addr);

            if (page == null) {
                throw new SegmentationFaultException (addr);
            }
            if ((page.Permission & access) != access) {
                Logger.Fatalf (Logger.Categories.Memory, "Memory.accessPageBoundary: permission denied at 0x{0:x8}, page.Permission: 0x{1:x8}, access: 0x{2:x8}", addr, page.Permission, access);
            }

            Debug.Assert (addr.GetDisplacement () + size <= MemoryConstants.PAGE_SIZE);

            switch (access) {
            case MemoryAccessType.Read:
            case MemoryAccessType.Execute:
                Array.Copy (page.Data, addr.GetDisplacement (), buf, offset, size);
                break;
            case MemoryAccessType.Write:
            case MemoryAccessType.Init:
                Array.Copy (buf, offset, page.Data, addr.GetDisplacement (), size);
                break;
            default:
                Logger.Panic (Logger.Categories.Memory, "Memory.accessPageBoundary: unknown access");
                break;
            }
        }
Exemple #16
0
        public void UpdatePpuRegions(CartridgeState state)
        {
            List <MemoryRegionInfo> regions = new List <MemoryRegionInfo>();

            MemoryAccessType accessType = MemoryAccessType.Unspecified;
            ChrMemoryType?   memoryType = null;
            int  currentSize            = 0;
            int  startIndex             = 0;
            bool alternateColor         = true;

            Action <int> addSection = (int i) => {
                if (currentSize == 0)
                {
                    return;
                }

                if (memoryType == null)
                {
                    regions.Add(new MemoryRegionInfo()
                    {
                        Name = "N/A", Size = currentSize, Color = Color.FromArgb(222, 222, 222)
                    });
                }
                else if (memoryType == ChrMemoryType.NametableRam)
                {
                    int   page  = (int)(state.ChrMemoryOffset[startIndex] / 0x400);
                    Color color = alternateColor ? Color.FromArgb(0xF4, 0xC7, 0xD4) : Color.FromArgb(0xD4, 0xA7, 0xB4);
                    alternateColor = !alternateColor;
                    regions.Add(new MemoryRegionInfo()
                    {
                        Name = "NT" + page.ToString(), Size = currentSize, Color = color
                    });
                }
                else if (memoryType == ChrMemoryType.ChrRom || memoryType == ChrMemoryType.Default && state.ChrRomSize > 0)
                {
                    int   page  = (int)(state.ChrMemoryOffset[startIndex] / state.ChrPageSize);
                    Color color = alternateColor ? Color.FromArgb(0xC4, 0xE7, 0xD4) : Color.FromArgb(0xA4, 0xD7, 0xB4);
                    alternateColor = !alternateColor;
                    regions.Add(new MemoryRegionInfo()
                    {
                        Name = "$" + page.ToString("X2"), Size = currentSize, Color = color
                    });
                }
                else if (memoryType == ChrMemoryType.ChrRam || memoryType == ChrMemoryType.Default && state.ChrRomSize == 0)
                {
                    int   page  = (int)(state.ChrMemoryOffset[startIndex] / state.ChrRamPageSize);
                    Color color = alternateColor ? Color.FromArgb(0xC4, 0xE0, 0xF4) : Color.FromArgb(0xB4, 0xD0, 0xE4);
                    alternateColor = !alternateColor;
                    regions.Add(new MemoryRegionInfo()
                    {
                        Name = "$" + page.ToString("X2"), Size = currentSize, Color = color, AccessType = accessType
                    });
                }
                currentSize = 0;
                startIndex  = i;
            };

            for (int i = 0; i < 0x30; i++)
            {
                if (state.ChrMemoryAccess[i] != MemoryAccessType.NoAccess)
                {
                    bool forceNewBlock = (
                        (memoryType == ChrMemoryType.NametableRam && state.ChrMemoryOffset[i] % 0x400 == 0) ||
                        (memoryType == ChrMemoryType.ChrRom && state.ChrMemoryOffset[i] % state.ChrPageSize == 0) ||
                        (memoryType == ChrMemoryType.ChrRam && state.ChrMemoryOffset[i] % state.ChrRamPageSize == 0)
                        );

                    if (forceNewBlock || memoryType != state.ChrMemoryType[i] || state.ChrMemoryOffset[i] - state.ChrMemoryOffset[i - 1] != 0x100)
                    {
                        addSection(i);
                    }
                    accessType = state.ChrMemoryAccess[i];
                    memoryType = state.ChrMemoryType[i];
                }
                else
                {
                    if (memoryType != null)
                    {
                        addSection(i);
                    }
                    accessType = MemoryAccessType.Unspecified;
                    memoryType = null;
                }
                currentSize += 0x100;
            }
            addSection(-1);

            UpdateRegionArray(regions);
        }
Exemple #17
0
        public void UpdateCpuRegions(CartridgeState state)
        {
            List <MemoryRegionInfo> regions = new List <MemoryRegionInfo>();

            regions.Add(new MemoryRegionInfo()
            {
                Name = "Internal RAM", Size = 0x2000, Color = Color.FromArgb(222, 222, 222)
            });
            regions.Add(new MemoryRegionInfo()
            {
                Name = "CPU Registers", Size = 0x2020, Color = Color.FromArgb(222, 222, 222)
            });

            Action <int> addEmpty = (int size) => { regions.Add(new MemoryRegionInfo()
                {
                    Name = "N/A", Size = size, Color = Color.FromArgb(222, 222, 222)
                }); };
            Action <int, int, MemoryAccessType> addWorkRam = (int page, int size, MemoryAccessType type) => {
                string name = size >= 0x2000 ? ("Work RAM ($" + page.ToString("X2") + ")") : (size >= 0x800 ? ("$" + page.ToString("X2")) : "");
                regions.Add(new MemoryRegionInfo()
                {
                    Name = name, Size = size, Color = Color.FromArgb(0xCD, 0xDC, 0xFA), AccessType = type
                });
            };
            Action <int, int, MemoryAccessType> addSaveRam = (int page, int size, MemoryAccessType type) => {
                string name = size >= 0x2000 ? ("Save RAM ($" + page.ToString("X2") + ")") : (size >= 0x800 ? ("$" + page.ToString("X2")) : "");
                regions.Add(new MemoryRegionInfo()
                {
                    Name = name, Size = size, Color = Color.FromArgb(0xFA, 0xDC, 0xCD), AccessType = type
                });
            };
            Action <int, int, Color> addPrgRom = (int page, int size, Color color) => { regions.Add(new MemoryRegionInfo()
                {
                    Name = "$" + page.ToString("X2"), Size = size, Color = color
                }); };

            PrgMemoryType?   memoryType = null;
            MemoryAccessType accessType = MemoryAccessType.Unspecified;
            int  currentSize            = 0;
            int  sizeOffset             = -0x20;
            int  startIndex             = 0x40;
            bool alternateColor         = true;

            Action <int> addSection = (int i) => {
                if (currentSize == 0)
                {
                    return;
                }

                int size = currentSize + sizeOffset;
                if (memoryType == null)
                {
                    addEmpty(size);
                }
                else if (memoryType == PrgMemoryType.PrgRom)
                {
                    addPrgRom((int)(state.PrgMemoryOffset[startIndex] / state.PrgPageSize), size, alternateColor ? Color.FromArgb(0xC4, 0xE7, 0xD4) : Color.FromArgb(0xA4, 0xD7, 0xB4));
                    alternateColor = !alternateColor;
                }
                else if (memoryType == PrgMemoryType.WorkRam)
                {
                    addWorkRam((int)(state.PrgMemoryOffset[startIndex] / state.WorkRamPageSize), size, accessType);
                }
                else if (memoryType == PrgMemoryType.SaveRam)
                {
                    if (state.HasBattery)
                    {
                        addSaveRam((int)(state.PrgMemoryOffset[startIndex] / state.SaveRamPageSize), size, accessType);
                    }
                    else
                    {
                        addWorkRam((int)(state.PrgMemoryOffset[startIndex] / state.SaveRamPageSize), size, accessType);
                    }
                }
                sizeOffset  = 0;
                currentSize = 0;
                startIndex  = i;
            };

            for (int i = 0x40; i < 0x100; i++)
            {
                if (state.PrgMemoryAccess[i] != MemoryAccessType.NoAccess)
                {
                    bool forceNewBlock = (
                        (memoryType == PrgMemoryType.PrgRom && state.PrgMemoryOffset[i] % state.PrgPageSize == 0) ||
                        (memoryType == PrgMemoryType.WorkRam && state.PrgMemoryOffset[i] % state.WorkRamPageSize == 0) ||
                        (memoryType == PrgMemoryType.SaveRam && state.PrgMemoryOffset[i] % state.SaveRamPageSize == 0)
                        );

                    if (forceNewBlock || memoryType != state.PrgMemoryType[i] || state.PrgMemoryOffset[i] - state.PrgMemoryOffset[i - 1] != 0x100)
                    {
                        addSection(i);
                    }
                    memoryType = state.PrgMemoryType[i];
                    accessType = state.PrgMemoryAccess[i];
                }
                else
                {
                    if (memoryType != null)
                    {
                        addSection(i);
                    }
                    memoryType = null;
                    accessType = MemoryAccessType.Unspecified;
                }
                currentSize += 0x100;
            }
            addSection(-1);

            UpdateRegionArray(regions);
        }
Exemple #18
0
 public void Map(uint addr, int size, MemoryAccessType permission)
 {
     for (uint tag = addr.GetTag (); tag <= ((uint)(addr + size - 1)).GetTag (); tag += MemoryConstants.PAGE_SIZE) {
         MemoryPage page = this.GetPage (tag);
         if (page == null) {
             page = this.AddPage (tag, permission);
             page.Permission |= permission;
         }
     }
 }