VirtualBox

Changeset 87334 in vbox


Ignore:
Timestamp:
Jan 20, 2021 8:58:26 PM (4 years ago)
Author:
vboxsync
Message:

VMM/HMR0A.asm: Converted SVMR0VMRun to proper stack frame, eliminating most of the pushing and popping.

File:
1 edited

Legend:

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

    r87330 r87334  
    7676
    7777%ifdef ASM_CALL64_GCC
     78 %define CALLEE_PRESERVED_REGISTER_COUNT 5
    7879 %macro PUSH_CALLEE_PRESERVED_REGISTERS 0
    7980   push    r15
     
    9293
    9394%else ; ASM_CALL64_MSC
     95 %define CALLEE_PRESERVED_REGISTER_COUNT 7
    9496 %macro PUSH_CALLEE_PRESERVED_REGISTERS 0
    9597   push    r15
     
    10551057    mov     rbp, rsp
    10561058    pushf
     1059    sub     rsp, 30h - 8h                   ; The frame is 30h bytes, but the rbp-08h entry is the above pushf.
     1060                                            ; And we have CALLEE_PRESERVED_REGISTER_COUNT following it.
     1061%define frm_uHostXcr0       -18h            ; 128-bit
     1062%define frm_fNoRestoreXcr0  -20h            ; Non-zero if we should skip XCR0 restoring.
     1063%define frm_pVCpu           -28h            ; Where we stash pVCpu for use after the vmrun.
     1064%define frm_HCPhysVmcbHost  -30h            ; Where we stash HCPhysVmcbHost for the vmload after vmrun.
     1065%define cbFrame            ( 30h + CALLEE_PRESERVED_REGISTER_COUNT*8 )
    10571066
    10581067    ; Manual save and restore:
     
    10771086
    10781087    ; Save the host XCR0 and load the guest one if necessary.
     1088    mov     ecx, 3fh                        ; indicate that we need not restore XCR0 (in case we jump)
    10791089    test    byte [rsi + VMCPU.hm + HMCPU.fLoadSaveGuestXcr0], 1
    10801090    jz      .xcr0_before_skip
     
    10821092    xor     ecx, ecx
    10831093    xgetbv                                  ; save the host XCR0 on the stack
    1084     push    rdx
    1085     push    rax
     1094    mov     [rbp + frm_uHostXcr0 + 8], rdx
     1095    mov     [rbp + frm_uHostXcr0    ], rax
    10861096
    10871097    mov     eax, [rsi + VMCPU.cpum.GstCtx + CPUMCTX.aXcr] ; load the guest XCR0
    10881098    mov     edx, [rsi + VMCPU.cpum.GstCtx + CPUMCTX.aXcr + 4]
    1089     xor     ecx, ecx                        ; paranoia
     1099    xor     ecx, ecx                        ; paranoia; Also, indicates that we must restore XCR0 (moved into ecx, thus 0).
    10901100    xsetbv
    10911101
    1092     push    0                               ; indicate that we must restore XCR0 (popped into ecx, thus 0)
    1093     jmp     .xcr0_before_done
    1094 
    10951102.xcr0_before_skip:
    1096     push    3fh                             ; indicate that we need not restore XCR0
    1097 .xcr0_before_done:
     1103    mov     [rbp + frm_fNoRestoreXcr0], rcx
    10981104
    10991105    ; Save pVCpu pointer for simplifying saving of the GPRs afterwards.
    1100     push    rsi
     1106    mov     qword [rbp + frm_pVCpu], rsi
    11011107
    11021108    ; Save host fs, gs, sysenter msr etc.
    11031109    mov     rax, [rsi + VMCPU.hm + HMCPU.u + HMCPUSVM.HCPhysVmcbHost]
    1104     push    rax                             ; save for the vmload after vmrun
     1110    mov     qword [rbp + frm_HCPhysVmcbHost], rax          ; save for the vmload after vmrun
    11051111    vmsave
    11061112
     
    11411147
    11421148    ; Load host fs, gs, sysenter msr etc.
    1143     pop     rax                         ; load HCPhysVmcbHost (pushed above)
     1149    mov     rax, [rsp + cbFrame + frm_HCPhysVmcbHost] ; load HCPhysVmcbHost (rbp is not operational yet, thus rsp)
    11441150    vmload
    11451151
     
    11481154    stgi
    11491155
    1150     ; Pop pVCpu (pushed above) and save the guest GPRs (sans RSP and RAX).
    1151     pop     rax
     1156    ; Pop pVCpu (saved above) and save the guest GPRs (sans RSP and RAX).
     1157    mov     rax, [rsp + cbFrame + frm_pVCpu] ; (rbp still not operational)
    11521158
    11531159    mov     qword [rax + VMCPU.cpum.GstCtx + CPUMCTX.ebx], rbx
     
    11621168    mov     rdi, rbx
    11631169    mov     qword [rax + VMCPU.cpum.GstCtx + CPUMCTX.ebp], rbp
    1164     mov     rbp, rbx
     1170    lea     rbp, [rsp + cbFrame]
    11651171    mov     qword [rax + VMCPU.cpum.GstCtx + CPUMCTX.r8],  r8
    11661172    mov     r8, rbx
     
    11841190
    11851191    ; Restore the host xcr0 if necessary.
    1186     pop     rcx
     1192    mov     rcx, [rbp + frm_fNoRestoreXcr0]
    11871193    test    ecx, ecx
    11881194    jnz     .xcr0_after_skip
    1189     pop     rax
    1190     pop     rdx
     1195    mov     rdx, [rbp + frm_uHostXcr0 + 8]
     1196    mov     rax, [rbp + frm_uHostXcr0]
    11911197    xsetbv                              ; ecx is already zero
    11921198.xcr0_after_skip:
     
    11971203    mov     eax, VINF_SUCCESS
    11981204
     1205    add     rsp, 30h - 8h
    11991206    popf
    1200     pop     rbp                         ; Do not use leave! rbp is trashed.
     1207    leave
    12011208    ret
     1209%undef frm_uHostXcr0
     1210%undef frm_fNoRestoreXcr0
     1211%undef frm_pVCpu
     1212%undef frm_HCPhysVmcbHost
     1213%undef cbFrame
    12021214ENDPROC SVMR0VMRun
    12031215
Note: See TracChangeset for help on using the changeset viewer.

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