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 '/?<3F>/ Pr <20><><EFBFBD>"1<><31><EFBFBD>"'" Set DEST "{1}"
Set DEST_X "{TempFolder}LinkedPowerROM.x"
If {#} <20>< 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} <20>< {OffsetSoFar}` If {NewOffset} <20>< {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} <20>> {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 <20>"<22>{TempFolder<65>}Zeros_{Delta}.s<>";<3B>t" >> "{TempPrepFile}"
Echo -n 'If !`Exists "{F}"' >> "{TempPrepFile}"
Echo -n "{Streamer}" >> "{TempPrepFile}"
Echo -n '`; ' >> "{TempPrepFile}"
Echo -n "Echo <20><>tDCB.B {Delta}, 0" '> "{F}"; ' >> "{TempPrepFile}"
Echo -n 'PPCAsm "{F}"; ' >> "{TempPrepFile}"
Echo "End" >> "{TempPrepFile}"
Echo -n "<22>t<EFBFBD><74><EFBFBD>n<EFBFBD>t" >> "{TempCmdFile}"
Echo -n "<22>"<22>{TempFolder<65>}Zeros_{Delta}.s.o<>"" >> "{TempCmdFile}"
Set OffsetSoFar {1}
End
Else If "{1}" =~ /([A-Za-z0-9]+)<29>1:/ Else If "{1}" =~ /([A-Za-z0-9]+)<29>1:/
# Label argument Echo "Insert label for linker."
Set Label {<7B>1}
Echo -n "Set F <EFBFBD>"<22>{TempFolder<EFBFBD>}{<7B>1}.s<>";<3B>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 <20><>tEXPORT {<7B>1}<7D><>n{<7B>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 "<22>t<EFBFBD><74><EFBFBD>n<EFBFBD>t" >> "{TempCmdFile}"
Echo -n "<22>"<22>{TempFolder<65>}{<7B>1}.s.o<>"" >> "{TempCmdFile}"
Else Else
# Filename argument Echo "Link this file."
Set F "{1}"
If "{1}" !~ /<2F>.x/ # Convert to an xcoff if necessary
Echo -n "Set F " >> "{TempPrepFile}" If "{F}" !~ /<2F>.x/
Quote -n "{1}" >> "{TempPrepFile}" Echo "Converting to xcoff first."
Echo -n "; " >> "{TempPrepFile}" Set NewPath "`Echo {F} | StreamEdit -d -e '/(<28>:)*([<5B>:]*)<29>1/ print <20>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]+)<29>1b<31>/ Print <20>1'`
Else
Set TheXCOFF "{1}"
Set TextLen `DumpXCOFF -do h "{TheXCOFF}" | StreamEdit -d -e '/s_nameŶ".(<28>)<29>1<EFBFBD>"/ Set CurSec <20>1' -e '/s_sizeŶ((<28>)<29>1<EFBFBD>)/ Print CurSec " " <20>1' | StreamEdit -d -e '/text (<28>)<29>1/ Print <20>1'`
End End
Echo -n "<22>t<EFBFBD><74><EFBFBD>n<EFBFBD>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Ŷ".(<28>)<29>1<EFBFBD>"/ Set CurSec <20>1' -e '/s_sizeŶ((<28>)<29>1<EFBFBD>)/ Print CurSec " " <20>1' | StreamEdit -d -e '/text (<28>)<29>1/ Print <20>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 "<22>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 "<22>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<58>Addr<64>(0x[A-Fa-f0-9]+)<29>1<EFBFBD>ConfigInfoChecksum/ Print <20>1"`"'
Quote -n "{0}.tool"
Echo -n " cksum "
Quote -n "{DestFile}"
Echo ' {CksumOffsets}'

View File

@@ -7,6 +7,12 @@ MainTarget
{LinkerDir}LinkPowerROM.tool <09> {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 <09> {RomBin} {ExceptionTableBin} {ConfigInfoBin} {NKBin} {EmulatorBin} {ResultDir}PowerROM <09> {LinkerDir}LinkPowerROM.tool {RomBin} {ExceptionTableBin} {ConfigInfoBin} {NKBin} {EmulatorBin}
{LinkerDir}LinkPowerROM {Targ} <09> {LinkerDir}LinkPowerROM {Targ} <09>
RomTop: <09> RomTop: <09>
0x000000 Mac68kRomTop: <09> 0x000000 Mac68kRomTop: <09>
@@ -48,7 +54,7 @@ EmulatorBin = Emulator.x
0x300000 ExTblTop: <09> 0x300000 ExTblTop: <09>
{ExceptionTableBin} <09> {ExceptionTableBin} <09>
<09> <09>
0x30d000 ConfigInfoChecksum: <09> 0x30d000 CHECKSUM <09>
{ConfigInfoBin} <09> {ConfigInfoBin} <09>
<09> <09>
0x310000 NKTop: <09> 0x310000 NKTop: <09>
@@ -57,4 +63,4 @@ EmulatorBin = Emulator.x
0x360000 <09> 0x360000 <09>
{EmulatorBin} <09> {EmulatorBin} <09>
0x400000 RomBtm: <09> 0x400000 RomBtm: <09>
> {ResultDir}LinkerScript ; {ResultDir}LinkerScript > Dev:Null # unless you want debug output