minimal_rt/arch/x86_64/
enlightened_panic.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Enlightened panic registers for an x64 Hyper-V guest.
5
6use crate::arch::x86_64::msr::write_msr;
7use hvdef::HV_X64_MSR_GUEST_CRASH_CTL;
8use hvdef::HV_X64_MSR_GUEST_CRASH_P0;
9use hvdef::HV_X64_MSR_GUEST_CRASH_P1;
10use hvdef::HV_X64_MSR_GUEST_CRASH_P2;
11use hvdef::HV_X64_MSR_GUEST_CRASH_P3;
12use hvdef::HV_X64_MSR_GUEST_CRASH_P4;
13
14const REGS: [u32; 6] = [
15    HV_X64_MSR_GUEST_CRASH_P0,
16    HV_X64_MSR_GUEST_CRASH_P1,
17    HV_X64_MSR_GUEST_CRASH_P2,
18    HV_X64_MSR_GUEST_CRASH_P3,
19    HV_X64_MSR_GUEST_CRASH_P4,
20    HV_X64_MSR_GUEST_CRASH_CTL,
21];
22
23/// # Safety
24///
25/// Caller must ensure that the Hyper-V TLFS contract is followed.
26pub unsafe fn write_crash_reg(index: usize, value: u64) {
27    // SAFETY: Caller guaranteed.
28    unsafe {
29        write_msr(REGS[index], value);
30    }
31}