Skip to content

Commit

Permalink
x86 segment: add get_intr_handler() helper function
Browse files Browse the repository at this point in the history
Add a helper function to retrieve offset field of an interrupt gate.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Aug 6, 2021
1 parent b46ca32 commit 810a4e3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/arch/x86/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down

0 comments on commit 810a4e3

Please sign in to comment.