flat assembler
Message board for the users of flat assembler.
Index
> Main > I have a question about re positioning code (PIC) |
Author |
|
sid123 06 Apr 2014, 09:11
Hello,
I am right now trying to reposition my kernel to 32MB (just for fun) so I use the code below: Code: format MZ ;; real mode code ...... ;; okay copy the code mov esi, next_code mov ecx, [kernel_32_size] mov edi, KERNEL_PHYSICAL_REMAP rep movsb jmp CODE_SEL:KERNEL_PHYSICAL_REMAP next_code: ...... ;; code ;; code ;; code ;; code ;; code ;; end of code kernel_32_size: dd $ - next_code It works. Now this has left me wondering how did FASM knew that the code after next_code is at 32MB? As I see it, position independent code is only possible in 64-bit (with RIP-addressing), or am I missing something? I guess it's the work of DOS-MZ format which produces relocatable code. I hope people would clear my misunderstanding. _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
06 Apr 2014, 09:11 |
|
sid123 06 Apr 2014, 10:41
Quote: I suspect you are still referencing your variables in low memory. So when you say "it works" I think that means it woks as long a you don't overwrite the variables in low memory with other stuff. You got it there. I tried to clear the low memory and guess what? It triple faulted. I see. So what should be the solution? Use an ORG? Or is there perhaps a better solution? I can't use an ORG because I have certain parts that are referenced by both parts that are in low memory as well as the code in high memory (GDT, IDT etc.), using an ORG will cause problems. And do you want me to post 20,000+ lines of code? _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
06 Apr 2014, 10:41 |
|
cod3b453 06 Apr 2014, 10:49
The easiest way to do this would be re-base you code image automatically [assuming it's constant]:
Code: jmp CODE_SEL:KERNEL_PHYSICAL_REMAP org KERNEL_PHYSICAL_REMAP next_code: Code: jmp CODE_SEL:@f @@: jmp edi next_code: sub edi,next_code ; ... mov eax,qword [edi+var] ;... var dd 0 |
|||
06 Apr 2014, 10:49 |
|
revolution 06 Apr 2014, 10:58
sid123 wrote: So what should be the solution? Use an ORG? Or is there perhaps a better solution? Code: call @f @@: pop ebp mov eax,[ebp+something] ;<--- this is position independent |
|||
06 Apr 2014, 10:58 |
|
DOS386 21 Apr 2014, 07:58
> position independent code is only possible in 64-bit
> (with RIP-addressing), or am I missing something? YES. 32-bit code itself (jumps and callls) is position independent, absolute addresses are not. But there is a solution, see post above by revo. |
|||
21 Apr 2014, 07:58 |
|
sid123 21 Apr 2014, 09:03
revolution wrote: . Sorry for replying late but is it possible to tell FASM to add EBP to all internal references (know that'll cause problems in some cases), but that would make my life easier. _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
21 Apr 2014, 09:03 |
|
revolution 21 Apr 2014, 09:14
Something like the following might be useful (not tested):
Code: call var_base var_base: pop ebp mov eax,[var1] align 4 virtual at ebp+($-var_base) var1 dd ? end virtual rb 4 ;make sure the var1 space is reserved non-virtually |
|||
21 Apr 2014, 09:14 |
|
edfed 21 Apr 2014, 11:57
a virtual assembly langage (based on raw data) can achieve perfectlly the need of repositionnable code.
Code: and will also be executable on any machine. means, java needs a jvm, data are always declared in a data section accessed by references (not pointer, but pointers to pointers, double * programming), but other designs are possible. Code: mov eax,[[myData]] this addressing mode doesn't exist directlly Code: mov eax,[dataRef] mov eax,[eax] |
|||
21 Apr 2014, 11:57 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.