Write Bin Files To Floppy

broken image


Hello,
I want to write a *.bin(Assembly compiled file) to an floppy drive, but i don't know how to do this, remember that i have to write to the cylinder 0, head 0 and sector 1, because it's an boot program, only if needed here is the code:

  1. Write Bin Files To Floppy File
  2. What Is A Bin Files
  3. Write Bin Files To Floppy Disk

#Build bin file: nasm loader.asm -f bin -o loader.bin # Write bin file to floppy dd if=loader.bin bs=512 of=/dev/fd0. If you have an image file that you want to write onto a diskette, all you have to do, after selecting the floppy drive is to navigate to the location here it is stored and select it.

Thanks,
Nathan Paulino Campos

  • 2 Contributors
  • forum2 Replies
  • 400 Views
  • 10 Hours Discussion Span
  • commentLatest PostLatest Postby Nathan Campos

Recommended Answers

Write

Hello, you could read your bare binary file into a segment
of memory and write it out to the disk drive using
interrupt 13h function 03h (write sectors),
get ralf browns interrupt list!
You would need to write it out to head 0,cylinder 0,sector 1.
The last word of the …

Jump to Post

All 2 Replies

Hello, you could read your bare binary file into a segment
of memory and write it out to the disk drive using
interrupt 13h function 03h (write sectors),
get ralf browns interrupt list!
You would need to write it out to head 0,cylinder 0,sector 1.
The last word of the sector must contain the signature
0xAA55 at offset 01FE [55] - 01FF [AA] and the boot loader
must fit onto one 512 byte sector.

I used to make a disk image using 16-bit NASM and boot
the 1.44MB floppy images using Bochs x86 emulator,
I used the following directives to use the assembler
to produce a floppy disk image:

This allowed me to quickly debug and test my bootloader.

Write bin files to floppy disk
Page 1 of 1
[ 5 posts ]
Write Bin Files To Floppy

Hello, you could read your bare binary file into a segment
of memory and write it out to the disk drive using
interrupt 13h function 03h (write sectors),
get ralf browns interrupt list!
You would need to write it out to head 0,cylinder 0,sector 1.
The last word of the …

Jump to Post

All 2 Replies

Hello, you could read your bare binary file into a segment
of memory and write it out to the disk drive using
interrupt 13h function 03h (write sectors),
get ralf browns interrupt list!
You would need to write it out to head 0,cylinder 0,sector 1.
The last word of the sector must contain the signature
0xAA55 at offset 01FE [55] - 01FF [AA] and the boot loader
must fit onto one 512 byte sector.

I used to make a disk image using 16-bit NASM and boot
the 1.44MB floppy images using Bochs x86 emulator,
I used the following directives to use the assembler
to produce a floppy disk image:

This allowed me to quickly debug and test my bootloader.

Page 1 of 1
[ 5 posts ]

Write Bin Files To Floppy File

Print viewPrevious topic | Next topic
AuthorMessage
Post subject: Writing *.bin Files To Floppy in Windows
Member

Joined: Sun Jul 19, 2009 1:48 pm
Posts: 201
Location: Brazil
Hello,
I'm trying to write my OS to an floppy disk, but when i try to boot up, Bochs says that i don't have any OS on that floppy, here is the command that i'm using to write:
#1 Try:
C:Assembly> DEBUG os.asm
-w 100 0 0 1
-q

#2 Try:
C:Assembly> DEBUG os.bin
-w 100 0 0 1
-q

Here is my code:
[BITS 16] ; 16 bit code generation
[ORG 0x7C00] ; ORGin location is 7C00
JMP short main ; Jump past disk description section
NOP ; Pad out before disk description
; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5' diskette
OEMLabel db 'BERL OS' ; Disk label - 8 chars
BytesPerSector dw 512 ; Bytes per sector
SectorsPerCluster db 1 ; Sectors per cluster
ReservedForBoot dw 1 ; Reserved sectors for boot record
NumberOfFats db 2 ; Number of copies of the FAT
RootDirEntries dw 224 ; Number of entries in root dir
LogicalSectors dw 2880 ; Number of logical sectors
MediumByte db 0F0h ; Medium descriptor byte
SectorsPerFat dw 9 ; Sectors per FAT
SectorsPerTrack dw 18 ; Sectors per track (36/cylinder)
Sides dw 2 ; Number of sides/heads
HiddenSectors dd 0 ; Number of hidden sectors
LargeSectors dd 0 ; Number of LBA sectors
DriveNo dw 0 ; Drive No: 0
Signature db 41 ; Drive signature: 41 for floppy
VolumeID dd 00000000h ; Volume ID: any number
VolumeLabel db 'BERL OS '; Volume Label: any 11 chars
FileSystem db 'FAT12' ; File system type: don't change!
main:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 0011_1011b
MOV CX, osmsgend - os_msg ; calculate message size.
MOV DL, 30
MOV DH, 0
PUSH CS
POP ES
MOV BP, os_msg
MOV AH, 13h
INT 10h
JMP wel
wel:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 0011_1011b
MOV CX, welcome_end - welcome ; calculate message size.
MOV DL, 32
MOV DH, 2
PUSH CS
POP ES
MOV BP, welcome
MOV AH, 13h
INT 10h
JMP osmsgend
welcome DB 'Welcome !'
welcome_end:
os_msg DB 'BerlOS v0.0.1'
osmsgend:
JMP $
; Boot things
TIMES 510-($-$$) DB 0 ; Fill the rest of the sector with zeros
DW 0xAA55 ; Boot signature

