Where is this going?

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:

Where is this going?

Post by Firestryke31 »

Hi all, long time no post. I've been itching to get back into OSDev, and wanted to start with the MBR/GPT bootsector. I've got a disk image formatted as GPT, and my boot sector written to the protective MBR. It successfully detects that the disk is using GPT as opposed to MBR, and is at the point where it's trying to load the first sector of the GPT. I'm using int 13h ah=42h, and am populating the EDD read structure with the following values (according to Bochs just before the int):

Code: Select all

;; Header
0x10 0x00
;; Sectors
0x0001
;; Where?
0x0200
0x0100
;; Which?
0x00000000 00000001
When I see that, I see "Load one sector, starting at sector 1, to 0x0100:0x0200 (aka phys 0x1200)". The code returns no error (after directly examining processor state immediately after the int 13h), but examining all of 0x1200, 0x2100, 0x01000200 and 0x02000100 doesn't reveal the data I'm expecting. This is driving me nuts now, since I can't see in any way why it's not working.

The code used to generate the structure is as follows:

Code: Select all

loadSector:
;; Save a couple of important registers
	push bp
	push si
;; Set the stack frame
	mov bp, sp
;; Align the stack to a dword boundary (I chose to 16 bytes)
	and sp, 0xFFF0
;; Put the structure on the stack
	push dword ebx
	push dword eax
	push es
	push di
	push cx
	push 16
;; Get the location of the structure
	mov si, sp
;; Save some more registers
	push dx
	push ds
;; Copy SS to DS for the int
;; because the structure is on the stack
	push ss
	pop ds
;; Which subfunction
	mov ax, 0x42
;; One last register
	push bp
;; Do it!
	int 13h

;; At this point, I can find nothing that I expect despite no errors reported

;; Restore the various registers
	pop bp
	pop ds
	pop dx
;; Remove the structure & alignment padding from the stack
	mov sp, bp
;; Restore the pointers
	pop si
	pop bp
	ret
So, what am I doing wrong now? Something stupid I'm sure, but it's not apparent to me...
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?
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Re: Where is this going?

Post by Rudster816 »

http://wiki.osdev.org/ATA_in_x86_RealMo ... ended_Mode

You need to set DL to the drive letter if that isn't already set correctly by the code making the call. The BIOS will pass you the correct drive number in DL when your code first executes, so you'll need to save that somewhere at the very beginning of your bootsector.

This is the code I use in my bootloader for a reference. Feel free to use it any way.

Code: Select all

DAPACK:
		db	0x10
		db	0
blkcnt	dw	0						; int 13 resets this to # of blocks actually read/written
db_add	dw	0						; memory buffer destination address
db_seg	dw	0						; in memory page zero
d_lba	dd	1						; put the lba to read in this spot
		dd	0						; more storage bytes only for big lba's ( > 4 bytes )

ReadSectors:						; EBX is LBA to start, CX is sectors to read, ES:DI is destination address
	pushad
	mov si, WORD DAPACK
	mov [db_add], di
	mov [d_lba], ebx
	mov [blkcnt], cx
	mov [db_seg], es
	mov ah, 0x42
	movzx edx, BYTE [BootDrive]
	int 0x13
	jc .Error
	popad
	ret
	
	.Error:
		mov si, DiskErrorMsg
		call Error
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: Where is this going?

Post by Yoda »

There is already made MBR boot sector for legacy systems to boot from GPT partitioned disks. It is in my signature right below.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Where is this going?

Post by Firestryke31 »

Rudster816 wrote: You need to set DL to the drive letter if that isn't already set correctly by the code making the call. The BIOS will pass you the correct drive number in DL when your code first executes, so you'll need to save that somewhere at the very beginning of your bootsector.
DL is passed as a parameter to the function, hence pushing DX just before the int 13h to preserve it. I examined the processor state in Bochs just before the interrupt and everything indicates what it should be as far as I can see.
Yoda wrote:There is already made MBR boot sector for legacy systems to boot from GPT partitioned disks. It is in my signature right below.
I'm writing this to help me jump back in to OS dev, helping get those cobwebs dusted off. I enjoy this kind of programming, and consider it a puzzle to solve. Thanks for the offer though.

Edit: Found the problem: AX needs to be 0x4200, not 0x42
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?
Post Reply