wok-6.x diff BootProg/stuff/boot32.asm @ rev 25485

BootProg/fat32: active fat support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 01 16:13:12 2022 +0000 (23 months ago)
parents 4c101652eb90
children f7324cde07d7
line diff
     1.1 --- a/BootProg/stuff/boot32.asm	Mon Oct 03 08:28:51 2022 +0000
     1.2 +++ b/BootProg/stuff/boot32.asm	Tue Nov 01 16:13:12 2022 +0000
     1.3 @@ -79,16 +79,18 @@
     1.4  
     1.5  %define bx(label)       bx+label-boot
     1.6  %define si(label)       si+label-boot
     1.7 +ExtraBootSector         equ     1
     1.8  ClusterMask             equ     1               ; +9 bytes
     1.9  NullEntryCheck          equ     1               ; +5 bytes
    1.10 +CheckAttrib             equ     1               ; +6 bytes
    1.11 +NonMirroredFATs         equ     1               ; +18 bytes
    1.12  ReadRetry               equ     1               ; +7 bytes
    1.13  LBA48bits               equ     1               ; +15 bytes
    1.14 -CHSsupport              equ     1               ; +27 bytes
    1.15 -CHSupTo8GB              equ     1               ; +11 bytes
    1.16 -CHSupTo32MB             equ     1               ; +7 bytes
    1.17 -SectorOf512Bytes        equ     1               ; -5 bytes
    1.18 +CHSsupport              equ     1               ; +27 bytes max 16MB, 32MB or 8GB
    1.19 +CHSupTo32MB             equ     1               ; +6 bytes
    1.20 +CHSupTo8GB              equ     1               ; +14 bytes
    1.21 +SectorOf512Bytes        equ     0               ; -5 bytes
    1.22  Always2FATs             equ     0               ; -4 bytes
    1.23 -CheckAttrib             equ     0               ; +6 bytes
    1.24  
    1.25  [BITS 16]
    1.26  
    1.27 @@ -173,8 +175,10 @@
    1.28  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    1.29  
    1.30          mov     es, ax          ; cs:0 = ds:0 = ss:0 -> top - 512 - StackSize
    1.31 +%if ExtraBootSector == 0
    1.32          mov     ss, ax
    1.33          mov     sp, 512+StackSize ; bytes 0-511 are reserved for the boot code
    1.34 +%endif
    1.35  
    1.36  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    1.37  ;; Copy ourselves to top of memory ;;
    1.38 @@ -192,13 +196,25 @@
    1.39  ;;;;;;;;;;;;;;;;;;;;;;
    1.40  
    1.41          push    byte main
    1.42 +        push    es
    1.43 +        pop     ds
    1.44          retf
    1.45  
    1.46  main:
    1.47 -        push    cs
    1.48 -        pop     ds
    1.49 -
    1.50          xor     ebx, ebx
    1.51 +%if ExtraBootSector != 0
    1.52 +        add     al, 32
    1.53 +        mov     es, ax
    1.54 +        mov     eax, [bx(bpbHiddenSectors)]
    1.55 +        inc     eax
    1.56 + %if LBA48bits != 0
    1.57 +        mov     [bx(HiLBA)], bx
    1.58 + %endif
    1.59 +        call    ReadSectorBoot
    1.60 +        push    ds
    1.61 +        pop     ss
    1.62 +        mov     sp, 512+StackSize ; bytes 0-511 are reserved for the boot code
    1.63 +%endif
    1.64  
    1.65  %if ClusterMask != 0
    1.66          and     byte [bx(bsRootDirectoryClusterNo+3)], 0Fh ; mask cluster value
    1.67 @@ -305,7 +321,12 @@
    1.68          mov     ss, bp
    1.69          xor     sp, sp
    1.70          push    bp                      ; cs, ds and es
    1.71 +%if ExtraBootSector != 0
    1.72 +        jmp     Run
    1.73 +%macro BootFileName 0
    1.74 +%else
    1.75          jmp     short Run
    1.76 +%endif
    1.77  
    1.78  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    1.79  ;; Relocate, setup and run a .EXE program     ;;
    1.80 @@ -356,6 +377,9 @@
    1.81  ;; All done, transfer control to the program now ;;
    1.82  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    1.83          retf
    1.84 +%if ExtraBootSector != 0
    1.85 +%endm
    1.86 +%endif
    1.87  
    1.88  ;;;;;;;;;;;;;;;;;;;;;;;;;;
    1.89  ;; Error Messaging Code ;;
    1.90 @@ -413,8 +437,19 @@
    1.91          div     esi                             ; eax=FAT sector #, edx=entry # in sector
    1.92  
    1.93          imul    si, dx, byte 4                  ; si=entry # in sector, clear C
    1.94 -%if LBA48bits != 0
    1.95 +%if NonMirroredFATs != 0
    1.96 +        cwde
    1.97 +        or      dl, byte [bx(bsExtendedFlags)]
    1.98 +        jns     MirroredFATs                    ; Non-mirrored FATs ?
    1.99 +        and     dl, 0Fh
   1.100 +        imul    edx, dword [bx(bsSectorsPerFAT32)] ; we need to read the active one
   1.101 +        add     eax, edx
   1.102 +MirroredFATs:
   1.103 +        cwde
   1.104 +%else
   1.105 + %if LBA48bits != 0
   1.106          xor     dx, dx
   1.107 + %endif
   1.108  %endif
   1.109          call    ReadSectorLBAfromFAT            ; read 1 FAT32 sector
   1.110  
   1.111 @@ -464,6 +499,7 @@
   1.112  %if LBA48bits != 0
   1.113          adc     word [bx(HiLBA)], bx
   1.114  %endif
   1.115 +ReadSectorBoot:
   1.116          mov     dx, [bx(DriveNumber)]   ; restore BIOS boot drive number
   1.117          pusha
   1.118  
   1.119 @@ -572,3 +608,10 @@
   1.120  ;;;;;;;;;;;;;;;;;;;;;;;;;;
   1.121  
   1.122                  dw      0AA55h          ; BIOS checks for this ID
   1.123 +
   1.124 +%if ExtraBootSector != 0
   1.125 +                dd      61415252h       ; "RRaA"
   1.126 +                BootFileName
   1.127 +                times (996-($-$$)) db 0
   1.128 +;                dd      41617272h       ; "rrAa"
   1.129 +%endif