flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Which Format To Use?

Author
Thread Post new topic Reply to topic
nathanpc



Joined: 23 Aug 2009
Posts: 40
Location: Brazil
nathanpc
Hello,
I have a main file that contains a code to allocate the bootloader and the kernel at their respective places:
Code:
org 7C00h
    include "boot.asm"

org 1000h
    include "kernel.asm"    

At the boot.asm source we have commands to boot the kernel at that part of the floppy, but I want to know which format instruction I should use to make a readable floppy disk to test at Bochs.

Best Regards,
Nathan Paulino Campos

_________________
Developer: C++, Java, C/C++, Java ME, Java EE, Pascal, Assembly(8086, 6502, z80, ARM and MIPS), Delphi, Visual Basic, Pascal, Ruby and Perl
Post 17 Sep 2010, 01:33
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
"format binary" but remember to specify bitness, it will default to 16bit. You can also use "format binary as "img"" to tell Fasm to use "img" as the extension.
Post 17 Sep 2010, 02:11
View user's profile Send private message Reply with quote
nathanpc



Joined: 23 Aug 2009
Posts: 40
Location: Brazil
nathanpc
How to specify the bitness, because I've tried bits 16(like on Nasm) and I got an error. Also, how is the macro declaration at Fasm?

Best Regards
Post 17 Sep 2010, 09:36
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
nathanpc wrote:
How to specify the bitness, because I've tried bits 16(like on Nasm) and I got an error.

It is use16.

nathanpc wrote:
Also, how is the macro declaration at Fasm?

Again, the manual comes to the rescue.
Post 17 Sep 2010, 09:42
View user's profile Send private message Reply with quote
nathanpc



Joined: 23 Aug 2009
Posts: 40
Location: Brazil
nathanpc
Now I'm having problems on this code:
Code:
macro print string
{
    mov si, word string
    
    char_loop:
        lodsb
        or al, al
        jz cdone
        mov ah, 09h
        mov bl, 19h
        int 10h
        jmp char_loop
    cdone:
}    

Here are the errors:
Code:
D:\Meus documentos\LeafBoot>fasm write.asm
flat assembler  version 1.69.24  (1130971 kilobytes memory)
kernel.asm [3]:
print test
stdio.inc [11] print [1]:
    mov si, word string
error: invalid operand.

D:\Meus documentos\LeafBoot>    
Post 17 Sep 2010, 15:58
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Are you passing a pointer or a variable?
Code:
mov si,string ;passing a pointer
mov si,word[string] ;passing a variable    
A more accurate answer could be supplied if you show the whole code
Post 17 Sep 2010, 16:04
View user's profile Send private message Visit poster's website Reply with quote
nathanpc



Joined: 23 Aug 2009
Posts: 40
Location: Brazil
nathanpc
Now it's like this:
Code:
flat assembler  version 1.69.24  (1076811 kilobytes memory)
kernel.asm [3]:
print test
stdio.inc [11] print [1]:
    mov si,word[string]    ;passing a variable
error: reserved word used as symbol.    
Post 17 Sep 2010, 17:07
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
You are not showing much code really... But it may be happening that the instruction is passed to the assembling stage as " mov si,word[test]" and of course it doesn't work, because test is an instruction and cannot be a symbol.
Post 17 Sep 2010, 17:19
View user's profile Send private message Reply with quote
nathanpc



Joined: 23 Aug 2009
Posts: 40
Location: Brazil
nathanpc
But now I have this:
Code:
D:\Meus documentos\LeafBoot>fasm write.asm
flat assembler  version 1.69.24  (1059063 kilobytes memory)
kernel.asm [1]:
print tst
stdio.inc [13] print [3]:
    char_loop:
error: symbol already defined.

D:\Meus documentos\LeafBoot>    

