Skip to content

Commit

Permalink
Feature: PalmOS support for MacsBug symbols
Browse files Browse the repository at this point in the history
* Moved the MacsBugSymbolScanner.cs from MacOS.csproj to PalmOS.csproj, renaming it to SymbolScanner.cs in the ProcessJumpTable
* Added new assembly, Reko.Libraries.MacsBug, to the solution.
  • Loading branch information
uxmal committed Dec 6, 2023
1 parent aaa8f91 commit 5fb8e03
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 72 deletions.
1 change: 1 addition & 0 deletions src/Drivers/Common.items
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ by the PreBuild.targets file.
<SymbolSources Include="$(SolutionDir)Sources\LGSymLoader\bin\$(Configuration)\Reko.Symbols.LGSymLoader.*" />

<Libraries Include="$(SolutionDir)Libraries\Libc\bin\$(StandardOutputDir)\Reko.Libraries.Libc.*" />
<Libraries Include="$(SolutionDir)Libraries\MacsBug\bin\$(StandardOutputDir)\Reko.Libraries.MacsBug.*" />
<Libraries Include="$(SolutionDir)Libraries\Python\bin\$(StandardOutputDir)\Reko.Libraries.Python.*" />
<Libraries Include="$(SolutionDir)Libraries\Microchip\Utils\bin\$(Configuration)\Reko.Libraries.Microchip.Utils.*" />

Expand Down
19 changes: 9 additions & 10 deletions src/Environments/MacOS/Classic/ResourceFork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
*/
#endregion

using Reko.Arch.M68k;
using Reko.Core;
using Reko.Core.Loading;
using Reko.Core.Memory;
using Reko.Core.Types;
using Reko.Libraries.MacsBug;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -38,10 +37,10 @@ namespace Reko.Environments.MacOS.Classic
/// </summary>
public class ResourceFork
{
private byte[] image;
private MacOSClassic platform;
private IProcessorArchitecture arch;
private ResourceTypeCollection rsrcTypes;
private readonly byte[] image;
private readonly MacOSClassic platform;
private readonly IProcessorArchitecture arch;
private readonly ResourceTypeCollection rsrcTypes;

uint rsrcDataOff;
uint rsrcMapOff;
Expand Down Expand Up @@ -101,9 +100,9 @@ public ResourceReference(ushort rsrcID, string name, uint offset)
public class ResourceTypeCollection : ICollection<ResourceType>
{
private byte[] bytes;
uint rsrcTypeListOff ;
uint rsrcNameListOff;
int crsrcTypes;
uint rsrcTypeListOff ;
uint rsrcNameListOff;
int crsrcTypes;

public ResourceTypeCollection(byte [] bytes, uint offset, uint size)
{
Expand Down Expand Up @@ -391,7 +390,7 @@ private void AddCodeSegment(SortedList<Address, ImageSymbol> symbols, Dictionary
{
segment.Access |= AccessMode.Execute;
codeSegs.Add(rsrc.ResourceID, segment);
var macsBug = new MacsBugSymbolScanner(arch, memSeg);
var macsBug = new SymbolScanner(arch, memSeg);
var mbSymbols = macsBug.ScanForSymbols();
foreach (var symbol in mbSymbols)
{
Expand Down
1 change: 1 addition & 0 deletions src/Environments/MacOS/MacOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<ProjectReference Include="..\..\Arch\M68k\M68k.csproj" />
<ProjectReference Include="..\..\Arch\PowerPC\PowerPC.csproj" />
<ProjectReference Include="..\..\Core\Core.csproj" />
<ProjectReference Include="..\..\Libraries\MacsBug\MacsBug.csproj" />
</ItemGroup>
</Project>
20 changes: 16 additions & 4 deletions src/Environments/PalmOS/PRC/PrcLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Reko.Core.Loading;
using Reko.Core.Memory;
using Reko.Core.Services;
using Reko.Libraries.MacsBug;
using System;
using System.Collections.Generic;
using System.Text;
Expand Down Expand Up @@ -54,24 +55,28 @@ public override Program LoadProgram(Address? addrLoad)
addrLoad ??= PreferredBaseAddress;
var rdr = new BeImageReader(base.RawImage);
var cfgSvc = Services.RequireService<IConfigurationService>();
var arch = cfgSvc.GetArchitecture("m68k")!;

var header = LoadHeader(rdr);
if (header is null)
throw new BadImageFormatException();
var rsrcHeaders = LoadResourceHeaders(rdr, header.num_records);
if (rsrcHeaders is null)
throw new BadImageFormatException();
var (segments, ep) = LoadResources(rdr, rsrcHeaders, addrLoad);
var (segments, ep, symbols) = LoadResources(arch, rdr, rsrcHeaders, addrLoad);
if (segments is null)
throw new BadImageFormatException();

var arch = cfgSvc.GetArchitecture("m68k")!;
var platform = new PalmOSPlatform(Services, arch, "palmOS");
var program = new Program(segments, arch, platform);
if (ep is not null)
{
program.EntryPoints.Add(ep, ImageSymbol.Procedure(arch, ep));
}
foreach (var sym in symbols)
{
program.ImageSymbols[sym.Address] = sym;
}
return program;
}

Expand Down Expand Up @@ -138,9 +143,14 @@ public override Program LoadProgram(Address? addrLoad)
return headers;
}

private (SegmentMap, Address?) LoadResources(BeImageReader rdr, List<ResourceHeader> rsrcHeaders, Address addrBase)
private (SegmentMap, Address?, List<ImageSymbol>) LoadResources(
IProcessorArchitecture arch,
BeImageReader rdr,
List<ResourceHeader> rsrcHeaders,
Address addrBase)
{
var segments = new List<ImageSegment>();
var symbols = new List<ImageSymbol>();
var addr = addrBase;
Address? addrEntrypoint = null;
for (int i = 0; i < rsrcHeaders.Count - 1; ++i)
Expand Down Expand Up @@ -169,14 +179,16 @@ public override Program LoadProgram(Address? addrLoad)
{
addrEntrypoint = addr;
}
var symScanner = new SymbolScanner(arch, mem);
symbols.AddRange(symScanner.ScanForSymbols());
}
}
var seg = new ImageSegment(name, mem, accessMode);
segments.Add(seg);
addr += length; //$TODO: align to even paragraph boundary?
}
var map = new SegmentMap(segments.ToArray());
return (map, addrEntrypoint);
return (map, addrEntrypoint, symbols);
}

private void LoadCode0Resource()
Expand Down
1 change: 1 addition & 0 deletions src/Environments/PalmOS/PalmOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<ItemGroup>
<ProjectReference Include="..\..\Arch\M68k\M68k.csproj" />
<ProjectReference Include="..\..\Core\Core.csproj" />
<ProjectReference Include="..\..\Libraries\MacsBug\MacsBug.csproj" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion src/Environments/PalmOS/Traps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,6 @@ private static DataType CreateParameterType(string arg)
}

