flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > Backawrd jumps in ELF (16 bit) |
Author |
|
DOS386 14 Jul 2007, 04:49
I wonder what OS would load and allow execution of this ELF-16
|
|||
14 Jul 2007, 04:49 |
|
Jeronimus Linuxius 14 Jul 2007, 16:39
NTOSKRNL_VXE wrote: I wonder what OS would load and allow execution of this ELF-16 :? Duh! Now, another obvious point, in case you don't get it... This will be linked with some C code compiled by gcc, that's why I don't use format bin. JJ |
|||
14 Jul 2007, 16:39 |
|
LocoDelAssembly 14 Jul 2007, 17:16
The problem is that the destination address is above of the limit of 16-bit numbers. I again forgot the exact reason (Alzheimer is killing me), but I think it has something to do with the fact that a 16-bit jump only does "IP = IP + rel" but it is required to do "EIP = EIP + rel". You can use "jnz dword @b" and that way it will work (but note that on 16-bit mode it will use EIP and on 32-bit mode it will use IP). Aditionally you can adjust the origin to something below 64K (though, this kills relocations, I think). Anyway I think you will have more troubles in future because the format is intended for 32-bit code, there is no 16-bit relocations so I don't know how your object will work with non-relative references.
If it's possible for you make a loader that sets up the processor to 32-bit and loads your linked elf. |
|||
14 Jul 2007, 17:16 |
|
LocoDelAssembly 14 Jul 2007, 18:47
Now that I took my pills:
http://board.flatassembler.net/topic.php?p=55118#55118 http://board.flatassembler.net/topic.php?t=5162 |
|||
14 Jul 2007, 18:47 |
|
Jeronimus Linuxius 14 Jul 2007, 21:58
LocoDelAssembly wrote: Anyway I think you will have more troubles in future because the format is intended for 32-bit code, there is no 16-bit relocations so I don't know how your object will work with non-relative references. Quote: If it's possible for you make a loader that sets up the processor to 32-bit and loads your linked elf. JJ |
|||
14 Jul 2007, 21:58 |
|
LocoDelAssembly 14 Jul 2007, 22:43
Quote:
Too bad, that means that them don't care about the zeroing of the upper 16 bits of EIP. Quote:
Well something like Code: format ELF section ".text16" executable _start16: file 'stub.bin' ; CF=0 if switching to 32-bit protected mode was successful jc error jmp _start32 ; Not simple jnc _start32 because if the label is too far a 32-bit rel will be generated but 16-bit mode will wrongly interpret it as 16-bit rel. The "jc error" has no problems because the error label is very near and the encoding is the same for both modes. error: use16 ; Handle error here . . . |
|||
14 Jul 2007, 22:43 |
|
Jeronimus Linuxius 14 Jul 2007, 23:56
LocoDelAssembly wrote:
Quote:
Quote: Could work. Remember to make the stub position independent. JJ |
|||
14 Jul 2007, 23:56 |
|
LocoDelAssembly 15 Jul 2007, 03:27
Quote: I think they generate the form that only takes IP into account. And that's the problem, taking into account only IP means that the jump performs "EIP = (EIP + displacement) and 0xFFFF" and that is pretty bad if target address is above 0xFFFF. With "format binary" happens the same if target is above 0xFFFF but fasm allows you to jump otherwise (because even with the zero extending EIP will be correctly set). Quote: however it will appear in the executable image in a compile-time know location, so there is no problem... The final location is decided at link-time, since this is the main object (is it?) perhaps it will be located first but this is a linker's desition. |
|||
15 Jul 2007, 03:27 |
|
Jeronimus Linuxius 17 Jul 2007, 00:20
LocoDelAssembly wrote:
Quote: however it will appear in the executable image in a compile-time know location, so there is no problem... JJ |
|||
17 Jul 2007, 00:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.