Problem Getting Extended Disk info on QEMU

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
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Problem Getting Extended Disk info on QEMU

Post by kemosparc »

Hi,

I am having a problem with function 48h int 13h work.

I am trying to get the information for a qcow2 drive on qemu within my bootloader.

Here is my code:

Code: Select all

[ORG 0x7c00]

jmp bootloader
;--------------------------------------------------------
BiosPrint:
    push eax
    ch_loop:
        lodsb
        or al, al
        jz done
        mov ah, 0x0E
        int 0x10
        jmp ch_loop
    done:
    pop eax
ret
;--------------------------------------------------------
printNum:       ;Print a number (ax)
    push ecx
    push edx
    push ebx
    mov ecx,000Ah    ;divide by 10
    mov bx, sp
    getDigit:
            mov edx,0        ;puting 0 in the high part of the divided number (DX:AX)
            div ecx          ;DX:AX/cx.  ax=dx:ax/cx  and dx=dx:ax%cx(modulus)
            push edx
            cmp eax,0
    jne getDigit

    printNmb:
            pop eax
            add al, 30h     ;adding the '0' char for printing
            mov ah,0eh      ;print char interrupt
            int 10h
            cmp bx, sp
    jne printNmb
    pop ebx
    pop edx
    pop ecx
RET


;------------------------------------------------------------------
getDiskInfo:
    mov ah,41h				; Check if Extended Functions are supported
    mov dl,80h
    mov bx,0xAA55
    int 13h
    jc getDiskInfoNotSupport

    mov ah,48h				; Read Disk Extended Information
    mov al,1
    mov dl,80h
    mov si,disk_info
    int 13h
    jc getDiskInfoError			; Jump on error to print error number
					; The carry is always raises (THIS IS MY PROBLEM)
    mov ax,[disk_info]
    call printNum
    mov si,comma
    call BiosPrint

    mov ax,[disk_info+2]
    call printNum
    mov si,comma
    call BiosPrint
    mov eax,[disk_info+4]
    call printNum
    mov si,comma
    call BiosPrint

    jmp getDiskInfoExit
    getDiskInfoError:			; It always branch to here and prints (Disk Error: 1)
        mov si,disk_error
        call BiosPrint
        mov al,ah
        xor ah,ah
        call printNum
        jmp getDiskInfoExit
    getDiskInfoNotSupport:
        mov si,disk_info_not_supported
        call BiosPrint

    getDiskInfoExit:
ret


bootloader:
	call getDiskInfo

halt:
jmp halt
disk_info_not_supported   db 'Disk Info not supported !!!!', 13, 10, 0
disk_error   db 'Disk Error: ',  0
disk_info times 200 db 0

times 510-($-$$) db 0
db 0x55
db 0xAA



I have created a 1 GB qcow2 disk image with the following command:

Code: Select all

qemu-img create -f raw hwdetect.raw 1G
And I run my VM using the following command:

Code: Select all

qemu-system-x86_64 -m 4096 -fda hwdetect.img -boot a -hda hwdetect.img
What happen is that the carry flag is always raised and I get an error code 1 in AH.


Kindly if anyone can see what it the problem pleas let me know.

Thanks
Karim
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: Problem Getting Extended Disk info on QEMU

Post by M2004 »

You fail to setup stack and segment registers to known
state. Don't expect bios to do that for you.

Regards
M2004
mikegonta
Member
Member
Posts: 229
Joined: Thu May 19, 2011 5:13 am
Contact:

Re: Problem Getting Extended Disk info on QEMU

Post by mikegonta »

kemosparc wrote:I am having a problem with function 48h int 13h work.

Code: Select all

getDiskInfo:
    mov ah,41h				; Check if Extended Functions are supported
    mov dl,80h
    mov bx,0xAA55
    int 13h
    jc getDiskInfoNotSupport
bx needs to be 0x55AA.
Mike Gonta
look and see - many look but few see

https://mikegonta.com
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: Problem Getting Extended Disk info on QEMU

Post by kemosparc »

Hi,

I changed that and still gives the same


Okay, I have a couple of general questions though:
1. Is there any consideration when using virtual qcow2 disks
2. Does anyone nows some sort of a Baby steps for communicating with drives in protected and long modes.
3. Is there any tutorials that explains through simple examples how to communicate with devices in bare metal through ports. I mean I need to understand and try small examples that help me proceed reliably.


Thanks a lot
azblue
Member
Member
Posts: 147
Joined: Sat Feb 27, 2010 8:55 pm

Re: Problem Getting Extended Disk info on QEMU

Post by azblue »

kemosparc wrote:Hi,
2. Does anyone nows some sort of a Baby steps for communicating with drives in protected and long modes.
3. Is there any tutorials that explains through simple examples how to communicate with devices in bare metal through ports. I mean I need to understand and try small examples that help me proceed reliably.
http://www.osdever.net/tutorials/view/l ... ss-via-pio
http://wiki.osdev.org/ATA_PIO_Mode
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: Problem Getting Extended Disk info on QEMU

Post by kemosparc »

Thanks a lot

Sorry I was out of the country and I did not look at the forum for a while sio I did not reply

I will definitely follow the link

Thanks
Karim.
Post Reply