I need help with bootloader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
TheDev100
Member
Member
Posts: 27
Joined: Wed Jan 11, 2017 3:29 pm

I need help with bootloader

Post by TheDev100 »

Hey guys. I've put a BIOS parameter block in my bootloader. I assemble it using NASM.

Then, I do file boatload.bin

DOS/MBR boot sector (with BPB values separated by commas).

How would I fix it so it goes to a 1.44MB floppy? What would be wrong with my BPB table?

Thanks
John
Last edited by TheDev100 on Fri Jan 13, 2017 8:18 am, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Bootloader won't show as floppy image

Post by Octocontrabass »

Why is that a problem? The file command is not designed to validate your BPB.
TheDev100
Member
Member
Posts: 27
Joined: Wed Jan 11, 2017 3:29 pm

Re: Bootloader won't show as floppy image

Post by TheDev100 »

My BPB won't work. What might be wrong with it? When I use dd, the floppy image is 512 bytes.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Bootloader won't show as floppy image

Post by dozniak »

You created a 512 byte boot sector with BPB. You now need to create a floppy image perhaps with some FS on it.

I suspect his article on the wiki should clear it up - http://wiki.osdev.org/Loopback_Device
Learn to read.
mikegonta
Member
Member
Posts: 229
Joined: Thu May 19, 2011 5:13 am
Contact:

Re: Bootloader won't show as floppy image

Post by mikegonta »

dozniak wrote:You created a 512 byte boot sector with BPB. You now need to create a floppy image perhaps with some FS on it.
The FAT12 boot sector is typically followed by 2 (the second is a copy of the first) File Allocation Tables which is followed by the
root directory.

Code: Select all

  jmp start
  nop
  db "        " ; OEM string
  dw 512 ; bytes per sector
  db 1 ; sectors per cluster
  dw 1 ; reserved sector count
  db 2 ; number of FATs
  dw 14 * 16 ; root directory entries
  dw 18 * 2 * 80 ; sector count
  db 0xF0 ; media byte
  dw 9 ; sectors per fat
sectors_per_track:
  dw 18
number_of_heads:
  dw 2
  dd 0 ; hidden sector count
  dd 0 ; number of sectors huge
drive_number:
  db 0
  db 0 ; reserved
  db 0x29 ; signature
  dd 0x78563412 ; volume ID
  db "           " ; volume label
  db "FAT12   " ; file system type

start:

  times 510 - ($ - $$) db 0
  dw 0xAA55

fat1: ; empty FAT12 file system
  db 0xF0, 0xFF, 0xFF
  times (512 * 9) - ($ - fat1) db 0

fat2:
  db 0xF0, 0xFF, 0xFF
  times (512 * 9) - ($ - fat2) db 0

root_directory:
  times 512 * 14 db 0

  times (512 * 18 * 2 * 80) - ($ - $$) db 0xF6
Mike Gonta
look and see - many look but few see

https://mikegonta.com
TheDev100
Member
Member
Posts: 27
Joined: Wed Jan 11, 2017 3:29 pm

Re: Bootloader won't show as floppy image

Post by TheDev100 »

I'm talking about NASM right now.
Also, I've tried the dd command but it only shows 512 bytes instead of 1.44MB.

I've got a BPB. What should I do?

How do I make a floppy image with my bootloader and possibly other files?
TheDev100
Member
Member
Posts: 27
Joined: Wed Jan 11, 2017 3:29 pm

Re: Bootloader won't show as floppy image

Post by TheDev100 »

BPB won't work. Maybe I should try fat_imgen.
User avatar
matt11235
Member
Member
Posts: 286
Joined: Tue Aug 02, 2016 1:52 pm
Location: East Riding of Yorkshire, UK

Re: Bootloader won't show as floppy image

Post by matt11235 »

TheDev100 wrote:Also, I've tried the dd command but it only shows 512 bytes instead of 1.44MB.
Where do you expect dd to pull the extra bytes from? It can't read your mind.

Code: Select all

# create a 1.44MB file filled with zeroes
$ dd if=/dev/zero of=floppy.img count=1440 bs=1k

