From 810a4e3515dd211ddec6ce8f0f9bc2d8131bbe5e Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Fri, 6 Aug 2021 10:44:31 +0200 Subject: [PATCH] x86 segment: add get_intr_handler() helper function Add a helper function to retrieve offset field of an interrupt gate. Signed-off-by: Pawel Wieczorkiewicz --- include/arch/x86/segment.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/arch/x86/segment.h b/include/arch/x86/segment.h index 6deb4ffe..f04c0693 100644 --- a/include/arch/x86/segment.h +++ b/include/arch/x86/segment.h @@ -182,6 +182,10 @@ static inline void set_gate32_offset(struct x86_gate32 *gate, unsigned long offs gate->offset_hi = ((offset & _ul(0xffff0000)) >> 16); } +static inline uint32_t get_gate32_offset(const struct x86_gate32 *gate) { + return (gate->offset_hi << 16) | gate->offset_lo; +} + static inline void set_gate32(struct x86_gate32 *gate, uint8_t type, uint16_t selector, unsigned long offset, uint8_t dpl, bool present) { set_gate32_offset(gate, offset); @@ -218,6 +222,10 @@ static inline void set_gate64_offset(struct x86_gate64 *gate, unsigned long offs gate->offset_hi = ((offset & _ul(0xffffffff00000000)) >> 32); } +static inline uint64_t get_gate64_offset(const struct x86_gate64 *gate) { + return ((uint64_t) gate->offset_hi << 32) | (gate->offset_mi << 16) | gate->offset_lo; +} + static inline void set_gate64(struct x86_gate64 *gate, uint8_t type, uint16_t selector, unsigned long offset, uint8_t dpl, bool present, uint8_t ist) { @@ -287,6 +295,9 @@ static inline void set_intr_gate(struct x86_gate32 *gate, uint16_t selector, set_gate32(gate, GATE_TYPE_INTR, selector, offset, dpl, present); } +static inline uint32_t get_intr_handler(const struct x86_gate32 *gate) { + return get_gate32_offset(gate); +} #else typedef struct x86_gate64 task_gate_t; @@ -304,6 +315,10 @@ static inline void set_intr_gate(struct x86_gate64 *gate, uint16_t selector, uint8_t ist) { set_gate64(gate, GATE_TYPE_INTR, selector, offset, dpl, present, ist); } + +static inline uint64_t get_intr_handler(const struct x86_gate64 *gate) { + return get_gate64_offset(gate); +} #endif extern idt_entry_t idt[256];