OS writing: detecting which disk was used as boot disk 
Author Message
 OS writing: detecting which disk was used as boot disk

Hi. I'm writing a toy OS and only one question stops me from
completing the bootloader:

The boot code is loaded at 7C00h. It wakes up there, and it's got
no idea where it was loaded from. Was it the diskette drive
or hard disk (which one)? How can I find this out? It's
kinda hard to start loading the kernel if I don't know
what disk to access.

--
- Antti

     Hiroshima 1945
                 Tshernobyl 1986
                              Windows 2000



Wed, 11 Jun 2003 05:05:28 GMT  
 OS writing: detecting which disk was used as boot disk

As far as I know DL keeps disk number (0,1,80h,81h) the bootsector has been
loaded from.

Good Luck
--
Alexei A. Frounze
alexfru [AT] chat [DOT] ru
frounze [AT] ece [DOT] rochester [DOT] edu
http://alexfru.chat.ru
http://members.xoom.com/alexfru/
http://welcome.to/pmode/


Quote:

> Hi. I'm writing a toy OS and only one question stops me from
> completing the bootloader:

> The boot code is loaded at 7C00h. It wakes up there, and it's got
> no idea where it was loaded from. Was it the diskette drive
> or hard disk (which one)? How can I find this out? It's
> kinda hard to start loading the kernel if I don't know
> what disk to access.

> --
> - Antti

>      Hiroshima 1945
>                  Tshernobyl 1986
>                               Windows 2000



Wed, 11 Jun 2003 07:08:24 GMT  
 OS writing: detecting which disk was used as boot disk

Quote:
> The boot code is loaded at 7C00h. It wakes up there, and it's got
> no idea where it was loaded from.

Antti,

The solution to this problem is simple.  When you write the boot record to
the disk you simply indicate what disk it was written to via a simple drive
letter, such as "A" or "C".  Also write a unique string at a fixed/known
offset in the 512-byte boot sector.  Both of these can be the last few bytes
of the 512-byte boot sector.

Then, during boot you know for floppy drives it will always boot from drive
A:.  So, if the drive letter recognized in the boot-sector structure is "A"
you're done.  And for hard drives, you always know it will be the first hard
drive on IDE, or SCSI, or other supported controller.  By reading the first
sector of each of these drives you can look for the unique ID at the known
location and then recognize which drive you booted from.

To verify this, of course, you can always search the directory for bootable
files and verify they exist before determining that a particular drive is in
fact the bootable drive, etc.

Beyond that, think big.  Remember, when you're writing your own OS ... the
sky is the limit!  Be imaginative.  Be creative.  The only limitation to
making it work is your own ability.

- Rick C. Hodgin



Wed, 11 Jun 2003 07:08:27 GMT  
 OS writing: detecting which disk was used as boot disk

Quote:

> As far as I know DL keeps disk number (0,1,80h,81h) the bootsector has
been
> loaded from.

It does.
Or, at least, I've written code that depends on this and its worked on every
machine I've tried it with so far...

Beth :)



Wed, 11 Jun 2003 23:53:39 GMT  
 OS writing: detecting which disk was used as boot disk

Quote:

> As far as I know DL keeps disk number (0,1,80h,81h) the bootsector has been
> loaded from.

It's that simple? Thanks!

--
- Antti

     Hiroshima 1945
                 Tshernobyl 1986
                              Windows 2000



Thu, 12 Jun 2003 03:07:48 GMT  
 OS writing: detecting which disk was used as boot disk
That's it. BIOS doesn't erase DL contents after it loads a boot sector.

--
Alexei A. Frounze
alexfru [AT] chat [DOT] ru
frounze [AT] ece [DOT] rochester [DOT] edu
http://alexfru.chat.ru
http://members.xoom.com/alexfru/
http://welcome.to/pmode/


Quote:


> > As far as I know DL keeps disk number (0,1,80h,81h) the bootsector has
been
> > loaded from.

> It's that simple? Thanks!

> --
> - Antti

>      Hiroshima 1945
>                  Tshernobyl 1986
>                               Windows 2000



Thu, 12 Jun 2003 05:06:02 GMT  
 OS writing: detecting which disk was used as boot disk



Quote:
> > > As far as I know DL keeps disk number (0,1,80h,81h) the bootsector has
> been
> > > loaded from.

What if it was booted from the network?

eph



Thu, 12 Jun 2003 10:44:46 GMT  
 OS writing: detecting which disk was used as boot disk

Quote:
> > > As far as I know DL keeps disk number (0,1,80h,81h) the bootsector
> > > has been loaded from.

There's a potential problem relating to hard disks using this model.  If
BIOS supports booting from a motherboard SCSI device (on a motherboard that
also has onboard IDE) then you will not know which device it came from by
that value in dl.  Is the 80h representing the first hard drive on the IDE
channel or the first hard drive on the SCSI channel?  There is no way to
know.

There are additional steps that have to be taken before you can certify
which hard drive the boot device was.

- Rick C. Hodgin



Thu, 12 Jun 2003 10:44:56 GMT  
 OS writing: detecting which disk was used as boot disk
Have no idea. If I had a chance to work with tha stuff, I'd know.

--
Alexei A. Frounze
alexfru [AT] chat [DOT] ru
frounze [AT] ece [DOT] rochester [DOT] edu
http://alexfru.chat.ru
http://members.xoom.com/alexfru/
http://welcome.to/pmode/


Quote:



