sp1/amd64: cpu: Add interrupt descriptor table
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2026, Mirocom Laboratories
|
||||
* All rights reserved.
|
||||
*
|
||||
* The following sources are CONFIDENTIAL and PROPRIETARY
|
||||
* property of Mirocom Laboratories. Unauthorized copying,
|
||||
* use, distribution or modification of this file, in whole
|
||||
* and in part, is strictly prohibited without the prior written
|
||||
* consent from Mirocom Laboratories.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <machine/idt.h>
|
||||
#include <machine/gdt.h>
|
||||
|
||||
__align(8) static struct idt_gate idt[256];
|
||||
static struct idtr idtr = {
|
||||
.limit = sizeof(idt) - 1,
|
||||
.base = (uintptr_t)&idt[0]
|
||||
};
|
||||
|
||||
void
|
||||
md_idt_set_gate(uint8_t vector, uintptr_t isr, uint8_t type, uint8_t ist)
|
||||
{
|
||||
struct idt_gate *gate;
|
||||
|
||||
gate = &idt[vector];
|
||||
gate->offset_low = (isr & 0xFFFF);
|
||||
gate->offset_mid = (isr >> 16) & 0xFFFF;
|
||||
gate->offset_high = (isr >> 32) & 0xFFFFFFFF;
|
||||
gate->p = 1;
|
||||
gate->dpl = (type == IDT_USER_GATE) ? 3 : 0;
|
||||
gate->zero = 0;
|
||||
gate->zero1 = 0;
|
||||
gate->reserved = 0;
|
||||
gate->type = type;
|
||||
gate->ist = ist;
|
||||
gate->segment_sel = GDT_KCODE;
|
||||
}
|
||||
|
||||
void
|
||||
md_idt_load(void)
|
||||
{
|
||||
__asmv("lidt %0" :: "m" (idtr) : "memory");
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <mu/cpu.h>
|
||||
#include <lib/printf.h>
|
||||
#include <machine/cpuid.h>
|
||||
#include <machine/idt.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define pr_trace(fmt, ...) \
|
||||
@@ -87,4 +88,7 @@ mu_cpu_preinit(struct cpu_info *ci)
|
||||
|
||||
/* Log out some information */
|
||||
cpu_print_info(ci);
|
||||
|
||||
/* Load the IDT */
|
||||
md_idt_load();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/* Copyright (c) 2026, Mirocom Laboratories
|
||||
* All rights reserved.
|
||||
*
|
||||
* The following sources are CONFIDENTIAL and PROPRIETARY
|
||||
* property of Mirocom Laboratories. Unauthorized copying,
|
||||
* use, distribution or modification of this file, in whole
|
||||
* and in part, is strictly prohibited without the prior written
|
||||
* consent from Mirocom Laboratories.
|
||||
*/
|
||||
|
||||
#ifndef _MACHINE_IDT_H_
|
||||
#define _MACHINE_IDT_H_ 1
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#endif /* !__ASSEMBLER__ */
|
||||
|
||||
#define IDT_INT_GATE 0x8E
|
||||
#define IDT_TRAP_GATE 0x8F
|
||||
#define IDT_USER_GATE 0xEE
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
/*
|
||||
* 64-bit interrupt gate descriptor
|
||||
*/
|
||||
struct idt_gate {
|
||||
uint16_t offset_low;
|
||||
uint16_t segment_sel;
|
||||
uint8_t ist : 3;
|
||||
uint8_t zero : 5;
|
||||
uint8_t type : 4;
|
||||
uint8_t zero1 : 1;
|
||||
uint8_t dpl : 2;
|
||||
uint8_t p : 1;
|
||||
uint16_t offset_mid;
|
||||
uint32_t offset_high;
|
||||
uint32_t reserved;
|
||||
};
|
||||
|
||||
/*
|
||||
* Points to
|
||||
*/
|
||||
struct __packed idtr {
|
||||
uint16_t limit;
|
||||
uintptr_t base;
|
||||
};
|
||||
|
||||
/*
|
||||
* Set an IDT gate desriptor
|
||||
*
|
||||
* @vector: Interrupt vector to set
|
||||
* @isr: Interrupt service routine base
|
||||
* @type: Gate descriptor type
|
||||
* @ist: Interrupt stack table index
|
||||
*/
|
||||
void md_idt_set_gate(uint8_t vector, uintptr_t isr, uint8_t type, uint8_t ist);
|
||||
|
||||
/*
|
||||
* Load the IDT
|
||||
*/
|
||||
void md_idt_load(void);
|
||||
|
||||
#endif /* !__ASSEMBLER__ */
|
||||
#endif /* !_MACHINE_IDT_H_ */
|
||||
Reference in New Issue
Block a user