flat assembler
Message board for the users of flat assembler.

Index > OS Construction > "section" directive for binary format

Author
Thread Post new topic Reply to topic
egos



Joined: 10 Feb 2009
Posts: 144
egos 20 Aug 2010, 07:05
I'm developing OS kernel and using fasm. My kernel file have a binary format. For combining many sources I'm compelled to use "include" directive and special macroses to realize something like section paradigm.

Variant 1
Code:
macro section name { macro name { name }

ends fix }

macro initcode {}
macro initdata {}
macro code {}
macro data {}
macro bss {}
macro rma {}
...

macro put [name] { name }    


Variant 2
Code:
macro section name
{
_#name equ ,_#name
macro name {
}

ends fix }

macro put [name]
{
match params,_#name
\{
_#name equ
irp arg params
\{
name
purge name
\}
\}
}    


Is there a possibility to add support of "section" directive for binary format in fasm? Or I should use foreign compiler to combine object modules created by fasm.

_________________
If you have seen bad English in my words, tell me what's wrong, please.
Post 20 Aug 2010, 07:05
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 20 Aug 2010, 15:54
What's the point? If you want sections, use elf or PE, then you have a symbol table and all that other cool stuff, for dynamic linking and crap like that.
Post 20 Aug 2010, 15:54
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 20 Aug 2010, 16:15
Considering that "format binary" is a plain raw binary format, what do you expect fasm to do when it encounters a section directive?

If you want a custom object format, perhaps you may consider define specially named labels in the places where you would use "section '.whatever'", and then use the debugging information in your linking/loading tool as a guide for the manipulation of the binary file. It may also be possible with some macros to define a section table somewhere, but this way, although easier, would make the binary contain the real code plus the supporting data for linking/loading instead of your own code only.

PS: But bear in mind that with custom object format you miss relocations, so every object should use different origins and also should avoid overlap.
Post 20 Aug 2010, 16:15
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 21 Aug 2010, 08:55
I just need fasm to group code fragments by destination (i.e. by section names) and to put every group at special position in output file. For example:

Code:
org KERNEL_BASE
; put here all parts of code section
put code
virtual
; put here all parts of bss section
put bss
KERNEL_SIZE=$-KERNEL_BASE
end virtual    


Last edited by egos on 07 Oct 2010, 07:31; edited 2 times in total
Post 21 Aug 2010, 08:55
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 21 Aug 2010, 11:49
fasm by design always generates the output in the order exactly reflecting the source (that explains the "flat" word in its name). Your "variant 2" macros are the correct way to do such grouping with fasm. It is also possible to make a variant that wouldn't require "ends" for each section, but only some at the end of the source.
Post 21 Aug 2010, 11:49
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 21 Aug 2010, 14:26
OK, thanks to all.
Post 21 Aug 2010, 14:26
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 19 Nov 2010, 11:42
I have make new section macro:
Code:
macro section name
{
_#name equ ,_#name
macro name
}
    

But there's one problem. Error occures when "{" is placed on the same row.
Code:
section code {} ; error

section code
{} ; no error
    

If I could remove "_#name equ ,_#name" from section macro then I could use short definition "section fix macro". The question is, is there way to do something like this:
Code:
while defined macros
{
macros
purge macros
}
    
Post 19 Nov 2010, 11:42
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 19 Nov 2010, 18:03
egos,

Macro can purge itself. As a safeguard, define/equate it as empty somewhere before.
Post 19 Nov 2010, 18:03
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 20 Nov 2010, 06:36
baldr, I know this. I want to put the code of all macroses with same name at one place.
Post 20 Nov 2010, 06:36
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
bitRAKE 20 Nov 2010, 07:09
Look at how I create the COLORS macro:
http://board.flatassembler.net/topic.php?p=119555#119555

...it does just as you desire.
(Hopefully, not n^2 space complexity? Confused)
Code:
macro directory [name] {
  macro _#name \{ \}
}

macro section name {
  macro _#name {
    _#name
}
ends fix }

directory \
  text, \
  const

section const
  db 'one',0
ends

section text
  nop
ends

section const
  db 'two',0
ends

section text
  int3
ends


_text

_const    
...of course, directory could build an output macro; or section could MATCH to find new sections and do it all. This just shows basic form.
Post 20 Nov 2010, 07:09
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.