print is a instruction too?
Post 19 Sep 2010, 19:06
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
No, the problem is that you must used print macro more than once (are you sure you don't prefer some procedure to call instead?)

Anyway, to fix this problem simply do this:
Code:
macro print string
{
common
local ..char_loop, ..cdone
    mov si, word string
    
    ..char_loop:
        lodsb
        or al, al
        jz cdone
        mov ah, 09h
        mov bl, 19h
        int 10h
        jmp ..char_loop
    ..cdone:
}    
Now the labels will be local to the macro. Additionally, I've prefixed them with double dot, that is to prevent those labels to break the labels scope of the caller. Note that with this method, each time you call this macro all of its code is expanded at the call point, so if you call print ten times, then ten times the print code will appear in the binary instead of just one and ten calls to a single copy of the code.
Post 19 Sep 2010, 19:17
View user's profile Send private message Reply with quote
nathanpc



Joined: 23 Aug 2009
Posts: 40
Location: Brazil
nathanpc
Thanks, I've corrected the jz cdone to jz ..cdone and it's compiling nice now. But when I've tried to emulate it using Bochs, it said that there is no bootable device. Why? Sad
Post 20 Sep 2010, 00:48
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
You may be generating the image incorrectly. Additionally, make sure it has the AA55 signature at the end of the first sector.

Example I've posted somewhere else but can't search for it:
Code:
format binary as 'img'
org $7c00

      xor     ax, ax
      cli
      mov     ss, ax
      mov     sp, $7C00
      sti

      mov     ds, ax

      mov     ah, $0E
      xor     bx, bx
      mov     si, msg
      jmp     .loadChar

.printChar:
      int     $10

.loadChar:
      lodsb
      test    al, al
      jnz     .printChar

      xor     ax, ax
      int     $16

      int     $19

msg db "Hello world Very Happy", 13, 10,\
       "Now remove the floppy disk and press a key or else you'll see this message again", 13, 10, 0

; Padding before boot signature
rb 512 - 2 + $$ - $

dw $AA55

; Padding to make the image floppy-sized
rb 1440*1024 - 512 - 1
db 0    

Try if the above works in Bochs (it works in VirtualPC).
Post 20 Sep 2010, 01:14
View user's profile Send private message Reply with quote
nathanpc



Joined: 23 Aug 2009
Posts: 40
Location: Brazil
nathanpc
It failed another time Sad
Post 20 Sep 2010, 09:34
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Try This...
Code:
format binary as 'img'
org $7c00

 jmp     @Skip_BPB
   nop

;======================
; Bios Parameter Block
; Floppy
;======================

OEM                  db "nathanpc"
Bytes_per_sector     dw 512          
Sectors_per_cluster db 1            
Reserved_sectors    dw 1            
Number_of_FATs              db 2            
Root_entries                dw 224          
Total_sector_count  dw 2880                 ; 80*2*18               
Media_descriptor    db $F0                  ; Floppy
Sectors_per_FAT     dw 9
Sectors_per_track       db 18
Heads                  dw 2
Hidden_sectors          dd 0
Total_sector_FAT32      dd 0                    ; Total sector count for FAT32 (0 for FAT12 and FAT16)
BIOS_drive            db 0
Unused                  db 0
Boot_signature          db $29                  ; Extended boot signature ,IF 29H next 3 fields are present     
Volume_ID           dd 0
Volume_label            db "           "
File_system_type  db "FAT12   "


@Skip_BPB:

      xor     ax, ax
      cli
      mov     ss, ax
      mov     sp, $7C00
      sti

      mov     ds, ax

      mov     ah, $0E
      mov     bx,$0007
      mov     si, msg
      jmp     .loadChar

.printChar:
      int     $10

.loadChar:
      lodsb
      test    al, al
      jnz     .printChar

      xor     ax, ax
      int     $16

      int     $19

msg db "Hello world Very Happy", 13, 10,\
       "Now remove the floppy disk and press a key or else you'll see this message again", 13, 10, 0

; Padding before boot signature
rb 510 - ($ - $$)

dw $AA55

; Padding to make the image floppy-sized
rb 1440*1024 - 512 - 1
db 0
    

_________________
Nil Volentibus Arduum Razz
Post 20 Sep 2010, 10:00
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
If DJ Mauretto's code is really needed, I'll be very disappointed at Bochs for terribly bad BIOS emulation (and half-disappointed if the JMP/NOP sequence was the only extra thing needed)
Post 20 Sep 2010, 16:12
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.