Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why iopmod-link is not adding .iopmod section it-sellf? #12

Open
fjtrujy opened this issue Dec 13, 2022 · 1 comment
Open

Why iopmod-link is not adding .iopmod section it-sellf? #12

fjtrujy opened this issue Dec 13, 2022 · 1 comment

Comments

@fjtrujy
Copy link

fjtrujy commented Dec 13, 2022

Hello,

I was trying to go deeper using your marvelous tool, because it is a waste of effort and time to keep using the modified binutils/gcc version for the IOP CPU (speaking about the PS2DEV env).

We have been working separately, @rickgaiser, @uyjulian, myself, and probably more people, into trying to achieve something similar, using several approaches.

I honestly think that the best way is the way you are doing it, creating a tinny C app that makes the necessary changes to the ELF to adjust to the IOP requirements.

The first thing that I have found is that the iopmod-link is not creating the .iopmod section.
I was expecting that having _irx_id symbol in the binary, should be enough to have all the needed information for creating the .iopmod section, or maybe I'm confused....

Having the next example

#include <stdint.h>

struct irx_id {
	const char *n;
	uint16_t v;
};

#define IRX_VER(major, minor)	((((major) & 0xff) << 8) + ((minor) & 0xff))

struct irx_id _irx_id = {
    "DUMMY", 
    IRX_VER(2, 1)
};

int _start(int argc, char *argv[]) {
    return 0;
}

And compile it using:

mipsel-ps2-elf-gcc -D_IOP -fno-builtin -G0 -Wall  -I/Users/fjtrujy/toolchains/ps2/ps2dev/ps2sdk/iop/include -DDEBUG -O0 -g -msoft-float -mno-explicit-relocs -c main.c -o obj/main.o
mipsel-ps2-elf-gcc -D_IOP -fno-builtin -G0 -Wall  -I/Users/fjtrujy/toolchains/ps2/ps2dev/ps2sdk/iop/include -DDEBUG -O0 -g -msoft-float -mno-explicit-relocs -o dummy.elf obj/main.o -nostdlib

Then if we execute:

mipsel-ps2-elf-readelf -Ws dummy.elf | grep _irx_id
    20: 001000cc     8 OBJECT  GLOBAL DEFAULT    5 _irx_id

We have from there the offset where the information about the IRX_ID it is on the binary.

What do you think?

@frno7
Copy link
Owner

frno7 commented Dec 14, 2022

The iopmod-link tool was made simpler by putting most of the logic, including the .iopmod section, into the script/iop.ld linker script:

iopmod/script/iop.ld

Lines 15 to 24 in a5d2360

.iopmod 0 (COPY) : ALIGN(4) {
LONG (DEFINED(_module_id) ? _module_id : 0xffffffff);
LONG (_module_init);
LONG (_unknown); /* FIXME */
LONG (SIZEOF(.text));
LONG (SIZEOF(.data));
LONG (SIZEOF(.bss));
KEEP(*(.module.version))
KEEP(*(.module.name))
} :iopmod

I put some effort into making the whole IOP module command suite compatible with PS2DEV. So, for example, thbase_create that a Linux driver might use, is also, as an alias, perfectly linkable as CreateThread for PS2DEV drivers:

id_(4) int thbase_create(const struct iop_thread *thread)
alias_(CreateThread);
id_(5) int thbase_delete(int thid)
alias_(DeleteThread);

I’ve only enumerated a small subset of all IOP functions so far, though. The module init/exit code is simplified and streamlined compared to PS2DEV. The intention was that only minor changes were needed to compile PS2DEV code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants