MOS Source Code
Loading...
Searching...
No Matches
descriptors.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
3
#pragma once
4
5
#include <
mos/platform/platform.hpp
>
6
#include <
mos/types.hpp
>
7
8
#define GDT_NULL 0x00
9
#define GDT_SEGMENT 0x10
10
#define GDT_PRESENT 0x80
11
12
#define GDT_GRANULARITY_BYTE 0x40
13
#define GDT_GRANULARITY_PAGE 0xC0
14
15
#define GDT_SEGMENT_NULL 0x00
16
17
#define GDT_SEGMENT_KCODE 0x10
18
#define GDT_SEGMENT_KDATA 0x20
19
#define GDT_SEGMENT_USERCODE 0x30
20
#define GDT_SEGMENT_USERDATA 0x40
21
#define GDT_SEGMENT_TSS 0x50
22
23
#define GDT_ENTRY_COUNT 6
24
25
typedef
struct
26
{
27
u32
limit_low
: 16;
//
28
u32
base_low
: 24;
//
29
u32
accessed
: 1;
//
30
u32
read_write
: 1;
// readable for code, writable for data
31
u32
conforming_expand_down
: 1;
// conforming for code, expand down for data
32
u32
executable
: 1;
// 1 for code, 0 for data
33
u32
code_data_segment
: 1;
// should be 1 for everything but TSS and LDT
34
u32
dpl
: 2;
// privilege level
35
u32
present
: 1;
//
36
u32
limit_high
: 4;
//
37
u32
available
: 1;
// only used in software; has no effect on hardware
38
u32
long_mode_code
: 1;
// long-mode code segment
39
u32
pm32_segment
: 1;
// 32-bit opcodes for code, uint32_t stack for data
40
u32
granularity
: 1;
// 1 to use 4k page addressing, 0 for byte addressing
41
u32
base_high
: 8;
42
u32
base_veryhigh
;
// upper 32 bits of base address
43
u32
reserved
;
44
}
__packed
gdt_entry_t
;
45
46
MOS_STATIC_ASSERT
(
sizeof
(
gdt_entry_t
) == 16,
"gdt_entry_t is not 16 bytes"
);
47
48
typedef
struct
49
{
50
u16
limit
;
51
gdt_entry_t
*
base
;
52
}
__packed
gdt_ptr_t
;
53
54
MOS_STATIC_ASSERT
(
sizeof
(
gdt_ptr_t
) == 2 +
sizeof
(
void
*),
"gdt_ptr_t is not 6 bytes"
);
55
56
typedef
struct
57
{
58
u32
__reserved1
;
59
u64
rspN
[3];
60
u64
__reserved2
;
61
u64
IntrStackTable
[7];
62
u64
__reserved3
;
63
u16
__reserved4
;
64
u16
iomap
;
65
}
__packed
tss64_t
;
66
67
MOS_STATIC_ASSERT
(
sizeof
(
tss64_t
) == 0x68,
"tss64_t is not 0x68 bytes"
);
68
69
typedef
struct
70
{
71
tss64_t
tss
__aligned
(32);
72
gdt_entry_t
gdt[
GDT_ENTRY_COUNT
]
__aligned
(32);
73
gdt_ptr_t
gdt_ptr
__aligned
(32);
74
}
__packed
x86_cpu_descriptor_t
;
75
76
extern
PER_CPU_DECLARE
(
x86_cpu_descriptor_t
, x86_cpu_descriptor);
77
78
typedef
struct
79
{
80
u16
isr_low
;
// The lower 16 bits of the ISR's address
81
u16
segment
;
// The GDT segment selector that the CPU will load into CS before calling the ISR
82
u32
reserved
: 8;
83
u32
type
: 4;
// The type of interrupt
84
u32
zero
: 1;
85
u32
dpl
: 2;
86
u32
present
: 1;
87
u32
isr_high
: 16;
// The upper 16 bits of the ISR's address
88
u32
isr_veryhigh
;
// The upper 32 bits of the ISR's address
89
u32
reserved2
;
90
}
__packed
idt_entry_t
;
91
92
typedef
struct
93
{
94
u16
limit
;
95
idt_entry_t
*
base
;
96
}
__packed
idtr_t
;
97
98
MOS_STATIC_ASSERT
(
sizeof
(
idt_entry_t
) == 16,
"idt_entry_t is not 16 bytes"
);
99
100
MOS_STATIC_ASSERT
(
sizeof
(
idtr_t
) == 2 +
sizeof
(
void
*),
"idtr32_t is not 6 bytes"
);
101
102
void
x86_init_percpu_gdt
(
void
);
103
void
x86_init_percpu_tss
(
void
);
104
void
x86_init_percpu_idt
(
void
);
105
106
void
x86_idt_init
(
void
);
107
108
// The following 5 symbols are defined in the descriptor_flush.asm file.
109
extern
"C"
void
gdt_flush
(
gdt_ptr_t
*gdt_ptr);
110
extern
"C"
void
tss_flush
(
u32
tss_selector);
111
extern
"C"
void
gdt_flush_only
(
gdt_ptr_t
*gdt_ptr);
x86_init_percpu_idt
void x86_init_percpu_idt(void)
Definition
idt.cpp:36
x86_idt_init
void x86_idt_init(void)
Definition
idt.cpp:41
GDT_ENTRY_COUNT
#define GDT_ENTRY_COUNT
Definition
descriptors.hpp:23
gdt_flush
void gdt_flush(gdt_ptr_t *gdt_ptr)
gdt_flush_only
void gdt_flush_only(gdt_ptr_t *gdt_ptr)
x86_init_percpu_tss
void x86_init_percpu_tss(void)
Definition
descriptors.cpp:86
tss_flush
void tss_flush(u32 tss_selector)
x86_init_percpu_gdt
void x86_init_percpu_gdt(void)
Definition
descriptors.cpp:59
__packed
#define __packed
Definition
mos_global.h:29
MOS_STATIC_ASSERT
#define MOS_STATIC_ASSERT
Definition
mos_global.h:14
platform.hpp
PER_CPU_DECLARE
#define PER_CPU_DECLARE(type, name)
Definition
platform.hpp:26
gdt_entry_t
Definition
descriptors.hpp:26
gdt_entry_t::long_mode_code
u32 long_mode_code
Definition
descriptors.hpp:38
gdt_entry_t::limit_high
u32 limit_high
Definition
descriptors.hpp:36
gdt_entry_t::base_veryhigh
u32 base_veryhigh
Definition
descriptors.hpp:42
gdt_entry_t::code_data_segment
u32 code_data_segment
Definition
descriptors.hpp:33
gdt_entry_t::pm32_segment
u32 pm32_segment
Definition
descriptors.hpp:39
gdt_entry_t::dpl
u32 dpl
Definition
descriptors.hpp:34
gdt_entry_t::accessed
u32 accessed
Definition
descriptors.hpp:29
gdt_entry_t::executable
u32 executable
Definition
descriptors.hpp:32
gdt_entry_t::available
u32 available
Definition
descriptors.hpp:37
gdt_entry_t::base_low
u32 base_low
Definition
descriptors.hpp:28
gdt_entry_t::conforming_expand_down
u32 conforming_expand_down
Definition
descriptors.hpp:31
gdt_entry_t::read_write
u32 read_write
Definition
descriptors.hpp:30
gdt_entry_t::base_high
u32 base_high
Definition
descriptors.hpp:41
gdt_entry_t::reserved
u32 reserved
Definition
descriptors.hpp:43
gdt_entry_t::present
u32 present
Definition
descriptors.hpp:35
gdt_entry_t::limit_low
u32 limit_low
Definition
descriptors.hpp:27
gdt_entry_t::granularity
u32 granularity
Definition
descriptors.hpp:40
gdt_ptr_t
Definition
descriptors.hpp:49
gdt_ptr_t::limit
u16 limit
Definition
descriptors.hpp:50
gdt_ptr_t::base
gdt_entry_t * base
Definition
descriptors.hpp:51
idt_entry_t
Definition
descriptors.hpp:79
idt_entry_t::zero
u32 zero
Definition
descriptors.hpp:84
idt_entry_t::segment
u16 segment
Definition
descriptors.hpp:81
idt_entry_t::isr_veryhigh
u32 isr_veryhigh
Definition
descriptors.hpp:88
idt_entry_t::reserved2
u32 reserved2
Definition
descriptors.hpp:89
idt_entry_t::isr_low
u16 isr_low
Definition
descriptors.hpp:80
idt_entry_t::dpl
u32 dpl
Definition
descriptors.hpp:85
idt_entry_t::isr_high
u32 isr_high
Definition
descriptors.hpp:87
idt_entry_t::reserved
u32 reserved
Definition
descriptors.hpp:82
idt_entry_t::present
u32 present
Definition
descriptors.hpp:86
idt_entry_t::type
u32 type
Definition
descriptors.hpp:83
idtr_t
Definition
descriptors.hpp:93
idtr_t::limit
u16 limit
Definition
descriptors.hpp:94
idtr_t::base
idt_entry_t * base
Definition
descriptors.hpp:95
tss64_t
Definition
descriptors.hpp:57
tss64_t::__reserved2
u64 __reserved2
Definition
descriptors.hpp:60
tss64_t::IntrStackTable
u64 IntrStackTable[7]
Definition
descriptors.hpp:61
tss64_t::iomap
u16 iomap
Definition
descriptors.hpp:64
tss64_t::__reserved3
u64 __reserved3
Definition
descriptors.hpp:62
tss64_t::rspN
u64 rspN[3]
Definition
descriptors.hpp:59
tss64_t::__reserved4
u16 __reserved4
Definition
descriptors.hpp:63
tss64_t::__reserved1
u32 __reserved1
Definition
descriptors.hpp:58
x86_cpu_descriptor_t
Definition
descriptors.hpp:70
x86_cpu_descriptor_t::__aligned
gdt_entry_t gdt[6] __aligned(32)
x86_cpu_descriptor_t::__aligned
tss64_t tss __aligned(32)
x86_cpu_descriptor_t::__aligned
gdt_ptr_t gdt_ptr __aligned(32)
u32
unsigned int u32
Definition
types.h:17
u16
unsigned short u16
Definition
types.h:16
u64
unsigned long long u64
Definition
types.h:19
types.hpp
kernel
arch
x86_64
include
private
mos
x86
descriptors
descriptors.hpp
Generated on
for MOS Source Code by
1.14.0