Changeset 61058 in vbox for trunk/src/VBox/VMM/VMMR0/CPUMR0A.asm
- Timestamp:
- May 19, 2016 7:12:56 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR0/CPUMR0A.asm
r61031 r61058 5 5 6 6 ; 7 ; Copyright (C) 2006-201 5Oracle Corporation7 ; Copyright (C) 2006-2016 Oracle Corporation 8 8 ; 9 9 ; This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 ; 17 17 18 18 19 ;******************************************************************************* 19 20 ;* Header Files * 20 21 ;******************************************************************************* 22 %define RT_ASM_WITH_SEH64 23 %include "iprt/asmdefs.mac" 21 24 %include "VBox/asmdefs.mac" 22 25 %include "VBox/vmm/vm.mac" … … 27 30 %include "VBox/vmm/cpum.mac" 28 31 29 %ifdef IN_RING330 %error "The jump table doesn't link on leopard."31 %endif32 32 33 33 ;******************************************************************************* … … 123 123 ; @uses rax, rdx 124 124 ; @param pCpumCpu Define for the register containing the CPUMCPU pointer. 125 ; @param pXState Define for the reg siter containing the extended state pointer.125 ; @param pXState Define for the register containing the extended state pointer. 126 126 ; 127 127 %macro CPUMR0_SAVE_HOST 0 … … 164 164 ; @uses rax, rdx 165 165 ; @param pCpumCpu Define for the register containing the CPUMCPU pointer. 166 ; @param pXState Define for the reg siter containing the extended state pointer.166 ; @param pXState Define for the register containing the extended state pointer. 167 167 ; 168 168 %macro CPUMR0_LOAD_HOST 0 … … 246 246 ; @uses rax, rdx 247 247 ; @param pCpumCpu Define for the register containing the CPUMCPU pointer. 248 ; @param pXState Define for the reg siter containing the extended state pointer.248 ; @param pXState Define for the register containing the extended state pointer. 249 249 ; 250 250 %macro CPUMR0_SAVE_GUEST 0 … … 314 314 ; @uses rax, rdx 315 315 ; @param pCpumCpu Define for the register containing the CPUMCPU pointer. 316 ; @param pXState Define for the reg siter containing the extended state pointer.316 ; @param pXState Define for the register containing the extended state pointer. 317 317 ; 318 318 %macro CPUMR0_LOAD_GUEST 0 … … 352 352 ; Saves the host FPU/SSE/AVX state and restores the guest FPU/SSE/AVX state. 353 353 ; 354 ; @returns 0355 354 ; @param pCpumCpu x86:[ebp+8] gcc:rdi msc:rcx CPUMCPU pointer 356 355 ; 357 356 align 16 358 357 BEGINPROC cpumR0SaveHostRestoreGuestFPUState 358 push xBP 359 SEH64_PUSH_xBP 360 mov xBP, xSP 361 SEH64_SET_FRAME_xBP 0 362 SEH64_END_PROLOGUE 363 359 364 ; 360 365 ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input. … … 369 374 %define pXState r10 370 375 %else 371 push ebp372 mov ebp, esp373 376 push ebx 374 377 push esi … … 381 384 cli ; interrupt occurs while we're doing fxsave/fxrstor/cr0. 382 385 386 %ifdef VBOX_WITH_KERNEL_USING_XMM 387 movaps xmm0, xmm0 ; Make 100% sure it's used before we save it or mess with CR0/XCR0. 388 %endif 383 389 SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use! 384 390 391 ; 392 ; Save the host state. 393 ; 394 test dword [pCpumCpu + CPUMCPU.fUseFlags], CPUM_USED_FPU_HOST 395 jnz .already_saved_host 385 396 CPUMR0_SAVE_HOST 397 %ifdef VBOX_WITH_KERNEL_USING_XMM 398 jmp .load_guest 399 %endif 400 .already_saved_host: 401 %ifdef VBOX_WITH_KERNEL_USING_XMM 402 ; If we didn't save the host state, we must save the non-volatile XMM registers. 403 mov pXState, [pCpumCpu + CPUMCPU.Host.pXStateR0] 404 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 060h], xmm6 405 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 070h], xmm7 406 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 080h], xmm8 407 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 090h], xmm9 408 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0a0h], xmm10 409 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0b0h], xmm11 410 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0c0h], xmm12 411 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0d0h], xmm13 412 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0e0h], xmm14 413 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0f0h], xmm15 414 415 ; 416 ; Load the guest state. 417 ; 418 .load_guest: 419 %endif 386 420 CPUMR0_LOAD_GUEST 387 421 … … 401 435 %endif 402 436 437 ;; @todo Save CR0 + XCR0 bits related to FPU, SSE and AVX*, leaving these register sets accessible to IEM. 403 438 RESTORE_CR0 xCX 404 or dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU | CPUM_USED_FPU_SINCE_REM)439 or dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_SINCE_REM | CPUM_USED_FPU_HOST) 405 440 popf 406 441 … … 408 443 pop esi 409 444 pop ebx 445 %endif 410 446 leave 411 %endif412 xor eax, eax413 447 ret 414 448 ENDPROC cpumR0SaveHostRestoreGuestFPUState 415 449 416 450 417 %ifndef RT_ARCH_AMD64418 %ifdef VBOX_WITH_64_BITS_GUESTS419 451 ;; 420 452 ; Saves the host FPU/SSE/AVX state. … … 425 457 align 16 426 458 BEGINPROC cpumR0SaveHostFPUState 427 ; 428 ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input. 429 ; 430 %ifdef RT_ARCH_AMD64 431 %ifdef RT_OS_WINDOWS 432 mov r11, rcx 433 %else 434 mov r11, rdi 435 %endif 436 %define pCpumCpu r11 437 %define pXState r10 438 %else 439 push ebp 440 mov ebp, esp 441 push ebx 442 push esi 443 mov ebx, dword [ebp + 8] 444 %define pCpumCpu ebx 445 %define pXState esi 446 %endif 447 448 pushf ; The darwin kernel can get upset or upset things if an 449 cli ; interrupt occurs while we're doing fxsave/fxrstor/cr0. 450 SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use! 451 452 CPUMR0_SAVE_HOST 453 454 RESTORE_CR0 xCX 455 or dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU | CPUM_USED_FPU_SINCE_REM) 456 popf 457 458 %ifdef RT_ARCH_X86 459 pop esi 460 pop ebx 461 leave 462 %endif 463 xor eax, eax 464 ret 465 %undef pCpumCpu 466 %undef pXState 467 ENDPROC cpumR0SaveHostFPUState 468 %endif 469 %endif 470 471 472 ;; 473 ; Saves the guest FPU/SSE/AVX state and restores the host FPU/SSE/AVX state. 474 ; 475 ; @returns VINF_SUCCESS (0) in eax. 476 ; @param pCpumCpu x86:[ebp+8] gcc:rdi msc:rcx CPUMCPU pointer 477 ; 478 align 16 479 BEGINPROC cpumR0SaveGuestRestoreHostFPUState 459 push xBP 460 SEH64_PUSH_xBP 461 mov xBP, xSP 462 SEH64_SET_FRAME_xBP 0 463 SEH64_END_PROLOGUE 464 480 465 ; 481 466 ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input. … … 490 475 %define pXState r10 491 476 %else 492 push ebp493 mov ebp, esp494 477 push ebx 495 478 push esi … … 499 482 %endif 500 483 501 ;502 ; Only restore FPU if guest has used it.503 ;504 test dword [pCpumCpu + CPUMCPU.fUseFlags], CPUM_USED_FPU505 jz .fpu_not_used506 507 484 pushf ; The darwin kernel can get upset or upset things if an 508 485 cli ; interrupt occurs while we're doing fxsave/fxrstor/cr0. 486 %ifdef VBOX_WITH_KERNEL_USING_XMM 487 movaps xmm0, xmm0 ; Make 100% sure it's used before we save it or mess with CR0/XCR0. 488 %endif 509 489 SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use! 510 490 511 CPUMR0_SAVE_ GUEST512 CPUMR0_LOAD_HOST491 CPUMR0_SAVE_HOST 492 ;; @todo Save CR0 + XCR0 bits related to FPU, SSE and AVX*, leaving these register sets accessible to IEM. 513 493 514 494 RESTORE_CR0 xCX 515 and dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU495 or dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU_HOST | CPUM_USED_FPU_SINCE_REM) ; Latter is not necessarily true, but normally yes. 516 496 popf 517 497 518 .fpu_not_used:519 498 %ifdef RT_ARCH_X86 520 499 pop esi 521 500 pop ebx 501 %endif 522 502 leave 523 %endif524 xor eax, eax525 503 ret 526 504 %undef pCpumCpu 527 505 %undef pXState 528 ENDPROC cpumR0SaveGuestRestoreHostFPUState 529 530 531 ;; 532 ; Restores the host's FPU/SSE/AVX state from pCpumCpu->Host. 533 ; 534 ; @returns 0 506 ENDPROC cpumR0SaveHostFPUState 507 508 509 ;; 510 ; Saves the guest FPU/SSE/AVX state and restores the host FPU/SSE/AVX state. 511 ; 535 512 ; @param pCpumCpu x86:[ebp+8] gcc:rdi msc:rcx CPUMCPU pointer 536 513 ; 537 514 align 16 538 BEGINPROC cpumR0RestoreHostFPUState 515 BEGINPROC cpumR0SaveGuestRestoreHostFPUState 516 push xBP 517 SEH64_PUSH_xBP 518 mov xBP, xSP 519 SEH64_SET_FRAME_xBP 0 520 SEH64_END_PROLOGUE 521 539 522 ; 540 523 ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input. … … 549 532 %define pXState r10 550 533 %else 534 push ebx 535 push esi 536 mov ebx, dword [ebp + 8] 537 %define pCpumCpu ebx 538 %define pXState esi 539 %endif 540 pushf ; The darwin kernel can get upset or upset things if an 541 cli ; interrupt occurs while we're doing fxsave/fxrstor/cr0. 542 SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use! 543 544 545 %ifdef VBOX_WITH_KERNEL_USING_XMM 546 ; 547 ; Copy non-volatile XMM registers to the host state so we can use 548 ; them while saving the guest state (we've gotta do this anyway). 549 ; 550 mov pXState, [pCpumCpu + CPUMCPU.Host.pXStateR0] 551 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 060h], xmm6 552 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 070h], xmm7 553 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 080h], xmm8 554 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 090h], xmm9 555 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0a0h], xmm10 556 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0b0h], xmm11 557 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0c0h], xmm12 558 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0d0h], xmm13 559 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0e0h], xmm14 560 movdqa [pXState + XMM_OFF_IN_X86FXSTATE + 0f0h], xmm15 561 %endif 562 563 ; 564 ; Save the guest state if necessary. 565 ; 566 test dword [pCpumCpu + CPUMCPU.fUseFlags], CPUM_USED_FPU_GUEST 567 jz .load_only_host 568 569 %ifdef VBOX_WITH_KERNEL_USING_XMM 570 ; Load the guest XMM register values we already saved in HMR0VMXStartVMWrapXMM. 571 mov pXState, [pCpumCpu + CPUMCPU.Guest.pXStateR0] 572 movdqa xmm0, [pXState + XMM_OFF_IN_X86FXSTATE + 000h] 573 movdqa xmm1, [pXState + XMM_OFF_IN_X86FXSTATE + 010h] 574 movdqa xmm2, [pXState + XMM_OFF_IN_X86FXSTATE + 020h] 575 movdqa xmm3, [pXState + XMM_OFF_IN_X86FXSTATE + 030h] 576 movdqa xmm4, [pXState + XMM_OFF_IN_X86FXSTATE + 040h] 577 movdqa xmm5, [pXState + XMM_OFF_IN_X86FXSTATE + 050h] 578 movdqa xmm6, [pXState + XMM_OFF_IN_X86FXSTATE + 060h] 579 movdqa xmm7, [pXState + XMM_OFF_IN_X86FXSTATE + 070h] 580 movdqa xmm8, [pXState + XMM_OFF_IN_X86FXSTATE + 080h] 581 movdqa xmm9, [pXState + XMM_OFF_IN_X86FXSTATE + 090h] 582 movdqa xmm10, [pXState + XMM_OFF_IN_X86FXSTATE + 0a0h] 583 movdqa xmm11, [pXState + XMM_OFF_IN_X86FXSTATE + 0b0h] 584 movdqa xmm12, [pXState + XMM_OFF_IN_X86FXSTATE + 0c0h] 585 movdqa xmm13, [pXState + XMM_OFF_IN_X86FXSTATE + 0d0h] 586 movdqa xmm14, [pXState + XMM_OFF_IN_X86FXSTATE + 0e0h] 587 movdqa xmm15, [pXState + XMM_OFF_IN_X86FXSTATE + 0f0h] 588 %endif 589 CPUMR0_SAVE_GUEST 590 591 ; 592 ; Load the host state. 593 ; 594 .load_only_host: 595 CPUMR0_LOAD_HOST 596 597 ;; @todo Restore CR0 + XCR0 bits related to FPU, SSE and AVX* (for IEM). 598 RESTORE_CR0 xCX 599 and dword [pCpumCpu + CPUMCPU.fUseFlags], ~(CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST) 600 601 popf 602 %ifdef RT_ARCH_X86 603 pop esi 604 pop ebx 605 %endif 606 leave 607 ret 608 %undef pCpumCpu 609 %undef pXState 610 ENDPROC cpumR0SaveGuestRestoreHostFPUState 611 612 613 %if ARCH_BITS == 32 614 %ifdef VBOX_WITH_64_BITS_GUESTS 615 ;; 616 ; Restores the host's FPU/SSE/AVX state from pCpumCpu->Host. 617 ; 618 ; @param pCpumCpu x86:[ebp+8] gcc:rdi msc:rcx CPUMCPU pointer 619 ; 620 align 16 621 BEGINPROC cpumR0RestoreHostFPUState 622 ; 623 ; Prologue - xAX+xDX must be free for XSAVE/XRSTOR input. 624 ; 551 625 push ebp 552 626 mov ebp, esp … … 554 628 push esi 555 629 mov ebx, dword [ebp + 8] 556 %define pCpumCpu ebx 557 %define pXState esi 558 %endif 559 560 ; 561 ; Restore FPU if guest has used it. 562 ; 563 test dword [pCpumCpu + CPUMCPU.fUseFlags], CPUM_USED_FPU 564 jz short .fpu_not_used 565 630 %define pCpumCpu ebx 631 %define pXState esi 632 633 ; 634 ; Restore host CPU state. 635 ; 566 636 pushf ; The darwin kernel can get upset or upset things if an 567 637 cli ; interrupt occurs while we're doing fxsave/fxrstor/cr0. … … 571 641 572 642 RESTORE_CR0 xCX 573 and dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU 643 and dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU_HOST 574 644 popf 575 645 576 .fpu_not_used:577 %ifdef RT_ARCH_X86578 646 pop esi 579 647 pop ebx 580 648 leave 581 %endif582 xor eax, eax583 649 ret 584 %undef pCpumCPu585 %undef pXState650 %undef pCpumCPu 651 %undef pXState 586 652 ENDPROC cpumR0RestoreHostFPUState 587 653 %endif ; VBOX_WITH_64_BITS_GUESTS 654 %endif ; ARCH_BITS == 32 655
Note:
See TracChangeset
for help on using the changeset viewer.