Changeset 126


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

Added a function that specifically loads the MBR [v1.1.1-testing]

Besides loading the MBR, this function also checks if a signature is
present, if primary and/or extended partitions are present, and also
if AirBoot is installed on the disk.

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

    r124 r126  
    696696DriveIO_LoadSector      EndP
    697697
     698
     699;##############################################################################
     700;# ACTION   : Loads the Master Boot Record from the specified drive into buffer
     701;# ----------------------------------------------------------------------------
     702;# EFFECTS  : Modifies DAP structure and fills or clears transfer buffer
     703;# ----------------------------------------------------------------------------
     704;# IN       : DL     - BIOS disk number (80h,81h,etc)
     705;#          : SI     - Pointer to transfer buffer
     706;# ----------------------------------------------------------------------------
     707;# OUT      : CF=1   - failure
     708;#          : AL.0   - MBR signature present
     709;#          : AL.1   - Primary partitions present
     710;#          : AL.2   - Extended partitions present
     711;#          : AL.3   - AiR-BOOT signature present
     712;#          : AL.4:7 - Reserved, returned as 0
     713;#          : AH.0:7 - Reserved, returned as 0
     714;##############################################################################
     715DriveIO_LoadMBR     Proc Near uses bx cx dx si di
     716
     717        ; Always clear the transfer buffer first
     718        call    ClearSectorBuffer
     719
     720        ; Assume an invalid MBR
     721        xor     ax, ax
     722
     723        ; Accept only valid harddisks
     724        call    DriveIO_IsValidHarddisk
     725        jc      DriveIO_LoadMBR_exit
     726
     727        ; Save the address of the transfer buffer
     728        mov     di, si
     729
     730        ; Read the MBR from disk
     731        xor     ax, ax                  ; LBA low
     732        xor     bx, bx                  ; LBA high
     733        xor     dh, dh                  ; Head 0
     734        mov     cx, 1                   ; Sector 1
     735        call    DriveIO_LoadSector      ; Read the sector from disk
     736
     737        ; Check the loaded MBR for a signature
     738        xor     ax, ax                  ; Assume an invalid MBR
     739        mov     dx, [si+LocBR_Magic]    ; Get word from MBR signature location
     740        cmp     dx, 0aa55h              ; Is it the magic value ?
     741        jne     DriveIO_LoadMBR_exit    ; Nope, no need to test anything else
     742
     743        ; Indicate we have a MBR signature
     744        or      al, 01h
     745
     746        ; Advance to the partition table
     747        add     si, 01beh
     748
     749        ; Total of 4 entries to check
     750        mov     cx, 4
     751
     752    DriveIO_LoadMBR_next_entry:
     753        mov     dl, [si+LocBRPT_SystemID]   ; Get partition-type / system-id
     754        add     si, 10h                     ; Point to next entry
     755        test    dl, dl                      ; Nothing in this one ?
     756        loopz   DriveIO_LoadMBR_next_entry  ; Then check next entry
     757
     758        ; All entries checked and last one was also empty, we're done
     759        jz      DriveIO_LoadMBR_check_ab
     760
     761        ; Found a non-empty entry, set bits according to its type
     762        cmp     dl, 05h                     ; Old style extended container ?
     763        jne     @F                          ; Nope...
     764        or      al, 04h                     ; Yep, mark ext. container present
     765    @@: cmp     dl, 0fh                     ; New style extended container ?
     766        jne     @F                          ; Nope...
     767        or      al, 04h                     ; Yep, mark ext. container present
     768    @@: or      al, 02h                     ; Then is must be a primary
     769        jcxz    DriveIO_LoadMBR_check_ab    ; CX=0? Then all entries processed,
     770        jmp     DriveIO_LoadMBR_next_entry  ; otherwise check next entry
     771
     772        ; Check if an AiR-BOOT signature is present
     773    DriveIO_LoadMBR_check_ab:
     774        mov     si, offset [MBR_ABSig]      ; Offset of AiR-BOOT signature
     775        inc     di                          ; Advance buffer pointer
     776        inc     di                          ; to AiR-BOOT signature location
     777        mov     cx, 7                       ; Length of AiR-BOOT signature
     778        cld                                 ; Direction upwards
     779        repe    cmpsb                       ; Compare 7 bytes
     780        jne     DriveIO_LoadMBR_exit        ; Nope, no AiR-BOOT on this disk
     781        or      al, 08h                     ; Yep, AiR-BOOT is on this disk
     782        ;~ jmp     DriveIO_LoadMBR_exit
     783
     784    DriveIO_LoadMBR_exit:
     785        ret
     786DriveIO_LoadMBR     EndP
    698787
    699788
Note: See TracChangeset for help on using the changeset viewer.