Help understanding PRX sections

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Help understanding PRX sections

Post by m0skit0 »

Hello again!

This time I'm a bit confused about some PRX sections.

.rodata.sceModuleInfo

Is this the correct stucture for this section?

Code: Select all

#define MAX_MODULE_NAME 0x1c

/* .rodata.sceModuleInfo */
typedef struct
{
	Elf32_Half module_attributes;
	Elf32_Half module_version;
	BYTE       module_name[MAX_MODULE_NAME];
	Elf32_Addr gp;
	Elf32_Addr library_entry;
	Elf32_Addr library_entry_end;
	Elf32_Addr library_stubs;
	Elf32_Addr library_stubs_end;
} tModInfoEntry;
The Elf32_Addr, are they actually pointers or am I mistaken the type? File offsets maybe? If they're addresses, how can I relocate them? What is gp used for?

.rel

Code: Select all

/* .rel entry */
typedef struct 
{
    Elf32_Addr r_offset; // Offset of relocation
    Elf32_Word r_info;   // Packed information about relocation
} tRelEntry;

// Defines for the r_info field
#define ELF32_R_ADDR_BASE(i) (((i)> >16) & 0xFF)
#define ELF32_R_OFS_BASE(i) (((i)> >8) & 0xFF)
#define ELF32_R_TYPE(i) (i&0xFF) 
I quite do not understand what are ADDR_BASE and OFS_BASE used for...

Hope you can enlighten me a bit...
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
usertestprueba
Posts: 12
Joined: Tue Sep 15, 2009 6:31 pm
Location: Spain

Post by usertestprueba »

I think nobody knows the answer :-S
(Or maybe they are too lazy to type it here xD)

I think you know more than me about PRXs :-S
Sorry!
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

Of course they know the answer because otherwise they couldn't create an SDK that links PRXs :)

Maybe I'll find something in linker source...
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

There's lots of info out there on ELF files, including MIPS specific ELF. There's no reason for use to answer when a quick google will turn up the info. As stated many times before, we don't give beginner lessons here.
ab5000
Posts: 74
Joined: Tue May 06, 2008 2:37 am

Re: Help understanding PRX sections

Post by ab5000 »

m0skit0 wrote:Hello again!

This time I'm a bit confused about some PRX sections.

.rodata.sceModuleInfo

Is this the correct stucture for this section?

Code: Select all

#define MAX_MODULE_NAME 0x1c

/* .rodata.sceModuleInfo */
typedef struct
{
	Elf32_Half module_attributes;
	Elf32_Half module_version;
	BYTE       module_name[MAX_MODULE_NAME];
	Elf32_Addr gp;
	Elf32_Addr library_entry;
	Elf32_Addr library_entry_end;
	Elf32_Addr library_stubs;
	Elf32_Addr library_stubs_end;
} tModInfoEntry;
Yes, that's ok.
m0skit0 wrote:The Elf32_Addr, are they actually pointers or am I mistaken the type?
They're offsets from relocation.
m0skit0 wrote:What is gp used for?
As you know, usually you need to do a lui/ori to sore a memory address in a registry cause you can use only 16 bits of immediate value.
The compiler just uses a 32KB space for some data (not too big). the $gp is set as the address in the middle of the space. so, if you need to read some data from that space, you can just do an addi: you can move -16KB/+16KB.

Code: Select all

%&#58;include<stdio.h>
int _&#40;int __,int ___,int ____,int _____&#41;
<%for&#40;;____<___;_____=_____*__,____++&#41;;
return _____;%>main&#40;&#41;<%printf
&#40;"%d\n",_&#40;2,5,0,1&#41;&#41;;%>
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

@J.F.: PRXs are not standard ELF neither they have standard MIPS relocation entries. What I'm asking is PRX specific (thus PSP specific), no other ELFs have those entries. Try a Google search about PRX and please tell me if you find something. I didn't, except YAPSPD, which is outdated and sometimes erroneous.

@ab5000: thanks, but I still don't understand the GP thing :P
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
ab5000
Posts: 74
Joined: Tue May 06, 2008 2:37 am

Post by ab5000 »

the compiler allocates a 128KB (not 32KB, i made a mistake) space in data section (or the bss section, don't remeber well now). then it set $gp to the adress in the middle of the space.
the compiler uses those 128KB for storing data. suppose it's at 0xABC00000.
so $gp will be at 0xABC0FFFF.
then if you want to get a word from offset 0 from the start of the space...

Code: Select all

lw $t0, -0xFFFF&#40;$gp&#41;
or if you want a pointer...

Code: Select all

addi $t0, $gp, -0xFFFF
or maybe you want the byte after 65 KB from start...

Code: Select all

lw $t0, 0x401&#40;$gp&#41;
understood?

note that the space isn't exactly 128KB, is 128KB - 1 byte ;)

Code: Select all

%&#58;include<stdio.h>
int _&#40;int __,int ___,int ____,int _____&#41;
<%for&#40;;____<___;_____=_____*__,____++&#41;;
return _____;%>main&#40;&#41;<%printf
&#40;"%d\n",_&#40;2,5,0,1&#41;&#41;;%>
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

m0skit0 wrote:@J.F.: PRXs are not standard ELF neither they have standard MIPS relocation entries. What I'm asking is PRX specific (thus PSP specific), no other ELFs have those entries. Try a Google search about PRX and please tell me if you find something. I didn't, except YAPSPD, which is outdated and sometimes erroneous.
It's not THAT different. If you wish to know the difference, just look at the part of the toolchain that converts the ELF output of the linker into a PRX.
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

About what matters to me (loading code in memory and relocate) it is different. In fact, it has no similarities whatsoever with standards.

Thanks for the advice, that's what I'm doing :)
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Post Reply