hyperlight_common/
outb.rs1use core::convert::TryFrom;
18
19use anyhow::{Error, anyhow};
20
21#[repr(u8)]
25#[derive(Debug, Clone, Copy)]
26pub enum Exception {
27 DivideByZero = 0,
28 Debug = 1,
29 NonMaskableInterrupt = 2,
30 Breakpoint = 3,
31 Overflow = 4,
32 BoundRangeExceeded = 5,
33 InvalidOpcode = 6,
34 DeviceNotAvailable = 7,
35 DoubleFault = 8,
36 CoprocessorSegmentOverrun = 9,
37 InvalidTSS = 10,
38 SegmentNotPresent = 11,
39 StackSegmentFault = 12,
40 GeneralProtectionFault = 13,
41 PageFault = 14,
42 Reserved = 15,
43 X87FloatingPointException = 16,
44 AlignmentCheck = 17,
45 MachineCheck = 18,
46 SIMDFloatingPointException = 19,
47 VirtualizationException = 20,
48 SecurityException = 30,
49 NoException = 0xFF,
50}
51
52impl TryFrom<u8> for Exception {
53 type Error = Error;
54
55 fn try_from(value: u8) -> Result<Self, Self::Error> {
56 use Exception::*;
57 let exception = match value {
58 0 => DivideByZero,
59 1 => Debug,
60 2 => NonMaskableInterrupt,
61 3 => Breakpoint,
62 4 => Overflow,
63 5 => BoundRangeExceeded,
64 6 => InvalidOpcode,
65 7 => DeviceNotAvailable,
66 8 => DoubleFault,
67 9 => CoprocessorSegmentOverrun,
68 10 => InvalidTSS,
69 11 => SegmentNotPresent,
70 12 => StackSegmentFault,
71 13 => GeneralProtectionFault,
72 14 => PageFault,
73 15 => Reserved,
74 16 => X87FloatingPointException,
75 17 => AlignmentCheck,
76 18 => MachineCheck,
77 19 => SIMDFloatingPointException,
78 20 => VirtualizationException,
79 30 => SecurityException,
80 0xFF => NoException,
81 _ => return Err(anyhow!("Unknown exception code: {:#x}", value)),
82 };
83
84 Ok(exception)
85 }
86}
87
88pub enum OutBAction {
97 Log = 99,
98 CallFunction = 101,
99 Abort = 102,
100 DebugPrint = 103,
101 #[cfg(feature = "trace_guest")]
102 TraceBatch = 104,
103 #[cfg(feature = "mem_profile")]
104 TraceMemoryAlloc = 105,
105 #[cfg(feature = "mem_profile")]
106 TraceMemoryFree = 106,
107}
108
109impl TryFrom<u16> for OutBAction {
110 type Error = anyhow::Error;
111 fn try_from(val: u16) -> anyhow::Result<Self> {
112 match val {
113 99 => Ok(OutBAction::Log),
114 101 => Ok(OutBAction::CallFunction),
115 102 => Ok(OutBAction::Abort),
116 103 => Ok(OutBAction::DebugPrint),
117 #[cfg(feature = "trace_guest")]
118 104 => Ok(OutBAction::TraceBatch),
119 #[cfg(feature = "mem_profile")]
120 105 => Ok(OutBAction::TraceMemoryAlloc),
121 #[cfg(feature = "mem_profile")]
122 106 => Ok(OutBAction::TraceMemoryFree),
123 _ => Err(anyhow::anyhow!("Invalid OutBAction value: {}", val)),
124 }
125 }
126}