PSY-Q PATCHER version 0.9 ========================= Overview -------- This tool is designed to create medium assembly patches to a PSX executable file, aka, a PSY-Q. The idea is quite simple: you have a modified version of the GNU gas tool, targetted to produce PSX code. So, you write your asm modifications as .s files, compile them to .o files using psx-as, and then, you "link" them together to form the patch using the special linker I wrote. Changelog --------- 0.8: first version ever 0.9: fixed a bug in some R_MIPS_LO/HI16 relocations added raw output Source code and legal stuff --------------------------- psx-as, objdump and readelf were hacked version of binutils. I don't remember what I did exactly, so, please don't bug me about "give me the patch". The only two things that were changed are: support for register aliases (that is, you can put names like $t0 or $v1 instead of the dumb old numbers) and defaulting the .text section alignment to 4 bytes instead of 16. linker uses ELFIO, available at http://elfio.sf.net to read the .o produced by psx-as. If you want its source code, mail-me: pixel@nobis-crew.org so we can get in touch. linker is covered by the GPL license. How it works ------------ First, you need to know the binutils's gas. I provided a short example.s file, so, you can read it to get some pieces of informations about how gas works. Please be aware this is a really advanced tool, that can compute for you a lot of macros and stuff about the mips r3000. Read the example.s for the most important features. Now, the rules for writting a .s file are quite simple: -) Only one .text section per .s file. No .data section nor whatever. -) All symbols are exported. Even the non-globals one. -) Simply use any symbol as if it was existing. No need to pre-define them. Then, compile all your .s files into .o files using the -c option of psx-as: psx-as -c example.s This should produce the file "example.o". Afterward, you have to produce a "map" file, to describe the locations the .o files should be put in. The way the map file works is really simple. I provided an example.map file. The syntax is, line per line: symbol address You can put comments in this file by placing a # at the exact begin of the line you want to comment out. There has to be at least one symbol in each .o file matching one symbol of the map file. This way, the linker can build constraints that will help it placing your file in the PSX memory. Finally, you "link" together all the files, like this for example: linker -i original.exe -o patched.exe -m symbols.map file1.o file2.o If no output (-o) file is provided, the input file will be used. You can also ask linker to change certains parameters of the psy-q file, especially the loading address, the size, and the starting point, by using respectively the command line options -s, -e and -p. Note that -e will tell the ending address, not the size. The size will get computed using the loading address. Note also that you can use symbols instead of absolute addresses here. If no input psy-q file is provided, linker will create a psy-q file from scratch. Then, there are three built-in symboles that will be enventually read from the map file, if the command-line equivalents are not present: start, start_pc, and end. Bugs and limitations -------------------- -) For the relocation R_MIPS_R16 (branch), there is no boundary check. So, the relocation may fail silently. -) The PSY-Q creation from scratch (no input file) is far from beeing complete. -) If two symbols are defined in two different .o file, the latest one will erase silently the first one. -) As a loading side effect, the map file will get enhanced with all the symbols loaded from all the .o files, incrementally. Author ------ Nicolas "Pixel" Noble - http://www.nobis-crew.org Thanks ------ To Neill Corlett, for giving me out this idea a long time ago. To Vincent "Yazoo" Hamm, for giving me the taste of PSX hacking.