~ubuntu-branches/ubuntu/vivid/virtualbox-ose/vivid

« back to all changes in this revision

Viewing changes to src/VBox/VMM/VMMR0/CPUMR0.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-09-14 18:25:07 UTC
  • mfrom: (0.4.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090914182507-c98g07mq16hjmn6d
Tags: 3.0.6-dfsg-1ubuntu1
* Merge from debian unstable (LP: #429697), remaining changes:
  - Enable DKMS support on virtualbox host and guest modules (LP: #267097)
    - Drop virtualbox-ose{-guest,}-modules-* package templates
    - Recommend *-source instead of *-modules packages
    - Replace error messages related to missing/mismatched
      kernel module accordingly
  - Autoload kernel module
    - LOAD_VBOXDRV_MODULE=1 in virtualbox-ose.default
  - Disable update action
    - patches/u01-disable-update-action.dpatch
  - Virtualbox should go in Accessories, not in System tools (LP: #288590)
    - virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add apport hook
    - virtualbox-ose.files/source_virtualbox-ose.py
    - virtualbox-ose.install
  - Add launchpad integration
    - control
    - lpi-bug.xpm
    - patches/u02-lp-integration.dpatch
  - virtualbox, virtualbox-* (names of the upstream proprietary packages)
    conflict with virtualbox-ose (LP: #379878)
* Make debug package depend on normal or guest utils package
* Drop patches/22-pulseaudio-stubs.dpatch (applied upstream)
* Rename Ubuntu specific patches to uXX-*.dpatch
* Fix lintian warnings in maintainer scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
223
223
    {
224
224
#ifndef CPUM_CAN_HANDLE_NM_TRAPS_IN_KERNEL_MODE
225
225
# if defined(VBOX_WITH_HYBRID_32BIT_KERNEL) || defined(VBOX_WITH_KERNEL_USING_XMM) /** @todo remove the #else here and move cpumHandleLazyFPUAsm back to VMMGC after branching out 3.0!!. */
 
226
        Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_MANUAL_XMM_RESTORE));
226
227
        /** @todo Move the FFXR handling down into
227
228
         *        cpumR0SaveHostRestoreguestFPUState to optimize the
228
229
         *        VBOX_WITH_KERNEL_USING_XMM handling. */
443
444
     * Restore the host's debug state. DR0-3, DR6 and only then DR7!
444
445
     * DR7 contains 0x400 right now.
445
446
     */
446
 
#ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
447
 
    AssertCompile((uintptr_t)&pVCpu->cpum.s.Host.dr3 - (uintptr_t)&pVCpu->cpum.s.Host.dr0 == sizeof(uint64_t) * 3);
448
 
    cpumR0LoadDRx(&pVCpu->cpum.s.Host.dr0);
449
 
#else
450
 
    ASMSetDR0(pVCpu->cpum.s.Host.dr0);
451
 
    ASMSetDR1(pVCpu->cpum.s.Host.dr1);
452
 
    ASMSetDR2(pVCpu->cpum.s.Host.dr2);
453
 
    ASMSetDR3(pVCpu->cpum.s.Host.dr3);
454
 
#endif
455
 
    ASMSetDR6(pVCpu->cpum.s.Host.dr6);
456
 
    ASMSetDR7(pVCpu->cpum.s.Host.dr7);
457
 
 
458
 
    pVCpu->cpum.s.fUseFlags &= ~CPUM_USE_DEBUG_REGS;
 
447
    CPUMR0LoadHostDebugState(pVM, pVCpu);
 
448
    Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_USE_DEBUG_REGS));
459
449
    return VINF_SUCCESS;
460
450
}
461
451
 
472
462
VMMR0DECL(int) CPUMR0LoadGuestDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, bool fDR6)
473
463
{
474
464
    /* Save the host state. */
 
465
    CPUMR0SaveHostDebugState(pVM, pVCpu);
 
466
    Assert(ASMGetDR7() == X86_DR7_INIT_VAL);
 
467
 
 
468
    /* Activate the guest state DR0-3; DR7 is left to the caller. */
 
469
#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
 
470
    if (CPUMIsGuestInLongModeEx(pCtx))
 
471
    {
 
472
        /* Restore the state on entry as we need to be in 64 bits mode to access the full state. */
 
473
        pVCpu->cpum.s.fUseFlags |= CPUM_SYNC_DEBUG_STATE;
 
474
    }
 
475
    else
 
476
#endif
 
477
    {
 
478
#ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
 
479
        cpumR0LoadDRx(&pCtx->dr[0]);
 
480
#else
 
481
        ASMSetDR0(pCtx->dr[0]);
 
482
        ASMSetDR1(pCtx->dr[1]);
 
483
        ASMSetDR2(pCtx->dr[2]);
 
484
        ASMSetDR3(pCtx->dr[3]);
 
485
#endif
 
486
        if (fDR6)
 
487
            ASMSetDR6(pCtx->dr[6]);
 
488
    }
 
489
 
 
490
    pVCpu->cpum.s.fUseFlags |= CPUM_USE_DEBUG_REGS;
 
491
    return VINF_SUCCESS;
 
492
}
 
493
 
 
494
/**
 
495
 * Save the host debug state
 
496
 *
 
497
 * @returns VBox status code.
 
498
 * @param   pVM         VM handle.
 
499
 * @param   pVCpu       VMCPU handle.
 
500
 */
 
