Compare commits
2 Commits
631b7729a9
...
5afe970ff0
| Author | SHA1 | Date | |
|---|---|---|---|
| 5afe970ff0 | |||
| 2c0b174f8e |
38
src/m1x/arch/x86_64/cpu/cpu_idt.c
Normal file
38
src/m1x/arch/x86_64/cpu/cpu_idt.c
Normal 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");
|
||||||
|
}
|
||||||
21
src/m1x/include/arch/x86_64/gdt.h
Normal file
21
src/m1x/include/arch/x86_64/gdt.h
Normal 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_ */
|
||||||
57
src/m1x/include/arch/x86_64/idt.h
Normal file
57
src/m1x/include/arch/x86_64/idt.h
Normal 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_ */
|
||||||
Reference in New Issue
Block a user