flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Data reservations in include files

Author
Thread Post new topic Reply to topic
scippie



Joined: 26 Jan 2017
Posts: 11
Hi,

I am in the process of developing my own OS completely in assembler with FASM. It has grown quite far already but of course, there is still way more to do.

Idiotic or not (so no need to discuss this), the thing I am trying to achieve with this OS is to reinvent everything. This also includes the executable format. I am not using PE or ELF formats but pure binary. This means I can't use sections because I don't have them, well I think so, I tried using them and it wasn't allowed.

On to the question: I am coding the kernel and for separate functionality, I create separate include files (fat32.inc for example - no, I am not reinventing the filesystem at this time because it is very convenient at the moment).

My kernel code starts at memory offset 0x10000 and at the end of the main asm file is an org 0x5000 with a lot of rb/rw/rd/rq/... definitions so that the code knows where to position them in memory. Now, my fat32 implementation also needs some variables that need to be set up in that area. I want those variables to also exist in the 0x5000-0x10000 area, but I would love to be able to declare them in the fat32.inc file instead of the main asm file.

How can I achieve this?

I hope my question is clear?

D.
Post 03 Feb 2019, 13:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
This is where header files can be handy. But they can be cumbersome to deal with sometimes.

Another pure fasm way is to use either 1) macros to define the defs and instantiate at the proper place, or 2) tagged virtual blocks.

The macro way:
Code:
;in fat32.inc
macro define_fat32_data {
 length dd ?
 ;...
}
;----------------
;in main.asm
include 'fat32.inc'
;...
org 0x5000
define_fat32_data    
Tagged virtual blocks are like this:
Code:
;in main.asm
virtual at data_definitions
  data_defs::
end virtual
;...
include 'fat32.inc'
;...
org 0x5000
data_definitions:
        virtual data_defs
                sizeof.data_defs = $ - $$
        end virtual
        repeat sizeof.data_defs
                load char byte from data_defs:data_definitions + (% - 1)
                db char
        end repeat
;--------------------
;in fat32.inc
virtual data_defs
 length rd 1
 ;... etc
end virtual
;and you can add more later
virtual data_defs
 sectors rd 1
 ;... etc
end virtual    
Post 03 Feb 2019, 14:30
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2796
Location: dank orb
Nothing is idiotic here. Your learning experience far less so.

One of the beautiful things about using asm is that the variables are just memory addresses - if they aren't initialized then using a VIRTUAL block would suffice. If you want to define data in a non-linear manner - to be pieced together later - then the most general way is https://board.flatassembler.net/topic.php?p=207326#207326 . I do recommend switching to FASMG.

FYI: the board has a OS development section:
https://board.flatassembler.net/forum.php?f=11

_________________
¯\(°_o)/¯ unlicense.org
Post 03 Feb 2019, 14:39
View user's profile Send private message Visit poster's website Reply with quote
scippie



Joined: 26 Jan 2017
Posts: 11
revolution wrote:
This is where header files can be handy. But they can be cumbersome to deal with sometimes.

Another pure fasm way is to use either 1) macros to define the defs and instantiate at the proper place, or 2) tagged virtual blocks.
...


Thanks man! One of these will certainly be fine for me.

bitRAKE wrote:
Nothing is idiotic here. Your learning experience far less so.

Thanks... I am used to another forum where I would probably get shouted at with my post...

bitRAKE wrote:
FYI: the board has a OS development section.

Ooh... I have been a member for a while here, but never saw it. See you there!
Post 03 Feb 2019, 15:09
View user's profile Send private message Reply with quote
scippie



Joined: 26 Jan 2017
Posts: 11
bitRAKE wrote:
I do recommend switching to FASMG.

I never heard of it before (I have been away a long time it seems) and I just looked it up, but I don't really see how it would be better for me. Why would it be better?
Post 03 Feb 2019, 15:28
View user's profile Send private message Reply with quote
sts-q



Joined: 29 Nov 2018
Posts: 26
Raise hand everybody with the same question: me! Wink

fasmg is reported to be slower?

Is there a **switching-to-fasmg-thread** somewhere in this forum?
Post 03 Feb 2019, 16:08
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
fasmg is of interest if you want to make your own assembler by using the macro language it has.

If you don't really want to make your own assembler then it might not be of interest to you.

fasmg, by its nature, will be slower than the native fasm. That may impact you for larger sources. For small sources you might not notice.

fasmg has a completely different macro syntax, so if you have existing code written for fasm then you need to rewrite all of those; macro, struct, irp, match, etc.

fasmg is more flexible if you need to customise anything. Whereas fasm needs you to rewrite the source code and reassemble it to make any custom changes.

So there is no single answer for everyone. Your needs might be served best by either fasm or fasmg depending upon your goals.
Post 03 Feb 2019, 16:28
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7371
Location: Kraków, Poland
sts-q wrote:
Is there a **switching-to-fasmg-thread** somewhere in this forum?
This is a good idea, I should write one. Please give me some time, though.

For now, you can read my original post comparing languages of fasmg and fasm, but keep in mind that it was several years ago. Since then things like a macro package providing partial compatibility with fasm 1 (especially for Windows programming) have been developed.

Oh, and there is also a thread that serves as a central information hub concerning fasmg.
Post 03 Feb 2019, 16:30
View user's profile Send private message Visit poster's website Reply with quote
scippie



Joined: 26 Jan 2017
Posts: 11
Thanks for the info everyone!
I will be here more often. Great community here. And at some point, I will probably understand whether fasmg is better for me and at that point, I won't mind rewriting a bunch of code Smile
Post 03 Feb 2019, 17:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
bitRAKE wrote:
One of the beautiful things about using asm is that the variables are just memory addresses - if they aren't initialized then using a VIRTUAL block would suffice.
Yes, you are correct. The last part where the values are copied into the output from the virtual block can be removed. It would just put useless zero values into the binary output.
Post 03 Feb 2019, 18:11
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-2019, Tomasz Grysztar.

Powered by rwasa.