[SOLVED] Get device booted

Programming, for all ages and all languages.
Post Reply
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

[SOLVED] Get device booted

Post by HugeCode »

Hi all. I'm trying to load my kernel reading filesystem and I don't know which disk should I read.
Does anybody have any idea how can I get the device which was booted? If it was HDD or floppy, primary or secondary bus, master or slave....
I don't think that reading first sector on each drive and then comparing it with actual bootsector would be accurate (there can be same OS on two HDDs).
Last edited by HugeCode on Tue Apr 16, 2013 9:49 am, edited 1 time in total.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Get device booted

Post by dozniak »

BIOS gives the bootloader information about boot device in DL upon giving it control.

It's up to bootloader to save it. iirc GRUB puts it into boot_device variable somewhere in multiboot info block.
Learn to read.
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

Re: Get device booted

Post by HugeCode »

Thanks... BTW does the DL=3 mean primary bus slave, or secondary bus master?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Get device booted

Post by Combuster »

No, it most likely means a bug.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Get device booted

Post by Mikemk »

Combuster wrote:No, it most likely means a bug.
Unless you are booting from the third floppy disk on the system.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

Re: Get device booted

Post by HugeCode »

Oh uh oh. What about DL=0x80/0x81? Master/Slave or Primary/Secondary bus?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Get device booted

Post by Combuster »

I've actually seen drive 0x80 to be:
- ATA primary master
- ATA primary slave
- ATA secondary master
- A bootable CD
- SCSI drive
- SATA drive (various channels)
- All other options I haven't seen with my own eyes.
I've also seen fixed drives changing numbers and/or disappearing from your system when booting from removable media, and some hard drives never being given a number at all.
You get the idea yet? :wink:

If you're in an emulator with just your OS, you can bet on it that a harddisk boot will give DL=0x80 for that harddisk, and floppy boots give 0x00. On real machines, guessing is the best you can do.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply