Ignore:
Timestamp:
Apr 8, 2017, 12:26:57 AM (8 years ago)
Author:
Ben Rietbroek
Message:

Optimized reading a sector from disk using INT13X [v1.1.1-testing]

At this level it is more clear to talk about 'reading' and 'writing'
sectors, where 'disk read' and 'disk write' errors can occur.

CAUTION:
This is a testbuild !
AirBoot uses the BIOS to access disks and a small coding error can trash
partition tables or other vital disk structures. You are advised to make
backups of TRACK0 and EBRs before using this testbuild. More info at:
https://rousseaux.github.io/netlabs.air-boot/pdf/AirBoot-v1.1.0-manual.pdf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bootcode/regular/driveio.asm

    r100 r102  
    726726
    727727
    728 ;
    729 ; ############################################################
    730 ; # Load a specified sector from a disk using LBA addressing #
    731 ; ############################################################
    732 ;
    733 ; In
    734 ; --
    735 ; DL     = Physical Disk
    736 ; BX:CX  = LBA sector
    737 ; DI:SI  = Target buffer
    738 ;
    739 ; Out
    740 ; ---
    741 ; AX     = Error code
    742 ;
    743 DriveIO_LoadSectorLBA       Proc Near  Uses bx cx dx si di ds es
    744         ; Get one sector
     728;##############################################################################
     729;# ACTION   : Reads a sector from disk using INT13 extensions
     730;# ----------------------------------------------------------------------------
     731;# IN       : BX:CX - LBA address of sector
     732;#          : DI:SI - SEG:OFF of transfer buffer
     733;# ----------------------------------------------------------------------------
     734;# OUT      : CF=1  - failure, AH failure code
     735;# ----------------------------------------------------------------------------
     736;# EFFECTS  : Modifies DAP structure and fills transfer buffer
     737;##############################################################################
     738DriveIO_ReadSectorLBA       Proc Near  Uses bx cx dx si di ds es
     739
     740        ; One sector to read
    745741        mov     cs:[DriveIO_DAP_NumBlocks], 1
    746742
    747         ; Setup buffer address
    748         mov     wptr cs:[DriveIO_DAP_Transfer+0], si
    749         mov     wptr cs:[DriveIO_DAP_Transfer+2], di
    750 
    751         ; Setup LBA address of requested sector
    752         mov     wptr cs:[DriveIO_DAP_Absolute+0], cx
    753         mov     wptr cs:[DriveIO_DAP_Absolute+2], bx
    754         mov     wptr cs:[DriveIO_DAP_Absolute+4], 0
    755         mov     wptr cs:[DriveIO_DAP_Absolute+6], 0
     743        ; Setup transfer address
     744        mov     wptr cs:[DriveIO_DAP_Transfer+0], si    ; offset
     745        mov     wptr cs:[DriveIO_DAP_Transfer+2], di    ; segment
     746
     747        ; Setup LBA64 address of requested sector
     748        mov     wptr cs:[DriveIO_DAP_Absolute+0], cx    ; low word lower part
     749        mov     wptr cs:[DriveIO_DAP_Absolute+2], bx    ; high word lower part
     750        mov     wptr cs:[DriveIO_DAP_Absolute+4], 0     ; low word upper part
     751        mov     wptr cs:[DriveIO_DAP_Absolute+6], 0     ; high word upper part
    756752
    757753        ; Address of packet
    758         mov     si, offset DriveIO_DAP
     754        mov     si, offset [DriveIO_DAP]                ; disk address packet
    759755
    760756        ; Do the extended read
    761         mov     ah, 42h
    762         int     13h
    763 
    764         ; Looking good so far
    765         jnc     DriveIO_LoadSectorLBA_succes1
    766 
    767         ; AH should not be zero, if it is then set to undefined and set carry
    768         test    ah,ah
    769         jnz     DriveIO_LoadSectorLBA_error1
    770         mov     ah, 0bbh        ; Undefined error
    771     DriveIO_LoadSectorLBA_error1:
     757        mov     ah, 42h                                 ; read function
     758        int     13h                                     ; transfer to bios
     759
     760        ; Error occured
     761        jc      DriveIO_ReadSectorLBA_exit
     762
     763        ; AH should also be zero
     764        test    ah, ah
    772765        stc
    773         jmp     DriveIO_LoadSectorLBA_exit
    774 
    775         ; AL should be zero, if not then set to undefined and set carry
    776     DriveIO_LoadSectorLBA_succes1:
    777         test    ah,ah
    778         jz      DriveIO_LoadSectorLBA_exit
    779         stc
    780         jmp     DriveIO_LoadSectorLBA_exit
    781 
    782         ; Return to caller
    783     DriveIO_LoadSectorLBA_exit:
    784         ret
    785 DriveIO_LoadSectorLBA       EndP
     766        jnz     DriveIO_ReadSectorLBA_exit
     767
     768        ; Disk read succeeded, clear CF
     769        clc
     770
     771    DriveIO_ReadSectorLBA_exit:
     772        ret
     773
     774DriveIO_ReadSectorLBA       EndP
    786775
    787776
Note: See TracChangeset for help on using the changeset viewer.