What is Wrong?
Thanks,
Nathan Paulino Campos

_________________
About.Me - Blog


Top
Post subject: Re: Writing *.bin Files To Floppy in Windows
Member

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,
I'm trying to write my OS to an floppy disk, but when i try to boot up, Bochs says that i don't have any OS on that floppy, here is the command that i'm using to write:

I'm not sure how other people do it, but if I were using Windows I'd create a floppy disk image using the assembler, and then use something like RawWrite to transfer it to a floppy disk (and/or use it directly in Bochs).
For an example (for NASM):
org 0
incbin 'boot_loader.bin'
align 512
incbin 'something_else.bin'
times 1440*1024 - $ db 0 ;Some padding

Of course when your project becomes more complex you may need to write your own utilities to create disk images (and other things).
Cheers,
Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
Post subject: Re: Writing *.bin Files To Floppy in Windows
Member

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2637
Location: Devon, UK
Hi,
While there's probably nothing wrong with Rawrite, I'm just giving you an alternative: I like PartCopy which works very nicely. I have heard about people using MS Debug to do the same thing, but for some reason not many people seem to. I don't know whether that is because there's a problem with it or OS devvers just tend to prefer other utils...
That bit over, let's look at your command line (disclaimer: I guess Debug could overwrite you MBR if not used properly and I am not familiar with it myself, so please double check my command line below before you run anything).
Looking at your command lines below, and firing up help in the Debug program, it says that the format is:
write W [address] [drive] [firstsector] [number]

Thinking about what you want to achieve, should your command line be more like:
-w 0 [drive] 0 1

You seem to supply address=100. I assume this is an offset in to your source file, and you want to copy from byte 0, this should be zero. Next is the drive letter (or number). You provide '0', which I would assume to be the primary hard disk (remember that I am not familiar with Debug, so you may be right on this one). Next, I assume are the sector and length you wish to copy to. I think your parameters here are correct (first sector = 0 (LBA), copy one sector).
Anyway, if the above does not work out, take a look at Rawrite / Partcopy. If you go down the Partcopy route, I think there's a bootsector-copying tutorial on www.osdever.net.
Cheers,
Adam


Top

What Is A Bin Files

Post subject: Re: Writing *.bin Files To Floppy in Windows
Member

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2637
Location: Devon, UK
Hi Nathan,
I have now had a chance to read through some of your other posts. Please do not take this as an insult, but I think you could do with some further background reading to help you understand what is going on.
Take a look at this link. It points to a specific page on Bona Fide OS Dev containing sample code and tutorials for boot sectors and gives some additional background information on the subject of booting. This is where I started out with assembly language and have now become more and more confident (I'd only used HLL's and dabbled with HLA before I found Bona Fide).
When you have the 'Hello World' tutorial up and running on the emulator of your choice (and have it on a real or virtual floppy disk), you have a 512b play area to experiment with. At this point, don't worry about breaking anything (you're on an emulator ). Just have a go with some BIOS int's, have a go at writing your own version of PutString, MemCpy etc... and verify with the emulator that they all work. At this point, have a go at loading your next stage from disk using int 0x13. If something goes wrong, read other tutorials and sample code and have a go at debugging. If you really get stuck, describe the symptoms, copy the Bochs register dump, describe what you have tried along with the exact error details and post it here.
Looking at debugging your sample above, there are really only a few reasons your Bochs will say that it cannot boot the floppy:
1. The boot signature is in the wrong place or is not present (a source file issue).
2. The floppy disk or disk image is not present (a toolchain issue).
3. There is no boot sector on the disk (a toolchain issue).
1 and 2 are very easy to fix. If you are not sure about #1, get yourself a hex editor and check that bytes 510 and 511 of your boot sector are as expected.
You are now left with #3. You can diagnose this issue fairly simply. You know that the bootsector is 512 bytes starting at offset 0. Does the floppy spin up when you attempt the write operation? If so, chances are you are not writing to the correct sector on the disk. Again, a hex editor can help you here (especially if you are using disk images instead of physical disks - see Virtual Floppy Drive). If the boot sector is in the wrong place on the disk surface, verify your command line.
I hope some of this helps - sorry for the size of the post(s)!
Cheers,
Adam


Top
Post subject: Re: Writing *.bin Files To Floppy in Windows
Member

Joined: Sun Jul 19, 2009 1:48 pm
Posts: 201
Location: Brazil
Thanks now i write the floppy and my OS is booting!
Thanks very much!

_________________
About.Me - Blog


Top

Write Bin Files To Floppy Disk

Page 1 of 1
[ 5 posts ]




broken image