powermac-rom/Linker/LinkPowerROM

152 lines
4.1 KiB
Plaintext
Raw Normal View History

2017-11-19 04:11:07 +00:00
Set Streamer " | StreamEdit -d -e '/?<3F>/ Pr <20><><EFBFBD>"1<><31><EFBFBD>"'"
If {#} <20>< 2
Echo "USAGE: {0} DEST SRC ... > ShellScript"
Exit 1
End
Set DestFile "{1}"
Shift
Set TempPrepFile "{TempFolder}PPCROMLinkPrepCmds"
Set TempCmdFile "{TempFolder}PPCROMLinkCmds"
Echo -n "" > "{TempPrepFile}"
Echo -n "PPCLink -xm library -codestart 0 -warn -o " > "{TempCmdFile}"
Quote -n "{DestFile}.x" >> "{TempCmdFile}"
Set OffsetSoFar 0
Set NeedTool 1 # Always extract binary, so always need tool
Loop # over arguments
If !{#}
Break
End
If "{1}" =~ /[0-9]+/ || "{1}" =~ /0x[0-9a-f]+/
# Move-to-offset argument (hex or decimal literal)
If `Evaluate {1} <20>< {OffsetSoFar}`
Echo "{0} failed: cannot pad to offset {1} because we are already past it!"
Exit 1
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:/
# Label argument
Echo -n "Set F <20>"<22>{TempFolder<65>}{<7B>1}.s<>";<3B>t" >> "{TempPrepFile}"
Echo -n 'If !`Exists "{F}"' >> "{TempPrepFile}"
Echo -n "{Streamer}" >> "{TempPrepFile}"
Echo -n '`; ' >> "{TempPrepFile}"
Echo -n "Echo <20><>tEXPORT {<7B>1}<7D><>n{<7B>1}" '> "{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>}{<7B>1}.s.o<>"" >> "{TempCmdFile}"
Else
# Filename argument
If "{1}" !~ /<2F>.x/
Echo -n "Set F " >> "{TempPrepFile}"
Quote -n "{1}" >> "{TempPrepFile}"
Echo -n "; " >> "{TempPrepFile}"
Echo -n 'If !`Exists "{F}.x"' >> "{TempPrepFile}"
Echo -n "{Streamer}" >> "{TempPrepFile}"
Echo -n '` || `Newer "{F}" "{F}.x"' >> "{TempPrepFile}"
Echo -n "{Streamer}" >> "{TempPrepFile}"
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
Echo -n "<22>t<EFBFBD><74><EFBFBD>n<EFBFBD>t" >> "{TempCmdFile}"
Quote -n "{TheXCOFF}" >> "{TempCmdFile}"
Set OffsetSoFar `Evaluate {OffsetSoFar} + {TextLen}`
End
Shift
End
If {NeedTool}
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 -n '-o "{TempFolder}LinkPowerROM.o" '
Quote "{0}.c"
Echo -n "<22>tILink -d -t MPST -c 'MPS ' -o "
Quote -n "{0}.tool"
Echo ' "{Libraries}Stubs.o" "{CLibraries}StdCLib.o" "{Libraries}MacRuntime.o" "{Libraries}IntEnv.o" "{Libraries}Interface.o" "{TempFolder}LinkPowerROM.o"'
Echo "End"
Echo
End
Echo "# Auto-generate some XCOFFs (padding and labels)"
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}'