flat assembler
Message board for the users of flat assembler.
Index
> Programming Language Design > Ask to Tomasz (x64 porting) |
Author |
|
Tomasz Grysztar 13 Jan 2019, 07:37
What I have done is not "porting", it is adapting 32-bit program to run in long mode with very little alterations, a trick similar to what I have done with fasm 1 before (but now, with instruction set in form of macros we have ability to make some even more interesting tricks - note that I demonstrated we could get rid of all 67h prefixes in case of fasmg). The original source can be maintained as a 32-bit program still, while this set of tricks allows to assemble it at any moment to a 64-bit ELF that you can run on a system not supporting 32-bit executables.
Actual porting would require the original sources to be modified, all pointer fields in structures would have to be updated, many of structures would grow quite much because of that (and because of additional alignment adjustments). Then the code would need to be altered to use Rxx registers where it operates on pointers, but not for other uses of 32-bit values, etc. etc. This would certainly take much longer than the 3 hours I recorded while making the tricky adaptation. At core, fasmg continues to be 32-bit, as this allows it to run in more places. Also, the growth of data structures because of use of larger pointers would most likely hit performance, while it is very unlikely to need that much memory in any of the usual uses of fasmg (though I'm ready to be surprised). |
|||
13 Jan 2019, 07:37 |
|
Tomasz Grysztar 13 Jan 2019, 07:52
Oh, perhaps I misunderstood the question at first. If you're asking why I have not simply done something like
Code: esp equ rsp |
|||
13 Jan 2019, 07:52 |
|
ProMiNick 13 Jan 2019, 09:36
_esp equ rsp - not esp equ rsp, I mean make replacement only in places where it needed (in square brackets for example). And field extending to qword only in places were it needed too (In assembler core there is no need to extend structure fields because of 32bit logic of it) i mean extend fields only in places where assembler need to communicate with x86/x64 environment.
|
|||
13 Jan 2019, 09:36 |
|
Tomasz Grysztar 13 Jan 2019, 10:24
ProMiNick wrote: _esp equ rsp - not esp equ rsp, I mean make replacement only in places where it needed (in square brackets for example). Because as soon we start modifying the original sources and effectively make a fork, then why not go all the way? ProMiNick wrote: And field extending to qword only in places were it needed too (In assembler core there is no need to extend structure fields because of 32bit logic of it) i mean extend fields only in places where assembler need to communicate with x86/x64 environment. The idea I had originally was to define things like: Code: rbx equ ebx ; for 32-bit version ; for 64-bit version no definition needed Code: struc dr? values& . dd values ; for 32-bit version end struc Code: struc dr? values& . dq values ; for 64-bit version end struc But this would be a lot work (compared to the trick I used) for probably a very little gain (in 64-bit version the structures would grow substantially, so cache problems would become worse and overall performance might suffer). And this still would not be taking advantage of other things long mode offers, like additional registers, ability to process data in larger units, etc. |
|||
13 Jan 2019, 10:24 |
|
ProMiNick 13 Jan 2019, 12:07
I still trying to maintain fasm&fasmgAllInOne package (trying to collect every ideas & examples related to fasm & fasmg in one place), and evolve it. But some portions stoped to work due to fasm&fasmg updates that are out of concept.
In parallel I trying to add fasmarm to it. I found a bug in kolibry part of my packege - I fix it, but later I found disadvantage in fasm adapted to menuet & kolibry - they couldn`t work effectively with includes located somewhere (every include is relative to current dir of current source or it has full path, and can`t be relative to variable include dir, because of absence of initialisation of such variable - so this is a bug of my package too.) I don`t upload package for a long long time because I can`t make everything work and in same time can`t fix all bugs found earlier. Macro porting is out of my concept - so I have to drop fasmg x64 linux. |
|||
13 Jan 2019, 12:07 |
|
Tomasz Grysztar 13 Jan 2019, 13:23
Are your problems caused by some modifications to fasmg core files? That is, by forking it?
In principle, when porting fasm[g] to another OS, you should not have to modify the core files. That was my general idea that seemed to work well in case of fasm 1 and with fasmg it is better developed, I hope. I hinted at this when I was showing stripping down to "raw core" of fasmg during my first session. I may dedicate another session to this topic in the future - perhaps port to some less-mainstream OS, or maybe just make a DOS/DPMI port - to demonstrate the idea how separation of "core" and "interface" works in fasmg (which is a refinement of the same idea used by fasm 1). I could also talk about fedit in relation to this topic - it shows how the idea of OS-independent core may work even in case of something requiring a UI, like text editor. Note how introduction of a new "interface" (like fasmg.x64 discussed here) does not then affect the other ones, because "core" remains unchanged. All the rules how to interface with core stay as they were and nothing is broken just because we want to make a new interface. Currently there are only console interfaces for fasmg (and one library interface in form of DLL), though in theory we could make a UI one (analogous to fasmw, perhaps also based on fedit) too. And again, core would remain "as is" - and it could still be developed independently of all the different interfaces, as long as all interfaces followed the documented rules. During these recorded sessions I was pointing out how important it is to strictly follow all the conventions documented in source (and at the same time, how important it is to document them in detail), for this reason exactly. You should rely only on what is documented and not make any assumptions outside of that. BTW... (please forgive me all the digressions, there are so many interesting directions to follow here...) Since I mentioned library interface - in principle it should also be possible to make .so/PIE version of fasmg. When all the variables used by fasmg are given EBP-based addresses, like DLL version already does, the entire core effectively becomes position-independent. |
|||
13 Jan 2019, 13:23 |
|
ProMiNick 13 Jan 2019, 14:24
Yes I forked core a little (removed format binary as built in) and macros that could be say that they are forked - alterencoding - is mainencoding in my realization - sometimes it conflicts with something that come with update. And I restructured includes.
But all is dosn`t matter: What convinient to me, and what not. With task of increasing frendliness of fasm for kolibry & menuet I will do it self. Tomasz, all of that what you creating is cool and interesting. Especialy I glad to read that in plans fasmg .so. |
|||
13 Jan 2019, 14:24 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.