Changeset 60365 in vbox for trunk/src/VBox/ValidationKit/bootsectors
- Timestamp:
- Apr 7, 2016 2:57:15 AM (9 years ago)
- Location:
- trunk/src/VBox/ValidationKit/bootsectors/bs3kit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-bootsector.asm
r60319 r60365 8 8 9 9 ; 10 ; Copyright (C) 2007-201 5Oracle Corporation10 ; Copyright (C) 2007-2016 Oracle Corporation 11 11 ; 12 12 ; This file is part of VirtualBox Open Source Edition (OSE), as … … 49 49 50 50 BITS 16 51 CPU 8086 51 52 start: 52 53 jmp short bs3InitCode … … 106 107 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.rax], ax 107 108 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.rsp], sp 108 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.rbp], bp109 109 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.ss], ss 110 110 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.ds], ds 111 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.es], es112 111 113 112 ; set up the segment reisters and stack. 114 113 mov ax, 0 115 114 mov ds, ax 116 mov es, ax117 115 mov ss, ax 118 116 mov sp, BS3_ADDR_STACK 117 118 ; Save more registers, without needing cs prefix. 119 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rcx], cx 120 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdi], di 121 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.es], es 122 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rbp], bp 123 124 ; Load es and setup bp frame. 125 mov es, ax 119 126 mov bp, sp 120 127 mov [bp], ax ; clear the first 8 bytes (terminates the ebp chain) … … 129 136 ; Clear the register area. 130 137 ; 131 push cx132 push di133 138 mov di, BS3_ADDR_REG_SAVE 134 139 mov cx, BS3REGCTX_size/2 135 140 cld 136 141 rep stosw 137 pop di138 pop cx139 142 140 143 ; … … 148 151 149 152 ; 2. On a 286 you cannot popf IOPL and NT from real mode. 150 or ah, (X86_EFL_IOPL | X86_EFL_NT) >> 8 153 .detect_286_or_386plus: 154 CPU 286 155 mov ah, (X86_EFL_IOPL | X86_EFL_NT) >> 8 151 156 push ax 152 157 popf 153 158 pushf 159 cmp ah, [bp - 3] 154 160 pop ax 155 test ah, (X86_EFL_IOPL | X86_EFL_NT) >> 8 156 jz .is_80286 157 ; 386 or later. 158 161 je .is_386plus 162 .is_80286: 163 CPU 286 164 smsw [BS3_ADDR_REG_SAVE + BS3REGCTX.cr0] 165 .pre_80286: 166 CPU 8086 167 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rbx], bx 168 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdx], dx 169 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rsi], si 170 jmp .do_load 159 171 160 172 ; Save 386 registers. We can now skip the CS prefix as DS is flat. 173 CPU 386 174 .is_386plus: 161 175 shr eax, 16 162 176 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rax+2], ax … … 167 181 shr eax, 16 168 182 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rbp+2], ax 183 shr edi, 16 184 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdi+2], di 185 shr ecx, 16 186 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rcx+2], cx 169 187 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.fs], fs 170 188 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.gs], gs 171 189 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rbx], ebx 172 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rcx], ecx173 190 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdx], edx 174 191 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rsi], esi 175 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdi], edi176 192 mov eax, cr2 177 193 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.cr2], eax … … 186 202 ; Pentium/486+: CR4 requires VME/CPUID, so we need to detect that before accessing it. 187 203 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.cr4], eax 188 popf 204 popf ; (restores IOPL+NT) 189 205 pushfd 190 206 pop eax … … 205 221 and eax, ~(X86_CR0_NW | X86_CR0_CD | X86_CR0_AM) 206 222 mov cr0, eax 207 jmp .do_load208 209 .is_80286:210 smsw [BS3_ADDR_REG_SAVE + BS3REGCTX.cr0]211 .pre_80286:212 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rbx], bx213 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rcx], cx214 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdx], dx215 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rsi], si216 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdi], di217 223 218 224 ; Load all the code. … … 220 226 mov [g_bBootDrv], dl 221 227 call bs3InitLoadImage 228 %if 0 229 mov al, '=' 230 call bs3PrintChrInAl 231 %endif 222 232 223 233 ; … … 230 240 Bs3Panic: 231 241 cli 232 ;hlt233 242 jmp Bs3Panic 243 244 245 ;; For debug and error handling. 246 ; @uses ax 247 bs3PrintHexInAl: 248 CPU 286 249 push ax 250 shr al, 4 251 call bs3PrintHexDigitInAl 252 pop ax 253 bs3PrintHexDigitInAl: 254 and al, 0fh 255 cmp al, 10 256 jb .decimal 257 add al, 'a' - '0' - 10 258 .decimal: 259 add al, '0' 260 bs3PrintChrInAl: 261 push bx 262 mov ah, 0eh 263 mov bx, 0ff00h 264 int 10h 265 pop bx 266 ret 234 267 235 268 … … 251 284 push dx 252 285 %define bMaxSector byte [bp - 06h] 253 push 0 286 xor ax, ax 287 push ax 254 288 %define bMaxHead byte [bp - 08h] 255 push 0289 push ax 256 290 %define bMaxCylinder byte [bp - 0ah] 257 push 0291 push ax 258 292 259 293 ; … … 277 311 xor dh, dh ; dh/head=0 278 312 .the_load_loop: 313 %if 0 314 mov al, 'c' 315 call bs3PrintChrInAl 316 mov al, ch 317 call bs3PrintHexInAl 318 mov al, 's' 319 call bs3PrintChrInAl 320 mov al, cl 321 call bs3PrintHexInAl 322 mov al, 'h' 323 call bs3PrintChrInAl 324 mov al, dh 325 call bs3PrintHexInAl 326 mov al, ';' 327 call bs3PrintChrInAl 328 %endif 279 329 xor bx, bx 280 330 mov es, di ; es:bx -> buffer … … 300 350 dec si 301 351 jnz .the_load_loop 352 %if 0 353 mov al, 'D' 354 call bs3PrintChrInAl 355 %endif 302 356 303 357 add sp, 3*2 304 358 pop dx 305 359 pop es 306 leave360 pop bp 307 361 ret 308 362 … … 311 365 ; 312 366 .failure: 313 push a367 push ax 314 368 315 369 ; print message … … 317 371 .failure_next_char: 318 372 lodsb 319 mov ah, 0eh 320 mov bx, 0ff00h 321 int 10h 373 call bs3PrintChrInAl 322 374 cmp si, .s_szErrMsgEnd 323 375 jb .failure_next_char 324 376 325 377 ; panic 326 popa 378 pop ax 379 %if 1 380 mov al, ah 381 push bs3PrintHexInAl 382 %endif 327 383 call Bs3Panic 328 384 .s_szErrMsg: 329 db 13, 10, 'r ead error!'385 db 13, 10, 'rd err! ' 330 386 .s_szErrMsgEnd: 331 387 ;ENDPROC bs3InitLoadImage - don't want the padding. -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-CpuDetect.asm
r60335 r60365 46 46 push xBP 47 47 mov xBP, xSP 48 pushf 48 49 push xCX 49 50 push xDX 50 51 push xBX 51 pushf52 52 53 53 %ifndef TMPL_CMN_PAGING … … 114 114 ; of a 80387 or later co-processor (a 80287+80386 => ET=0). 486 and 115 115 ; later should be hardcoding this to 1, according to the documentation 116 ; (need to test on 486SX). The 286 should never have it set. 116 ; (need to test on 486SX). The initial idea here then would be to 117 ; assume 386+ if ET=1. 118 ; 119 ; However, it turns out the 286 I've got here has bits 4 thru 15 all 120 ; set. This is very nice though, because only bits 4 and 5 are defined 121 ; on later CPUs and the remainder MBZ. So, check whether any of the MBZ 122 ; bits are set, if so, then it's 286. 117 123 ; 118 124 smsw ax 119 test ax, X86_CR0_ET 120 jnz .386plus 121 %ifndef TMPL_RM ; remove once 286plus_protmode is implemented (relevant in DOS context). 122 test ax, X86_CR0_PE 123 jnz .286plus_protmode ;; @todo The test below doesn't work in prot mode, I think... 124 %endif 125 test ax, ~(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS | X86_CR0_ET | X86_CR0_NE) 126 jnz .is_286 125 127 126 128 ; … … 138 140 ; observed a 386SX here. 139 141 ; 140 cli ; Disable interrupts to be on the safe side. 141 mov ax, [xBP - xCB] 142 or ax, X86_EFL_IOPL | X86_EFL_NT 142 test al, X86_CR0_PE ; This flag test doesn't work in protected mode, ... 143 jnz .386plus ; ... so ASSUME 386plus if in PE for now. 144 145 pushf ; Save a copy of the original flags for restoring IF. 146 pushf 147 pop ax 148 xor ax, X86_EFL_IOPL | X86_EFL_NT ; Try modify IOPL and NT. 149 and ax, ~X86_EFL_IF ; Try clear IF. 143 150 push ax ; Load modified flags. 144 151 popf 145 152 pushf ; Get actual flags. 146 pop ax 147 test ax, X86_EFL_IOPL | X86_EFL_NT 148 jnz .386plus ; If any of the flags are set, we're on 386+. 153 pop dx 154 popf ; Restore IF, IOPL and NT. 155 cmp ax, dx 156 je .386plus ; If any of the flags are set, we're on 386+. 149 157 150 158 ; While we could in theory be in v8086 mode at this point and be fooled 151 159 ; by a flaky POPF implementation, we assume this isn't the case in our 152 160 ; execution environment. 161 162 .is_286: 153 163 mov ax, BS3CPU_80286 154 164 jmp .return 155 %endif 165 %endif ; !TMPL_CMN_PAGING 156 166 157 167 CPU 386 … … 278 288 ; Epilogue. 279 289 ; 280 popf281 290 pop xBX 282 291 pop xDX 283 292 pop xCX 293 popf 284 294 pop xBP 285 295 ret
Note:
See TracChangeset
for help on using the changeset viewer.