- Timestamp:
- Nov 20, 2023 11:14:01 AM (15 months ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-DiskQueryGeometry.asm
r102144 r102149 55 55 BS3_BEGIN_TEXT16 56 56 extern RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_rm) 57 BS3_EXTERN_DATA16 g_aBs3RmIvtOriginal 57 58 58 59 59 60 ;; 60 ; Performs a int 15h function 0xe820 call. 61 ; 62 ; @cproto BS3_MODE_PROTO_STUB(bool, Bs3BiosInt15hE820,(INT15E820ENTRY BS3_FAR *pEntry, uint32_t BS3_FAR *pcbEntry, 63 ; uint32_t BS3_FAR *puContinuationValue)); 64 ; 65 ; @returns Success indicator. 66 ; @param pEntry The return buffer. 67 ; @param pcbEntry Input: The size of the buffer (min 20 bytes); 68 ; Output: The size of the returned data. 69 ; @param puContinuationValue Where to get and return the continuation value (EBX) 70 ; Set to zero the for the first call. Returned as zero 71 ; after the last entry. 61 ; Performs a int 13h function 8 call. 62 ; 63 ; @cproto BS3_MODE_PROTO_STUB(uint8_t, Bs3DiskQueryGeometry,(uint8_t bDrive, uint16_t *puMaxCylinder, 64 ; uint8_t *puMaxHead, uint8_t *puMaxSector)); 65 ; 66 ; @returns Register value (ax/eax). Zero on success, non-zero on failure. 67 ; 68 ; @uses No GPRs (only return full register(s)). In 64-bit mode DS and ES is trashed. 72 69 ; 73 70 ; @remarks ASSUMES we're in ring-0 when not in some kind of real mode. 74 71 ; @remarks ASSUMES we're on a 16-bit suitable stack. 75 72 ; 76 ; @uses rax77 ;78 73 TMPL_BEGIN_TEXT 79 BS3_PROC_BEGIN_MODE Bs3 BiosInt15hE820, BS3_PBC_HYBRID74 BS3_PROC_BEGIN_MODE Bs3DiskQueryGeometry, BS3_PBC_HYBRID 80 75 push xBP 81 76 mov xBP, xSP 77 ;; @todo does not work on 286 and earlier! 82 78 sPUSHF 83 79 cli … … 87 83 push sSI 88 84 push sDI 89 %if def TMPL_16BIT85 %ifndef TMPL_64BIT 90 86 push ds 91 87 push es 92 88 %endif 89 93 90 ; Load/Save parameters. 94 %define a_pEntry [xBP + xCB + cbCurRetAddr + sCB*0] 95 %define a_pcbEntry [xBP + xCB + cbCurRetAddr + sCB*1] 96 %define a_puContinuationValue [xBP + xCB + cbCurRetAddr + sCB*2] 91 %define a_bDrive [xBP + xCB + cbCurRetAddr + xCB*0] 92 %define a_puMaxCylinder [xBP + xCB + cbCurRetAddr + xCB + sCB*0] 93 %define a_pMaxHead [xBP + xCB + cbCurRetAddr + xCB + sCB*1] 94 %define a_puMaxSector [xBP + xCB + cbCurRetAddr + xCB + sCB*2] 95 97 96 %ifdef TMPL_64BIT 98 mov a_pEntry, rcx ; save pEntry 99 mov a_pcbEntry, rdx ; save pcbEntry 100 mov a_puContinuationValue, r8 ; save a_puContinuationValue 101 mov ebx, [r8] ; uContinuationValue for int15 102 mov ecx, [rdx] ; Buffer size for int15. 103 %elifdef TMPL_16BIT 104 les bx, a_pcbEntry 105 mov ecx, [es:bx] ; Buffer size for int15. 106 les bx, a_puContinuationValue 107 mov ebx, [es:bx] ; Buffer size for int15. 97 mov a_bDrive, rcx ; save bDrive 98 mov a_puMaxCylinder, rdx ; save pcCylinders 99 mov a_pMaxHead, r8 ; save pcHeads 100 mov a_puMaxSector, r9 ; save pcSectors 101 movzx edx, cl ; dl = drive 108 102 %else 109 mov ecx, a_pcbEntry 110 mov ecx, [ecx] ; Buffer size for int15. 111 mov ebx, a_puContinuationValue 112 mov ebx, [ebx] ; uContinuationValue for int15 113 %endif 114 ; 115 ; Check that the cbEntry isn't too big or too small before doing 116 ; the stack allocation. (Our BIOS doesn't check if too small.) 117 ; 118 cmp ecx, 100h 119 jae .failed 120 cmp cl, 14h 121 jb .failed 122 123 %if TMPL_MODE != BS3_MODE_RM 124 sub xSP, xCX ; allocate a temporary buffer on the stack. 125 and xSP, ~0fh 126 %endif 127 128 ; 129 ; Switch to real mode, first we just ot the 16-bit text segment. 103 mov dl, a_bDrive ; dl = drive 104 %endif 105 106 ; 107 ; Switch to real mode, first we just to the 16-bit text segment. 130 108 ; This preserve all 32-bit register values. 131 109 ; … … 140 118 BS3_SET_BITS 16 141 119 %endif 120 ; Ralf Brown suggest setting es:di to NULL before the call. This is also helpful 121 ; wrt to IVT manipulation (next step). 122 xor di, di 123 mov es, di 124 125 ; 126 ; Save current and restore the original IVT[13h] entry. 127 ; 128 mov si, seg g_aBs3RmIvtOriginal 129 mov ds, si 130 mov si, g_aBs3RmIvtOriginal 131 132 push word [es:13h * 4] 133 mov ax, [si + 13h * 4] 134 mov [es:13h * 4], ax 135 136 push word [es:13h * 4 + 2] 137 mov ax, [si + 13h * 4 + 2] 138 mov [es:13h * 4 + 2], ax 142 139 143 140 ; 144 141 ; Make the call. 145 142 ; 146 %if TMPL_MODE == BS3_MODE_RM 147 les di, a_pEntry 148 %else 149 push ss ; es:di -> ss:sp 150 pop es 151 mov di, sp 152 %endif 153 mov edx, INT15_E820_SIGNATURE 154 mov eax, 0e820h ; BIOS function number 155 int 15h 143 mov ax, 0800h ; ah=08h 144 xor di, di ; ralf brown suggestion to guard against bios bugs. 145 mov es, di 146 int 13h 147 148 ; 149 ; Restore the modified IVT[13h] entry. 150 ; Must not touch EFLAGS.CF! 151 ; 152 push word 0 153 pop ds 154 pop word [ds:13h * 4 + 2] 155 pop word [ds:13h * 4] 156 156 157 157 ; … … 170 170 ; Check that we didn't failed. 171 171 ; 172 jc .failed 173 cmp eax, INT15_E820_SIGNATURE 174 jc .failed 175 cmp ecx, 20 176 jb .failed 177 178 ; 179 ; Save the continuation value. 172 jc .failed_return_ah 173 174 ; 175 ; Save the return values. 176 ; CL[7:6]:CH = max cylinders. 177 ; DH = max heads 178 ; CL[5:0] = max sectors 179 ; Other stuff we don't care about: 180 ; AH = 0 181 ; AL = undefined/zero 182 ; BL = drive type 183 ; DL = max drives. 184 ; ES:DI = driver parameter table for floppies. 180 185 ; 181 186 %ifdef TMPL_16BIT 182 mov eax, ebx 183 lds bx, a_puContinuationValue 184 mov [bx], eax 187 les di, a_pMaxHead 188 mov [es:di], dh 189 190 les di, a_puMaxSector 191 mov al, 3fh 192 and al, cl 193 mov [es:di], al 194 195 les di, a_puMaxCylinder 196 shr cl, 6 197 xchg cl, ch 198 mov [es:di], cx 185 199 %else 186 mov xAX, a_puContinuationValue 187 mov [xAX], ebx 188 %endif 189 190 ; 191 ; Save the entry size. 192 ; 193 %ifdef TMPL_16BIT 194 lds bx, a_pcbEntry 195 %else 196 mov xBX, a_pcbEntry 197 %endif 198 mov [xBX], ecx 199 200 %if TMPL_MODE != BS3_MODE_RM 201 ; 202 ; Copy the returned stuff into the caller's buffer. 203 ; 204 mov xSI, xSP 205 %ifdef TMPL_16BIT 206 push ss 207 pop es 208 lds di, a_pEntry 209 %else 210 mov xDI, a_pEntry 211 %endif 212 cld 213 rep movsb 200 mov xDI, a_pMaxHead 201 mov [xDI], dh 202 203 mov xDI, a_puMaxSector 204 mov al, 3fh 205 and al, cl 206 mov [xDI], al 207 208 mov xDI, a_puMaxCylinder 209 shr cl, 6 210 xchg cl, ch 211 mov [xDI], cx 214 212 %endif 215 213 … … 217 215 ; Return success 218 216 ; 219 mov al, 1217 mov al, 0 220 218 221 219 .return: 222 %if def TMPL_16BIT220 %ifndef TMPL_64BIT 223 221 lea xSP, [xBP - sCB * 6 - xCB*2] 224 222 pop es … … 239 237 ; Failed. 240 238 ; 241 .failed: 242 xor al, al 239 .failed_return_ah: 240 mov al, ah 241 cmp al, 0 242 jne .return 243 dec al 243 244 jmp .return 244 245 BS3_PROC_END_MODE Bs3BiosInt15hE820
Note:
See TracChangeset
for help on using the changeset viewer.