Author Topic: Sample FAT12 boot code  (Read 30564 times)

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Sample FAT12 boot code
« on: August 31, 2016, 10:33:50 PM »
This will hopefully be the first in a series of sample code I post here.

This is a FAT12 boot sector (ie for a 1.44 MB floppy). It moves itself to a new place in memory then loads a file named LOADER.BIN (not included). It then jumps to the start of the loader to run it. LOADER.BIN can be anywhere on disc, and does not need to be in contiguous sectors (ie it doesn't matter how fragmented it is).

Any questions? Feel free to ask, I'll try to answer your questions.
« Last Edit: March 30, 2019, 12:54:11 AM by debs3759 »
My graphics card database: www.gpuzoo.com

Offline johnfound

  • Jr. Member
  • *
  • Posts: 5
  • Country: bg
    • Fresh IDE
Re: Sample FAT12 boot code
« Reply #1 on: September 01, 2016, 01:04:13 PM »
Oh, is she a bot?  :o

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: Sample FAT12 boot code
« Reply #2 on: September 01, 2016, 01:43:08 PM »
Hey!
Well, I think, it is all about syntax. A lot of devs just don't doublecheck the grammar, while programming at so low-level languages and platforms. One of the possible ways to struggle this is to improve your level of the syntax. You can make your best at my blog that is totally about writing and everything around it.

If you are trying to tell me there is something wrong with my code, tell me what it is. It has been tried successfully on several machines, is well documented, and has room for another 39 bytes of code! Before you criticise me, prove that you know what you are talking about, and don't spam me.
My graphics card database: www.gpuzoo.com

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: Sample FAT12 boot code
« Reply #3 on: September 01, 2016, 08:32:37 PM »
I just updated the attachment - I forgot I had commented out an important line of code :)
My graphics card database: www.gpuzoo.com

Offline JennTT

  • New Member
  • Posts: 1
Re: Sample FAT12 boot code
« Reply #4 on: February 28, 2018, 06:10:00 PM »
Hey!
Well, I think, it is all about syntax. A lot of devs just don't doublecheck the grammar, while programming at so low-level languages and platforms. One of the possible ways to struggle this is to improve your level of the syntax. You can make your best at my blog that is totally about writing and everything around it.

If you are trying to tell me there is something wrong with my code, tell me what it is. It has been tried successfully on several machines, is well documented, and has room for another 39 bytes of code! Before you criticise me, prove that you know what you are talking about, and don't spam me.

Wow, when you said "is well documented" you weren't kidding  ;D.

If you run Linux, you won't be able to run partcopy unless you install wine and execute it from there, you can do this instead,
from the terminal;

dd if=/dev/zero of=fd_osloader.img bs=512 count=2880
mkfs.fat -D 0 -F 12 -s 1 fd_osloader.img
dd if=bootsect.bin of=fd_osloader.img seek=0 count=1 conv=notrunc

the first command creates an empty (zero-filled) floppy image of 1.44 MB

The second creates a File Allocation Table (FAT) with:
'-D 0' set drive number to 0, as in 'DriveNum    db   00h' from BPB
'-F 12' creates a FAT with 12 bits entries (FAT12).
'-s 1' creates clusters of 1 sector each, as in 'nSecPerClust   db   01h' from BPB

the last command loads 'bootsect.bin' into the first sector of our newly formated floppy image. 'conv=notrunc' is specified so the dd program won't resize out image to the size of our bootsector.

Thanks, Debs.  :)


 


Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: Sample FAT12 boot code
« Reply #5 on: April 22, 2018, 11:31:47 PM »
Thanks JennTT.
My graphics card database: www.gpuzoo.com

Offline T145

  • Jr. Member
  • *
  • Posts: 12
  • Country: 00
  • Hacker, Jacker & All-Around Gobsmacker
    • CodeReview
Re: Sample FAT12 boot code
« Reply #6 on: November 21, 2019, 03:43:15 AM »
What would a sample "LOADER.BIN" look like? Is it alright if such a file is just alone in the same directory as "bootsect.bin," or does it need to be compiled into something like a *.img?

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: Sample FAT12 boot code
« Reply #7 on: November 21, 2019, 01:27:51 PM »
What would a sample "LOADER.BIN" look like? Is it alright if such a file is just alone in the same directory as "bootsect.bin," or does it need to be compiled into something like a *.img?

You can either put it in the root directory or in a directory. My code will only search the root directory. You need to load your bin file into memory, then jump to the entry point of your code. Bootsect.bin needs to be loaded to the bootsector of your disc. The code I shared is only for a floppy. Loading your loader from the bootsector of a HDD should be easier, as a floppy disc uses 12 bit FAT, and all other drives (other than very early, small drives) use 16-bit FAT or 32-bit, which is easier to code for. If you get stuck at any point, please post the code you have written, and we will try to help.

I hope I answered your question.
My graphics card database: www.gpuzoo.com