From 1f786d7c9ebd40d27bc2cafe9d535468d90663ce Mon Sep 17 00:00:00 2001 From: GZTime Date: Fri, 15 Mar 2024 13:59:10 +0800 Subject: [PATCH] feat: add constructor for `InterruptStackFrameValue` --- src/structures/idt.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/structures/idt.rs b/src/structures/idt.rs index 3952ae96..2b24f89b 100644 --- a/src/structures/idt.rs +++ b/src/structures/idt.rs @@ -971,6 +971,24 @@ impl EntryOptions { pub struct InterruptStackFrame(InterruptStackFrameValue); impl InterruptStackFrame { + /// Creates a new interrupt stack frame with the given values. + #[inline] + pub fn new( + instruction_pointer: VirtAddr, + code_segment: SegmentSelector, + cpu_flags: RFlags, + stack_pointer: VirtAddr, + stack_segment: SegmentSelector, + ) -> Self { + Self(InterruptStackFrameValue::new( + instruction_pointer, + code_segment, + cpu_flags, + stack_pointer, + stack_segment, + )) + } + /// Gives mutable access to the contents of the interrupt stack frame. /// /// The `Volatile` wrapper is used because LLVM optimizations remove non-volatile @@ -1030,6 +1048,26 @@ pub struct InterruptStackFrameValue { } impl InterruptStackFrameValue { + /// Creates a new interrupt stack frame with the given values. + #[inline] + pub fn new( + instruction_pointer: VirtAddr, + code_segment: SegmentSelector, + cpu_flags: RFlags, + stack_pointer: VirtAddr, + stack_segment: SegmentSelector, + ) -> Self { + Self { + instruction_pointer, + code_segment, + _reserved1: Default::default(), + cpu_flags, + stack_pointer, + stack_segment, + _reserved2: Default::default(), + } + } + /// Call the `iretq` (interrupt return) instruction. /// /// This function doesn't have to be called in an interrupt handler.