Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
The only time you have to worry about addressing, in relation to the jmp instruction, is when you make a far jump (Segment/Selector : Offset). If you aren't changing Segment/Selector then all the offsets should be relative (Any decent assembler will calculate labels as offsets in this scenario) and are therefore unaffected by changes in base address.
Your example would most likely be encoded as 0xEB 0x00 (Note the lack of any absolute address information).
well, so it looks you need a 32 bits offset at the linker and issued an operation with a 16bits offset. Make sure you are in the proper [ bits ] mode, etc.
Is totally independent of the base address your code is linked to, or the address it is loaded at. All it says is to jump 0x500 bytes forward from the end of the jump instruction. Exactly the same goes for using labels (Including the pre-defined ones) because labels are also just immediate values.
If you want to start jumping to actual memory addresses then you MUST use a different form of jmp. Out of preference for simplicity just load a register (eax for example) with the appropriate address and do:
Is it possible to create a section in the linker skript, which is only for this function(s) and have another base address (0x500). Then copy this section to 0x500 and ready? If it is possible I don't know how to code this.
Ok why i will do this is, i want to re-enter realmode, because i'm to stupid to understand how i can do it in another way. My problem is that i've no place in my kernel to setup a 16 bit GDT entry, and I won't recompile etc. my bootloader everytime if I want to change something in my memory maps. So I want to do this in my kernel, in the start.asm (load a new GDT etc., or can I simply load a new in Pmode). see thread: http://www.mega-tokyo.com/forum/index.php?board=1;action=display;threadid=5806
but please don't stop helping me with this thread (copy a function...) perhaps it will be usefull.
ich_will wrote:
That means, i have to know all address (of labels for example), if I want to move the function after linking? Is there no easier way?
No, just the opposite: the only address you need to know is the new function entry point. The rest of the labels are recalculated by the assembler to give an offset relative to the jmp instruction itself, and thus don't need to be changed.
Since the entry point should be at the beginning of the block which you moved the function to, all you need to do is keep track of the new location. If you have more than one such function, you'll probably want a table of some sort for this.