Compare commits

...

2 Commits

Author SHA1 Message Date
5afe970ff0 m1x/x86_64: Add interrupt descriptor table groundwork
Signed-off-by: Ian Moffett <ian@mirocom.org>
2026-03-25 19:18:45 -04:00
2c0b174f8e m1x/x86_64: Add GDT related definitions
Signed-off-by: Ian Moffett <ian@mirocom.org>
2026-03-25 19:18:45 -04:00
3 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2026, Mirocom Laboratories
* Provided under the BSD-3 clause
*/
#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_gate_set(uint8_t vector, uintptr_t isr, uint8_t ist, uint8_t type)
{
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");
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) 2026, Mirocom Laboratories
* Provided under the BSD-3 clause
*/
#ifndef _MACHINE_GDT_H_
#define _MACHINE_GDT_H_ 1
/* Kernel code/data */
#define GDT_KCODE 0x08
#define GDT_KDATA 0x10
/* User code/data */
#define GDT_UCODE 0x18
#define GDT_UDATA 0x20
/* Task state segment */
#define GDT_TSS 0x28
#define GDT_TSS_INDEX 0x05
#endif /* !_MACHINE_GDT_H_ */

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2026, Mirocom Laboratories
* Provided under the BSD-3 clause
*/
#ifndef _MACHINE_IDT_H_
#define _MACHINE_IDT_H_ 1
#include <sys/types.h>
#include <sys/cdefs.h>
#define IDT_INT_GATE 0x8E
#define IDT_TRAP_GATE 0x8F
#define IDT_USER_GATE 0xEE
/*
* Represents an interrupt descriptor table gate
* entry
*/
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;
};
/*
* References an interrupt descriptor table
*/
struct __packed idtr {
uint16_t limit;
uintptr_t base;
};
/*
* Set an entry in the interrupt descriptor table
*
* @vector: Interrupt vector to set
* @isr: Interrupt service routine base
* @ist: Interrupt stack table
* @type: Interrupt gate type
*/
void md_idt_gate_set(uint8_t vector, uintptr_t isr, uint8_t ist, uint8_t type);
/*
* Load the interrupt descriptor table register
*/
void md_idt_load(void);
#endif /* !_MACHINE_IDT_H_ */