VirtualBox

Changeset 47660 in vbox for trunk/src/VBox/VMM/VMMSwitcher


Ignore:
Timestamp:
Aug 12, 2013 12:37:34 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
87863
Message:

VMM: Debug register handling redo. (only partly tested on AMD-V so far.)

Location:
trunk/src/VBox/VMM/VMMSwitcher
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMSwitcher/AMD64andLegacy.mac

    r41985 r47660  
    55
    66;
    7 ; Copyright (C) 2006-2012 Oracle Corporation
     7; Copyright (C) 2006-2013 Oracle Corporation
    88;
    99; This file is part of VirtualBox Open Source Edition (OSE), as
     
    355355
    356356    ; debug registers.
    357     test    esi, CPUM_USE_DEBUG_REGS | CPUM_USE_DEBUG_REGS_HOST
    358     jz      htg_debug_regs_no
    359     jmp     htg_debug_regs_save
     357    test    esi, CPUM_USE_DEBUG_REGS_HYPER | CPUM_USE_DEBUG_REGS_HOST
     358    jnz     htg_debug_regs_save
    360359htg_debug_regs_no:
    361360    DEBUG_CHAR('a')                     ; trashes esi
     
    439438    mov     rax, dr7                    ; not sure, but if I read the docs right this will trap if GD is set. FIXME!!!
    440439    mov     [rdx + r8 + CPUMCPU.Host.dr7], rax
    441     xor     eax, eax                    ; clear everything. (bit 12? is read as 1...)
    442     mov     dr7, rax
     440    mov     ecx, X86_DR7_INIT_VAL
     441    cmp     eax, ecx
     442    je      .htg_debug_regs_dr7_disabled
     443    mov     dr7, rcx
     444.htg_debug_regs_dr7_disabled:
    443445    mov     rax, dr6                    ; just in case we save the state register too.
    444446    mov     [rdx + r8 + CPUMCPU.Host.dr6], rax
    445447    ; save host DR0-3?
    446     test    esi, CPUM_USE_DEBUG_REGS
    447     jz near htg_debug_regs_no
     448    test    esi, CPUM_USE_DEBUG_REGS_HYPER
     449    jz     htg_debug_regs_no
    448450DEBUG_S_CHAR('S');
    449451    mov     rax, dr0
     
    455457    mov     rax, dr3
    456458    mov     [rdx + r8 + CPUMCPU.Host.dr3], rax
     459    or      dword [rdx + r8 + CPUMCPU.fUseFlags], CPUM_USED_DEBUG_REGS_HOST
    457460    jmp     htg_debug_regs_no
    458461
     
    513516GLOBALNAME JmpGCTarget
    514517    DEBUG_CHAR('-')
    515 ;mov eax, 0ffff0000h
    516 ;.delay_loop:
    517 ;nop
    518 ;dec eax
    519 ;nop
    520 ;jnz .delay_loop
    521518    ; load final cr3 and do far jump to load cs.
    522519    mov     cr3, ebp                ; ebp set above
     
    565562
    566563    ; debug registers
    567     test    esi, CPUM_USE_DEBUG_REGS
     564    test    esi, CPUM_USE_DEBUG_REGS_HYPER
    568565    jnz     htg_debug_regs_guest
    569566htg_debug_regs_guest_done:
     
    622619    mov     ebx, [edx + CPUMCPU.Hyper.dr + 8*3]
    623620    mov     dr3, ebx
    624     ;mov     eax, [edx + CPUMCPU.Hyper.dr + 8*6]
    625     mov     ecx, 0ffff0ff0h
     621    mov     ecx, X86_DR6_INIT_VAL
    626622    mov     dr6, ecx
    627623    mov     eax, [edx + CPUMCPU.Hyper.dr + 8*7]
    628624    mov     dr7, eax
     625    or      dword [edx + CPUMCPU.fUseFlags], CPUM_USED_DEBUG_REGS_HYPER
    629626    jmp     htg_debug_regs_guest_done
    630627
     
    793790    ; FPU context is saved before restore of host saving (another) branch.
    794791
     792    ; Disable debug registers if active so they cannot trigger while switching.
     793    test    dword [edi + CPUMCPU.fUseFlags], CPUM_USED_DEBUG_REGS_HYPER
     794    jz      .gth_disabled_dr7
     795    mov     eax, X86_DR7_INIT_VAL
     796    mov     dr7, eax
     797.gth_disabled_dr7:
    795798
    796799    ;;
     
    991994    ;mov     cr2, rcx
    992995
    993     ; restore debug registers (if modified) (esi must still be fUseFlags!)
    994     ; (must be done after cr4 reload because of the debug extension.)
    995     test    esi, CPUM_USE_DEBUG_REGS | CPUM_USE_DEBUG_REGS_HOST
    996     jz short gth_debug_regs_no
    997     jmp     gth_debug_regs_restore
    998 gth_debug_regs_no:
    999 
    1000996    ; Restore MSRs
    1001997    mov     rbx, rdx
     
    10141010    mov     rdx, rbx
    10151011
    1016     ; restore general registers.
     1012    ; Restore debug registers (if modified). (ESI must still be fUseFlags! Must be done late, at least after CR4!)
     1013    test    esi, CPUM_USE_DEBUG_REGS_HOST | CPUM_USED_DEBUG_REGS_HOST | CPUM_USE_DEBUG_REGS_HYPER
     1014    jnz     gth_debug_regs_restore
     1015gth_debug_regs_done:
     1016    and     dword [edx + CPUMCPU.fUseFlags], ~(CPUM_USED_DEBUG_REGS_HOST | CPUM_USED_DEBUG_REGS_HYPER)
     1017
     1018    ; Restore general registers.
    10171019    mov     eax, edi                    ; restore return code. eax = return code !!
    10181020    ; mov     rax, [rdx + r8 + CPUMCPU.Host.rax] - scratch + return code
     
    10491051gth_debug_regs_restore:
    10501052    DEBUG_S_CHAR('d')
    1051     xor     eax, eax
    1052     mov     dr7, rax                    ; paranoia or not?
    1053     test    esi, CPUM_USE_DEBUG_REGS
    1054     jz short gth_debug_regs_dr7
     1053    mov     rax, dr7                    ; Some DR7 paranoia first...
     1054    mov     ecx, X86_DR7_INIT_VAL
     1055    cmp     rax, rcx
     1056    je      .gth_debug_skip_dr7_disabling
     1057    mov     dr7, rcx
     1058.gth_debug_skip_dr7_disabling:
     1059    test    esi, CPUM_USED_DEBUG_REGS_HOST
     1060    jz      .gth_debug_regs_dr7
     1061
    10551062    DEBUG_S_CHAR('r')
    10561063    mov     rax, [rdx + r8 + CPUMCPU.Host.dr0]
     
    10621069    mov     rax, [rdx + r8 + CPUMCPU.Host.dr3]
    10631070    mov     dr3, rax
    1064 gth_debug_regs_dr7:
     1071.gth_debug_regs_dr7:
    10651072    mov     rbx, [rdx + r8 + CPUMCPU.Host.dr6]
    10661073    mov     dr6, rbx
    10671074    mov     rcx, [rdx + r8 + CPUMCPU.Host.dr7]
    10681075    mov     dr7, rcx
    1069     jmp     gth_debug_regs_no
     1076
     1077    ; We clear the USED flags in the main code path.
     1078    jmp     gth_debug_regs_done
    10701079
    10711080ENDPROC vmmRCToHostAsm
  • trunk/src/VBox/VMM/VMMSwitcher/LegacyandAMD64.mac

    r47652 r47660  
    445445    mov     esi, [rdx + CPUMCPU.fUseFlags] ; esi == use flags.
    446446    test    esi, CPUM_SYNC_FPU_STATE
    447     jz      near gth_fpu_no
     447    jz      near htg_fpu_no
    448448
    449449%ifdef VBOX_WITH_CRASHDUMP_MAGIC
     
    460460    and     dword [rdx + CPUMCPU.fUseFlags], ~CPUM_SYNC_FPU_STATE
    461461
    462 gth_fpu_no:
     462htg_fpu_no:
    463463    ; Check if we need to restore the guest debug state
    464     test    esi, CPUM_SYNC_DEBUG_STATE
    465     jz      near gth_debug_no
     464    test    esi, CPUM_SYNC_DEBUG_REGS_GUEST | CPUM_SYNC_DEBUG_REGS_HYPER
     465    jz      htg_debug_done
    466466
    467467%ifdef VBOX_WITH_CRASHDUMP_MAGIC
    468468    mov dword [rdx + CPUMCPU.Guest.dr + 4*8], 8
    469469%endif
    470 
     470    test    esi, CPUM_SYNC_DEBUG_REGS_HYPER
     471    jnz     htg_debug_hyper
     472
     473    ; Guest values in DRx, letting the guest access them directly.
    471474    mov     rax, qword [rdx + CPUMCPU.Guest.dr + 0*8]
    472475    mov     dr0, rax
     
    480483    mov     dr6, rax    ; not required for AMD-V
    481484
    482     and     dword [rdx + CPUMCPU.fUseFlags], ~CPUM_SYNC_DEBUG_STATE
    483 
    484 gth_debug_no:
     485    and     dword [rdx + CPUMCPU.fUseFlags], ~CPUM_SYNC_DEBUG_REGS_GUEST
     486    or      dword [rdx + CPUMCPU.fUseFlags], CPUM_USED_DEBUG_REGS_GUEST
     487    jmp     htg_debug_done
     488
     489htg_debug_hyper:
     490    ; Combined values in DRx, intercepting all accesses.
     491    mov     rax, qword [rdx + CPUMCPU.Hyper.dr + 0*8]
     492    mov     dr0, rax
     493    mov     rax, qword [rdx + CPUMCPU.Hyper.dr + 1*8]
     494    mov     dr1, rax
     495    mov     rax, qword [rdx + CPUMCPU.Hyper.dr + 2*8]
     496    mov     dr2, rax
     497    mov     rax, qword [rdx + CPUMCPU.Hyper.dr + 3*8]
     498    mov     dr3, rax
     499    mov     rax, qword [rdx + CPUMCPU.Hyper.dr + 6*8]
     500    mov     dr6, rax    ; not required for AMD-V
     501
     502    and     dword [rdx + CPUMCPU.fUseFlags], ~CPUM_SYNC_DEBUG_REGS_HYPER
     503    or      dword [rdx + CPUMCPU.fUseFlags], CPUM_USED_DEBUG_REGS_HYPER
     504
     505htg_debug_done:
    485506
    486507%ifdef VBOX_WITH_CRASHDUMP_MAGIC
    487508    mov dword [rdx + CPUMCPU.Guest.dr + 4*8], 9
    488509%endif
     510
     511    ;
     512    ; "Call" the specified helper function.
     513    ;
    489514
    490515    ; parameter for all helper functions (pCtx)
    491516    DEBUG64_CHAR('9')
    492517    lea     rsi, [rdx + CPUMCPU.Guest.fpu]
    493     lea     rax, [gth_return wrt rip]
     518    lea     rax, [htg_return wrt rip]
    494519    push    rax                         ; return address
    495520
     
    505530    jz      NAME(HMRCTestSwitcher64)
    506531    mov     eax, VERR_HM_INVALID_HM64ON32OP
    507 gth_return:
     532htg_return:
    508533    DEBUG64_CHAR('r')
    509534
  • trunk/src/VBox/VMM/VMMSwitcher/PAEand32Bit.mac

    r41985 r47660  
    55
    66;
    7 ; Copyright (C) 2006-2012 Oracle Corporation
     7; Copyright (C) 2006-2013 Oracle Corporation
    88;
    99; This file is part of VirtualBox Open Source Edition (OSE), as
     
    256256
    257257    ; debug registers.
    258     test    esi, CPUM_USE_DEBUG_REGS | CPUM_USE_DEBUG_REGS_HOST
     258    test    esi, CPUM_USE_DEBUG_REGS_HYPER | CPUM_USE_DEBUG_REGS_HOST
    259259    jnz     htg_debug_regs_save_dr7and6
    260260htg_debug_regs_no:
     
    407407
    408408    ; debug registers
    409     test    esi, CPUM_USE_DEBUG_REGS
     409    test    esi, CPUM_USE_DEBUG_REGS_HYPER
    410410    jnz     htg_debug_regs_guest
    411411htg_debug_regs_guest_done:
     
    515515    mov     eax, dr3
    516516    mov     [edx + CPUMCPU.Host.dr3], eax
     517    or      dword [edi + CPUMCPU.fUseFlags], CPUM_USED_DEBUG_REGS_HOST
    517518
    518519    ; load hyper DR0-7
     
    525526    mov     ebx, [edx + CPUMCPU.Hyper.dr + 8*3]
    526527    mov     dr3, ebx
    527     ;mov     eax, [edx + CPUMCPU.Hyper.dr + 8*6]
    528     mov     ecx, 0ffff0ff0h
     528    mov     ecx, X86_DR6_INIT_VAL
    529529    mov     dr6, ecx
    530530    mov     eax, [edx + CPUMCPU.Hyper.dr + 8*7]
    531531    mov     dr7, eax
     532    or      dword [edi + CPUMCPU.fUseFlags], CPUM_USED_DEBUG_REGS_HYPER
    532533    jmp     htg_debug_regs_guest_done
    533534
     
    686687    ; No need to save CRx here. They are set dynamically according to Guest/Host requirements.
    687688    ; FPU context is saved before restore of host saving (another) branch.
     689
     690    ; Disable debug regsiters if active so they cannot trigger while switching.
     691    test    dword [edi + CPUMCPU.fUseFlags], CPUM_USED_DEBUG_REGS_HYPER
     692    jz      .gth_disabled_dr7
     693    mov     eax, X86_DR7_INIT_VAL
     694    mov     dr7, eax
     695.gth_disabled_dr7:
    688696
    689697%ifdef VBOX_WITH_NMI
     
    887895    ; restore debug registers (if modified) (esi must still be fUseFlags!)
    888896    ; (must be done after cr4 reload because of the debug extension.)
    889     test    esi, CPUM_USE_DEBUG_REGS | CPUM_USE_DEBUG_REGS_HOST
    890     jz short gth_debug_regs_no
    891     jmp     gth_debug_regs_restore
    892 gth_debug_regs_no:
     897    test    esi, CPUM_USE_DEBUG_REGS_HYPER | CPUM_USE_DEBUG_REGS_HOST | CPUM_USED_DEBUG_REGS_HOST
     898    jnz     gth_debug_regs_restore
     899gth_debug_regs_done:
    893900
    894901    ; restore general registers.
     
    911918gth_debug_regs_restore:
    912919    DEBUG_S_CHAR('d')
    913     xor     eax, eax
    914     mov     dr7, eax                    ; paranoia or not?
    915     test    esi, CPUM_USE_DEBUG_REGS
    916     jz short gth_debug_regs_dr7
     920    mov     eax, dr7                    ; Some DR7 paranoia first...
     921    mov     ecx, X86_DR7_INIT_VAL
     922    cmp     eax, ecx
     923    je      .gth_debug_skip_dr7_disabling
     924    mov     dr7, ecx
     925.gth_debug_skip_dr7_disabling:
     926    test    esi, CPUM_USED_DEBUG_REGS_HOST
     927    jz      .gth_debug_regs_dr7
     928
    917929    DEBUG_S_CHAR('r')
    918930    mov     eax, [edx + CPUMCPU.Host.dr0]
     
    924936    mov     eax, [edx + CPUMCPU.Host.dr3]
    925937    mov     dr3, eax
    926 gth_debug_regs_dr7:
     938.gth_debug_regs_dr7:
    927939    mov     ebx, [edx + CPUMCPU.Host.dr6]
    928940    mov     dr6, ebx
    929941    mov     ecx, [edx + CPUMCPU.Host.dr7]
    930942    mov     dr7, ecx
    931     jmp     gth_debug_regs_no
     943
     944    and     dword [edx + CPUMCPU.fUseFlags], ~(CPUM_USED_DEBUG_REGS_HOST | CPUM_USED_DEBUG_REGS_HYPER)
     945    jmp     gth_debug_regs_done
    932946
    933947ENDPROC vmmRCToHostAsm
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