501
VMMR0DECL(int) CPUMR0SaveHostDebugState(PVM pVM, PVMCPU pVCpu)
 
502
{
 
503
    /* Save the host state. */
475
504
#ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
476
505
    AssertCompile((uintptr_t)&pVCpu->cpum.s.Host.dr3 - (uintptr_t)&pVCpu->cpum.s.Host.dr0 == sizeof(uint64_t) * 3);
477
506
    cpumR0SaveDRx(&pVCpu->cpum.s.Host.dr0);
487
516
    /* Make sure DR7 is harmless or else we could trigger breakpoints when restoring dr0-3 (!) */
488
517
    ASMSetDR7(X86_DR7_INIT_VAL);
489
518
 
 
519
    return VINF_SUCCESS;
 
520
}
 
521
 
 
522
/**
 
523
 * Load the host debug state
 
524
 *
 
525
 * @returns VBox status code.
 
526
 * @param   pVM         VM handle.
 
527
 * @param   pVCpu       VMCPU handle.
 
528
 */
 
529
VMMR0DECL(int) CPUMR0LoadHostDebugState(PVM pVM, PVMCPU pVCpu)
 
530
{
 
531
    Assert(pVCpu->cpum.s.fUseFlags & (CPUM_USE_DEBUG_REGS | CPUM_USE_DEBUG_REGS_HYPER));
 
532
 
 
533
    /*
 
534
     * Restore the host's debug state. DR0-3, DR6 and only then DR7!
 
535
     * DR7 contains 0x400 right now.
 
536
     */
 
537
#ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
 
538
    AssertCompile((uintptr_t)&pVCpu->cpum.s.Host.dr3 - (uintptr_t)&pVCpu->cpum.s.Host.dr0 == sizeof(uint64_t) * 3);
 
539
    cpumR0LoadDRx(&pVCpu->cpum.s.Host.dr0);
 
540
#else
 
541
    ASMSetDR0(pVCpu->cpum.s.Host.dr0);
 
542
    ASMSetDR1(pVCpu->cpum.s.Host.dr1);
 
543
    ASMSetDR2(pVCpu->cpum.s.Host.dr2);
 
544
    ASMSetDR3(pVCpu->cpum.s.Host.dr3);
 
545
#endif
 
546
    ASMSetDR6(pVCpu->cpum.s.Host.dr6);
 
547
    ASMSetDR7(pVCpu->cpum.s.Host.dr7);
 
548
 
 
549
    pVCpu->cpum.s.fUseFlags &= ~(CPUM_USE_DEBUG_REGS | CPUM_USE_DEBUG_REGS_HYPER);
 
550
    return VINF_SUCCESS;
 
551
}
 
552
 
 
553
 
 
554
/**
 
555
 * Lazily sync in the hypervisor debug state
 
556
 *
 
557
 * @returns VBox status code.
 
558
 * @param   pVM         VM handle.
 
559
 * @param   pVCpu       VMCPU handle.
 
560
 * @param   pCtx        CPU context
 
561
 * @param   fDR6        Include DR6 or not
 
562
 */
 
563
VMMR0DECL(int) CPUMR0LoadHyperDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, bool fDR6)
 
564
{
 
565
    /* Save the host state. */
 
566
    CPUMR0SaveHostDebugState(pVM, pVCpu);
 
567
    Assert(ASMGetDR7() == X86_DR7_INIT_VAL);
 
568
 
490
569
    /* Activate the guest state DR0-3; DR7 is left to the caller. */
491
570
#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
492
571
    if (CPUMIsGuestInLongModeEx(pCtx))
493
572
    {
494
 
        /* Restore the state on entry as we need to be in 64 bits mode to access the full state. */
495
 
        pVCpu->cpum.s.fUseFlags |= CPUM_SYNC_DEBUG_STATE;
 
573
        AssertFailed();
 
574
        return VERR_NOT_IMPLEMENTED;
496
575
    }
497
576
    else
498
577
#endif
499
578
    {
500
579
#ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
501
 
        cpumR0LoadDRx(&pCtx->dr[0]);
 
580
        AssertFailed();
 
581
        return VERR_NOT_IMPLEMENTED;
502
582
#else
503
 
        ASMSetDR0(pCtx->dr[0]);
504
 
        ASMSetDR1(pCtx->dr[1]);
505
 
        ASMSetDR2(pCtx->dr[2]);
506
 
        ASMSetDR3(pCtx->dr[3]);
 
583
        ASMSetDR0(CPUMGetHyperDR0(pVCpu));
 
584
        ASMSetDR1(CPUMGetHyperDR1(pVCpu));
 
585
        ASMSetDR2(CPUMGetHyperDR2(pVCpu));
 
586
        ASMSetDR3(CPUMGetHyperDR3(pVCpu));
507
587
#endif
508
588
        if (fDR6)
509
 
            ASMSetDR6(pCtx->dr[6]);
 
589
            ASMSetDR6(CPUMGetHyperDR6(pVCpu));
510
590
    }
511
591
 
512
 
    pVCpu->cpum.s.fUseFlags |= CPUM_USE_DEBUG_REGS;
 
592
    pVCpu->cpum.s.fUseFlags |= CPUM_USE_DEBUG_REGS_HYPER;
513
593
    return VINF_SUCCESS;
514
594
}
515
595