Open Hinkiii opened 7 months ago
Hey! Thanks for your bug report.
Sadly create_config
currently does not support generating a yaml for PS2 games. You'll have to create a yaml from scratch. You could use kh1's yaml as a reference: https://github.com/ethteck/kh1
I agree the script should probably give an error message for not supported formats tho.
There was talk of reading some data from the ELF header to distinguish different elf types.. i think that checking the arch is 5900 seems good enough?
$ mips-linux-gnu-objdump -x SCUS_974.72
SCUS_974.72: file format elf32-tradlittlemips
SCUS_974.72
architecture: mips:5900, flags 0x00000102:
EXEC_P, D_PAGED
start address 0x00100010
Program Header:
0x70000000 off 0x00032bb4 vaddr 0x00131bb4 paddr 0x00131bb4 align 2**2
filesz 0x00000018 memsz 0x00000018 flags r--
LOAD off 0x00001000 vaddr 0x00100000 paddr 0x00100000 align 2**12
filesz 0x00031bcc memsz 0x00031bcc flags rwx
LOAD off 0x00032c00 vaddr 0x00131c00 paddr 0x00131c00 align 2**12
filesz 0x00008580 memsz 0x00038798 flags rw-
private flags = 20924001: [abi=EABI64] [mips3] [not 32bitmode] [noreorder]
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00031bac 00100000 00100000 00001000 2**6
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .text_nop 00000008 00131bac 00131bac 00032bac 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .reginfo 00000018 00131bb4 00131bb4 00032bb4 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA, LINK_ONCE_SAME_SIZE
3 .data 000044cc 00131c00 00131c00 00032c00 2**7
CONTENTS, ALLOC, LOAD, DATA
4 .ctors 00000008 001360cc 001360cc 000370cc 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .dtors 00000008 001360d4 001360d4 000370d4 2**2
CONTENTS, ALLOC, LOAD, DATA
6 .eh_frame 00000004 001360e0 001360e0 000370e0 2**3
CONTENTS, ALLOC, LOAD, DATA
7 .rodata 00003c58 00136100 00136100 00037100 2**4
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .lit4 00000004 00139d80 00139d80 0003ad80 2**2
CONTENTS, ALLOC, LOAD, DATA
9 .data_nop 00000008 00139d84 00139d84 0003ad84 2**0
CONTENTS, ALLOC, LOAD, DATA
10 .sdata 00000380 00139e00 00139e00 0003ae00 2**3
CONTENTS, ALLOC, LOAD, DATA
11 .sbss 00000010 0013a180 0013a180 0003b180 2**2
ALLOC
12 .bss 00030198 0013a200 0013a200 0003b1f0 2**7
ALLOC
13 .mdebug.eabi64 00000000 00000000 00000000 0003b1f0 2**0
CONTENTS, READONLY
SYMBOL TABLE:
no symbols
Specifically looking at the e_flags
(see EF_MIPS_MACH_5900 = 0x00920000, // MIPS R5900).
>>> with open("SCUS_974.72", "rb") as f:
... data = f.read()
>>> int.from_bytes(data[0x24:0x28], byteorder="little") & 0x00920000 == 0x00920000
True
Believe the accurate flags will be 0x2092xxxx 0x20000000 for EF_MIPS_ARCH_3 (MIPS3 instruction set) 0x00920000 for EF_MIPS_MACH_5900 (MIPS R5900)
EABI seems to sometimes vary between binaries, but very commonly is in 64 bit mode (0x4000).
I confirmed with Kingdom Hearts, Kingdom Hearts Re:Chain of Memories, and Sly Cooper, all of which have the flag 0x20924001. Kingdom Hearts 2 was an outlier in the KH series with the flag 0x20920001, seemingly not setting an eabi flag. Both Radiata Stories and Rogue Galaxy, compiled with MWCCPS2 instead of ee-gcc, similarly had the flag 0x20924000.
My thoughts for just looking for 0x0092 was that it should be enough without having to worry about any edge cases. As it stands create_config doesn't support ps2, so the 5900 arch would be sufficient. Ps2 and onwards are going to see more games written in c++ than plain c, so I'm not sure how many more platforms can be added without major work
I'm not aware of any other device ever using r5900 besides ps2, so that's probably completely accurate enough as is, though I think that 0x20000000 would always be present for ps2, since EE utilizes a custom variation of mips 3, leading the check to be for 0x2092 rather than 0x0092. Another possible benefit from the elf header on ps2, though I'm uncertain if it would be something parseable during create_config, is the e_entry pointing to the initial segment of the crt0.s file, which distinctly provides information such as the the address that the bss segment begins, the main function, and the address that the binary officially begins, such as 0x88 for KH or 0x1008 for Parappa, as a couple examples, which -8 to account for padding would provide the address for the first subsegment split of a given ps2 binary, like kh1's [0x80, asm, crt0] and Parappa's [0x1000, asm, sce/crt0]
C:\Users\mynam\mygame>py -3.10 -m splat create_config SLPM_661.32
C:\Users\mynam\mygame>
nothing