MOS Source Code
Loading...
Searching...
No Matches
idt.c
Go to the documentation of this file.
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
3
#include "
mos/x86/descriptors/descriptors.h
"
4
5
#include <
mos/platform/platform.h
>
6
#include <
mos/x86/x86_interrupt.h
>
7
#include <
mos/x86/x86_platform.h
>
8
9
static
idt_entry_t
idt[
IDT_ENTRY_COUNT
]
__aligned
(16) = { 0 };
10
static
idtr_t
idtr
;
11
12
#define IDT_FLAG_P (1 << 7)
13
14
#define STS_IG32 0xE
// 32-bit Interrupt Gate
15
#define STS_TG32 0xF
// 32-bit Trap Gate
16
17
__attribute__
((sysv_abi))
void
idt_flush(
idtr_t
*
idtr
);
18
19
static
void
idt_set_descriptor(
u8
vector,
void
*isr,
bool
usermode,
bool
is_trap)
20
{
21
idt_entry_t
*descriptor = &idt[vector];
22
23
descriptor->
isr_veryhigh
= (
uintn
) isr >> 32;
24
descriptor->
reserved2
= 0;
25
26
descriptor->
isr_low
= (
uintn
) isr & 0xFFFF;
27
descriptor->
isr_high
= (
uintn
) isr >> 16;
28
descriptor->
segment
=
GDT_SEGMENT_KCODE
;
29
descriptor->
present
=
true
;
30
descriptor->
dpl
= usermode ? 3 : 0;
31
descriptor->
type
= is_trap ?
STS_TG32
:
STS_IG32
;
32
descriptor->
zero
= 0;
33
descriptor->
reserved
= 0;
34
}
35
36
void
x86_init_percpu_idt
()
37
{
38
idt_flush(&
idtr
);
39
}
40
41
void
x86_idt_init
()
42
{
43
for
(
u8
isr = 0; isr <
ISR_MAX_COUNT
; isr++)
44
idt_set_descriptor(isr,
isr_stub_table
[isr],
false
,
false
);
45
46
for
(
u8
irq_n = 0; irq_n <
IRQ_MAX_COUNT
; irq_n++)
47
idt_set_descriptor(irq_n +
IRQ_BASE
,
irq_stub_table
[irq_n],
false
,
false
);
48
49
// system calls
50
idt_set_descriptor(
MOS_SYSCALL_INTR
,
isr_stub_table
[
MOS_SYSCALL_INTR
],
true
,
true
);
51
52
for
(
u8
ipi_n = 0; ipi_n <
IPI_TYPE_MAX
; ipi_n++)
53
idt_set_descriptor(ipi_n +
IPI_BASE
,
isr_stub_table
[ipi_n +
IPI_BASE
],
false
,
false
);
54
55
idtr
.
base
= &idt[0];
56
idtr
.
limit
= (
u16
)
sizeof
(
idt_entry_t
) *
IDT_ENTRY_COUNT
- 1;
57
}
descriptors.h
GDT_SEGMENT_KCODE
#define GDT_SEGMENT_KCODE
Definition
descriptors.h:17
STS_IG32
#define STS_IG32
Definition
idt.c:14
__attribute__
__attribute__((sysv_abi))
Definition
idt.c:17
STS_TG32
#define STS_TG32
Definition
idt.c:15
x86_init_percpu_idt
void x86_init_percpu_idt()
Definition
idt.c:36
x86_idt_init
void x86_idt_init()
Definition
idt.c:41
idtr
static idtr_t idtr
Definition
idt.c:10
IPI_TYPE_MAX
@ IPI_TYPE_MAX
Definition
ipi.h:16
__aligned
#define __aligned(x)
Definition
mos_global.h:27
platform.h
idt_entry_t
Definition
descriptors.h:87
idt_entry_t::zero
u32 zero
Definition
descriptors.h:92
idt_entry_t::segment
u16 segment
Definition
descriptors.h:89
idt_entry_t::isr_veryhigh
u32 isr_veryhigh
Definition
descriptors.h:96
idt_entry_t::reserved2
u32 reserved2
Definition
descriptors.h:97
idt_entry_t::isr_low
u16 isr_low
Definition
descriptors.h:88
idt_entry_t::dpl
u32 dpl
Definition
descriptors.h:93
idt_entry_t::isr_high
u32 isr_high
Definition
descriptors.h:95
idt_entry_t::reserved
u32 reserved
Definition
descriptors.h:90
idt_entry_t::present
u32 present
Definition
descriptors.h:94
idt_entry_t::type
u32 type
Definition
descriptors.h:91
idtr_t
Definition
descriptors.h:101
idtr_t::limit
u16 limit
Definition
descriptors.h:102
idtr_t::base
idt_entry_t * base
Definition
descriptors.h:103
uintn
unsigned long uintn
Definition
types.h:30
u16
unsigned short u16
Definition
types.h:20
u8
unsigned char u8
Definition
types.h:19
x86_interrupt.h
IPI_BASE
#define IPI_BASE
Definition
x86_interrupt.h:12
isr_stub_table
void * isr_stub_table[]
irq_stub_table
void * irq_stub_table[]
ISR_MAX_COUNT
#define ISR_MAX_COUNT
Definition
x86_interrupt.h:14
IDT_ENTRY_COUNT
#define IDT_ENTRY_COUNT
Definition
x86_interrupt.h:16
IRQ_BASE
#define IRQ_BASE
Definition
x86_interrupt.h:11
IRQ_MAX_COUNT
#define IRQ_MAX_COUNT
Definition
x86_interrupt.h:15
x86_platform.h
MOS_SYSCALL_INTR
#define MOS_SYSCALL_INTR
Definition
x86_platform.h:15
kernel
arch
x86_64
interrupt
idt.c
Generated on Sun Sep 1 2024 18:22:52 for MOS Source Code by
1.12.0