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
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
25typedef 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; //
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
42 u32 base_veryhigh; // upper 32 bits of base address
45
46MOS_STATIC_ASSERT(sizeof(gdt_entry_t) == 16, "gdt_entry_t is not 16 bytes");
47
48typedef struct
49{
53
54MOS_STATIC_ASSERT(sizeof(gdt_ptr_t) == 2 + sizeof(void *), "gdt_ptr_t is not 6 bytes");
55
66
67MOS_STATIC_ASSERT(sizeof(tss64_t) == 0x68, "tss64_t is not 0x68 bytes");
68
75
76extern PER_CPU_DECLARE(x86_cpu_descriptor_t, x86_cpu_descriptor);
77
78typedef 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
83 u32 type : 4; // The type of interrupt
84 u32 zero : 1;
85 u32 dpl : 2;
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
91
92typedef struct
93{
97
98MOS_STATIC_ASSERT(sizeof(idt_entry_t) == 16, "idt_entry_t is not 16 bytes");
99
100MOS_STATIC_ASSERT(sizeof(idtr_t) == 2 + sizeof(void *), "idtr32_t is not 6 bytes");
101
102void x86_init_percpu_gdt(void);
103void x86_init_percpu_tss(void);
104void x86_init_percpu_idt(void);
105
106void x86_idt_init(void);
107
108// The following 5 symbols are defined in the descriptor_flush.asm file.
109extern "C" void gdt_flush(gdt_ptr_t *gdt_ptr);
110extern "C" void tss_flush(u32 tss_selector);
111extern "C" void gdt_flush_only(gdt_ptr_t *gdt_ptr);
void x86_init_percpu_idt(void)
Definition idt.cpp:36
void x86_idt_init(void)
Definition idt.cpp:41
#define GDT_ENTRY_COUNT
void gdt_flush(gdt_ptr_t *gdt_ptr)
void gdt_flush_only(gdt_ptr_t *gdt_ptr)
void x86_init_percpu_tss(void)
void tss_flush(u32 tss_selector)
void x86_init_percpu_gdt(void)
#define __packed
Definition mos_global.h:29
#define MOS_STATIC_ASSERT
Definition mos_global.h:14
#define PER_CPU_DECLARE(type, name)
Definition platform.hpp:26
u32 long_mode_code
u32 limit_high
u32 base_veryhigh
u32 code_data_segment
u32 pm32_segment
u32 dpl
u32 accessed
u32 executable
u32 available
u32 base_low
u32 conforming_expand_down
u32 read_write
u32 base_high
u32 reserved
u32 present
u32 limit_low
u32 granularity
gdt_entry_t * base
u32 zero
u16 segment
u32 isr_veryhigh
u32 reserved2
u16 isr_low
u32 dpl
u32 isr_high
u32 reserved
u32 present
u32 type
idt_entry_t * base
u64 __reserved2
u64 IntrStackTable[7]
u64 __reserved3
u64 rspN[3]
u16 __reserved4
u32 __reserved1
gdt_entry_t gdt[6] __aligned(32)
tss64_t tss __aligned(32)
gdt_ptr_t gdt_ptr __aligned(32)
unsigned int u32
Definition types.h:17
unsigned short u16
Definition types.h:16
unsigned long long u64
Definition types.h:19