> > > > As far as I know DL keeps disk number (0,1,80h,81h) the bootsector
has
> > been
> > > > loaded from.

> What if it was booted from the network?

> eph



Thu, 12 Jun 2003 13:55:11 GMT  
 OS writing: detecting which disk was used as boot disk
Same here. I have no idea.

--
Alexei A. Frounze
alexfru [AT] chat [DOT] ru
frounze [AT] ece [DOT] rochester [DOT] edu
http://alexfru.chat.ru
http://members.xoom.com/alexfru/
http://welcome.to/pmode/


Quote:

> > > > As far as I know DL keeps disk number (0,1,80h,81h) the bootsector
> > > > has been loaded from.

> There's a potential problem relating to hard disks using this model.  If
> BIOS supports booting from a motherboard SCSI device (on a motherboard
that
> also has onboard IDE) then you will not know which device it came from by
> that value in dl.  Is the 80h representing the first hard drive on the IDE
> channel or the first hard drive on the SCSI channel?  There is no way to
> know.

> There are additional steps that have to be taken before you can certify
> which hard drive the boot device was.

> - Rick C. Hodgin



Thu, 12 Jun 2003 13:55:14 GMT  
 OS writing: detecting which disk was used as boot disk

Quote:

> > The boot code is loaded at 7C00h. It wakes up there, and it's got
> > no idea where it was loaded from.

> Antti,

> The solution to this problem is simple.  When you write the boot record to
> the disk you simply indicate what disk it was written to via a simple drive
> letter, such as "A" or "C".  Also write a unique string at a fixed/known
> offset in the 512-byte boot sector.  Both of these can be the last few bytes
> of the 512-byte boot sector.

Say you write your boot record on your A: drive, and I try to boot from
it in my B: drive...

However you're right, imagination is the key. Precedent doesn't matter
all that much.

Phil



Wed, 25 Jun 2003 02:36:04 GMT  
 OS writing: detecting which disk was used as boot disk

I do not have, yet, personal experience with this problem, but I read
that the BIOS is expected to place a pointer to the Disk Parameter Table
in the INT 1EH address.  This might reduce the ambiguity or maybe even
completely resolve it.



Quote:

> > > > As far as I know DL keeps disk number (0,1,80h,81h) the
bootsector
> > > > has been loaded from.

> There's a potential problem relating to hard disks using this model.
If
> BIOS supports booting from a motherboard SCSI device (on a motherboard
that
> also has onboard IDE) then you will not know which device it came from
by
> that value in dl.  Is the 80h representing the first hard drive on the
IDE
> channel or the first hard drive on the SCSI channel?  There is no way
to
> know.

> There are additional steps that have to be taken before you can
certify
> which hard drive the boot device was.

> - Rick C. Hodgin

Sent via Deja.com
http://www.deja.com/


Mon, 30 Jun 2003 05:26:43 GMT  
 OS writing: detecting which disk was used as boot disk

Quote:

> As far as I know DL keeps disk number (0,1,80h,81h) the bootsector
has been
> loaded from.

> Good Luck
> --
> Alexei A. Frounze

    Generally Booting can be done thru first IDE or first SCSI only.
But some BIOSs give support to booting from any IDE drive or any SCSI
drive. Even if that case, DL value will be 80h only. I hope Possible of
values of DL are 0, 80h. Please check it out

Sivasakthivel

Sent via Deja.com
http://www.deja.com/



Mon, 30 Jun 2003 12:33:34 GMT  
 OS writing: detecting which disk was used as boot disk

I have just decoded the boot sector for MS-DOS 5.0 and noticed that the
code leaves both DL and INT 1EH intact.  It issues BIOS read requests
INT 013H with whatever values the BIOS did originally put in these two
without explicitly referring to them.  I guess that this boot code
assumes that since the BIOS has already selected the drive for the boot,
it would select the same drive for additional input.


Quote:

> I do not have, yet, personal experience with this problem, but I read
> that the BIOS is expected to place a pointer to the Disk Parameter
Table
> in the INT 1EH address.  This might reduce the ambiguity or maybe even
> completely resolve it.



> > > > > As far as I know DL keeps disk number (0,1,80h,81h) the
> bootsector
> > > > > has been loaded from.

> > There's a potential problem relating to hard disks using this model.
> If
> > BIOS supports booting from a motherboard SCSI device (on a
motherboard
> that
> > also has onboard IDE) then you will not know which device it came
from
> by
> > that value in dl.  Is the 80h representing the first hard drive on
the
> IDE
> > channel or the first hard drive on the SCSI channel?  There is no
way
> to
> > know.

> > There are additional steps that have to be taken before you can
> certify
> > which hard drive the boot device was.

> > - Rick C. Hodgin

> Sent via Deja.com
> http://www.deja.com/

Sent via Deja.com
http://www.deja.com/

Get the FAQs http://www2.dgsys.com/~raymoon/x86faqs.html



Sat, 26 Jul 2003 02:59:08 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Help wanted on reading/writing disk and writing your own OS

2. Help wanted on reading/writing disk and writing your own OS

3. OS/2 boot disks and REXXUTIL

4. REXX on OS/2 boot disk?

5. Writing at boot sector to the first sector of a disk

6. Need help reading/writing boot sector (floppy disk)

7. Finding files on a given disk on other accessed disk

8. Large data array (operations) via disk disk files

9. GRUB boot disk

10. Running Rexx from Boot Disks

11. Enable rexx from boot disk

12. boot floppy disk

 

 
Powered by phpBB® Forum Software