OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 5:41 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: I need help with bootloader
PostPosted: Thu Jan 12, 2017 2:11 pm 
Offline
Member
Member

Joined: Wed Jan 11, 2017 3:29 pm
Posts: 27
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.

Top
 Profile  
 
 Post subject: Re: Bootloader won't show as floppy image
PostPosted: Thu Jan 12, 2017 2:53 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
Why is that a problem? The file command is not designed to validate your BPB.


Top
 Profile  
 
 Post subject: Re: Bootloader won't show as floppy image
PostPosted: Thu Jan 12, 2017 3:18 pm 
Offline
Member
Member

Joined: Wed Jan 11, 2017 3:29 pm
Posts: 27
My BPB won't work. What might be wrong with it? When I use dd, the floppy image is 512 bytes.


Top
 Profile  
 
 Post subject: Re: Bootloader won't show as floppy image
PostPosted: Thu Jan 12, 2017 3:29 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
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.


Top
 Profile  
 
 Post subject: Re: Bootloader won't show as floppy image
PostPosted: Thu Jan 12, 2017 4:42 pm 
Offline
Member
Member

Joined: Thu May 19, 2011 5:13 am
Posts: 229
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:
  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


Top
 Profile  
 
 Post subject: Re: Bootloader won't show as floppy image
PostPosted: Fri Jan 13, 2017 6:28 am 
Offline
Member
Member

Joined: Wed Jan 11, 2017 3:29 pm
Posts: 27
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?


Top
 Profile  
 
 Post subject: Re: Bootloader won't show as floppy image
PostPosted: Fri Jan 13, 2017 7:12 am 
Offline
Member
Member

Joined: Wed Jan 11, 2017 3:29 pm
Posts: 27
BPB won't work. Maybe I should try fat_imgen.


Top
 Profile  
 
 Post subject: Re: Bootloader won't show as floppy image
PostPosted: Fri Jan 13, 2017 9:43 am 
Offline
Member
Member
User avatar

Joined: Tue Aug 02, 2016 1:52 pm
Posts: 286
Location: East Riding of Yorkshire, UK
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:
# 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


Top
 Profile  
 
 Post subject: Re: I need help with bootloader
PostPosted: Fri Jan 13, 2017 11:59 am 
Offline
Member
Member

Joined: Wed Jan 11, 2017 3:29 pm
Posts: 27
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.


Top
 Profile  
 
 Post subject: Re: I need help with bootloader
PostPosted: Fri Jan 13, 2017 12:28 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
Wait, did you check the size of the file after you created it,

Code:
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:
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:
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.

_________________
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.


Last edited by Schol-R-LEA on Fri Jan 13, 2017 12:33 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: I need help with bootloader
PostPosted: Fri Jan 13, 2017 12:29 pm 
Offline
Member
Member
User avatar

Joined: Tue Aug 02, 2016 1:52 pm
Posts: 286
Location: East Riding of Yorkshire, UK
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:
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


Top
 Profile  
 
 Post subject: Re: I need help with bootloader
PostPosted: Sat Jan 14, 2017 5:07 am 
Offline
Member
Member

Joined: Wed Jan 11, 2017 3:29 pm
Posts: 27
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 171 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group