DataType dt;
Storage stg;
if (arg.Length == a + 1)
{
switch (arg[a])
Expand Down
12 changes: 7 additions & 5 deletions src/Installers/NuGetPackage/reko-files.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@
<var id="var.Xex.TargetPath" >$SolutionDir$/ImageLoaders/XexLoader/$TargetDir$/Reko.ImageLoaders.Xex.dll</var>
<var id="var.Xbe.TargetPath" >$SolutionDir$/ImageLoaders/Xbe/$TargetDir$/Reko.ImageLoaders.Xbe.dll</var>

<var id="var.LGSymLoader.TargetPath" >$SolutionDir$/Symbols/LGSymLoader/$TargetDir$/Reko.Symbols.LGSymLoader.dll</var>
<var id="var.Libc.TargetPath" >$SolutionDir$/Libraries/Libc/$TargetDir$/Reko.Libraries.Libc.dll</var>
<var id="var.Python.TargetPath" >$SolutionDir$/Libraries/Python/$TargetDir$/Reko.Libraries.Python.dll</var>
<var id="var.LGSymLoader.TargetPath">$SolutionDir$/Symbols/LGSymLoader/$TargetDir$/Reko.Symbols.LGSymLoader.dll</var>
<var id="var.Libc.TargetPath">$SolutionDir$/Libraries/Libc/$TargetDir$/Reko.Libraries.Libc.dll</var>
<var id="var.MacsBug.TargetPath">$SolutionDir$/Libraries/MacsBug/$TargetDir$/Reko.Libraries.MacsBug.dll</var>
<var id="var.Python.TargetPath">$SolutionDir$/Libraries/Python/$TargetDir$/Reko.Libraries.Python.dll</var>

<var id="var.Scripts.Python.ProjectDir" >$SolutionDir$/Scripts/Python/</var>
<var id="var.Scripts.Python.TargetPath" >$SolutionDir$/Scripts/Python/$TargetDir$/Reko.Scripts.Python.dll</var>
<var id="var.Scripts.Python.ProjectDir">$SolutionDir$/Scripts/Python/</var>
<var id="var.Scripts.Python.TargetPath">$SolutionDir$/Scripts/Python/$TargetDir$/Reko.Scripts.Python.dll</var>
</vars>

<Component Id="ProductComponent" Guid="9C3E003B-43CB-47B3-B5B8-DC6373A38AE1">
Expand Down Expand Up @@ -333,6 +334,7 @@

<!-- Libraries -->
<File Source="$(var.Libc.TargetPath)" nuget_target="f:" />
<File Source="$(var.MacsBug.TargetPath)" nuget_target="f:" />
<File Source="$(var.Python.TargetPath)" nuget_target="f:" />
<File Source="$(var.Microchip.Utils.TargetPath)" nuget_target="f:" />

Expand Down
17 changes: 17 additions & 0 deletions src/Libraries/MacsBug/MacsBug.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(ProjectDir)../../Drivers/CommonBuildProperties.items"/>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Reko.Libraries.MacsBug</RootNamespace>
<AssemblyName>Reko.Libraries.MacsBug</AssemblyName>
<TargetFramework>net6.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Core.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Reko.Core;
using Reko.Core.Lib;
using System.Text.RegularExpressions;
using Reko.Core.Memory;
using Reko.Core.Loading;
using Reko.Core.Memory;
using System.Text;
using System.Text.RegularExpressions;

namespace Reko.Environments.MacOS.Classic
namespace Reko.Libraries.MacsBug
{
/*
MacsBug accepts and returns addresses as procedure names and offsets.
Expand Down Expand Up @@ -77,7 +72,7 @@ procedure in memory. The first word after the name specifies how many bytes
of constant data are present. If there are no constants, a length of 0
must be given.
*/
public class MacsBugSymbolScanner
public class SymbolScanner
{
public const ushort LINK = 0x4E56;
public const ushort RTS = 0x4E75;
Expand All @@ -88,7 +83,7 @@ public class MacsBugSymbolScanner
private readonly EndianImageReader rdr;
private readonly Regex reValidVariableLengthProcedureName;

public MacsBugSymbolScanner(IProcessorArchitecture arch, ByteMemoryArea mem)
public SymbolScanner(IProcessorArchitecture arch, ByteMemoryArea mem)
{
this.arch = arch;
this.rdr = mem.CreateBeReader(0);
Expand Down
Loading

0 comments on commit 5fb8e03

Please sign in to comment.