feat(shim-sev): add debug function
Add `_enarx_asm_triple_debug` to debug values in the very early boot
stage, via registers, where no sallyport debug print is possible.
@@ -12,6 +12,33 @@ use x86_64::VirtAddr;
#[allow(clippy::integer_arithmetic)]
const SHIM_OFFSET: u64 = 1u64 + SHIM_VIRT_OFFSET + MAX_SETUP_SIZE as u64;
+/// Debug helper function for the early boot
+///
+/// # Safety
+///
+/// This function causes a triple fault!
+#[inline(never)]
+pub unsafe fn _enarx_asm_triple_debug(value: u64) -> ! {
+ // Create an invalid DescriptorTablePointer with no base and limit
+ let dtp = DescriptorTablePointer {
+ limit: 0,
+ base: VirtAddr::new(0),
+ };
+ // Load the invalid IDT
+ lidt(&dtp);
+
+ // Provoke an #UD, which will lead to a triple fault, because of the invalid IDT
+ asm!("ud2",
+ in("rax") value, // the first two frames are from panic
+ options(nomem, nostack)
+ );
+
+ // Extra hlt loop, in case hell freezes
+ loop {
+ x86_64::instructions::hlt()
+ }
+}
+
/// Provoke a triple fault to shutdown the machine
///
/// An illegal IDT is loaded with limit=0 and an #UD is produced
