Ignore:
Timestamp:
May 5, 2011, 2:00:00 PM (14 years ago)
Author:
Ben Rietbroek
Message:

AiR-BOOT v1.06 -- Complete sourceforge mirror. (r56) [2010-02-19]
Signature-date: 2006-03-13.
Also contains binairy releases from v1.01 to v1.06, cd-rom images, etc.
If you want the whole pre v1.07 shebang, checkout this revision's trunk.
The v1.06 reference version is in 'tags/v1.06r'.
Note that this reference version uses 'NL' for 'Dutch'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BOOTCODE/REGULAR/DRIVEIO.ASM

    r26 r29  
    1 
    2 ; Disclaimer:
    3 ;=============
    4 ; The sourcecode is released via www.netlabs.org CVS *ONLY*.
    5 ;  You MUST NOT upload it to other servers nor republish it in any way.
    6 The sourcecode is still COPYRIGHTED and NOT RELEASED UNDER GPL.
    7 It's (c) Copyright 1998-2003 by Martin Kiewitz.
    8 You may recompile the source and do *PRIVATE* modifications, but please keep
    9 ;  in mind that modifying this code needs at least *some* assembly skill. If
    10 ;  you mess up your system, because you needed to hack your way through, don't
    11 blame me. Releasing a customized version of AiR-BOOT, selling it in any form
    12 or reusing parts of this source is *PROHIBITED*. Ask me, if you have some
    13 idea about new functionality *before* developing the code, otherwise I will
    14 ;  definitely reject it. Also please accept, that I have some basic design
    15 ;  rules on AiR-BOOT and I will maintain them at all costs, so this won't get
    16 another GRUB.
    17 
     1; AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
     2;
     3; This file is part of AiR-BOOT
     4;
     5; AiR-BOOT is free software: you can redistribute it and/or modify it under
     6the terms of the GNU General Public License as published by the Free
     7Software Foundation, either version 3 of the License, or (at your option)
     8any later version.
     9;
     10; AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
     11WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
     12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     13details.
     14;
     15; You should have received a copy of the GNU General Public License along with
     16AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
     17;
    1818;---------------------------------------------------------------------------
    1919;                                                      AiR-BOOT / DRIVE I/O
    2020;---------------------------------------------------------------------------
    2121
    22 ; Note: Some routines set DS/ES to CS, even if its not needed.
    23 ;        This was done for SECURITY. So DO NOT remove it. Its there to make
    24 ;        sure the correct data is loaded/written to/from harddrive.
    25 ;
    26 ;  IF YOU MODIFY ANYTHING IN HERE, YOU CAN EASILY BREAK YOUR HARDDRIVE!
     22; Note: Some routines set DS/ES to CS or even address via CS, even if its not
     23;        needed. This was done for SECURITY. So DO NOT remove it.
     24;        Its there to make sure the correct data is loaded/written to/from
     25;        harddrive.
     26;
     27;  IF YOU MODIFY ANYTHING IN HERE, YOU MAY EASILY BREAK YOUR HARDDRIVE!
    2728
    2829; Will only load base-configuration, will NOT load IPT nor Hide-Config
     
    124125;  Internal access (to AiR-BOOT) is always done via INT 13h/CHS.
    125126
     127DriveIO_GetHardDriveCount       Proc Near   Uses ds si
     128   push    ds si
     129      push    0040h
     130      pop     ds
     131      mov     si, 0075h
     132      mov     dh, ds:[si]                ; 40:75 -> POST: Total Harddiscs == DL
     133   pop     si ds
     134   mov     TotalHarddiscs, dh
     135   ret
     136DriveIO_GetHardDriveCount       EndP
     137
     138
     139; Fills our LBA-Usage table. It holds the LBA-address, where BIOS/CHS access is
     140;  stopped and BIOS/LBA access is started.
     141;  This is calculated by Sector*Heads. Comparing will get done with Bit 25-10
     142;  on LBA sectors, so we actually divide sector number by 1024.
     143DriveIO_InitLBASwitchTable      Proc Near   Uses es di
     144   mov     di, offset LBASwitchTable
     145   mov     dh, TotalHarddiscs
     146   mov     dl, 80h
     147  DIOILUT_DriveLoop:
     148      push    dx di
     149         mov     ah, 08h
     150         int     13h            ; DISK - GET DRIVE PARAMETERS
     151         mov     ah, 0FBh       ; Assume 255 heads/63 sectors, if error
     152         jc      DIOILUT_Error
     153         and     cl, 111111b    ; Isolate lower 6 bits of CL -> sector count
     154         movzx   ax, cl
     155         mov     bl, dh         ; DH -> head count
     156         mul     bl             ; AX = Sectors*Heads
     157         shl     ah, 1
     158         shl     ah, 1          ; Shift 2 bits, so we are able to compare to
     159                                ;  bit 16-23 of the LBA address
     160        DIOILUT_Error:
     161      pop     di dx
     162      mov     bptr ds:[di], ah  ; Save that value
     163      inc     di                ; Go to next BYTE
     164      inc     dl
     165   dec     dh
     166   jnz     DIOILUT_DriveLoop
     167   ret
     168DriveIO_InitLBASwitchTable      EndP
     169
     170; Adjusts BX:AX / CX:DX to meet LVM sector location
     171;  Destroys SI
     172DriveIO_LVMAdjustToInfoSector   Proc Near   Uses
     173   push    cx
     174      xor     ch, ch
     175      and     cl, 63                     ; Isolate lower bits, because upper
     176      mov     si, 63                     ;  ones may be used for cylinder
     177      sub     si, cx
     178   pop     cx
     179   add     ax, si
     180   adc     bx, 0                         ; Adjust LBA Sector (BX:AX)
     181   or      cl, 63                        ; Set Sector to 63
     182   ret
     183DriveIO_LVMAdjustToInfoSector   EndP
     184
    126185Comment *ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    127186 Routine: Loads partition to ExecBase and checks for validity
     
    132191 Preserve: all registers
    133192 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ*
    134 DriveIO_LoadPartition           Proc Near  Uses ds si
    135    int 3
     193DriveIO_LoadPartition           Proc Near  Uses si
    136194   mov     wptr cs:[CurPartition_Location+0], ax
    137195   mov     wptr cs:[CurPartition_Location+2], bx
    138196   mov     wptr cs:[CurPartition_Location+4], dx
    139197   mov     wptr cs:[CurPartition_Location+6], cx ; Saves the location
    140    push    ExecBaseSeg
    141    pop     ds
    142    mov     si, ExecBasePtr               ; DS:SI - ExecBase
     198   mov     si, offset PartitionSector    ; DS:SI - ExecBase
    143199   call    DriveIO_LoadSector
    144200   clc
    145    cmp     word ptr ds:[si+LocBR_Magic], 0AA55h
     201   cmp     wptr [si+LocBR_Magic], 0AA55h
    146202   je      DIOLP_Success
    147203   ; We check, if we are scanning partitions. In that case, if CHS is not 0/0/1
     
    165221 Preserve: all registers
    166222 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ*
    167 DriveIO_SavePartition           Proc Near  Uses ax bx cx dx ds si
     223DriveIO_SavePartition           Proc Near  Uses ax bx cx dx si
    168224   mov     ax, wptr cs:[CurPartition_Location+0]
    169225   mov     bx, wptr cs:[CurPartition_Location+2]
    170226   mov     dx, wptr cs:[CurPartition_Location+4]
    171227   mov     cx, wptr cs:[CurPartition_Location+6] ; Gets prev. saved location
    172    push    ExecBaseSeg
    173    pop     ds
    174    mov     si, ExecBasePtr               ; DS:SI - ExecBase
     228   mov     si, offset PartitionSector    ; DS:SI - ExecBase
     229   cmp     wptr [si+LocBR_Magic], 0AA55h ; Checks for signature, if not found
     230   jne     DIOSP_SevereError             ;  we assume a really bad error
    175231   call    DriveIO_SaveSector
     232  DIOSP_SevereError:
    176233   ret
    177234DriveIO_SavePartition           EndP
    178235
    179 ; L„sst DS:SI fr Aufrufer
     236; Keeps DS:SI for caller
    180237DriveIO_LoadTmpSector           Proc Near  Uses
    181    push    cs
    182    pop     ds
    183238   mov     si, offset TmpSector
    184239   call    DriveIO_LoadSector
     
    186241DriveIO_LoadTmpSector           EndP
    187242
    188 ; L„sst DS:SI fr Aufrufer
     243; Keeps DS:SI for caller
    189244DriveIO_SaveTmpSector           Proc Near  Uses
    190    push    cs
    191    pop     ds
    192245   mov     si, offset TmpSector
    193246   call    DriveIO_SaveSector
    194247   ret
    195248DriveIO_SaveTmpSector           EndP
     249
     250; Keeps DS:SI for caller, sets carry if valid LVM sector encountered
     251DriveIO_LoadLVMSector           Proc Near  Uses ax bx cx dx
     252   test    [CFG_IgnoreLVM], 1            ; We are supposed to ignore LVM, so
     253   jnz     DIOLLVMS_NoLVMSector          ;  don't load but declare as bad!
     254   mov     ax, wptr cs:[CurPartition_Location+0]
     255   mov     bx, wptr cs:[CurPartition_Location+2]
     256   mov     dx, wptr cs:[CurPartition_Location+4]
     257   mov     cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location
     258   call    DriveIO_LVMAdjustToInfoSector
     259   mov     si, offset LVMSector
     260   call    DriveIO_LoadSector
     261   call    LVM_CheckSectorSignature
     262   jnc     DIOLLVMS_NoLVMSector
     263   call    LVM_CheckSectorCRC
     264   jnc     DIOLLVMS_NoLVMSector
     265   ret
     266   ; This here is called, if an invalid (or no) LVM information sector is found
     267   ;  It will truncate the first byte of the sector, so all other routines
     268   ;  will notice it easily by just comparing the first byte.
     269  DIOLLVMS_NoLVMSector:
     270   mov     bptr [si+LocLVM_SignatureStart], 0
     271   ret
     272DriveIO_LoadLVMSector           EndP
     273
     274; Keeps DS:SI for caller, saves at anytime w/o checks (!)
     275DriveIO_SaveLVMSector           Proc Near  Uses ax bx cx dx
     276   test    [CFG_IgnoreLVM], 1            ; We are supposed to ignore LVM, so
     277   jnz     DIOSLVMS_SevereError          ;  don't save at anytime (security!)
     278   mov     ax, wptr cs:[CurPartition_Location+0]
     279   mov     bx, wptr cs:[CurPartition_Location+2]
     280   mov     dx, wptr cs:[CurPartition_Location+4]
     281   mov     cx, wptr cs:[CurPartition_Location+6] ; Gets cur. partition location
     282   call    LVM_CheckSectorSignature
     283   jnc     DIOSLVMS_SevereError                  ; LVM Signature must be there
     284   call    DriveIO_LVMAdjustToInfoSector
     285   mov     si, offset LVMSector
     286   call    DriveIO_SaveSector
     287  DIOSLVMS_SevereError:
     288   ret
     289DriveIO_SaveLVMSector           EndP
    196290
    197291; Memory-Block that holds information for LBA-access via INT 13h
     
    206300;  so users will notice that something is bad with their partition table(s)
    207301DriveIO_GotLoadError            Proc Near
    208    test    cs:CurIO_Scanning, 1          ; Must be CS:, cause DS!=CS here
     302   test    cs:CurIO_Scanning, 1          ; Must be CS:, cause DS!=CS maybe here
    209303   jnz     InScanMode
    210304   jmp     MBR_LoadError
     
    213307   push    cs
    214308   pop     ds
     309   call    MBR_Teletype
     310   mov     si, offset BrokenHDD
     311   sub     dl, 50h                       ; 80h -> '0'
     312   cmp     dl, 39h
     313   jbe     DIOGLE_BelowA
     314   add     dl, 7                         ; 3Ah -> 'A'
     315  DIOGLE_BelowA:
     316   mov     bptr [si+5], dl
    215317   call    MBR_Teletype
    216318   jmp     MBRLE_Halt
     
    227329 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ*
    228330DriveIO_LoadSector              Proc Near  Uses ax bx ds si es di
    229    test    cs:[CurIO_UseExtension], 1
    230    jz      DIOLS_UseNormal
    231    ; LBA-boundary >16450560 (FB0400h)
    232    cmp     bx, 00FBh
    233    jae     DIOLS_UseExtension
    234    ; or are we forced do use LBA?
    235    test    cs:[CFG_ForceLBAUsage], 1
    236    jnz     DIOLS_UseExtension
     331   test     cs:[CurIO_UseExtension], 1
     332   jz       DIOLS_UseNormal
     333   ; Are we forced do use LBA via Setting?
     334   test     cs:[CFG_ForceLBAUsage], 1
     335   jnz      DIOLS_UseExtension
     336   ; Is the drive not a harddrive?
     337   cmp      dl, 80h
     338   jb       DIOLS_UseNormal
     339   ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
     340   or       bh, bh
     341   jnz      DIOLS_UseExtension
     342   ; Compare Switch-Table value to bit 16-23 of LBA-address
     343   mov      di, dx
     344   and      di, 007Fh
     345   cmp      bptr cs:[LBASwitchTable+di], bl
     346   jbe      DIOLS_UseExtension
    237347  DIOLS_UseNormal:
    238       mov     di, 3
     348      mov      di, 3
    239349     DIOLS_ErrorLoop:
    240          push    ds
    241          pop     es
    242          mov     bx, si                      ; ES:BX - Destination
    243          mov     ax, 0201h                   ; Function 2 - Load Sector
    244          int     13h
    245          jnc     DIOLS_Success
    246       dec     di
    247       jnz     DIOLS_ErrorLoop
     350         push     ds
     351         pop      es
     352         mov      bx, si                     ; ES:BX - Destination
     353         mov      ax, 0201h                  ; Function 2 - Load Sector
     354         int      13h
     355         jnc      DIOLS_Success
     356      dec      di
     357      jnz      DIOLS_ErrorLoop
    248358      ; Sector load failed...
    249       jmp     DriveIO_GotLoadError
     359      jmp      DriveIO_GotLoadError
    250360
    251361  DIOLS_UseExtension:
     
    260370      pop     ds
    261371      mov     si, offset DriveIO_DAP
    262       mov     ah, 42h                         ; Extended Read
     372      mov     ah, 42h                        ; Extended Read
    263373      int     13h
    264374   pop     cx
     
    281391 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ*
    282392DriveIO_SaveSector              Proc Near  Uses ax bx cx ds si es di
    283    test    cs:[CurIO_UseExtension], 1
    284    jz      DIOSS_UseNormal
    285    ; LBA-boundary >16450560 (FB0400h)
    286    cmp     bx, 00FBh
    287    jae     DIOSS_UseExtension
    288    ; or are we forced do use LBA?
    289    test    cs:[CFG_ForceLBAUsage], 1
    290    jnz     DIOSS_UseExtension
     393   test     cs:[CurIO_UseExtension], 1
     394   jz       DIOSS_UseNormal
     395   ; Are we forced do use LBA via Setting?
     396   test     cs:[CFG_ForceLBAUsage], 1
     397   jnz      DIOSS_UseExtension
     398   ; Is the drive not a harddrive?
     399   cmp      dl, 80h
     400   jb       DIOSS_UseNormal
     401   ; Upper 8 bits of LBA-address set? -> Use LBA (maximum boundary is FB0400h)
     402   or       bh, bh
     403   jnz      DIOSS_UseExtension
     404   ; Compare Switch-Table value to bit 16-23 of LBA-address
     405   mov      di, dx
     406   and      di, 007Fh
     407   cmp      bptr cs:[LBASwitchTable+di], bl
     408   jbe      DIOSS_UseExtension
    291409  DIOSS_UseNormal:
    292       mov     di, 3
     410      mov      di, 3
    293411     DIOSS_ErrorLoop:
    294          push    ds
    295          pop     es
    296          mov     bx, si                      ; ES:BX - Destination
    297          mov     ax, 0301h                   ; Function 3 - Write Sector
    298          int     13h
    299          jnc     DIOSS_Success
    300       dec     di
    301       jnz     DIOSS_ErrorLoop
    302       call    MBR_SaveError
     412         push     ds
     413         pop      es
     414         mov      bx, si                     ; ES:BX - Destination
     415         mov      ax, 0301h                  ; Function 3 - Write Sector
     416         int      13h
     417         jnc      DIOSS_Success
     418      dec      di
     419      jnz      DIOSS_ErrorLoop
     420      call     MBR_SaveError
    303421
    304422  DIOSS_UseExtension:
Note: See TracChangeset for help on using the changeset viewer.