flat assembler
Message board for the users of flat assembler.

Index > Main > Extra characters on line (NASM to FASM)

Author
Thread Post new topic Reply to topic
VelcroMan



Joined: 14 Feb 2010
Posts: 7
Location: Sweden
VelcroMan 18 Feb 2010, 07:13
I'm working on a small hobby OS, and i'm using GRUB for booting. I'm using a kernel loader with the multiboot header. I'm basically copied Embarassed a NASM loader, and now i want to rewrite it in FASM.

This is the NASM code;
Code:
global loader           ; making entry point visible to linker
extern kmain            ; kmain is defined elsewhere
 
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ  1<<0                   ; align loaded modules on page boundaries
MEMINFO     equ  1<<1                   ; provide memory map
FLAGS       equ  MODULEALIGN | MEMINFO  ; this is the Multiboot 'flag' field
MAGIC       equ    0x1BADB002           ; 'magic number' lets bootloader find the header
CHECKSUM    equ -(MAGIC + FLAGS)        ; checksum required
 
section .text
align 4
MultiBootHeader:
   dd MAGIC
   dd FLAGS
   dd CHECKSUM
 
; reserve initial kernel stack space
STACKSIZE equ 0x4000                  ; that's 16k.
 
loader:
   mov esp, stack+STACKSIZE           ; set up the stack
   push eax                           ; pass Multiboot magic number
   push ebx                           ; pass Multiboot info structure
 
   call  kmain                       ; call kernel proper
 
   cli
hang:
   hlt                                ; halt machine should kernel return
   jmp   hang
 
section .bss
align 4
stack:
   resb STACKSIZE                     ; reserve 16k stack on a doubleword boundary
    


I have changed global loader to public loader, and i added format elf at the top. I also changed extern kmain to extrn kmain.

FASM doesn't like CHECKSUM equ -(MAGIC + FLAGS) so i changed it to CHECKSUM equ 0 - MAGIC - FLAGS which didn't raise an error, and of what i understand it should be equal.

I added ' to the section names.

So this is what i got so far:
Code:
format elf

public loader         ; making entry point visible to linker
extrn kmain           ; kmain is defined elsewhere
 
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ       1<<0                      ; align loaded modules on page boundaries
MEMINFO     equ    1<<1                      ; provide memory map
FLAGS       equ MODULEALIGN | MEMINFO    ; this is the Multiboot 'flag' field
MAGIC       equ      0x1BADB002               ; 'magic number' lets bootloader find the header
CHECKSUM    equ  0 - MAGIC - FLAGS        ; checksum required
 
section '.text'
align 4
MultiBootHeader:
   dd MAGIC
   dd FLAGS
   dd CHECKSUM
 
; reserve initial kernel stack space
STACKSIZE equ 0x4000                  ; that's 16k.
 
loader:
   mov esp, stack+STACKSIZE           ; set up the stack
   push eax                           ; pass Multiboot magic number
   push ebx                           ; pass Multiboot info structure
 
   call  kmain                       ; call kernel proper
 
   cli
hang:
   hlt                                ; halt machine should kernel return
   jmp   hang
 
section '.bss'
align 4
stack:
   resb STACKSIZE                     ; reserve 16k stack on a doubleword boundary
    


The line dd FLAGS gives me the error "extra characters on line". I guess FASM's syntax isn't MODULEALIGN | MEMINFO. Now i need some help finishing this code Smile
Post 18 Feb 2010, 07:13
View user's profile Send private message MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 18 Feb 2010, 07:19
You need this:
Code:
FLAGS       equ MODULEALIGN or MEMINFO    
The | operator is for logical tests. or is for binary 'or'ing.
Post 18 Feb 2010, 07:19
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 18 Feb 2010, 07:22
Code:
format elf

public loader         ; making entry point visible to linker
extrn kmain           ; kmain is defined elsewhere
 
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ (1 shl 0)                    ; align loaded modules on page boundaries
MEMINFO     equ (1 shl 1)                    ; provide memory map
FLAGS       equ (MODULEALIGN or MEMINFO)    ; this is the Multiboot 'flag' field
MAGIC       equ 0x1BADB002               ; 'magic number' lets bootloader find the header
CHECKSUM    equ (0 - MAGIC - FLAGS)        ; checksum required
 
section '.text'
align 4
MultiBootHeader:
   dd MAGIC
   dd FLAGS
   dd CHECKSUM
 
; reserve initial kernel stack space
STACKSIZE equ 0x4000                  ; that's 16k.
 
loader:
   mov esp, _stack+STACKSIZE           ; set up the stack
   push eax                           ; pass Multiboot magic number
   push ebx                           ; pass Multiboot info structure
 
   call  kmain                       ; call kernel proper
 
   cli
hang:
   hlt                                ; halt machine should kernel return
   jmp   hang
 
section '.bss'
align 4
_stack: ;stack is a reserved word so I prefixed it with "_"
   rb STACKSIZE                     ; reserve 16k stack on a doubleword boundary    
I guarantee that it compiles, I can't tell whether it will also work or not.

If you define constants with EQU make sure to always surround calculations with parentheses because otherwise you risk to have undesired results. Also note that in fasm you could use just "=" instead of EQU. The "=" is interpreted at assembler stage and has the ability to be forward referenced and parentheses are not needed since the value is calculated and stored like a variable rather than being just a chunk of text that is expanded anywhere it is referred.
Post 18 Feb 2010, 07:22
View user's profile Send private message Reply with quote
VelcroMan



Joined: 14 Feb 2010
Posts: 7
Location: Sweden
VelcroMan 18 Feb 2010, 07:49
LocoDelAssembly wrote:

Code:
code...    

If you define constants with EQU make sure to always surround calculations with parentheses because otherwise you risk to have undesired results. Also note that in fasm you could use just "=" instead of EQU. The "=" is interpreted at assembler stage and has the ability to be forward referenced and parentheses are not needed since the value is calculated and stored like a variable rather than being just a chunk of text that is expanded anywhere it is referred.


Thank you. As i'm facing several problems with syntax i'll read through the FASM tutorials and the syntax parts in the manual. Just another question.. NASM's syntax isn't really "standard" compared to other intel-syntax assemblers, right? Razz
Post 18 Feb 2010, 07:49
View user's profile Send private message MSN Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 22 Feb 2010, 08:38
VelcroMan wrote:
another question.. NASM's syntax isn't really "standard" compared to other intel-syntax assemblers, right?


There is none, see http://board.flatassembler.net/topic.php?t=9343
Post 22 Feb 2010, 08:38
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.