diff --git a/src/Emulator/Cores/Arm-M/CortexM.cs b/src/Emulator/Cores/Arm-M/CortexM.cs index 708f58088..7aa75b962 100644 --- a/src/Emulator/Cores/Arm-M/CortexM.cs +++ b/src/Emulator/Cores/Arm-M/CortexM.cs @@ -143,16 +143,16 @@ protected override UInt32 BeforePCWrite(UInt32 value) private void InitPCAndSP() { - var firstNotNullSection = machine.SystemBus.Lookup.FirstNotNullSectionAddress; - if(!vtorInitialized && firstNotNullSection.HasValue) + var firstNotNullSegment = machine.SystemBus.Lookup.FirstNotNullSegmentAddress; + if(!vtorInitialized && firstNotNullSegment.HasValue) { - if((firstNotNullSection.Value & (2 << 6 - 1)) > 0) + if((firstNotNullSegment.Value & (2 << 6 - 1)) > 0) { this.Log(LogLevel.Warning, "Alignment of VectorTableOffset register is not correct."); } else { - var value = firstNotNullSection.Value; + var value = firstNotNullSegment.Value; this.Log(LogLevel.Info, "Guessing VectorTableOffset value to be 0x{0:X}.", value); VectorTableOffset = checked((uint)value); } diff --git a/src/Emulator/Main/Peripherals/Bus/SymbolLookup.cs b/src/Emulator/Main/Peripherals/Bus/SymbolLookup.cs index cc8837dbe..e6d700721 100644 --- a/src/Emulator/Main/Peripherals/Bus/SymbolLookup.cs +++ b/src/Emulator/Main/Peripherals/Bus/SymbolLookup.cs @@ -11,6 +11,7 @@ using ELFSharp.ELF; using ELFSharp.ELF.Sections; +using ELFSharp.ELF.Segments; using Antmicro.Renode.Utilities.Collections; using System.Collections; @@ -154,7 +155,7 @@ public SymbolAddress? EntryPoint private set; } - public ulong? FirstNotNullSectionAddress + public ulong? FirstNotNullSegmentAddress { get; private set; @@ -181,9 +182,9 @@ private void LoadELF(ELF elf, bool useVirtualAddress) where T : struct .Where(x => x.PointedSectionIndex != (uint)SpecialSectionIndex.Undefined).Select(x => new Symbol(x, thumb)); InsertSymbols(elfSymbols); EntryPoint = elf.GetEntryPoint(); - FirstNotNullSectionAddress = elf.Sections - .Where(x => x.Type != SectionType.Null && x.Flags.HasFlag(SectionFlags.Allocatable)) - .Select(x => x.GetSectionPhysicalAddress()) + FirstNotNullSegmentAddress = elf.Segments + .Where(x => x.Type == ELFSharp.ELF.Segments.SegmentType.Load && x.FileSize > 0) + .Select(x => x.GetSegmentPhysicalAddress()) .Cast() .Min(); var segments = elf.Segments.Where(x => x.Type == ELFSharp.ELF.Segments.SegmentType.Load).OfType>(); diff --git a/src/Emulator/Main/Peripherals/Bus/SystemBus.cs b/src/Emulator/Main/Peripherals/Bus/SystemBus.cs index f5ca5089a..2a2e70d0c 100644 --- a/src/Emulator/Main/Peripherals/Bus/SystemBus.cs +++ b/src/Emulator/Main/Peripherals/Bus/SystemBus.cs @@ -497,7 +497,7 @@ public void LoadELF(string fileName, bool useVirtualAddress = false, bool allowL this.DebugLog("Loading ELF {0}.", fileName); using(var elf = GetELFFromFile(fileName)) { - var segmentsToLoad = elf.Segments.Where(x => x.Type == SegmentType.Load); + var segmentsToLoad = elf.Segments.Where(x => x.Type == SegmentType.Load && x.FileSize > 0); if(!segmentsToLoad.Any()) { throw new RecoverableException($"ELF '{fileName}' has no loadable segments.");