/// <summary> /// Constructor. /// </summary> /// <param name="traits">The memory traits.</param> /// <param name="sRegion">The unique name of the memory region.</param> /// <param name="regnAddr">The region's (start,end) addresses.</param> /// <param name="memDomain">The memory domain type.</param> /// <param name="memSubDomain">The memory sub-domain type.</param> /// <exception cref="InvalidOperationException">Thrown if the map can't provide the region's /// memory traits.</exception> public MemoryRegionBase(MemTraits traits, string sRegion, AddressRange regnAddr, PICMemoryDomain memDomain, PICMemorySubDomain memSubDomain) { this.Trait = null !; this.traits = traits; RegionName = sRegion; if (regnAddr != null) { LogicalByteAddrRange = regnAddr; PhysicalByteAddrRange = regnAddr; } else { LogicalByteAddrRange = PhysicalByteAddrRange = new AddressRange(Address.Ptr32(0), Address.Ptr32(0)); } TypeOfMemory = memDomain; SubtypeOfMemory = memSubDomain; if (SubtypeOfMemory != PICMemorySubDomain.NNMR) // Non-Memory-Mapped-Registers have no memory characteristics. { if (!this.traits.GetTrait(memDomain, memSubDomain, out IPICMemTrait trait)) { throw new InvalidOperationException($"Missing characteristics for [{memDomain}/{memSubDomain}] memory region '{RegionName}'"); } Trait = trait; } }
/// <summary> /// Gets the memory trait corresponding to the specified memory domain and sub-domain. /// </summary> /// <param name="dom">A memory domain value from the <see cref="PICMemoryDomain"/> enumeration.</param> /// <param name="subdom">A sub-domain value from the <see cref="PICMemorySubDomain"/> enumeration.</param> /// <param name="trait">[out] The memory trait.</param> /// <returns> /// True if it succeeds, false if it fails. /// </returns> public bool GetTrait(PICMemoryDomain dom, PICMemorySubDomain subdom, out IPICMemTrait trait) { if (!maptraits.TryGetValue(new MemoryDomainKey(dom, subdom), out trait)) { trait = memtraitdefault; } return(true); }
public static PICMemoryDomain GetDomain(this PICMemorySubDomain subdom) => (PICMemoryDomain)(subdom2dom[subdom] ?? PICMemoryDomain.Unknown);
public MemoryDomainKey(PICMemoryDomain dom, PICMemorySubDomain subdom) { Domain = dom; SubDomain = subdom; }
/// <summary> /// Instantiates a new data memory region. /// </summary> /// <param name="traits">The memory traits (characteristics).</param> /// <param name="sRegion">The region's name.</param> /// <param name="regnAddr">The region memory address range.</param> /// <param name="memSubDomain">The memory sub-domain code.</param> /// <param name="bankSel">The memory bank selector.</param> public DataMemRegion(MemTraits traits, string sRegion, AddressRange regnAddr, PICMemorySubDomain memSubDomain, Constant bankSel) : base(traits, sRegion, regnAddr, PICMemoryDomain.Data, memSubDomain) { BankSelector = bankSel; }
/// <summary> /// Instantiates a new program memory region. /// </summary> /// <param name="traits">The memory traits (characteristics).</param> /// <param name="sRegion">The region's name.</param> /// <param name="regnAddr">The region memory address range.</param> /// <param name="memSubDomain">The memory sub-domain code.</param> public ProgMemRegion(MemTraits traits, string sRegion, AddressRange regnAddr, PICMemorySubDomain memSubDomain) : base(traits, sRegion, regnAddr, PICMemoryDomain.Prog, memSubDomain) { }
/// <summary> /// Gets the memory trait corresponding to the specified memory sub-domain. /// </summary> /// <param name="subdom">A sub-domain value from the <see cref="PICMemorySubDomain"/> enumeration.</param> /// <param name="trait">[out] The memory trait.</param> /// <returns> /// True if it succeeds, false if it fails. /// </returns> public bool GetTrait(PICMemorySubDomain subdom, out IPICMemTrait trait) => GetTrait(subdom.GetDomain(), subdom, out trait);