flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [solved] fasm1 separate structs to aligned & misaligned form |
Author |
|
ProMiNick 01 Feb 2019, 08:28
why align isn`t allowed by default in virtuals relative to reg?
and needed override to support this: Code: macro align boundary:sizeof.PTR,value:? { db (boundary-1)-(($-$$)+boundary-1) mod boundary dup value } use case: Code: virtual at eax db 1,2 align 8 A dd 0 end virtual db A-eax; we got 08 in output, and no errror that section is not aligned so allign.inc (it is crossbit) added and it precides struct.inc in list of includes: Code: macro align boundary:sizeof.PTR,value:? { db (boundary-1)-(($-$$)+boundary-1) mod boundary dup value } struc align boundary:sizeof.PTR,value:? { db (boundary-1)-(($-$$)+boundary-1) mod boundary dup value } struc PTR.aligned [val:?] { common align . PTR val } macro PTR.aligned [val:?] { common align PTR val } struc ptr.aligned [val:?] { common align . ptr val } macro ptr.aligned [val:?] { common align ptr val } struc HNDL.aligned [val:?] { common align . HNDL val } macro HNDL.aligned [val:?] { common align HNDL val } struc VOID.aligned [val:?] { common align . VOID val } macro VOID.aligned [val:?] { common align VOID val } struc VOID_8.aligned [val:?] { common . db val } macro VOID_8.aligned [val:?] { common db val } struc VOID_16.aligned [val:?] { common align sizeof.VOID_16 . VOID_16 val } macro VOID_16.aligned [val:?] { common align sizeof.VOID_16 VOID_16 val } struc VOID_32.aligned [val:?] { common align sizeof.VOID_32 . VOID_32 val } macro VOID_32.aligned [val:?] { common align sizeof.VOID_32 VOID_32 val } struc VOID_64.aligned [val:?] { common align sizeof.VOID_64 . VOID_64 val } macro VOID_64.aligned [val:?] { common align sizeof.VOID_64 VOID_64 val } struc TCHAR.aligned [val:?] { common align sizeof.TCHAR . TCHAR val } struc WCHAR.aligned [val:?] { common align sizeof.WCHAR . WCHAR val } strong_struct changed to this: Code: macro strong_struct name { virtual at 0 define @struct field@struct equ name match child parent, name \{ restore field@struct field@struct equ child,fields@\#parent \} sub@struct equ struc VOID_8 [val:?] \{ \common define field@struct .,VOID_8,<val> \} struc VOID_16 [val:?] \{ \common define field@struct .,VOID_16.aligned,<val> \} struc VOID_32 [val:?] \{ \common define field@struct .,VOID_32.aligned,<val> \} struc VOID_64 [val:?] \{ \common define field@struct .,VOID_64.aligned,<val> \} struc VOID [val:?] \{ \common define field@struct .,VOID.aligned,<val> \} struc PTR [val:?] \{ \common define field@struct .,PTR.aligned,<val> \} struc ptr [val:?] \{ \common define field@struct .,ptr.aligned,<val> \} struc HNDL [val:?] \{ \common define field@struct .,HNDL.aligned,<val> \} struc TCHAR [val:?] \{ \common define field@struct .,TCHAR.aligned,<val> \} struc ACHAR [val:?] \{ \common define field@struct .,ACHAR,<val> \} struc WCHAR [val:?] \{ \common define field@struct .,WCHAR.aligned,<val> \} macro VOID_8 [val:?] \{ \common \local anonymous define field@struct anonymous,VOID_8,<val> \} macro VOID_16 [val:?] \{ \common \local anonymous define field@struct anonymous,VOID_16.aligned,<val> \} macro VOID_32 [val:?] \{ \common \local anonymous define field@struct anonymous,VOID_32.aligned,<val> \} macro VOID_64 [val:?] \{ \common \local anonymous define field@struct anonymous,VOID_64.aligned,<val> \} macro VOID [val:?] \{ \common \local anonymous define field@struct anonymous,VOID.aligned,<val> \} macro PTR [val:?] \{ \common \local anonymous define field@struct anonymous,PTR.aligned,<val> \} macro ptr [val:?] \{ \common \local anonymous define field@struct anonymous,ptr.aligned,<val> \} macro HNDL [val:?] \{ \common \local anonymous define field@struct anonymous,HNDL.aligned,<val> \} macro align val:sizeof.VOID \{ \local anonymous define field@struct anonymous,align,val \} macro union \{ field@struct equ ,union,< sub@struct equ union \} macro struct \{ field@struct equ ,substruct,< sub@struct equ substruct \} } that helps!!!: as result 32 bit executables are assembled from crossbit structures. ARM 32 bit executables are assembled from same crossbit structures too. binary outs with legacy fasm struct format & crossbit structures differs only in parts of current datetime fields relative to compilation moment. And they are workable. 64 bit ones not tested yet. The question in above of this post remains: "Why align isn`t allowed by default in virtuals relative to regs?" and this limitation moved to fasmg realization of align? |
|||
01 Feb 2019, 08:28 |
|
ProMiNick 04 Feb 2019, 09:05
Can we bring back to struct macro?
In case of fasmg parameters passed in conjunctions with field names where they shouyld be passed. so adding alignment, padding or whatever is trivial. But in fasm1 parameters passed according to each overriden data definition line, so if we create struct: A dd ? ; must be dword size, not "rb 4", so that we couldn`t combine this & next line together rb 1 ; let suppose we need skip 1 byte; unnamed fields shouldnt be encountered in params for passing to struc or macro B db 7 dup (?) than if we pass to struc & macro of the same name 2 params: one of them goes to A. But second one not goes to B. we have to pass one additional param before B. May be this could be solved with extension struct element from 3 args [field,type,def] to 4, so aligment or padding lines would work with 4th arg, and will not create one more value that will be passed to struc & macro of the same name. |
|||
04 Feb 2019, 09:05 |
|
Tomasz Grysztar 04 Feb 2019, 09:27
ProMiNick wrote: Can we bring back to struct macro? |
|||
04 Feb 2019, 09:27 |
|
ProMiNick 12 Feb 2019, 01:25
post edited (temporary moved back to data definition types standard for fasm)
Code: force_align = 1;0 def.rb equ db def.rw equ dw def.rd equ dd def.rp equ dp def.rq equ dq def.rt equ dt core.datadefs equ db,dw,du,dd,dp,dq,dt core.datarsvs equ rb,rw,rd,rp,rq,rt Code: macro struct name { define @struct match _name rest, name: \{ @struct_name equ _name match :,rest \\{ @struct_field equ @struct_place equ \\} match parent:,rest \\{ @struct_field equ fieldsof.\#parent @struct_place equ placesof.\#parent \\} \} sub@struct equ virtual at 0 macro define@field name,type,value \{ define @struct_field name,type,value define @struct_place name,type,value \} macro reserve@field name,type,value \{ define @struct_place name,type,value \} irp datadef,core.datadefs \{ struc datadef [val:?] \\{ \\common define@field .,datadef,<val> \\} macro datadef [val:?] \\{ \\common \\local anonymous reserve@field anonymous,datadef,<val> \\} \} irp datadef,core.datarsvs \{ struc datadef count \\{ \\common define@field .,def.#datadef,count dup (?) \\} ;????????? wrong macro datadef count \\{ \\common \\local anonymous reserve@field anonymous,def.#datadef,count dup (?) \\} \} irp datadef,align,padding \{ struc datadef count \\{ \\common define@field .,datadef,count \\} macro datadef count \\{ \\common \\local anonymous reserve@field anonymous,datadef,count \\} \} irp datadef,union,struct \{ macro datadef \\{ field@struct equ ,datadef,< sub@struct equ datadef \\} \} macro ends \{ match , sub@struct \\{ irp datadef,core.datadefs,core.datarsvs,align,padding \\\{ restruc datadef purge datadef \\\} purge union,struct irpv fields,@struct_field \\\{ restore @struct_field \\\common define fieldsof.#@struct_name fields \\\} irpv fields,@struct_place \\\{ restore @struct_place \\\common define placesof.#@struct_name fields \\\} if $ display 'Error: definition of ',`@struct_name,' contains illegal instructions.',0Dh,0Ah err end if make@struct name,fieldsof.#@struct_name ;need uniqe name for fields & places separatedly make@struct name,placesof.#@struct_name ; end virtual \\} match any, sub@struct \\{ tmp@struct equ field@struct restore field@struct field@struct equ tmp@struct> \\} restore sub@struct \} } the main target of addition is passing data to structs only to named fields. and ofcourse add instructure padding & alignment features |
|||
12 Feb 2019, 01:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.