Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed VTOR guessing and segment loading #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Emulator/Cores/Arm-M/CortexM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Emulator/Main/Peripherals/Bus/SymbolLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using ELFSharp.ELF;
using ELFSharp.ELF.Sections;
using ELFSharp.ELF.Segments;

using Antmicro.Renode.Utilities.Collections;
using System.Collections;
Expand Down Expand Up @@ -154,7 +155,7 @@ public SymbolAddress? EntryPoint
private set;
}

public ulong? FirstNotNullSectionAddress
public ulong? FirstNotNullSegmentAddress
{
get;
private set;
Expand All @@ -181,9 +182,9 @@ private void LoadELF<T>(ELF<T> 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<ulong?>()
.Min();
var segments = elf.Segments.Where(x => x.Type == ELFSharp.ELF.Segments.SegmentType.Load).OfType<ELFSharp.ELF.Segments.Segment<T>>();
Expand Down
2 changes: 1 addition & 1 deletion src/Emulator/Main/Peripherals/Bus/SystemBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down