Simplify linker script

Previously the MPW linker script would generate a secondary script to be
executed. This was unnecessarily complicated, and it left some junk in
the build tree.
This commit is contained in:
Elliot Nunn 2018-05-21 12:31:06 +08:00
parent 6c199998f0
commit 0d277dc2e3
2 changed files with 77 additions and 125 deletions

View File

@ -1,151 +1,97 @@
Set Streamer " | StreamEdit -d -e '/?Å/ Pr ¶¶¶"1¶¶¶"'" Set DEST "{1}"
Set DEST_X "{TempFolder}LinkedPowerROM.x"
If {#} ¶< 2
Echo "USAGE: {0} DEST SRC ... > ShellScript"
Exit 1
End
Set DestFile "{1}"
Shift Shift
Echo "Hello from LinkPowerROM, the 21st-century PowerMac ROM linker"
Echo "DEST = {DEST}"
Set CTOOL "{0}".tool
Echo "Assuming that {CTOOL} is compiled"
Set TempPrepFile "{TempFolder}PPCROMLinkPrepCmds" Set CurOffset 0 # contains a decimal number throughout
Set TempCmdFile "{TempFolder}PPCROMLinkCmds" Set LinkList "" # contains space-separated quoted xcoff filenames
Echo -n "" > "{TempPrepFile}" Set CksumOffset 0x30d000 # a good default
Echo -n "PPCLink -xm library -codestart 0 -warn -o " > "{TempCmdFile}" Echo "{#} arguments..."
Quote -n "{DestFile}.x" >> "{TempCmdFile}"
Loop
Set OffsetSoFar 0
Set NeedTool 1 # Always extract binary, so always need tool
Loop # over arguments
If !{#} If !{#}
Break Break
End End
Echo ------------------------------
Echo "ARG '{1}'"
If "{1}" =~ /[0-9]+/ || "{1}" =~ /0x[0-9a-f]+/ If "{1}" =~ /[0-9]+/ || "{1}" =~ /0x[0-9a-f]+/
# Move-to-offset argument (hex or decimal literal) Echo "Move to offset."
Set NewOffset `Evaluate "{1}"`
If `Evaluate {1} ¶< {OffsetSoFar}` If {NewOffset} ¶< {CurOffset}
Echo "{0} failed: cannot pad to offset {1} because we are already past it!" Echo "{0} failed: cannot pad to offset {NewOffset} because we are already past it!" >> Dev:Stderr
Exit 1 Exit 1
Else If {NewOffset} ¶> {CurOffset}
Set Delta `Evaluate {NewOffset} - {CurOffset}`
Set F "Zeros_{Delta}.s"
Echo "Create {F}"
Set F "{TempFolder}{F}"
Echo " DCB.B {Delta}, 0" > "{F}"
PPCAsm "{F}"
Set LinkList "{LinkList} '{F}.o'"
Set CurOffset {NewOffset}
End End
Set Delta `Evaluate -h {1} - {OffsetSoFar}`
If {Delta}
Echo -n "Set F ¶"¶{TempFolder¶}Zeros_{Delta}.s¶";¶t" >> "{TempPrepFile}"
Echo -n 'If !`Exists "{F}"' >> "{TempPrepFile}"
Echo -n "{Streamer}" >> "{TempPrepFile}"
Echo -n '`; ' >> "{TempPrepFile}"
Echo -n "Echo ¶¶tDCB.B {Delta}, 0" '> "{F}"; ' >> "{TempPrepFile}"
Echo -n 'PPCAsm "{F}"; ' >> "{TempPrepFile}"
Echo "End" >> "{TempPrepFile}"
Echo -n "¶t¶¶¶n¶t" >> "{TempCmdFile}"
Echo -n "¶"¶{TempFolder¶}Zeros_{Delta}.s.o¶"" >> "{TempCmdFile}"
Set OffsetSoFar {1}
End
Else If "{1}" =~ /([A-Za-z0-9]+)¨1:/ Else If "{1}" =~ /([A-Za-z0-9]+)¨1:/
# Label argument Echo "Insert label for linker."
Set Label {¨1}
Echo -n "Set F ¶"¶{TempFolder¶}{¨1}.s¶";¶t" >> "{TempPrepFile}" Set F "{TempFolder}Label_{Label}.s"
Echo -n 'If !`Exists "{F}"' >> "{TempPrepFile}" Echo " EXPORT {Label}" > "{F}"
Echo -n "{Streamer}" >> "{TempPrepFile}" Echo "{Label}:" >> "{F}"
Echo -n '`; ' >> "{TempPrepFile}" PPCAsm "{F}"
Echo -n "Echo ¶¶tEXPORT {¨1}¶¶n{¨1}" '> "{F}"; ' >> "{TempPrepFile}" Set LinkList "{LinkList} '{F}.o'"
Echo -n 'PPCAsm "{F}"; ' >> "{TempPrepFile}"
Echo "End" >> "{TempPrepFile}" Else If "{1}" == CHECKSUM
Echo "Put the ConfigInfo checksum here."
Set CksumOffset {CurOffset}
Echo -n "¶t¶¶¶n¶t" >> "{TempCmdFile}"
Echo -n "¶"¶{TempFolder¶}{¨1}.s.o¶"" >> "{TempCmdFile}"
Else Else
# Filename argument Echo "Link this file."
Set F "{1}"
If "{1}" !~ /Å.x/ # Convert to an xcoff if necessary
Echo -n "Set F " >> "{TempPrepFile}" If "{F}" !~ /Å.x/
Quote -n "{1}" >> "{TempPrepFile}" Echo "Converting to xcoff first."
Echo -n "; " >> "{TempPrepFile}" Set NewPath "`Echo {F} | StreamEdit -d -e '/(Å:)*([Â:]*)¨1/ print ¨1'`.x"
Echo -n 'If !`Exists "{F}.x"' >> "{TempPrepFile}" Echo "Temporary file {NewPath}"
Echo -n "{Streamer}" >> "{TempPrepFile}" Set NewPath "{TempFolder}{NewPath}"
Echo -n '` || `Newer "{F}" "{F}.x"' >> "{TempPrepFile}" "{CTOOL}" tox "{F}" "{NewPath}"
Echo -n "{Streamer}" >> "{TempPrepFile}" Set F "{NewPath}"
Echo -n '`; ' >> "{TempPrepFile}"
Quote -n "{0}.tool" >> "{TempPrepFile}"
Echo -n ' tox "{F}" "{F}.x"; ' >> "{TempPrepFile}"
Echo "End" >> "{TempPrepFile}"
Set NeedTool 1
Set TheXCOFF "{1}.x"
Set TextLen `Files -x b -n "{1}" | StreamEdit -d -e '/([0-9]+)¨1b°/ Print ¨1'`
Else
Set TheXCOFF "{1}"
Set TextLen `DumpXCOFF -do h "{TheXCOFF}" | StreamEdit -d -e '/s_nameŶ".(Å)¨1¶"/ Set CurSec ¨1' -e '/s_sizeŶ((Å)¨1¶)/ Print CurSec " " ¨1' | StreamEdit -d -e '/text (Å)¨1/ Print ¨1'`
End End
Echo -n "¶t¶¶¶n¶t" >> "{TempCmdFile}"
Quote -n "{TheXCOFF}" >> "{TempCmdFile}"
Set OffsetSoFar `Evaluate {OffsetSoFar} + {TextLen}` Set LinkList "{LinkList} '{F}'"
Set TextLen `DumpXCOFF -do h "{F}" | StreamEdit -d -e '/s_nameŶ".(Å)¨1¶"/ Set CurSec ¨1' -e '/s_sizeŶ((Å)¨1¶)/ Print CurSec " " ¨1' | StreamEdit -d -e '/text (Å)¨1/ Print ¨1'`
Echo -n "File size = "; Evaluate -h {TextLen}
Set CurOffset `Evaluate {CurOffset} + {TextLen}`
End End
Echo -n "CurOffset = "; Evaluate -h {CurOffset}
Shift Shift
End End
If {NeedTool} Echo ------------------------------
Echo "# Compile a C program to create/extract basic XCOFFs"
Echo -n 'If !`Exists '
Quote -n "{0}.tool"
Echo -n "{Streamer}"
Echo '`'
Echo -n "¶tSC " Echo "Running PPCLink..."
Echo -n '-o "{TempFolder}LinkPowerROM.o" ' PPCLink -xm library -codestart 0 -warn -o "{DEST_X}" {LinkList}
Quote "{0}.c"
Echo -n "¶tILink -d -t MPST -c 'MPS ' -o " Echo "Dumping temp xcoff to DEST..."
Quote -n "{0}.tool" "{CTOOL}" fromx "{DEST_X}" "{DEST}"
Echo ' "{Libraries}Stubs.o" "{CLibraries}StdCLib.o" "{Libraries}MacRuntime.o" "{Libraries}IntEnv.o" "{Libraries}Interface.o" "{TempFolder}LinkPowerROM.o"'
Echo "End" Echo "Checksumming DEST..."
Echo "{CTOOL}" cksum "{DEST}" {CksumOffset}
End
Echo "# Auto-generate some XCOFFs (padding and labels)" Echo "All done."
Catenate "{TempPrepFile}"
Echo
Echo "# Link whole-ROM XCOFF"
Catenate "{TempCmdFile}"
Echo
Echo
Echo "# Extract raw ROM binary"
Quote -n "{0}.tool"
Echo -n " fromx "
Quote -n "{DestFile}.x"
Echo -n " "
Quote "{DestFile}"
Echo
Echo "# Checksum the ConfigInfo structure(s)"
Echo -n 'Set CksumOffsets "`DumpXCOFF -do s '
Quote -n "{DestFile}.x"
Echo ' | StreamEdit -d -e "/C_EXTÅAddrÅ(0x[A-Fa-f0-9]+)¨1ÅConfigInfoChecksum/ Print ¨1"`"'
Quote -n "{0}.tool"
Echo -n " cksum "
Quote -n "{DestFile}"
Echo ' {CksumOffsets}'

View File

@ -7,6 +7,12 @@ MainTarget
{LinkerDir}LinkPowerROM.tool Ä {LinkerDir}LinkPowerROM.c
SC -o "{TempFolder}LinkPowerROM.o" {Deps}
ILink -d -t MPST -c 'MPS ' -o {Targ} "{Libraries}Stubs.o" "{CLibraries}StdCLib.o" "{Libraries}MacRuntime.o" "{Libraries}IntEnv.o" "{Libraries}Interface.o" "{TempFolder}LinkPowerROM.o"
RomBin = :RomMondo.bin RomBin = :RomMondo.bin
@ -38,7 +44,7 @@ EmulatorBin = Emulator.x
{ResultDir}PowerROM Ä {RomBin} {ExceptionTableBin} {ConfigInfoBin} {NKBin} {EmulatorBin} {ResultDir}PowerROM Ä {LinkerDir}LinkPowerROM.tool {RomBin} {ExceptionTableBin} {ConfigInfoBin} {NKBin} {EmulatorBin}
{LinkerDir}LinkPowerROM {Targ} ¶ {LinkerDir}LinkPowerROM {Targ} ¶
RomTop: ¶ RomTop: ¶
0x000000 Mac68kRomTop: ¶ 0x000000 Mac68kRomTop: ¶
@ -48,7 +54,7 @@ EmulatorBin = Emulator.x
0x300000 ExTblTop: ¶ 0x300000 ExTblTop: ¶
{ExceptionTableBin} ¶ {ExceptionTableBin} ¶
0x30d000 ConfigInfoChecksum: 0x30d000 CHECKSUM
{ConfigInfoBin} ¶ {ConfigInfoBin} ¶
0x310000 NKTop: ¶ 0x310000 NKTop: ¶
@ -57,4 +63,4 @@ EmulatorBin = Emulator.x
0x360000 ¶ 0x360000 ¶
{EmulatorBin} ¶ {EmulatorBin} ¶
0x400000 RomBtm: ¶ 0x400000 RomBtm: ¶
> {ResultDir}LinkerScript ; {ResultDir}LinkerScript > Dev:Null # unless you want debug output