# copy your mbr onto the floppy
# we use conv=notrunc to make sure that the rest of the bytes in the file arent thrown away
$ dd if=your-mbr.bin of=floppy.img bs=512 count=1 conv=notrunc
Of course it should go without saying that you need to be careful when using dd to make sure you aren't overwriting your disks.
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
TheDev100
Member
Member
Posts: 27
Joined: Wed Jan 11, 2017 3:29 pm

Re: I need help with bootloader

Post by TheDev100 »

You mean that's what I had to do? Well, guess what. I did that many times and it failed. It was still 512 bytes.
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: I need help with bootloader

Post by Schol-R-LEA »

Wait, did you check the size of the file after you created it,

Code: Select all

dd if=/dev/zero of=floppy.img count=1440 bs=1k
(It should have been a 1.44M file filled with zeroes at this point)

but before you inserted to boot image?

Code: Select all

dd if=your-mbr.bin of=floppy.img bs=512 count=1 conv=notrunc
If it was 1.44M before insertion, but was reduced to 512 bytes afterwards, check to make sure that you remembered the conv=notrunc argument in the second shell command. I would actually add nocreat and fdatasync as well, to give you a sanity check on the file name (it would give an error message if the file doesn't already exist) and force it to write immediately rather than (potentially) cache the output. If that doesn't do it, I would further use the nocache flags for both the input and output files - while the chances that it would be a caching issue are negligible when working on a local fixed medium, IMAO it would be worth going belt-and-suspenders in this case just to see if it makes a difference.

Code: Select all

dd if=your-mbr.bin  iflag=nocache of=floppy.img oflag=nocache bs=512 count=1 conv=notrunc,nocreat,fdatasync
Beyond that, if you could paste the exact shell commands and/or shell scripts you are using, we might be able to double check them for you. It is all too easy for even an experience shell user to make less than obvious mistake, and getting more eyes on it might help.
Last edited by Schol-R-LEA on Fri Jan 13, 2017 12:33 pm, edited 3 times in total.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
matt11235
Member
Member
Posts: 286
Joined: Tue Aug 02, 2016 1:52 pm
Location: East Riding of Yorkshire, UK

Re: I need help with bootloader

Post by matt11235 »

TheDev100 wrote:You mean that's what I had to do? Well, guess what. I did that many times and it failed. It was still 512 bytes.
Are you sure you didn't forget conv=notrunc?

Code: Select all

matt@minidigger:~$ dd if=/dev/zero of=test.img count=1440 bs=1k
1440+0 records in
1440+0 records out
1474560 bytes (1.5 MB, 1.4 MiB) copied, 0.00276008 s, 534 MB/s
matt@minidigger:~$ ll test.img
-rw-r--r-- 1 matt matt 1474560 Jan 13 18:27 test.img
matt@minidigger:~$ dd if=/dev/zero of=test.img count=1 bs=512 conv=notrunc
1+0 records in
1+0 records out
512 bytes copied, 8.6221e-05 s, 5.9 MB/s
matt@minidigger:~$ ll test.img
-rw-r--r-- 1 matt matt 1474560 Jan 13 18:27 test.img
matt@minidigger:~$ dd if=/dev/zero of=test.img count=1 bs=512
1+0 records in
1+0 records out
512 bytes copied, 0.000143675 s, 3.6 MB/s
matt@minidigger:~$ ll test.img 
-rw-r--r-- 1 matt matt 512 Jan 13 18:27 test.img
You can see that without conv=notrunc my file is (unsurprisingly) truncated to 512 bytes.
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
TheDev100
Member
Member
Posts: 27
Joined: Wed Jan 11, 2017 3:29 pm

Re: I need help with bootloader

Post by TheDev100 »

Thank you so much! IT WORKED. The option worked. Thank you :) I must give you some free jokes:

- Why is everyone's code void these days? Never mind, its void main()!
- Mov aha aha! That's the way aha aha I like it aha aha. Mov aha aha, 0eh.
- Loading kernel... Loading trouble... Loading things that aren't required...

THANK YOU!
Post Reply