VirtualBox

Changeset 83067 in vbox for trunk/src/VBox/VMM/VMMR0


Ignore:
Timestamp:
Feb 13, 2020 4:39:07 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
136107
Message:

VMM/HM: Cleanup nits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/HMR0A.asm

    r83066 r83067  
    11; $Id$
    22;; @file
    3 ; HM - Ring-0 VMX, SVM world-switch and helper routines
     3; HM - Ring-0 VMX, SVM world-switch and helper routines.
    44;
    55
     
    6565
    6666;;
    67 ; Determine skipping restoring of GDTR, IDTR, TR across VMX non-root operation
     67; Determine skipping restoring of GDTR, IDTR, TR across VMX non-root operation.
    6868;
    6969%ifdef RT_ARCH_AMD64
     
    8383
    8484;; @def MYPUSHAD
    85 ; Macro generating an equivalent to pushad
     85; Macro generating an equivalent to PUSHAD instruction.
    8686
    8787;; @def MYPOPAD
    88 ; Macro generating an equivalent to popad
     88; Macro generating an equivalent to POPAD instruction.
    8989
    9090;; @def MYPUSHSEGS
    9191; Macro saving all segment registers on the stack.
    92 ; @param 1  full width register name
     92; @param 1  Full width register name.
    9393; @param 2  16-bit register name for \a 1.
    9494
    9595;; @def MYPOPSEGS
    96 ; Macro restoring all segment registers on the stack
    97 ; @param 1  full width register name
     96; Macro restoring all segment registers on the stack.
     97; @param 1  Full width register name.
    9898; @param 2  16-bit register name for \a 1.
    9999
     
    142142 %endmacro
    143143%else       ; !VBOX_SKIP_RESTORE_SEG
    144  ; trashes, rax, rdx & rcx
     144 ; Trashes, rax, rdx & rcx.
    145145 %macro MYPUSHSEGS64 2
    146146  %ifndef HM_64_BIT_USE_NULL_SEL
     
    151151  %endif
    152152
    153    ; Special case for FS; Windows and Linux either don't use it or restore it when leaving kernel mode, Solaris OTOH doesn't and we must save it.
     153   ; Special case for FS; Windows and Linux either don't use it or restore it when leaving kernel mode,
     154   ; Solaris OTOH doesn't and we must save it.
    154155   mov     ecx, MSR_K8_FS_BASE
    155156   rdmsr
     
    160161  %endif
    161162
    162    ; Special case for GS; OSes typically use swapgs to reset the hidden base register for GS on entry into the kernel. The same happens on exit
     163   ; Special case for GS; OSes typically use swapgs to reset the hidden base register for GS on entry into the kernel.
     164   ; The same happens on exit.
    163165   mov     ecx, MSR_K8_GS_BASE
    164166   rdmsr
     
    283285    mov     ecx, MSR_IA32_FLUSH_CMD
    284286    wrmsr
    285     jmp     %%no_mds_buffer_flushing    ; MDS flushing is included in L1D_FLUSH.
     287    jmp     %%no_mds_buffer_flushing    ; MDS flushing is included in L1D_FLUSH
    286288%%no_cache_flush_barrier:
    287289
     
    310312
    311313
    312 ;/**
    313 ; * Restores host-state fields.
    314 ; *
    315 ; * @returns VBox status code
    316 ; * @param   f32RestoreHost x86: [ebp + 08h]  msc: ecx  gcc: edi   RestoreHost flags.
    317 ; * @param   pRestoreHost   x86: [ebp + 0ch]  msc: rdx  gcc: rsi   Pointer to the RestoreHost struct.
    318 ; */
     314;;
     315; Restores host-state fields.
     316;
     317; @returns VBox status code
     318; @param   f32RestoreHost x86: [ebp + 08h]  msc: ecx  gcc: edi   RestoreHost flags.
     319; @param   pRestoreHost   x86: [ebp + 0ch]  msc: rdx  gcc: rsi   Pointer to the RestoreHost struct.
     320;
    319321ALIGNCODE(16)
    320322BEGINPROC VMXRestoreHostState
     
    357359    mov         dx, [rsi + VMXRESTOREHOST.uHostSelTR]
    358360    mov         ax, dx
    359     and         eax, X86_SEL_MASK_OFF_RPL                       ; Mask away TI and RPL bits leaving only the descriptor offset.
     361    and         eax, X86_SEL_MASK_OFF_RPL                       ; mask away TI and RPL bits leaving only the descriptor offset
    360362    test        edi, VMX_RESTORE_HOST_GDT_READ_ONLY | VMX_RESTORE_HOST_GDT_NEED_WRITABLE
    361363    jnz         .gdt_readonly
    362364    add         rax, qword [rsi + VMXRESTOREHOST.HostGdtr + 2]  ; xAX <- descriptor offset + GDTR.pGdt.
    363     and         dword [rax + 4], ~RT_BIT(9)                     ; Clear the busy flag in TSS desc (bits 0-7=base, bit 9=busy bit).
     365    and         dword [rax + 4], ~RT_BIT(9)                     ; clear the busy flag in TSS desc (bits 0-7=base, bit 9=busy bit)
    364366    ltr         dx
    365367    jmp short   .test_fs
     
    372374    and         rcx, ~X86_CR0_WP
    373375    mov         cr0, rcx
    374     and         dword [rax + 4], ~RT_BIT(9)                     ; Clear the busy flag in TSS desc (bits 0-7=base, bit 9=busy bit).
     376    and         dword [rax + 4], ~RT_BIT(9)                     ; clear the busy flag in TSS desc (bits 0-7=base, bit 9=busy bit)
    375377    ltr         dx
    376378    mov         cr0, r9
    377379    jmp short   .test_fs
    378380.gdt_readonly_need_writable:
    379     add         rax, qword [rsi + VMXRESTOREHOST.HostGdtrRw + 2]  ; xAX <- descriptor offset + GDTR.pGdtRw.
    380     and         dword [rax + 4], ~RT_BIT(9)                     ; Clear the busy flag in TSS desc (bits 0-7=base, bit 9=busy bit).
     381    add         rax, qword [rsi + VMXRESTOREHOST.HostGdtrRw + 2]  ; xAX <- descriptor offset + GDTR.pGdtRw
     382    and         dword [rax + 4], ~RT_BIT(9)                     ; clear the busy flag in TSS desc (bits 0-7=base, bit 9=busy bit)
    381383    lgdt        [rsi + VMXRESTOREHOST.HostGdtrRw]
    382384    ltr         dx
    383     lgdt        [rsi + VMXRESTOREHOST.HostGdtr]                 ; Load the original GDT
     385    lgdt        [rsi + VMXRESTOREHOST.HostGdtr]                 ; load the original GDT
    384386
    385387.test_fs:
     
    434436
    435437
    436 ;/**
    437 ; * Dispatches an NMI to the host.
    438 ; */
     438;;
     439; Dispatches an NMI to the host.
     440;
    439441ALIGNCODE(16)
    440442BEGINPROC VMXDispatchHostNmi
    441     int 2   ; NMI is always vector 2. The IDT[2] IRQ handler cannot be anything else. See Intel spec. 6.3.1 "External Interrupts".
     443    ; NMI is always vector 2. The IDT[2] IRQ handler cannot be anything else. See Intel spec. 6.3.1 "External Interrupts".
     444    int 2
    442445    ret
    443446ENDPROC VMXDispatchHostNmi
    444447
    445448
    446 ;/**
    447 ; * Executes VMWRITE, 64-bit value.
    448 ; *
    449 ; * @returns VBox status code.
    450 ; * @param   idxField   x86: [ebp + 08h]  msc: rcx  gcc: rdi   VMCS index.
    451 ; * @param   u64Data    x86: [ebp + 0ch]  msc: rdx  gcc: rsi   VM field value.
    452 ; */
     449;;
     450; Executes VMWRITE, 64-bit value.
     451;
     452; @returns VBox status code.
     453; @param   idxField   x86: [ebp + 08h]  msc: rcx  gcc: rdi   VMCS index.
     454; @param   u64Data    x86: [ebp + 0ch]  msc: rdx  gcc: rsi   VM field value.
     455;
    453456ALIGNCODE(16)
    454457BEGINPROC VMXWriteVmcs64
     
    485488
    486489
    487 ;/**
    488 ; * Executes VMREAD, 64-bit value.
    489 ; *
    490 ; * @returns VBox status code.
    491 ; * @param   idxField        VMCS index.
    492 ; * @param   pData           Where to store VM field value.
    493 ; */
     490;;
     491; Executes VMREAD, 64-bit value.
     492;
     493; @returns VBox status code.
     494; @param   idxField        VMCS index.
     495; @param   pData           Where to store VM field value.
     496;
    494497;DECLASM(int) VMXReadVmcs64(uint32_t idxField, uint64_t *pData);
    495498ALIGNCODE(16)
     
    527530
    528531
    529 ;/**
    530 ; * Executes VMREAD, 32-bit value.
    531 ; *
    532 ; * @returns VBox status code.
    533 ; * @param   idxField        VMCS index.
    534 ; * @param   pu32Data        Where to store VM field value.
    535 ; */
     532;;
     533; Executes VMREAD, 32-bit value.
     534;
     535; @returns VBox status code.
     536; @param   idxField        VMCS index.
     537; @param   pu32Data        Where to store VM field value.
     538;
    536539;DECLASM(int) VMXReadVmcs32(uint32_t idxField, uint32_t *pu32Data);
    537540ALIGNCODE(16)
     
    566569
    567570
    568 ;/**
    569 ; * Executes VMWRITE, 32-bit value.
    570 ; *
    571 ; * @returns VBox status code.
    572 ; * @param   idxField        VMCS index.
    573 ; * @param   u32Data         Where to store VM field value.
    574 ; */
     571;;
     572; Executes VMWRITE, 32-bit value.
     573;
     574; @returns VBox status code.
     575; @param   idxField        VMCS index.
     576; @param   u32Data         Where to store VM field value.
     577;
    575578;DECLASM(int) VMXWriteVmcs32(uint32_t idxField, uint32_t u32Data);
    576579ALIGNCODE(16)
     
    605608
    606609
    607 ;/**
    608 ; * Executes VMXON.
    609 ; *
    610 ; * @returns VBox status code.
    611 ; * @param   HCPhysVMXOn      Physical address of VMXON structure.
    612 ; */
     610;;
     611; Executes VMXON.
     612;
     613; @returns VBox status code.
     614; @param   HCPhysVMXOn      Physical address of VMXON structure.
     615;
    613616;DECLASM(int) VMXEnable(RTHCPHYS HCPhysVMXOn);
    614617BEGINPROC VMXEnable
     
    641644
    642645
    643 ;/**
    644 ; * Executes VMXOFF.
    645 ; */
     646;;
     647; Executes VMXOFF.
     648;
    646649;DECLASM(void) VMXDisable(void);
    647650BEGINPROC VMXDisable
     
    652655
    653656
    654 ;/**
    655 ; * Executes VMCLEAR.
    656 ; *
    657 ; * @returns VBox status code.
    658 ; * @param   HCPhysVmcs     Physical address of VM control structure.
    659 ; */
     657;;
     658; Executes VMCLEAR.
     659;
     660; @returns VBox status code.
     661; @param   HCPhysVmcs     Physical address of VM control structure.
     662;
    660663;DECLASM(int) VMXClearVmcs(RTHCPHYS HCPhysVmcs);
    661664ALIGNCODE(16)
     
    683686
    684687
    685 ;/**
    686 ; * Executes VMPTRLD.
    687 ; *
    688 ; * @returns VBox status code.
    689 ; * @param   HCPhysVmcs     Physical address of VMCS structure.
    690 ; */
     688;;
     689; Executes VMPTRLD.
     690;
     691; @returns VBox status code.
     692; @param   HCPhysVmcs     Physical address of VMCS structure.
     693;
    691694;DECLASM(int) VMXLoadVmcs(RTHCPHYS HCPhysVmcs);
    692695ALIGNCODE(16)
     
    714717
    715718
    716 ;/**
    717 ; * Executes VMPTRST.
    718 ; *
    719 ; * @returns VBox status code.
    720 ; * @param    [esp + 04h]  gcc:rdi  msc:rcx   Param 1 - First parameter - Address that will receive the current pointer.
    721 ; */
     719;;
     720; Executes VMPTRST.
     721;
     722; @returns VBox status code.
     723; @param    [esp + 04h]  gcc:rdi  msc:rcx   Param 1 - First parameter - Address that will receive the current pointer.
     724;
    722725;DECLASM(int) VMXGetCurrentVmcs(RTHCPHYS *pVMCS);
    723726BEGINPROC VMXGetCurrentVmcs
     
    741744ENDPROC VMXGetCurrentVmcs
    742745
    743 ;/**
    744 ; * Invalidate a page using INVEPT.
     746;;
     747; Invalidate a page using INVEPT.
     748;
    745749; @param   enmTlbFlush  msc:ecx  gcc:edi  x86:[esp+04]  Type of flush.
    746750; @param   pDescriptor  msc:edx  gcc:esi  x86:[esp+08]  Descriptor pointer.
    747 ; */
     751;
    748752;DECLASM(int) VMXR0InvEPT(VMXTLBFLUSHEPT enmTlbFlush, uint64_t *pDescriptor);
    749753BEGINPROC VMXR0InvEPT
     
    778782
    779783
    780 ;/**
    781 ; * Invalidate a page using invvpid
     784;;
     785; Invalidate a page using INVVPID.
     786;
    782787; @param   enmTlbFlush  msc:ecx  gcc:edi  x86:[esp+04]  Type of flush
    783788; @param   pDescriptor  msc:edx  gcc:esi  x86:[esp+08]  Descriptor pointer
    784 ; */
     789;
    785790;DECLASM(int) VMXR0InvVPID(VMXTLBFLUSHVPID enmTlbFlush, uint64_t *pDescriptor);
    786791BEGINPROC VMXR0InvVPID
     
    817822%if GC_ARCH_BITS == 64
    818823;;
    819 ; Executes INVLPGA
     824; Executes INVLPGA.
    820825;
    821826; @param   pPageGC  msc:rcx  gcc:rdi  x86:[esp+04]  Virtual page to invalidate
     
    855860 %else
    856861    ; from http://www.cs.cmu.edu/~fp/courses/15213-s06/misc/asm64-handout.pdf:
    857     ; ``Perhaps unexpectedly, instructions that move or generate 32-bit register
    858     ;   values also set the upper 32 bits of the register to zero. Consequently
    859     ;   there is no need for an instruction movzlq.''
     862    ; "Perhaps unexpectedly, instructions that move or generate 32-bit register
     863    ;  values also set the upper 32 bits of the register to zero. Consequently
     864    ;  there is no need for an instruction movzlq."
    860865    mov     eax, ecx
    861866    mov     ecx, edx
     
    906911        sub     xSP, 0b0h + 040h ; Don't bother optimizing the frame size.
    907912
    908         ; spill input parameters.
     913        ; Spill input parameters.
    909914        mov     [xBP + 010h], rcx       ; fResumeVM
    910915        mov     [xBP + 018h], rdx       ; pCtx
     
    959964        xrstor  [r10]
    960965
    961         ; Make the call (same as in the other case ).
     966        ; Make the call (same as in the other case).
    962967        mov     r11, [xBP + 38h]        ; pfnStartVM
    963968        mov     r10, [xBP + 30h]        ; pVCpu
     
    979984        xsave  [r10]
    980985
    981         mov     eax, r11d               ; restore return value.
     986        mov     eax, r11d               ; restore return value
    982987
    983988.restore_non_volatile_host_xmm_regs:
     
    10211026        ldmxcsr        [r10 + X86FXSTATE.MXCSR]
    10221027
    1023         ; Make the call (same as in the other case ).
     1028        ; Make the call (same as in the other case).
    10241029        mov     r11, [xBP + 38h]        ; pfnStartVM
    10251030        mov     r10, [xBP + 30h]        ; pVCpu
     
    10831088        push    xBP
    10841089        mov     xBP, xSP
    1085         sub     xSP, 0b0h + 040h        ; Don't bother optimizing the frame size.
    1086 
    1087         ; spill input parameters.
     1090        sub     xSP, 0b0h + 040h        ; don't bother optimizing the frame size
     1091
     1092        ; Spill input parameters.
    10881093        mov     [xBP + 010h], rcx       ; HCPhysVmcbHost
    10891094        mov     [xBP + 018h], rdx       ; HCPhysVmcb
     
    11381143        xrstor  [r10]
    11391144
    1140         ; Make the call (same as in the other case ).
     1145        ; Make the call (same as in the other case).
    11411146        mov     r11, [xBP + 38h]        ; pfnVMRun
    11421147        mov     r10, [xBP + 30h]        ; pVCpu
     
    11581163        xsave  [r10]
    11591164
    1160         mov     eax, r11d               ; restore return value.
     1165        mov     eax, r11d               ; restore return value
    11611166
    11621167.restore_non_volatile_host_xmm_regs:
     
    12001205        ldmxcsr        [r10 + X86FXSTATE.MXCSR]
    12011206
    1202         ; Make the call (same as in the other case ).
     1207        ; Make the call (same as in the other case).
    12031208        mov     r11, [xBP + 38h]        ; pfnVMRun
    12041209        mov     r10, [xBP + 30h]        ; pVCpu
     
    12421247;
    12431248%macro RESTORE_STATE_VM64 0
    1244     ; Restore base and limit of the IDTR & GDTR
     1249    ; Restore base and limit of the IDTR & GDTR.
    12451250 %ifndef VMX_SKIP_IDTR
    12461251    lidt    [xSP]
     
    12971302
    12981303 %ifndef VMX_SKIP_TR
    1299     ; Restore TSS selector; must mark it as not busy before using ltr (!)
    1300     ; ASSUME that this is supposed to be 'BUSY'. (saves 20-30 ticks on the T42p).
     1304    ; Restore TSS selector; must mark it as not busy before using ltr!
     1305    ; ASSUME that this is supposed to be 'BUSY' (saves 20-30 ticks on the T42p).
    13011306    ; @todo get rid of sgdt
    13021307    pop     xBX         ; Saved TR
     
    13041309    sgdt    [xSP]
    13051310    mov     xAX, xBX
    1306     and     eax, X86_SEL_MASK_OFF_RPL           ; Mask away TI and RPL bits leaving only the descriptor offset.
    1307     add     xAX, [xSP + 2]                      ; eax <- GDTR.address + descriptor offset.
    1308     and     dword [xAX + 4], ~RT_BIT(9)         ; Clear the busy flag in TSS desc (bits 0-7=base, bit 9=busy bit).
     1311    and     eax, X86_SEL_MASK_OFF_RPL           ; mask away TI and RPL bits leaving only the descriptor offset
     1312    add     xAX, [xSP + 2]                      ; eax <- GDTR.address + descriptor offset
     1313    and     dword [xAX + 4], ~RT_BIT(9)         ; clear the busy flag in TSS desc (bits 0-7=base, bit 9=busy bit)
    13091314    ltr     bx
    13101315    add     xSP, xCB * 2
     
    13401345;
    13411346; @returns VBox status code
    1342 ; @param    fResume    msc:rcx, gcc:rdi     Whether to use vmlauch/vmresume.
    1343 ; @param    pCtx       msc:rdx, gcc:rsi     Pointer to the guest-CPU context.
    1344 ; @param    pvUnused   msc:r8,  gcc:rdx     Unused argument.
    1345 ; @param    pVM        msc:r9,  gcc:rcx     The cross context VM structure.
    1346 ; @param    pVCpu      msc:[ebp+30], gcc:r8 The cross context virtual CPU structure of the calling EMT.
     1347; @param    fResume    msc:rcx, gcc:rdi       Whether to use vmlauch/vmresume.
     1348; @param    pCtx       msc:rdx, gcc:rsi       Pointer to the guest-CPU context.
     1349; @param    pvUnused   msc:r8,  gcc:rdx       Unused argument.
     1350; @param    pVM        msc:r9,  gcc:rcx       The cross context VM structure.
     1351; @param    pVCpu      msc:[ebp+30], gcc:r8   The cross context virtual CPU structure of the calling EMT.
    13471352;
    13481353ALIGNCODE(16)
     
    13591364    ; First we have to save some final CPU context registers.
    13601365    lea     r10, [.vmlaunch64_done wrt rip]
    1361     mov     rax, VMX_VMCS_HOST_RIP      ; Return address (too difficult to continue after VMLAUNCH?).
     1366    mov     rax, VMX_VMCS_HOST_RIP      ; return address (too difficult to continue after VMLAUNCH?)
    13621367    vmwrite rax, r10
    1363     ; Note: assumes success!
     1368    ; Note: ASSUMES success!
    13641369
    13651370    ;
     
    13891394
    13901395    xor     ecx, ecx
    1391     xgetbv                              ; Save the host one on the stack.
     1396    xgetbv                              ; save the host one on the stack
    13921397    push    xDX
    13931398    push    xAX
    13941399
    1395     mov     eax, [xSI + CPUMCTX.aXcr]   ; Load the guest one.
     1400    mov     eax, [xSI + CPUMCTX.aXcr]   ; load the guest one
    13961401    mov     edx, [xSI + CPUMCTX.aXcr + 4]
    13971402    xor     ecx, ecx                    ; paranoia
    13981403    xsetbv
    13991404
    1400     push    0                           ; Indicate that we must restore XCR0 (popped into ecx, thus 0).
     1405    push    0                           ; indicate that we must restore XCR0 (popped into ecx, thus 0)
    14011406    jmp     .xcr0_before_done
    14021407
    14031408.xcr0_before_skip:
    1404     push    3fh                         ; indicate that we need not.
     1409    push    3fh                         ; indicate that we need not
    14051410.xcr0_before_done:
    14061411
     
    14451450    mov     eax, VMX_VMCS_HOST_RSP
    14461451    vmwrite xAX, xSP
    1447     ; Note: assumes success!
     1452    ; Note: ASSUMES success!
    14481453    ; Don't mess with ESP anymore!!!
    14491454
     
    14781483    jc      near .vmxstart64_invalid_vmcs_ptr
    14791484    jz      near .vmxstart64_start_failed
    1480     jmp     .vmlaunch64_done;      ; Here if vmresume detected a failure.
     1485    jmp     .vmlaunch64_done;      ; here if vmresume detected a failure
    14811486
    14821487.vmlaunch64_launch:
     
    14841489    jc      near .vmxstart64_invalid_vmcs_ptr
    14851490    jz      near .vmxstart64_start_failed
    1486     jmp     .vmlaunch64_done;      ; Here if vmlaunch detected a failure.
     1491    jmp     .vmlaunch64_done;      ; here if vmlaunch detected a failure
    14871492
    14881493ALIGNCODE(16)
     
    15361541    ; Fake a cdecl stack frame
    15371542 %ifdef ASM_CALL64_GCC
    1538     push    r8                ;pVCpu
    1539     push    rcx               ;pVM
    1540     push    rdx               ;pCtx
    1541     push    rsi               ;HCPhysVmcb
    1542     push    rdi               ;HCPhysVmcbHost
     1543    push    r8                ; pVCpu
     1544    push    rcx               ; pVM
     1545    push    rdx               ; pCtx
     1546    push    rsi               ; HCPhysVmcb
     1547    push    rdi               ; HCPhysVmcbHost
    15431548 %else
    15441549    mov     rax, [rsp + 28h]
     
    15751580
    15761581    xor     ecx, ecx
    1577     xgetbv                                  ; save the host XCR0 on the stack.
     1582    xgetbv                                  ; save the host XCR0 on the stack
    15781583    push    xDX
    15791584    push    xAX
     
    15961601
    15971602    ; Save host fs, gs, sysenter msr etc.
    1598     mov     rax, [rbp + xCB * 2]                    ; HCPhysVmcbHost (64 bits physical address; x86: take low dword only)
    1599     push    rax                                     ; save for the vmload after vmrun
     1603    mov     rax, [rbp + xCB * 2]            ; HCPhysVmcbHost (64 bits physical address; x86: take low dword only)
     1604    push    rax                             ; save for the vmload after vmrun
    16001605    vmsave
    16011606
     
    16041609
    16051610    ; Setup rax for VMLOAD.
    1606     mov     rax, [rbp + xCB * 2 + RTHCPHYS_CB]      ; HCPhysVmcb (64 bits physical address; take low dword only)
     1611    mov     rax, [rbp + xCB * 2 + RTHCPHYS_CB] ; HCPhysVmcb (64 bits physical address; take low dword only)
    16071612
    16081613    ; Load guest general purpose registers (rax is loaded from the VMCB by VMRUN).
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette