forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Variable imports/exports

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Nov 03, 2006 6:43 am    Post subject: Variable imports/exports Reply with quote

Well I have finally got around to working out how to use variable imports in modules, it isn't exactly trivial to setup so I am just putting out the information until I can be arsed to get around to working out how to implement the damn things ;)

I assume the reader knows how the library imports work, I am not going to go over it again :)

If a library has variable imports it sets up an extra pointer after the function and nid pointers are taken care of. This points to a table which has the structures of:
Code:
struct VariableImport {
    u32 *pFixups;
    u32 nid;
};

The table contains a structure like this for each import. The nid value is obviously the value of the NID for the import entry, pFixup points to a mini relocation table which allows the kernel to patch your code to use the variable correctly.

Each fixup table is a list of 32bit integers terminated with a value of 0. Each entry represents one code fixup, the lower 26bits are the address of the fixup dividing by 4, the upper 6 bits correspond to the standard MIPS ELF relocation numbers which indicate what part to fixup, e.g.

Code:
// MIPS Reloc Entry Types
#define R_MIPS_NONE     0
#define R_MIPS_16       1
#define R_MIPS_32       2
#define R_MIPS_REL32    3
#define R_MIPS_26       4
#define R_MIPS_HI16     5
#define R_MIPS_LO16     6

etc...

The value which is inserted at run time is the pointer to the variable as defined by the export process. Therefore it would need to be dereferenced.

Now to do this properly I think would require modifying the toolchain itself, something I am not in the mood to do, therefore my proposed solution is thus.

For every variable you use allocate a single 32bit integer and add the entry to fixup it's value as a whole. This can then be referenced by your code through a direct pointer rather than having to fix it up in the code itself.

So if you export say 'int myvariable;' then in your linked app you would get 'int * const pmyvariable;' Not as clean as I would like but hey them are the breaks. I might see if I can do this sooner or later, it would require some modification to the SDK.

If anyone thinks of a way to implement this properly without toolchain modifications I am all ears ;)
Back to top
View user's profile Send private message
PSP250



Joined: 19 Nov 2005
Posts: 12

PostPosted: Sun Nov 05, 2006 5:01 am    Post subject: Reply with quote

Great explaination. I think this was the last "unknown" part in the import lists thus prxtool could be extended for fully supporting the whole module information.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group