flat assembler
Message board for the users of flat assembler.

flat assembler > OS Construction > How to patch labels dynamically?

Author
Thread Post new topic Reply to topic
milind



Joined: 15 Feb 2004
Posts: 33
If my kernel loads a code into memory and executes it, how should the code be compiled. I mean it is not known from before where the code will be placed in memory, so how will the lables and jumps be patched in it dynamically?? So that if there is any jump inside the program it reaches the correct place???
Post 06 Mar 2004, 21:20
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1135
Location: Russian Federation
you need to have relocations for system objects (kernel modules, drivers), much like DLL

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 06 Mar 2004, 22:12
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
I prefer relocations myself, but there's another approach as well - the one typically used by "shared libraries" in *u*x. You use a general-purpose register to point to the loaded imagebase, and access evreything relative to this. This is pretty annoying when coding at assembly level though, where with the GNU GCC compiler it's as easy as passing a command-line argument like "-fPIC".

It's not too bad "losing" a general-purpose register for this, you can always push/pop before and after critical loops where you need all the registers, code pieces could be moved dynamically around in memory if needed, and there's not the (very very tiny) overhead of relocating code on imagebase clashes.

But again, annoying if you don't have automated tools to handle this for you. If coding my own OS, I would definitely support both methods - "support" for "-fPIC" style would be something like putting imagebase in EAX on program start (and well, an app could always use the "delta trick" to get the imagebase manually).
Post 08 Mar 2004, 15:01
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.