How to determine the boot device?

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
tomvalois
Posts: 2
Joined: Thu Dec 06, 2012 3:36 pm

How to determine the boot device?

Post 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
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: How to determine the boot device?

Post by xenos »

Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
tomvalois
Posts: 2
Joined: Thu Dec 06, 2012 3:36 pm

Re: How to determine the boot device?

Post 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.
Post Reply