2 Stages bootloading from Hard Drive

Started by Curious, April 20, 2012, 11:09:53 AM

Previous topic - Next topic

Curious

Good point, I'll see what I can do ;)

MichaelW

Or use the BIOS Interrupt 13h extensions to access the drive, in which case the first and second sectors are blocks 0 and 1.
eschew obfuscation

Curious

Quote from: MichaelW on April 21, 2012, 09:35:17 PM
Or use the BIOS Interrupt 13h extensions to access the drive, in which case the first and second sectors are blocks 0 and 1.
I wish I knew what you mean! I AM trying to use Int 13h but can't get the code to work! I guess I need some kind of tracing but a bootable program is harder to debug, I guess the only option left is to read the sectors I want and print them to see what I'm actually loading into the RAM (in case I'm successfully loading to RAM!)

Have anyone tried the code I posted in the first post? It is updated with the latest changes you guys suggested...

dedndave

back in the day....
DOS came with a program called debug.com
if you can get one of those versions - not the exe
you can format a bootable DOS floppy (with io.sys, msdos.sys, and command.com)
delete the command.com file
copy debug.com over there and rename it command.com   :P
then boot up

i don't recall which versions - but some of them did not have the exe loader yet when command.com runs the first time

sinsi


;     mov ah, 2; read sector function (Floppy)
     mov ah, 0Ah; read sector function (HDD)
     mov al, 1; read 1 sector
     mov ch,1;
     mov cl,2; reading 2nd sector
     mov dh, 0
     mov dl, 0
     int 13h

Usually the second sector is on track/cylinder 0, you are reading track 1 (mov ch,1).
Light travels faster than sound, that's why some people seem bright until you hear them.

Curious

QuoteUsually the second sector is on track/cylinder 0, you are reading track 1 (mov ch,1).
I checked, it didn't work either!

BTW, is this reading the 2nd sector or not?
     mov cl,2; reading 2nd sector

@dedndave,
That is very clever, I'll see if I can debug the bootloader using this trick  :cheekygreen:

sinsi

In CHS mode cylinder and head are zero-based, sectors start from 1. Just to be contrary, in LBA mode sectors start from 0
So "mov ch,0" is the first track and "mov cl,2" is the second sector. (Not that it matters here but the upper 2 bits of the track are in CL).

If you like to live dangerously you can debug the whole thing with the debug version of Bochs :bdg
Light travels faster than sound, that's why some people seem bright until you hear them.

Curious

Quote from: sinsi on April 22, 2012, 05:24:10 AM
In CHS mode cylinder and head are zero-based, sectors start from 1. Just to be contrary, in LBA mode sectors start from 0
So "mov ch,0" is the first track and "mov cl,2" is the second sector. (Not that it matters here but the upper 2 bits of the track are in CL).
That explains it  :U

Quote
If you like to live dangerously you can debug the whole thing with the debug version of Bochs :bdg
Yeah, that would be an overkill for me right now  :green2


[Progress]
Ok, what dedndave said is totally doable, I've successfully loaded my kernel using MS-DOS bootloader and MIKE OS bootloader (just had to write the bootloader at sector 0 and re-name my kernel file according to bootloader of choice! MIKE OS uses kernel.bin)
My kernel is a simple bi-lingual font mapped kernel for now (around 2KB, hoping to add some more to it)

[Still in research]
1. How can I write my own bootloader from scratch (after seeing a few more bootloaders)
2. How can I boot from HDD not FDD (Still wondering!)

P.S: Booting from FDD is a lot easier in VMWare than mapping the V-OS as a drive then writing the bootloader to sector 0 (which is time consuming, btw), disconnecting the mapped drive and booting the OS all the time, phew!
In a floppy disk with correct BPB format, you just have to copy the file to the mounted image and voila, start you OS and see how it works  :cheekygreen:

dedndave

yah - Sinsi has you on the right track
make sure you understand how to calculate the cylinder/head/sector for the drive you are working with
then, make sure you know which cylinder/head/sector you are placing the second sector

FORTRANS

Hi,

   One thing I tried when responding to other boot strapping
threads was to conditionally assemble the program as a
binary to be executed on a real boot-up or as a DOS *.COM
program to debug what it was supposed to do.


;-------------------------------------------------------------------------

DOSish  EQU     0       ; Allow for a DOS program or a Boot Loader sector.
IF DOSish
        ORG     100H
ELSE
        ORG     0H
ENDIF


   Due to my Brownian Motion style of programming, that
saved many a reboot.  You assemble as a *.COM and use
DEBUG to get it working as wanted.  This is not for the boot
loader, but for the sector to be loaded in my case.

HTH,

Steve N.

dedndave

that's a good thought, Steve
debugging is really troubleshooting
the best tool in the toolbox is isolating the problem, often through a process of elimination
it will be a great time saver if you don't have to reboot (even virtual) each time you want to test something

FORTRANS

Hi Dave,

   Oh, yes.  For simple (read obvious) fixes, an edit, assemble,
and DEBUG cycle could be just a few seconds.  The edit, assemble,
muck about setting up the floppy, shut down, booting, stare at the
screen, and then reboot cycle was always a fair number of minutes.
Admittedly, the DEBUG cycle can eat up time on the harder bits,
but it always was shorter than the multiple reboots that would have
happened otherwise.

Regards,

Steve

Curious

Hey guys, thanks everyone here for your helps  :cheekygreen:

I kind of lost a lot of code two-three weeks earlier  :(

But I'm re-writing everything from scratch, no biggy  :U