Skip to content

Commit

Permalink
add VM-Exit Interruption-Information
Browse files Browse the repository at this point in the history
Signed-off-by: smallkirby <ssmallkirby@gmail.com>
  • Loading branch information
smallkirby committed Nov 15, 2024
1 parent 07567bd commit 871c004
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion ymir/arch/x86/vmx/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,42 @@ pub const EntryIntrInfo = packed struct(u32) {
entry,
exit,
};
};

/// VM-Exit Interruption-information.
/// SDM Vol.3C. Table 25-19.
pub const ExitIntrInfo = packed struct(u32) {
/// Vector of interrupt or exception.
vector: u8,
/// Interruption type.
type: Type,
/// Error Code is valid.
ec_valid: bool,
/// NMI unblocking due to IRET.
nmi_unblocking: bool,
/// Not currently defined.
_notused: u18 = 0,
/// Valid.
valid: bool,

const Type = enum(u3) {
external = 0,
_unused1 = 1,
nmi = 2,
hw = 3,
_unused2 = 4,
priviledged_sw = 5,
exception = 6,
_unused3 = 7,
};

const Kind = enum {
entry,
exit,
};

/// Get a VM-entry or VM-exit interrupt information from VMCS.
pub fn load(kind: Kind) VmxError!EntryIntrInfo {
pub fn load(kind: Kind) VmxError!ExitIntrInfo {
return @bitCast(@as(u32, @truncate(switch (kind) {
.entry => try vmread(vmcs.ctrl.entry_intr_info),
.exit => try vmread(vmcs.ro.exit_intr_info),
Expand Down
2 changes: 1 addition & 1 deletion ymir/arch/x86/vmx/vcpu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub const Vcpu = struct {
fn handleExit(self: *Self, exit_info: vmx.ExitInfo) VmxError!void {
switch (exit_info.basic_reason) {
.exception_nmi => {
const ii = try vmx.EntryIntrInfo.load(.exit);
const ii = try vmx.ExitIntrInfo.load(.exit);
if (!ii.valid) {
log.err("Invalid VM-exit interrupt information.", .{});
self.abort();
Expand Down

0 comments on commit 871c004

Please sign in to comment.