lba extended read: int 0x13, ah 0x42

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
frank

lba extended read: int 0x13, ah 0x42

Post by frank »

I have problems with int 0x13, function 0x42.
It should read a sector from the disk. (using lba)
The only output which is right is sector 0.
Does anyone know what the problem might be?

offtopic: this program is located in the bootblock, it gets loaded by lilo.. there is more code but this is the part not working

Code: Select all


; Check if LBA (Logical Block Addressing)
   ; is supported.
   mov ah,0x41
   mov bx,0x55AA
   mov dl,[disk]
   int 0x13
   cmp bx,0xAA55
   jne no_lba

   ; Read using LBA (Logical Block Addressing)
   ; Using a standard bios interrupt

   mov ah,0x42
   mov dl,[disk]
   lea si,[lbaadr]        
   int 0x13   
   cmp ah,0x00      ; check for error
   jne showerr



lbaadr:
 dw 0x0010            ; 2byte, reserved - size of packet.
 dw 0x0001            ; WORD 2bytes nr of blocks read. 
 dw 0x00002000            ; DWORD 4bytes Transfer buffer
; dd 0x0000000034009605         ; QWORD 4bytes,32bit LBA address
 dd 0x0000000000000000

Best,
Frank
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:lba extended read: int 0x13, ah 0x42

Post by Candy »

Code: Select all

lbaadr:
 dw 0x0010            ; 2byte, reserved - size of packet.
 dw 0x0001            ; WORD 2bytes nr of blocks read. 
 dw 0x00002000            ; DWORD 4bytes Transfer buffer
; dd 0x0000000034009605         ; QWORD 4bytes,32bit LBA address
 dd 0x0000000000000000

The simplest thing I can see wrong here is that your comments do not match your code. Seeing you want the packet size to be 0x10, you would need a dw, another dw, a dd and a dq respectively. You have 3 dw's and a dd.

Suggestion:

Code: Select all

lbaadr:
 dw 0x0010            ; 2byte, reserved - size of packet.
 dw 0x0001            ; WORD 2bytes nr of blocks read. 
 dd 0x00002000            ; DWORD 4bytes Transfer buffer
; dq 0x0000000034009605         ; QWORD 4bytes,32bit LBA address
 dq 0x0000000000000000

frank

Re:lba extended read: int 0x13, ah 0x42

Post by frank »

ty, you were right.
I had to do some changes in it though.
I got the stuff working ;D

Code: Select all


; Read using LBA (Logical Block Addressing)
   ; Using a standard bios interrupt

   mov ah,0x42
   mov dl,[disk]
   lea si,[lbaadr]        
   int 0x13   
   cmp ah,0x00      ; check for error
   jne showerr

; LBA parameter block
lbaadr:
 dw 0x0018            ; 2b reserved
 dw 0x0001            ; 2b nr of blocks read. 
 dw 0x00002000            ; 4b 4bytes Transfer buffer
 dw 0,0x00000001              ; 8b LBA  

frank

Re:lba extended read: int 0x13, ah 0x42

Post by frank »

Hmmm it seems not to work right...
Reading sector 0,1 and 2 works fine.

When I read sector 10 it shows me empty data.

I wrote a small textfile (+/- 16bytes) to sector 9/10 and 11 using dd as root.
(which does not matter since lilo is only in the first sector of the disk and my first partition starts at sector 63)
But it shows me an empty data.

Code: Select all

; LBA parameter block
lbaadr:
dw 0x0018               ; 2b reserved
dw 0x0001               ; 2b nr of blocks read. 
dw 0x2000               ; 4b 4bytes Transfer buffer
dw 0x0000,0x0010  ; 8b LBA  
Curufir

Re:lba extended read: int 0x13, ah 0x42

Post by Curufir »

Am I totally missing something here?

Code: Select all

dw 0x0000,0x0010  ; 8b LBA  
Is LBA sector 16, not 10.

Could it really be this?
frank

Re:lba extended read: int 0x13, ah 0x42

Post by frank »

Ok, I managed to read sector 63 and 10,1,2 etc
But when I try to read the first sector of my 4th partition it does not work..

( 4th partition sector is 34009605)


Code: Select all

; LBA parameter block
lbaadr:
 db 0x10            ; 1b 00h reserved -> size
 db 0x00            ; 1b 01h reserved
 dw 0x0001            ; 2b 02h nr of blocks read. 
 dw 0x2000            ; 2b 04h 4bytes Transfer buffer
 lbaa db 0x05,0xF2,0x06,0x02
Nayxx

Re:lba extended read: int 0x13, ah 0x42

Post by Nayxx »

Warning with dimension of fields !

Code: Select all

lbaadr:
   db 10h      ; packet size (16 bytes)
   db 0      ; reserved, must be 0
   db 1      ; number of sectors to transfer
   db 0      ; reserved, must be 0
   dw 2000h   ; Buffer's segment
   dw 0000h   ; Buffer's offset
   dq 0000000034009605h ; 64-bit starting sector number
frank

Re:lba extended read: int 0x13, ah 0x42

Post by frank »

I got it working. :)

Lilo loads the partition boot sector.
My asm bootblock loads the mbr, reads the C bootblock (10 sectors atm), switches to pmode and jumps.

For anyone who is interested in the code:
http://frank.nedbsd.nl/xope-0.0.1Z.tar.gz
(btw, do not write make before editing the Makefile)

Best,
Frank
Post Reply