flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > section directive in binary format ?

Author
Thread Post new topic Reply to topic
pini



Joined: 04 Jul 2005
Posts: 14
pini
Hello,

I'd like to know if there were plans to enable the use of the section directive for the binary format (like in nasm, for instance) ?
It would help to order code and data when including external files, for instance.

I know I could switch to elf format with fasm and then use a linker script, but I'd really like not to rely on either the elf format or an hypotetical external tool to link my program (which is an OS kernel, btw).

Thanks in advance,

pini
Post 21 Mar 2008, 11:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17249
Location: In your JS exploiting you and your system
revolution
How are you going to encode the section format? Binary has no format so what is the assembler supposed to write to the output file when it sees "section ..."?
Post 21 Mar 2008, 11:56
View user's profile Send private message Visit poster's website Reply with quote
pini



Joined: 04 Jul 2005
Posts: 14
pini
Well, I was thinking that the content of a given section could be regrouped before outputting to the file.
For instance:

Code:
section "text"

mov eax,0

section "data"

dd 0xAA

section "text"

mov ebx,1    


would regroup the two instructions together and then output the data dword (with some mechanism to specify the order).

No information about the section is outputted, they only serve as regroupers
Post 21 Mar 2008, 12:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17249
Location: In your JS exploiting you and your system
revolution
The core of fasm doesn't work that way. But you can use macros to do section grouping. Search for macros on this board with names like udata, gdata, iglobals, uglobals and similar. Various implementations have been posted.
Post 21 Mar 2008, 12:11
View user's profile Send private message Visit poster's website Reply with quote
pini



Joined: 04 Jul 2005
Posts: 14
pini
Thanks a lot !

I only needed a way to regroup things in the file, whether it's done with the section directive or some macros doesn't care for me.
Post 21 Mar 2008, 12:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17249
Location: In your JS exploiting you and your system
revolution
Here is my little "globals" macros that probably does something close to what you need.
Code:
;file name: globals.inc v0.0
;
;sets up five macros to define global data:
;
;.idata         - declaration of initialised global data
;.udata             - declaration of uninitialised global data
;.sdata           - declaration of initialised global string data
;.bcode              - declaration of one-time start up executed code
;.ecode             - declaration of one-time shut down executed code
;
;and sets up another 5 macros to instantiate the global data
;
;iData           - instantiate the initialised global data
;uData             - instantiate the uninitialised global data
;sData           - instantiate the initialised global string data
;bCode              - instantiate the one-time start up executed code
;eCode             - instantiate the one-time shut down executed code


;All macros are used like this:
;
;
;        .idata
;     {
;             global_var1 rd 1
;   }
;
;
;   .bcode
;     {
;             call MODULE_init_lut
;               ... other arbitrary code
;   }
;
;
;   iData
;      bCode


;initialised global data

.idata_list equ

macro .idata {
 local z
     .idata_list equ .idata_list,z
       macro z
}

macro iData {
 match data_list,.idata_list \{
                irp instr,data_list \\{
                      instr
               \\}
  \}
}


;uninitialised global data

.udata_list equ

macro .udata {
  local z
     .udata_list equ .udata_list,z
       macro z
}

macro uData {
 match data_list,.udata_list \{
                irp instr,data_list \\{
                      instr
               \\}
  \}
}


;global string data

.sdata_list equ

macro .sdata {
 local z
     .sdata_list equ .sdata_list,z
       macro z
}

macro sData {
 match data_list,.sdata_list \{
                irp instr,data_list \\{
                      instr
               \\}
  \}
}


;one time start-up initialisation/allocation code

.bcode_list equ

macro .bcode {
   local z
     .bcode_list equ .bcode_list,z
       macro z
}

macro bCode {
 match code_list,.bcode_list \{
                irp instr,code_list \\{
                      instr
               \\}
  \}
}


;one time shut-down deinitialisation/deallocation code

.ecode_list equ

macro .ecode {
      local z
     .ecode_list equ .ecode_list,z
       macro z
}

macro eCode {
 match code_list,.ecode_list \{
                irp instr,code_list \\{
                      instr
               \\}
  \}
}    
Post 21 Mar 2008, 12:18
View user's profile Send private message Visit poster's website Reply with quote
pini



Joined: 04 Jul 2005
Posts: 14
pini
I found the original thread were you posted them (and it does *exactly* what I need). Thanks anyway.
Post 21 Mar 2008, 12:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.