Page 1 of 1

How to determine the boot device?

Posted: Fri Dec 07, 2012 8:14 am
by tomvalois
I have what is probably a basic question, but I can't seem to find the answer here.

The BIOS loads the first sector into 0x7C00, and executes it. But I can't do much with 512 bytes. So the first thing my boot code does is loads extended boot code from the next 15 sectors into memory, by calling the BIOS interrupt for disk access. The problem I am having is that the drive number is supposed to go into the DL register. This is fine if I know what I am booting from. For example, the code below works when I boot from the hard drive, but not from a floppy or CD. How do I determine which device was booted from, so I can load the extended boot code from the correct device? 512 bytes isn't enough to do hardware or file system probing, so I am hoping there is a BIOS call I can make to determine the boot device. Any help would be appreciated.

Code: Select all

1:	boot:
2:		mov	ah, 0x02		; we are going to read
3:		mov	dl, 0x80		; this is the problem
4:		xor	cx, cx			; we want cylinder 0
5:		mov	cl, 2			; we want the second sector
6:		mov	dh, 0			; we want head 0
7:		mov	al, 0x0F		; read 15 sectors
8:		mov	bx, ext_boot		; read them into our code
9:		int	0x13
10:		jmp	ext_boot
11:		times ((0x200 - 2) - ($ - $$)) db 0 ; pad with 0's
12:		dw	0xAA55			; boot identifier
13:	ext_boot:
14:		do_something

Re: How to determine the boot device?

Posted: Fri Dec 07, 2012 10:26 am
by xenos

Re: How to determine the boot device?

Posted: Fri Dec 07, 2012 10:37 am
by tomvalois
So DL is supposed to contain the drive number when the BIOS starts executing the boot code. Exactly what I was looking for.

Thanks.