Detecting boot drive in protected mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Detecting boot drive in protected mode

Post by Firestryke31 »

I'm at the point where I'd much rather not drop back to real mode to do stuff, so I kind of need to know where my OS booted from. I know with the BIOS it's stored in DL, and I've used that quite a bit, but in protected mode that cute little number doesn't mean much. I've already searched this site through the search feature and with Google, and I've tried Googling the entire net for it, but I couldn't really find anything. It was all either real mode or completely irrelevant.

I hope to eventually support booting from USB, and so I can't just assume I booted from the first hard drive. Basically, what I'm asking is this: Is there a way to find out where I booted from without scanning each and every possible boot source?
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Detecting boot drive in protected mode

Post by bewing »

Unfortunately, this is indeed a big problem.
In some sense, you need to scan each drive attached to the system anyway -- because during your boot sequence you need to generate a hardware list. I am not trying to do my boot process in any ideal way yet, so I'm just preserving some BIOS-based boot loader info for the boot disk (such as the MBR/partition table) in memory -- and searching for a match, as I do my hardware search.

As I understand it, there is a list of drive info that the BIOS can supply (with some INT call during Real Mode) that can give you a more intelligent method for determining the boot drive. But I haven't looked into that yet. I'm pretty sure it's built into DexOS -- you may want to look at that source.
Last edited by bewing on Mon Jan 19, 2009 5:57 pm, edited 1 time in total.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Detecting boot drive in protected mode

Post by Dex »

There is no reliable way to do this from pmode, best to store it in realmode, for later use.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Detecting boot drive in protected mode

Post by Firestryke31 »

Is there some reliable way of getting the boot drive from the value stored in DL?

Edit: stupid question, if there were, everyone would use that...
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Detecting boot drive in protected mode

Post by bewing »

As I say, there IS such a way, in Real mode, but it's complicated.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Detecting boot drive in protected mode

Post by egos »

Firestryke31 wrote:Is there some reliable way of getting the boot drive from the value stored in DL?
The general way to get physical place of boot drive is int 13h/48h. For floppies (when DL = 0 or 1) I displace this value with DOR.0 value. For old IDE hard drives BIOS associates logical numbers with drives in detection order. Floppy/hard drive emulation on CD must be disabled.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Detecting boot drive in protected mode

Post by Love4Boobies »

There's also another way. The BBS defines a few extra PnP functions, one of which is "Get IPL Device from Last Boot". But keep in mind that although it can be used in protected mode, you need 16-bit descriptors.

Code: Select all

short FAR (* entryPoint) (Function, IPLEntry, BiosSelector);
short Function;                // PnP BIOS function 64h.
unsigned short FAR *IPLEntry;  // Index of entry in IPL Table.
unsigned short BiosSelector;   // PnP BIOS readable/writable selector.
EDIT: Nevermind my last edit :)

Enjoy!
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply