public static TMemoryModelRegion RegionByAddress(long aAddress) { TMemoryModelRegion region = TMemoryModelRegion.EMemoryModelRegionUnknown; // TMemoryModelType type = TypeByAddress(aAddress); if (type != TMemoryModelType.EMemoryModelUnknown) { region = RegionByAddress(aAddress, type); } // return(region); }
protected override void CleanupManagedResources() { try { base.CleanupManagedResources(); } finally { // When we aren't sure if we're being used to harmonise an XIP collection // we must check whether the base address has been set to something other than // zero and that the address is in the XIP range. // NB: Other cases are handled in the constructor. if (iType == TCollectionType.EPossiblyXIP) { if (!iCollection.IsEmptyApartFromDefaultSymbol) { Symbol first = iCollection.FirstSymbol; uint address = first.Address; if (address > 0) { TMemoryModelRegion region = MMUtilities.RegionByAddress(address); bool isFixed = (region == TMemoryModelRegion.EMemoryModelRegionROM); iCollection.IsFixed = isFixed; } else { // First address is zero, indicates RAM-loaded code and therefore // non-XIP. iCollection.IsFixed = false; } } else { // The collection only contains the default symbol so in that case // it can be thought to be relocatable (although in practise that wouldn't // be very helpful). The main point is that we don't want this collection // to start matching null addresses (quite common when performing symbolic // lookup). iCollection.IsFixed = false; } } } }
public static TMemoryModelRegion RegionByAddress(long aAddress, TMemoryModelType aType) { TMemoryModelRegion ret = TMemoryModelRegion.EMemoryModelRegionUnknown; // if (aType == TMemoryModelType.EMemoryModelMoving) { #region Moving Memory Model if (aAddress >= 0x00000000 && aAddress < 0x003FFFFF) { // 00000000-003FFFFF Unmapped ret = TMemoryModelRegion.EMemoryModelRegionUnmapped; } else if (aAddress >= 0x00400000 && aAddress < 0x2FFFFFFF) { // 00400000-2FFFFFFF Moving process data ret = TMemoryModelRegion.EMemoryModelRegionMovingProcessData; } else if (aAddress >= 0x30000000 && aAddress < 0x3FFFFFFF) { // 30000000-3FFFFFFF DLL static data (=phys ram size/2 up to 128M, always ends at 40000000) ret = TMemoryModelRegion.EMemoryModelRegionDLLStaticData; } else if (aAddress >= 0x40000000 && aAddress < 0x5FFFFFFF) { // 40000000-5FFFFFFF RAM drive ret = TMemoryModelRegion.EMemoryModelRegionRAMDrive; } else if (aAddress >= 0x60000000 && aAddress < 0x60001FFF) { // 60000000-60001FFF Super page/CPU page ret = TMemoryModelRegion.EMemoryModelRegionSuperAndCPUPages; } else if (aAddress >= 0x61000000 && aAddress < 0x61003FFF) { // 61000000-61003FFF Page directory (16K) ret = TMemoryModelRegion.EMemoryModelRegionPageDirectories; } else if (aAddress >= 0x61020000 && aAddress < 0x6103FFFF) { // 61020000-6103FFFF Page table info (4096 * 8bytes = 32K) ret = TMemoryModelRegion.EMemoryModelRegionPageTableInfo; } else if (aAddress >= 0x61100000 && aAddress < 0x611FFFFF) { // 61100000-611FFFFF Cache flush area ret = TMemoryModelRegion.EMemoryModelRegionCacheFlushArea; } else if (aAddress >= 0x61200000 && aAddress < 0x612FFFFF) { // 61200000-612FFFFF Alternate cache flush area ret = TMemoryModelRegion.EMemoryModelRegionCacheFlushAreaAlternate; } else if (aAddress >= 0x62000000 && aAddress < 0x623FFFFF) { // 62000000-623FFFFF Page tables (up to 4096 * 1K) ret = TMemoryModelRegion.EMemoryModelRegionPageTables; } else if (aAddress >= 0x63000000 && aAddress < 0x63FFFFFF) { // 63000000-63FFFFFF Primary I/O mappings ret = TMemoryModelRegion.EMemoryModelRegionPrimaryIOMappings; } else if (aAddress >= 0x64000000 && aAddress < 0x64FFFFFF) { // 64000000-64FFFFFF Kernel .data/.bss, initial stack, kernel heap ret = TMemoryModelRegion.EMemoryModelRegionKernelGlobalsInitialStackKernelHeap; } else if (aAddress >= 0x65000000 && aAddress < 0x655FFFFF) { // 65000000-655FFFFF fixed processes - usually 2 or 3Mb each. ret = TMemoryModelRegion.EMemoryModelRegionFixedProcesses; } else if (aAddress >= 0x65600000 && aAddress < 0xF1FFFFFF) { // 65600000-F1FFFFFF Kernel section (includes extra I/O mappings) ret = TMemoryModelRegion.EMemoryModelRegionExtraKernelMappings; } else if (aAddress >= 0xF2000000 && aAddress < 0xF3FFFFFF) { // F2000000-F3FFFFFF Kernel code (RAM size/2) ret = TMemoryModelRegion.EMemoryModelRegionKernelCode; } else if (aAddress >= 0xF4000000 && aAddress < 0xF7FFFFFF) { // F4000000-F7FFFFFF User code (RAM size) ret = TMemoryModelRegion.EMemoryModelRegionUserCode; } else if (aAddress >= 0xF8000000 && aAddress < 0xFFEFFFFF) { // F8000000-FFEFFFFF ROM ret = TMemoryModelRegion.EMemoryModelRegionROM; } else if (aAddress >= 0xFFF00000 && aAddress < 0xFFFFFFFF) { // FFF00000-FFFFFFFF Exception vectors ret = TMemoryModelRegion.EMemoryModelRegionExceptionVectors; } #endregion } else if (aType == TMemoryModelType.EMemoryModelMultiple) { #region Multiple Memory Model if (aAddress >= 0x00000000 && aAddress < 0x003FFFFF) { // 00000000-003FFFFF Unmapped ret = TMemoryModelRegion.EMemoryModelRegionUnmapped; } else if (aAddress >= 0x00400000 && aAddress < 0x6FFFFFFF) { // Skip overlapping 2gb vs 1gb regions ret = TMemoryModelRegion.EMemoryModelRegionUnknown; } else if (aAddress >= 0x70000000 && aAddress < 0x7FFFFFFF) { // 70000000-7FFFFFFF RAM Loaded Code ret = TMemoryModelRegion.EMemoryModelRegionRAMLoadedCode; } else if (aAddress >= 0x80000000 && aAddress < 0x8FFFFFFF) { // 80000000-8FFFFFFF ROM ret = TMemoryModelRegion.EMemoryModelRegionROM; } else if (aAddress >= 0x90000000 && aAddress < 0x9FFFFFFF) { // 90000000-9FFFFFFF User Global Area ret = TMemoryModelRegion.EMemoryModelRegionUserGlobalArea; } else if (aAddress >= 0xA0000000 && aAddress < 0xBFFFFFFF) { // A0000000-BFFFFFFF RAM drive ret = TMemoryModelRegion.EMemoryModelRegionRAMDrive; } else if (aAddress >= 0xC0000000 && aAddress < 0xC0001FFF) { // C0000000-C0001FFF Super page/CPU page ret = TMemoryModelRegion.EMemoryModelRegionSuperAndCPUPages; } else if (aAddress >= 0xC0040000 && aAddress < 0xC00403FF) { // C0040000-C00403FF ASID info (256 ASIDs) ret = TMemoryModelRegion.EMemoryModelRegionASIDInfo; } else if (aAddress >= 0xC0080000 && aAddress < 0xC00FFFFF) { // C0080000-C00FFFFF Page table info ret = TMemoryModelRegion.EMemoryModelRegionPageTableInfo; } else if (aAddress >= 0xC1000000 && aAddress < 0xC13FFFFF) { // C1000000-C13FFFFF Page directories (up to 256 * 16KB) ret = TMemoryModelRegion.EMemoryModelRegionPageDirectories; } else if (aAddress >= 0xC2000000 && aAddress < 0xC5FFFFFF) { // C2000000-C5FFFFFF Page tables ret = TMemoryModelRegion.EMemoryModelRegionPageTables; } else if (aAddress >= 0xC6000000 && aAddress < 0xC6FFFFFF) { // C6000000-C6FFFFFF Primary I/O mappings ret = TMemoryModelRegion.EMemoryModelRegionPrimaryIOMappings; } else if (aAddress >= 0xC7000000 && aAddress < 0xC7FFFFFF) { // C7000000-C7FFFFFF ret = TMemoryModelRegion.EMemoryModelRegionUnknown; } else if (aAddress >= 0xC8000000 && aAddress < 0xC8FFFFFF) { // C8000000-C8FFFFFF Kernel .data/.bss, initial stack, kernel heap ret = TMemoryModelRegion.EMemoryModelRegionKernelGlobalsInitialStackKernelHeap; } else if (aAddress >= 0xC9000000 && aAddress < 0xC91FFFFF) { // C9000000-C91FFFFF Kernel stacks ret = TMemoryModelRegion.EMemoryModelRegionKernelStacks; } else if (aAddress >= 0xC9200000 && aAddress < 0xFFEFFFFF) { // C9200000-FFEFFFFF Extra kernel mappings (I/O, RAM loaded device drivers) ret = TMemoryModelRegion.EMemoryModelRegionExtraKernelMappings; } else if (aAddress >= 0xFFF00000 && aAddress < 0xFFFFFFFF) { // FFF00000-FFFFFFFF Exception vectors ret = TMemoryModelRegion.EMemoryModelRegionExceptionVectors; } #endregion } // return(ret); }
private bool PreFilterBasedUponFlags(Symbol aSymbol) { // Do we need to update the length of the previous symbol? if ((iFlags & TFlags.EFlagsUpdateLengthOfPreviousSymbol) == TFlags.EFlagsUpdateLengthOfPreviousSymbol) { FlagBasedUpdateOfLastSymbolLength(aSymbol); } // Check for Image$$ER_RO$$Base // This symbol is emitted for user-side code and can be used to work around some maksym problems. string symbolName = aSymbol.Name; if (symbolName == KSectionNameUserBase) { int count = iCollection.Count; if (!iCollection.IsEmptyApartFromDefaultSymbol) { // Discard all the entries we've seen so far because most likely // they are invalid. System.Diagnostics.Debug.WriteLine(string.Format("Discarding {0} invalid symbols for library: {1}", count, iCollection.FileName)); iCollection.Clear(); // At this point, we need to reset the base address because any symbols that have gone // before are invalid. iFlags &= ~TFlags.EFlagsHaveSetXIPBaseAddress; } } // Do we need to set the base address for the symbol collection? bool haveSetXIPBase = ((iFlags & TFlags.EFlagsHaveSetXIPBaseAddress) == TFlags.EFlagsHaveSetXIPBaseAddress); if (!haveSetXIPBase && iType != TCollectionType.ENotXIP) { // If we're seeing the first valid symbol, then try to set the base address bool needToSet = true; if (iType == TCollectionType.EPossiblyXIP) { // Perhaps we're dealing with an XIP collection. In which case, we need to check // with the memory model utility to decide if it really is or not. // // If the symbol address is zero (NULL), then we can't be dealing with an // XIP collection. if (aSymbol.Address == 0) { // ROFS needToSet = true; } else { TMemoryModelRegion region = MMUtilities.RegionByAddress(aSymbol.Address); needToSet = (region == TMemoryModelRegion.EMemoryModelRegionROM); } } if (needToSet) { SetCollectionBaseAddress(aSymbol); } } bool disallowNewSymbols = (iFlags & TFlags.EFlagsDisallowFurtherSymbolsForCollection) == TFlags.EFlagsDisallowFurtherSymbolsForCollection; return(!disallowNewSymbols); }