flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Replacement for rb

Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 15 May 2010, 04:06
I need help on a replacement for rb that will allocate bss memory in a block at the end of my kernel my kernel. Currently I'm using something completely different because I don't know how to do it, but I'd like help on making a macro using Fasm's built-in syntax for rb. "reserved" is added to the ending address of my kernel and inserted into the bss dword in my grub header to tell grub to clear and reserve the area.
Code:
reserved = 0
macro reserve name, bytes
{
   virtual at reserved + base_addr
      name:
   end virtual
   reserved = reserved + bytes
}
    
Post 15 May 2010, 04:06
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 15 May 2010, 21:01
Code:
reserved = 0
macro rb bytes
{
   reserved = reserved + bytes
}
struc rb count
{
   label . byte at bss_base + reserved
   rb count
}
.
.
.
; bss area
bss_base db reserved dup(?)    
Question
Note however that every time rb is used it will end up in the bss_area (except when you use "times X rb Y", and some other circumstances where macros/strucs are skipped if exist).

[edit]
Quote:
; bss area
bss_base db reserved dup(?)
Maybe you don't need that, if the image is plain binary then that won't give extra info to the loader and hence, only setting the dword you mention to reserved value will suffice.[/edit]
Post 15 May 2010, 21:01
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 16 May 2010, 21:37
Neither way(mine or CrazyOfTheAssembly's Razz) is working, I think it's something to do with the order things are processed. Using Loco's macro/struc posted above, the below code results in "grub_bss_end_addr" being equal to "grub_load_end_addr". Help please.
Code:
grub_magic         = 1BADB002h
grub_flags         = 10003h
grub_checksum      = -(grub_magic + grub_flags)
grub_header_addr   = grub_header
grub_load_addr     = grub_kbeginning
grub_load_end_addr = grub_kend
grub_bss_end_addr  = grub_load_end_addr + reserved
grub_entry_addr    = kinit
grub_mode_type     = 1
grub_width         = 80
grub_height        = 25
grub_depth         = 0

grub_header:
dd grub_magic
dd grub_flags
dd grub_checksum
dd grub_header_addr
dd grub_load_addr
dd grub_load_end_addr
dd grub_bss_end_addr
dd grub_entry_addr
dd grub_mode_type
dd grub_width
dd grub_height
dd grub_depth  

rb 1
    
Post 16 May 2010, 21:37
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 16 May 2010, 21:46
Tyler, you should not use "reserved" but something like "final_reserved" and place "final_reserved = reserved" in any place where no more rb's can happen after the execution of that assignation. Other possibility is to define "grub_bss_end_addr" at any place after the last rb, that way you could use "reserved" since it will be in its final value.

PS: Note that I wrote the macro and struc named "rb" because that is what you asked but yet I don't advice to do that. If you use it in a virtual block for some reason, it will also end up in the bss area. You should use a distinct name for this "reserve in bss area" as you'll probably will need the plain "rb" in the future (and not only for the "virtual" case).
Post 16 May 2010, 21:46
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 16 May 2010, 22:40
LocoDelAssembly wrote:

[...] I don't advice to do that.

I guess I'll take your advice and use my original "reserve" macro. But why do you think that I should? This is for my (binary formatted) kernel rbs are going to take up disk space for no reason if I declare them Fasm's way, that's why I don't foresee using standard rbs.
Post 16 May 2010, 22:40
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 16 May 2010, 23:03
No, rbs should not take more space even in binary format if them are placed at the end (or at least no instruction or initialized data follows the rb), if them do, then you just found a bug in fasm.

If you are completely sure rb's won't be used in anything that would interfere with this (local variables, declaration of structures that will occupy memory outside the bss area, etc.), then go ahead, otherwise I suggest a distinctive name for this special type of allocation.
Post 16 May 2010, 23:03
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 17 May 2010, 02:13
Putting the "grub_bss_end_addr = grub_load_end_addr + reserved" at the end of my source file worked. Thanks LocoDelAssembly.
Post 17 May 2010, 02:13
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.