[90] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Functions for accessings RAMVARS.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | ;--------------------------------------------------------------------
|
---|
| 8 | ; Initializes RAMVARS.
|
---|
| 9 | ; Drive detection can be started after this function returns.
|
---|
| 10 | ;
|
---|
| 11 | ; RamVars_Initialize
|
---|
| 12 | ; Parameters:
|
---|
| 13 | ; Nothing
|
---|
| 14 | ; Returns:
|
---|
[97] | 15 | ; DS: RAMVARS segment
|
---|
[3] | 16 | ; Corrupts registers:
|
---|
[97] | 17 | ; AX, CX, DI
|
---|
[3] | 18 | ;--------------------------------------------------------------------
|
---|
| 19 | RamVars_Initialize:
|
---|
[90] | 20 | push es
|
---|
[97] | 21 | ; Fall to .StealMemoryForRAMVARS
|
---|
[3] | 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
[33] | 24 | ; .StealMemoryForRAMVARS
|
---|
[3] | 25 | ; Parameters:
|
---|
| 26 | ; Nothing
|
---|
| 27 | ; Returns:
|
---|
| 28 | ; DS: RAMVARS segment
|
---|
| 29 | ; Corrupts registers:
|
---|
| 30 | ; AX
|
---|
| 31 | ;--------------------------------------------------------------------
|
---|
[33] | 32 | .StealMemoryForRAMVARS:
|
---|
[3] | 33 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
|
---|
[97] | 34 | jz SHORT .InitializeRamvars ; No need to steal RAM
|
---|
[3] | 35 |
|
---|
[116] | 36 | LOAD_BDA_SEGMENT_TO ds, ax, ! ; Zero AX
|
---|
[3] | 37 | mov al, [cs:ROMVARS.bStealSize]
|
---|
[33] | 38 | sub [BDA.wBaseMem], ax
|
---|
| 39 | mov ax, [BDA.wBaseMem]
|
---|
[97] | 40 | eSHL_IM ax, 6 ; Segment to first stolen kB (*=40h)
|
---|
[33] | 41 | mov ds, ax
|
---|
[97] | 42 | mov WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
|
---|
| 43 | ; Fall to .InitializeRamvarsFromDS
|
---|
[3] | 44 |
|
---|
[33] | 45 | ;--------------------------------------------------------------------
|
---|
[97] | 46 | ; .InitializeRamvars
|
---|
[33] | 47 | ; Parameters:
|
---|
[97] | 48 | ; Nothing
|
---|
| 49 | ; Returns:
|
---|
[33] | 50 | ; DS: RAMVARS segment
|
---|
| 51 | ; Corrupts registers:
|
---|
| 52 | ; AX, CX, DI, ES
|
---|
| 53 | ;--------------------------------------------------------------------
|
---|
[97] | 54 | .InitializeRamvars:
|
---|
| 55 | call RamVars_GetSegmentToDS
|
---|
| 56 | mov cx, RAMVARS_size
|
---|
| 57 | xor di, di
|
---|
[33] | 58 | push ds
|
---|
| 59 | pop es
|
---|
[97] | 60 | call Memory_ZeroESDIwithSizeInCX
|
---|
| 61 | ; Fall to .InitializeDriveTranslationAndReturn
|
---|
[3] | 62 |
|
---|
[97] | 63 | ;--------------------------------------------------------------------
|
---|
| 64 | ; .InitializeDriveTranslationAndReturn
|
---|
| 65 | ; Parameters:
|
---|
| 66 | ; DS: RAMVARS segment
|
---|
| 67 | ; Returns:
|
---|
| 68 | ; Nothing
|
---|
| 69 | ; Corrupts registers:
|
---|
| 70 | ; AX
|
---|
| 71 | ;--------------------------------------------------------------------
|
---|
| 72 | .InitializeDriveTranslationAndReturn:
|
---|
| 73 | pop es
|
---|
| 74 | jmp DriveXlate_Reset
|
---|
[33] | 75 |
|
---|
[97] | 76 |
|
---|
[3] | 77 | ;--------------------------------------------------------------------
|
---|
| 78 | ; Returns segment to RAMVARS.
|
---|
| 79 | ; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
|
---|
| 80 | ; or at the top of system base RAM.
|
---|
| 81 | ;
|
---|
| 82 | ; RamVars_GetSegmentToDS
|
---|
| 83 | ; Parameters:
|
---|
| 84 | ; Nothing
|
---|
| 85 | ; Returns:
|
---|
| 86 | ; DS: RAMVARS segment
|
---|
| 87 | ; Corrupts registers:
|
---|
| 88 | ; DI
|
---|
| 89 | ;--------------------------------------------------------------------
|
---|
| 90 | ALIGN JUMP_ALIGN
|
---|
| 91 | RamVars_GetSegmentToDS:
|
---|
| 92 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
|
---|
[33] | 93 | jnz SHORT .GetStolenSegmentToDS
|
---|
[3] | 94 | mov di, SEGMENT_RAMVARS_TOP_OF_INTERRUPT_VECTORS
|
---|
| 95 | mov ds, di
|
---|
| 96 | ret
|
---|
| 97 |
|
---|
| 98 | ALIGN JUMP_ALIGN
|
---|
[33] | 99 | .GetStolenSegmentToDS:
|
---|
[3] | 100 | LOAD_BDA_SEGMENT_TO ds, di
|
---|
| 101 | mov di, [BDA.wBaseMem] ; Load available base memory size in kB
|
---|
[33] | 102 | eSHL_IM di, 6 ; Segment to first stolen kB (*=40h)
|
---|
[3] | 103 | ALIGN JUMP_ALIGN
|
---|
| 104 | .LoopStolenKBs:
|
---|
| 105 | mov ds, di ; EBDA segment to DS
|
---|
| 106 | add di, BYTE 64 ; DI to next stolen kB
|
---|
| 107 | cmp WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
|
---|
| 108 | jne SHORT .LoopStolenKBs ; Loop until sign found (always found eventually)
|
---|
| 109 | ret
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | ;--------------------------------------------------------------------
|
---|
| 113 | ; Checks if INT 13h function is handled by this BIOS.
|
---|
| 114 | ;
|
---|
| 115 | ; RamVars_IsFunctionHandledByThisBIOS
|
---|
| 116 | ; Parameters:
|
---|
| 117 | ; AH: INT 13h function number
|
---|
| 118 | ; DL: Drive number
|
---|
| 119 | ; DS: RAMVARS segment
|
---|
| 120 | ; Returns:
|
---|
| 121 | ; CF: Set if function is handled by this BIOS
|
---|
| 122 | ; Cleared if function belongs to some other BIOS
|
---|
| 123 | ; Corrupts registers:
|
---|
| 124 | ; DI
|
---|
| 125 | ;--------------------------------------------------------------------
|
---|
| 126 | ALIGN JUMP_ALIGN
|
---|
| 127 | RamVars_IsFunctionHandledByThisBIOS:
|
---|
| 128 | test ah, ah ; Reset for all floppy and hard disk drives?
|
---|
[32] | 129 | jz SHORT .FunctionIsHandledByOurBIOS
|
---|
| 130 | cmp ah, 08h ; Read Disk Drive Parameters?
|
---|
| 131 | jne SHORT RamVars_IsDriveHandledByThisBIOS
|
---|
[128] | 132 | test dl, dl ; We do not handle floppy drives
|
---|
| 133 | jns SHORT .FunctionIsNotHandledByOurBIOS
|
---|
[32] | 134 | ALIGN JUMP_ALIGN
|
---|
| 135 | .FunctionIsHandledByOurBIOS:
|
---|
[3] | 136 | stc
|
---|
[32] | 137 | .FunctionIsNotHandledByOurBIOS:
|
---|
[3] | 138 | ret
|
---|
| 139 |
|
---|
| 140 | ;--------------------------------------------------------------------
|
---|
| 141 | ; Checks if drive is handled by this BIOS.
|
---|
| 142 | ;
|
---|
| 143 | ; RamVars_IsDriveHandledByThisBIOS
|
---|
| 144 | ; Parameters:
|
---|
| 145 | ; DL: Drive number
|
---|
| 146 | ; DS: RAMVARS segment
|
---|
| 147 | ; Returns:
|
---|
| 148 | ; CF: Set if drive is handled by this BIOS
|
---|
| 149 | ; Cleared if drive belongs to some other BIOS
|
---|
| 150 | ; Corrupts registers:
|
---|
| 151 | ; DI
|
---|
| 152 | ;--------------------------------------------------------------------
|
---|
| 153 | ALIGN JUMP_ALIGN
|
---|
| 154 | RamVars_IsDriveHandledByThisBIOS:
|
---|
| 155 | xchg di, ax ; Backup AX
|
---|
| 156 | mov ax, [RAMVARS.wDrvCntAndFirst] ; Drive count to AL, First number to AH
|
---|
| 157 | add al, ah ; One past last drive to AL
|
---|
| 158 | cmp dl, al ; Above last supported?
|
---|
| 159 | jae SHORT .DriveNotHandledByThisBIOS
|
---|
| 160 | cmp dl, ah ; Below first supported?
|
---|
| 161 | jb SHORT .DriveNotHandledByThisBIOS
|
---|
| 162 | xchg ax, di
|
---|
| 163 | stc
|
---|
| 164 | ret
|
---|
| 165 | ALIGN JUMP_ALIGN
|
---|
| 166 | .DriveNotHandledByThisBIOS:
|
---|
| 167 | xchg ax, di
|
---|
| 168 | clc
|
---|
| 169 | ret
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | ;--------------------------------------------------------------------
|
---|
| 173 | ; RamVars_IncrementHardDiskCount
|
---|
| 174 | ; Parameters:
|
---|
| 175 | ; DL: Drive number for new drive
|
---|
| 176 | ; DS: RAMVARS segment
|
---|
| 177 | ; Returns:
|
---|
| 178 | ; Nothing
|
---|
| 179 | ; Corrupts registers:
|
---|
| 180 | ; Nothing
|
---|
| 181 | ;--------------------------------------------------------------------
|
---|
| 182 | RamVars_IncrementHardDiskCount:
|
---|
| 183 | inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
|
---|
| 184 | cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
|
---|
| 185 | ja SHORT .Return ; If so, return
|
---|
| 186 | mov [RAMVARS.bFirstDrv], dl ; Store first drive number
|
---|
| 187 | .Return:
|
---|
| 188 | ret
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | ;--------------------------------------------------------------------
|
---|
[32] | 192 | ; RamVars_GetHardDiskCountFromBDAtoCX
|
---|
[3] | 193 | ; Parameters:
|
---|
| 194 | ; DS: RAMVARS segment
|
---|
| 195 | ; Returns:
|
---|
[32] | 196 | ; CX: Total hard disk count
|
---|
[3] | 197 | ; Corrupts registers:
|
---|
[32] | 198 | ; Nothing
|
---|
[116] | 199 | ;--------------------------------------------------------------------
|
---|
[3] | 200 | ALIGN JUMP_ALIGN
|
---|
[32] | 201 | RamVars_GetHardDiskCountFromBDAtoCX:
|
---|
[3] | 202 | push es
|
---|
[32] | 203 | push dx
|
---|
| 204 |
|
---|
[116] | 205 | LOAD_BDA_SEGMENT_TO es, cx, ! ; Zero CX
|
---|
[32] | 206 | call RamVars_GetCountOfKnownDrivesToDL
|
---|
| 207 | MAX_U dl, [es:BDA.bHDCount]
|
---|
| 208 | mov cl, dl
|
---|
| 209 |
|
---|
| 210 | pop dx
|
---|
[3] | 211 | pop es
|
---|
| 212 | ret
|
---|
[32] | 213 |
|
---|
| 214 | ;--------------------------------------------------------------------
|
---|
| 215 | ; RamVars_GetCountOfKnownDrivesToDL
|
---|
| 216 | ; Parameters:
|
---|
| 217 | ; DS: RAMVARS segment
|
---|
| 218 | ; Returns:
|
---|
| 219 | ; DL: Total hard disk count
|
---|
| 220 | ; Corrupts registers:
|
---|
| 221 | ; Nothing
|
---|
[116] | 222 | ;--------------------------------------------------------------------
|
---|
[32] | 223 | ALIGN JUMP_ALIGN
|
---|
| 224 | RamVars_GetCountOfKnownDrivesToDL:
|
---|
| 225 | mov dl, [RAMVARS.bFirstDrv] ; Number for our first drive
|
---|
| 226 | add dl, [RAMVARS.bDrvCnt] ; Our drives
|
---|
| 227 | and dl, 7Fh ; Clear HD bit for drive count
|
---|
| 228 | ret
|
---|
[33] | 229 |
|
---|
| 230 |
|
---|
| 231 | ;--------------------------------------------------------------------
|
---|
| 232 | ; RamVars_GetIdeControllerCountToCX
|
---|
| 233 | ; Parameters:
|
---|
| 234 | ; Nothing
|
---|
| 235 | ; Returns:
|
---|
| 236 | ; CX: Number of IDE controllers to handle
|
---|
| 237 | ; Corrupts registers:
|
---|
| 238 | ; Nothing
|
---|
[116] | 239 | ;--------------------------------------------------------------------
|
---|
[33] | 240 | RamVars_GetIdeControllerCountToCX:
|
---|
[99] | 241 | eMOVZX cx, BYTE [cs:ROMVARS.bIdeCnt]
|
---|
[33] | 242 | ret
|
---|