Page 1 of 2

Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 12:57 am
by buten
Hi, I've created a bootloader that outputs a simple "hello world" message to the screen however I now want to add to that by making it a multistaged bootloader.

The problem I've run into is that I'm currently using nasm and dd (in windows) to create a virtual floppy .img file from my .asm file, which I am then mounting into Bochs and loading up.
As a result, I'm not entirely sure how to create a .img file that consists of my multiple bootloader files so that it runs correctly while mounted in Bochs

Is there a chain of commands I need to run in dd so that it "appends" the other stages of my bootloaders to the .img file?

I need to be able to test the bootloader in a virtual environment before using an actual floppy on a physical machine (which I don't currently have access to)

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 4:09 am
by Muazzam
buten wrote:Hi, I've created a bootloader that outputs a simple "hello world" message to the screen however I now want to add to that by making it a multistaged bootloader.

The problem I've run into is that I'm currently using nasm and dd (in windows) to create a virtual floppy .img file from my .asm file, which I am then mounting into Bochs and loading up.
As a result, I'm not entirely sure how to create a .img file that consists of my multiple bootloader files so that it runs correctly while mounted in Bochs

Is there a chain of commands I need to run in dd so that it "appends" the other stages of my bootloaders to the .img file?

I need to be able to test the bootloader in a virtual environment before using an actual floppy on a physical machine (which I don't currently have access to)
Use virtual floppy drive. It is an excellent windows utillity that you can use to edit virtual floppy files, mount them and to create .img or .flp files. http://sourceforge.net/projects/vfd/

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 5:59 am
by Combuster
VFD is just an user interface to manage a floppy image. Since it is a user interface, you can't fully automate building a fresh disk image with it.

One of the other important questions here is how your bootloader is supposed to work. Does it actually need a FAT filesystem and parses it to find files embedded on it? If it works anything else than that, then VFD is not going to be much help other than faking an image as a real disk - which you can do with the same DD command without VFD.
Any filesystem needs dedicated tools to read and write it. Filesystems other than FAT or SFS are problematic in this way because they lack tools that can directly use images. For FAT, mtools are the standard command-line oriented utility. A lack of a filesystem would be the normal use case for dd, but at that point, the specifics are all important, in which case you have to explain further.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 9:42 am
by buten
I dont need a filesystem at this stage of the bootloader.

Currently, I have a single-stage bootloader that displays a "hello world" message on boot and I am able to get that to show up by creating a .img file using dd and nasm, then mounting this .img file in bochs and booting from the floppy.

The next step is to create a multistaged bootloader where the first bootloader initially starts up and then, using an interrupt (int 13h in this case), "resets the floppy drive" and loads the second-stage bootloader, this second-stage bootloader will then display the "hello world" message.

I have two .asm files and one .inc (just for printing the string on the screen), I'm just not sure how to create the .img using dd so that all the files are represented correctly in the virtual disk image.

I know that using partcopy on a physical disk I would have to run something like this: "partcopy HelloWorld.bin 0 xxx -f0 200", in order to get the second-stage file "appended", just not sure how I would go about that using a virtual image.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 10:29 am
by seuti
muazzam wrote:
buten wrote:Hi, I've created a bootloader that outputs a simple "hello world" message to the screen however I now want to add to that by making it a multistaged bootloader.

The problem I've run into is that I'm currently using nasm and dd (in windows) to create a virtual floppy .img file from my .asm file, which I am then mounting into Bochs and loading up.
As a result, I'm not entirely sure how to create a .img file that consists of my multiple bootloader files so that it runs correctly while mounted in Bochs

Is there a chain of commands I need to run in dd so that it "appends" the other stages of my bootloaders to the .img file?

I need to be able to test the bootloader in a virtual environment before using an actual floppy on a physical machine (which I don't currently have access to)
Use virtual floppy drive. It is an excellent windows utillity that you can use to edit virtual floppy files, mount them and to create .img or .flp files. http://sourceforge.net/projects/vfd/
I had some issues with Virtual Floppy Drive on Windows 7.

You might be better off developing your OS under something other than Windows.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 12:04 pm
by jnc100
If you have a unix-like environment for Windows (e.g. msys/cygwin), you can simply 'cat' the various pieces together.

e.g. if stage1.bin is 512 bytes and stage2.bin should start straight after (i.e. in the second logical sector), you could do:

Code: Select all

cat stage1.bin stage2.bin > image
and then either write it to the disk with an imaging tool of your choice or run it directly in Bochs.

Regards,
John.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 12:04 pm
by SpyderTL
You will need to compile and link both of your ASM files, separately, into, let's say "file1.bin" and "file2.bin".

Then you will need to append both of these to a third file, say "file3.bin":

Code: Select all

copy /b file1.bin+file2.bin file3.bin
Then you can dd file3.bin to your disk image.

Keep in mind that your file1.bin will need to be exactly 512 bytes long in order for everything to line up properly.

Let us know how it goes. I've never tried this... I just found it by googling "command line append file to file".

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 1:54 pm
by Combuster
run it directly in Bochs.
You'll want to use dd to drop the parts into an actual 1.4M file. Bochs will complain yet still work if you forget, but other VMs are not so lenient and will often simply truncate your image file, making you magically lose compiled code.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 2:44 pm
by b.zaar
Here's a script I've been using for venom-os.

Code: Select all

#! /bin/bash

IMAGE=bin/image/fd144.img

mkdir -p bin/image
dd of=$IMAGE if=/dev/zero count=2880
dd of=$IMAGE if=bin/boot/boot.bin conv=notrunc obs=512 seek=0
[code]
[/code]

The important part is conv=notrunc so that it inserts into your file without changing the file size. If you keep adding after the last line just set the seek value to the new sector.

Code: Select all

# stage 2 - 2K
dd of=$IMAGE if=bin/boot/boot2.bin conv=notrunc obs=512 seek=1
# ramdisk
dd of=$IMAGE if=bin/boot/initrd conv=notrunc obs=512 seek=5
run dd --help to understand the options used.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Wed Oct 01, 2014 5:06 pm
by buten
SpyderTL wrote:You will need to compile and link both of your ASM files, separately, into, let's say "file1.bin" and "file2.bin".

Then you will need to append both of these to a third file, say "file3.bin":

Code: Select all

copy /b file1.bin+file2.bin file3.bin
Then you can dd file3.bin to your disk image.

Keep in mind that your file1.bin will need to be exactly 512 bytes long in order for everything to line up properly.

Let us know how it goes. I've never tried this... I just found it by googling "command line append file to file".

It worked! I made the .bin files using nasm and appended them just like you suggested, seemed to get the job done in bochs using the image file created from dd

I didn't think it would be so simple as combining the files using just the copy command but I'm not complaining :D

Thanks for the tip!
Thanks for all the suggestions guys! =D>

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Thu Oct 02, 2014 8:31 am
by Muazzam
seuti wrote:I had some issues with Virtual Floppy Drive on Windows 7.

You might be better off developing your OS under something other than Windows.
Are you using it as administrator?. Are you using 32-bit windows?

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Thu Oct 02, 2014 11:47 am
by seuti
muazzam wrote:
seuti wrote:I had some issues with Virtual Floppy Drive on Windows 7.

You might be better off developing your OS under something other than Windows.
Are you using it as administrator?. Are you using 32-bit windows?
Using it as an administrator.
64 bit Windows.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Thu Oct 02, 2014 10:23 pm
by Muazzam
seuti wrote: Using it as an administrator.
64 bit Windows.
Virtual floppy drive works only on 32-bit Windows.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Thu Oct 02, 2014 11:15 pm
by SoLDMG
muazzam wrote:
seuti wrote: Using it as an administrator.
64 bit Windows.
Virtual floppy drive works only on 32-bit Windows.
That's wrong. I've got VFD working on my 64 bit machine in Safe Mode.

Re: Simple MultiStaged Bootloader with dd and Bochs

Posted: Thu Oct 02, 2014 11:20 pm
by Muazzam
SoLDMG wrote: That's wrong. I've got VFD working on my 64 bit machine in Safe Mode.
Read this: http://vfd.sourceforge.net/ Note !!! This version works only on 32 bit systems !!!