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