[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:
|
---|
[241] | 33 | mov ax, LITE_MODE_RAMVARS_SEGMENT
|
---|
[3] | 34 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
|
---|
[97] | 35 | jz SHORT .InitializeRamvars ; No need to steal RAM
|
---|
[3] | 36 |
|
---|
[116] | 37 | LOAD_BDA_SEGMENT_TO ds, ax, ! ; Zero AX
|
---|
[3] | 38 | mov al, [cs:ROMVARS.bStealSize]
|
---|
[33] | 39 | sub [BDA.wBaseMem], ax
|
---|
| 40 | mov ax, [BDA.wBaseMem]
|
---|
[97] | 41 | eSHL_IM ax, 6 ; Segment to first stolen kB (*=40h)
|
---|
[150] | 42 | ; Fall to .InitializeRamvars
|
---|
[3] | 43 |
|
---|
[33] | 44 | ;--------------------------------------------------------------------
|
---|
[97] | 45 | ; .InitializeRamvars
|
---|
[33] | 46 | ; Parameters:
|
---|
[241] | 47 | ; AX: RAMVARS segment
|
---|
[97] | 48 | ; Returns:
|
---|
[33] | 49 | ; DS: RAMVARS segment
|
---|
| 50 | ; Corrupts registers:
|
---|
| 51 | ; AX, CX, DI, ES
|
---|
| 52 | ;--------------------------------------------------------------------
|
---|
[97] | 53 | .InitializeRamvars:
|
---|
[241] | 54 | mov ds, ax
|
---|
| 55 | mov es, ax
|
---|
[97] | 56 | mov cx, RAMVARS_size
|
---|
| 57 | xor di, di
|
---|
| 58 | call Memory_ZeroESDIwithSizeInCX
|
---|
[150] | 59 | mov WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
|
---|
[97] | 60 | ; Fall to .InitializeDriveTranslationAndReturn
|
---|
[3] | 61 |
|
---|
[97] | 62 | ;--------------------------------------------------------------------
|
---|
| 63 | ; .InitializeDriveTranslationAndReturn
|
---|
| 64 | ; Parameters:
|
---|
| 65 | ; DS: RAMVARS segment
|
---|
| 66 | ; Returns:
|
---|
| 67 | ; Nothing
|
---|
| 68 | ; Corrupts registers:
|
---|
| 69 | ; AX
|
---|
| 70 | ;--------------------------------------------------------------------
|
---|
| 71 | .InitializeDriveTranslationAndReturn:
|
---|
| 72 | pop es
|
---|
| 73 | jmp DriveXlate_Reset
|
---|
[33] | 74 |
|
---|
[97] | 75 |
|
---|
[3] | 76 | ;--------------------------------------------------------------------
|
---|
| 77 | ; Returns segment to RAMVARS.
|
---|
| 78 | ; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
|
---|
| 79 | ; or at the top of system base RAM.
|
---|
| 80 | ;
|
---|
| 81 | ; RamVars_GetSegmentToDS
|
---|
| 82 | ; Parameters:
|
---|
| 83 | ; Nothing
|
---|
| 84 | ; Returns:
|
---|
| 85 | ; DS: RAMVARS segment
|
---|
| 86 | ; Corrupts registers:
|
---|
| 87 | ; DI
|
---|
| 88 | ;--------------------------------------------------------------------
|
---|
| 89 | ALIGN JUMP_ALIGN
|
---|
| 90 | RamVars_GetSegmentToDS:
|
---|
| 91 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
|
---|
[33] | 92 | jnz SHORT .GetStolenSegmentToDS
|
---|
[181] | 93 | %ifndef USE_186
|
---|
[150] | 94 | mov di, LITE_MODE_RAMVARS_SEGMENT
|
---|
[3] | 95 | mov ds, di
|
---|
[181] | 96 | %else
|
---|
| 97 | push LITE_MODE_RAMVARS_SEGMENT
|
---|
| 98 | pop ds
|
---|
| 99 | %endif
|
---|
[3] | 100 | ret
|
---|
| 101 |
|
---|
| 102 | ALIGN JUMP_ALIGN
|
---|
[33] | 103 | .GetStolenSegmentToDS:
|
---|
[3] | 104 | LOAD_BDA_SEGMENT_TO ds, di
|
---|
| 105 | mov di, [BDA.wBaseMem] ; Load available base memory size in kB
|
---|
[33] | 106 | eSHL_IM di, 6 ; Segment to first stolen kB (*=40h)
|
---|
[3] | 107 | ALIGN JUMP_ALIGN
|
---|
| 108 | .LoopStolenKBs:
|
---|
| 109 | mov ds, di ; EBDA segment to DS
|
---|
| 110 | add di, BYTE 64 ; DI to next stolen kB
|
---|
[150] | 111 | cmp WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
|
---|
[3] | 112 | jne SHORT .LoopStolenKBs ; Loop until sign found (always found eventually)
|
---|
| 113 | ret
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | ;--------------------------------------------------------------------
|
---|
| 117 | ; Checks if INT 13h function is handled by this BIOS.
|
---|
| 118 | ;
|
---|
| 119 | ; RamVars_IsFunctionHandledByThisBIOS
|
---|
| 120 | ; Parameters:
|
---|
| 121 | ; AH: INT 13h function number
|
---|
| 122 | ; DL: Drive number
|
---|
| 123 | ; DS: RAMVARS segment
|
---|
| 124 | ; Returns:
|
---|
| 125 | ; CF: Set if function is handled by this BIOS
|
---|
| 126 | ; Cleared if function belongs to some other BIOS
|
---|
| 127 | ; Corrupts registers:
|
---|
[155] | 128 | ; Nothing
|
---|
[3] | 129 | ;--------------------------------------------------------------------
|
---|
| 130 | ALIGN JUMP_ALIGN
|
---|
| 131 | RamVars_IsFunctionHandledByThisBIOS:
|
---|
| 132 | test ah, ah ; Reset for all floppy and hard disk drives?
|
---|
[32] | 133 | jz SHORT .FunctionIsHandledByOurBIOS
|
---|
| 134 | cmp ah, 08h ; Read Disk Drive Parameters?
|
---|
| 135 | jne SHORT RamVars_IsDriveHandledByThisBIOS
|
---|
[128] | 136 | test dl, dl ; We do not handle floppy drives
|
---|
| 137 | jns SHORT .FunctionIsNotHandledByOurBIOS
|
---|
[32] | 138 | ALIGN JUMP_ALIGN
|
---|
| 139 | .FunctionIsHandledByOurBIOS:
|
---|
[3] | 140 | stc
|
---|
[32] | 141 | .FunctionIsNotHandledByOurBIOS:
|
---|
[3] | 142 | ret
|
---|
| 143 |
|
---|
| 144 | ;--------------------------------------------------------------------
|
---|
| 145 | ; Checks if drive is handled by this BIOS.
|
---|
| 146 | ;
|
---|
| 147 | ; RamVars_IsDriveHandledByThisBIOS
|
---|
| 148 | ; Parameters:
|
---|
| 149 | ; DL: Drive number
|
---|
| 150 | ; DS: RAMVARS segment
|
---|
| 151 | ; Returns:
|
---|
| 152 | ; CF: Set if drive is handled by this BIOS
|
---|
| 153 | ; Cleared if drive belongs to some other BIOS
|
---|
| 154 | ; Corrupts registers:
|
---|
[148] | 155 | ; Nothing
|
---|
[3] | 156 | ;--------------------------------------------------------------------
|
---|
| 157 | ALIGN JUMP_ALIGN
|
---|
| 158 | RamVars_IsDriveHandledByThisBIOS:
|
---|
[148] | 159 | push ax
|
---|
[3] | 160 | mov ax, [RAMVARS.wDrvCntAndFirst] ; Drive count to AL, First number to AH
|
---|
| 161 | add al, ah ; One past last drive to AL
|
---|
| 162 | cmp dl, al ; Above last supported?
|
---|
| 163 | jae SHORT .DriveNotHandledByThisBIOS
|
---|
[145] | 164 | cmp ah, dl ; Below first supported?
|
---|
| 165 | ja SHORT .DriveNotHandledByThisBIOS
|
---|
[3] | 166 | stc
|
---|
| 167 | .DriveNotHandledByThisBIOS:
|
---|
[148] | 168 | pop ax
|
---|
[3] | 169 | ret
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | ;--------------------------------------------------------------------
|
---|
[32] | 173 | ; RamVars_GetHardDiskCountFromBDAtoCX
|
---|
[3] | 174 | ; Parameters:
|
---|
| 175 | ; DS: RAMVARS segment
|
---|
| 176 | ; Returns:
|
---|
[32] | 177 | ; CX: Total hard disk count
|
---|
[3] | 178 | ; Corrupts registers:
|
---|
[32] | 179 | ; Nothing
|
---|
[116] | 180 | ;--------------------------------------------------------------------
|
---|
[3] | 181 | ALIGN JUMP_ALIGN
|
---|
[32] | 182 | RamVars_GetHardDiskCountFromBDAtoCX:
|
---|
[3] | 183 | push es
|
---|
[32] | 184 | push dx
|
---|
| 185 |
|
---|
[116] | 186 | LOAD_BDA_SEGMENT_TO es, cx, ! ; Zero CX
|
---|
[32] | 187 | call RamVars_GetCountOfKnownDrivesToDL
|
---|
[181] | 188 | mov cl, [es:BDA.bHDCount]
|
---|
| 189 | MAX_U cl, dl
|
---|
[32] | 190 |
|
---|
| 191 | pop dx
|
---|
[3] | 192 | pop es
|
---|
| 193 | ret
|
---|
[32] | 194 |
|
---|
| 195 | ;--------------------------------------------------------------------
|
---|
| 196 | ; RamVars_GetCountOfKnownDrivesToDL
|
---|
| 197 | ; Parameters:
|
---|
| 198 | ; DS: RAMVARS segment
|
---|
| 199 | ; Returns:
|
---|
| 200 | ; DL: Total hard disk count
|
---|
| 201 | ; Corrupts registers:
|
---|
| 202 | ; Nothing
|
---|
[116] | 203 | ;--------------------------------------------------------------------
|
---|
[32] | 204 | ALIGN JUMP_ALIGN
|
---|
| 205 | RamVars_GetCountOfKnownDrivesToDL:
|
---|
| 206 | mov dl, [RAMVARS.bFirstDrv] ; Number for our first drive
|
---|
| 207 | add dl, [RAMVARS.bDrvCnt] ; Our drives
|
---|
| 208 | and dl, 7Fh ; Clear HD bit for drive count
|
---|
| 209 | ret
|
---|
[33] | 210 |
|
---|
| 211 |
|
---|
| 212 | ;--------------------------------------------------------------------
|
---|
| 213 | ; RamVars_GetIdeControllerCountToCX
|
---|
| 214 | ; Parameters:
|
---|
| 215 | ; Nothing
|
---|
| 216 | ; Returns:
|
---|
| 217 | ; CX: Number of IDE controllers to handle
|
---|
| 218 | ; Corrupts registers:
|
---|
| 219 | ; Nothing
|
---|
[116] | 220 | ;--------------------------------------------------------------------
|
---|
[33] | 221 | RamVars_GetIdeControllerCountToCX:
|
---|
[99] | 222 | eMOVZX cx, BYTE [cs:ROMVARS.bIdeCnt]
|
---|
[33] | 223 | ret
|
---|