Turnstone Operating System
Loading...
Searching...
No Matches
descriptor.h File Reference

cpu segment descriptors for long mode. More...

#include <types.h>

Classes

struct  descriptor_gdt_null
 null segment descriptor for gdt More...
 
struct  descriptor_gdt_code
 code segment descriptor for gdt More...
 
struct  descriptor_gdt_data
 data segment descriptor for gdt More...
 
struct  descriptor_gdt
 general segment descriptor for gdt More...
 
struct  descriptor_idt
 idt table descriptor More...
 
struct  descriptor_register
 common register value for gdtr, idtr, ldtr, tr More...
 

Macros

#define ___CPU_DESCRIPTOR_H   0
 
#define DPL_RING0   0
 
#define DPL_RING1   1
 
#define DPL_RING2   2
 
#define DPL_RING3   3
 
#define DPL_KERNEL   DPL_RING0
 
#define DPL_USER   DPL_RING3
 
#define KERNEL_CODE_SEG   0x08
 
#define KERNEL_DATA_SEG   0x10
 
#define KERNEL_TSS_SEG   0x18
 
#define DESCRIPTOR_BUILD_GDT_NULL_SEG(seg)   {seg.null.unused1 = 0; seg.null.unused2 = 0;}
 null segment builder macro More...
 
#define DESCRIPTOR_BUILD_GDT_CODE_SEG(seg, DPL)
 code segment builder macro with privilage level More...
 
#define DESCRIPTOR_BUILD_GDT_DATA_SEG(seg, DPL)
 data segment builder macro More...
 
#define IDT_BASE_ADDRESS   (1 << 20)
 
#define SYSTEM_SEGMENT_TYPE_IDT   0x02
 
#define SYSTEM_SEGMENT_TYPE_TSS_A   0x09
 
#define SYSTEM_SEGMENT_TYPE_TSS_B   0x0B
 
#define SYSTEM_SEGMENT_TYPE_GATE_CALL   0x0C
 
#define SYSTEM_SEGMENT_TYPE_GATE_INT   0x0E
 
#define SYSTEM_SEGMENT_TYPE_GATE_TRAP   0x0F
 
#define DESCRIPTOR_BUILD_IDT_SEG(IE, FUNC_ADDR, SELECTOR, IST, DPL)
 assign a function to interrupt nomber More...
 

Typedefs

typedef struct descriptor_gdt_null descriptor_gdt_null_t
 struct short hand
 
typedef struct descriptor_gdt_code descriptor_gdt_code_t
 struct short hand
 
typedef struct descriptor_gdt_data descriptor_gdt_data_t
 struct short hand
 
typedef struct descriptor_gdt descriptor_gdt_t
 struct short hand
 
typedef struct descriptor_idt descriptor_idt_t
 struct short hand
 
typedef struct descriptor_register descriptor_register_t
 struct short hand
 

Functions

 _Static_assert (sizeof(descriptor_idt_t)==16, "descriptor_idt_t size must be 16")
 
uint8_t descriptor_build_gdt_register (void)
 builds a default gdt More...
 
uint8_t descriptor_build_idt_register (void)
 builds a default idt More...
 
uint8_t descriptor_build_ap_descriptors_register (void)
 builds gdt and tss for application processor More...
 

Variables

descriptor_register_tGDT_REGISTER
 static address of gdt for lgdtr/sgdtr
 
descriptor_register_tIDT_REGISTER
 static address of idt for lidtr/sidtr
 

Detailed Description

cpu segment descriptors for long mode.

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Macro Definition Documentation

◆ ___CPU_DESCRIPTOR_H

#define ___CPU_DESCRIPTOR_H   0

prevent duplicate header error macro

◆ DESCRIPTOR_BUILD_GDT_CODE_SEG

#define DESCRIPTOR_BUILD_GDT_CODE_SEG (   seg,
  DPL 
)
Value:
{seg.code.unused1 = 0; \
seg.code.unused2 = 0; \
seg.code.unused3 = 0; \
seg.code.readable = 1; \
seg.code.conforming = 0; \
seg.code.always1 = 3; \
seg.code.dpl = DPL; \
seg.code.present = 1; \
seg.code.unused4 = 0; \
seg.code.avl = 0; \
seg.code.long_mode = 1; \
seg.code.default_opsize = 0; \
seg.code.unused5 = 0; \
seg.code.unused6 = 0;}

code segment builder macro with privilage level

Parameters
segsegment to build as code
DPLprivilage level to build as code

◆ DESCRIPTOR_BUILD_GDT_DATA_SEG

#define DESCRIPTOR_BUILD_GDT_DATA_SEG (   seg,
  DPL 
)
Value:
{seg.data.unused1 = 0; \
seg.data.unused2 = 0; \
seg.data.unused3 = 0; \
seg.data.rw = 1; \
seg.data.unused4 = 0; \
seg.data.always0 = 0; \
seg.data.always1 = 1; \
seg.data.dpl = DPL; \
seg.data.present = 1; \
seg.data.unused5 = 0; \
seg.data.long_mode = 1; \
seg.data.unused6 = 0;}

data segment builder macro

Parameters
segsegment to build as data

◆ DESCRIPTOR_BUILD_GDT_NULL_SEG

#define DESCRIPTOR_BUILD_GDT_NULL_SEG (   seg)    {seg.null.unused1 = 0; seg.null.unused2 = 0;}

null segment builder macro

Parameters
segsegment to build as null

◆ DESCRIPTOR_BUILD_IDT_SEG

#define DESCRIPTOR_BUILD_IDT_SEG (   IE,
  FUNC_ADDR,
  SELECTOR,
  IST,
  DPL 
)
Value:
{ \
IE.selector = SELECTOR; \
IE.ist = IST; \
IE.always0_1 = 0; \
IE.type = 0xE; \
IE.always0_2 = 0; \
IE.dpl = DPL; \
IE.present = 1; \
IE.zero = 0; \
IE.offset_1 = (FUNC_ADDR >> 0) & 0xFFFF; \
IE.offset_2 = (FUNC_ADDR >> 16) & 0xFFFF; \
IE.offset_3 = (FUNC_ADDR >> 32) & 0xFFFFFFFF; \
}

assign a function to interrupt nomber

Parameters
[in]IEinterrupt vector
[in]FUNC_ADDRinterrupt vector's function address
[in]SELECTORgdt code selector for interrupt vector
[in]ISTist number for vector, if ist is zero not ist mechanism, else use ist at tss
[in]DPLprivilage level of interrupt

◆ DPL_KERNEL

#define DPL_KERNEL   DPL_RING0

a short hand for ring0 aka kernel space

◆ DPL_RING0

#define DPL_RING0   0

cpu privilage level 0 for kernel space

◆ DPL_RING1

#define DPL_RING1   1

cpu privilage level 1 for kernel additional space

◆ DPL_RING2

#define DPL_RING2   2

cpu privilage level 2 for kernel additional space

◆ DPL_RING3

#define DPL_RING3   3

cpu privilage level 3 for user space

◆ DPL_USER

#define DPL_USER   DPL_RING3

a short hand for ring3 aka user space

◆ KERNEL_CODE_SEG

#define KERNEL_CODE_SEG   0x08

hard coded gdt code segment value

◆ KERNEL_DATA_SEG

#define KERNEL_DATA_SEG   0x10

hard coded gdt data segment value

◆ KERNEL_TSS_SEG

#define KERNEL_TSS_SEG   0x18

hard coded gdt tss segment value

◆ SYSTEM_SEGMENT_TYPE_GATE_CALL

#define SYSTEM_SEGMENT_TYPE_GATE_CALL   0x0C

Call Gate segment type

◆ SYSTEM_SEGMENT_TYPE_GATE_INT

#define SYSTEM_SEGMENT_TYPE_GATE_INT   0x0E

Interrupt Gate segment type

◆ SYSTEM_SEGMENT_TYPE_GATE_TRAP

#define SYSTEM_SEGMENT_TYPE_GATE_TRAP   0x0F

Trap Gate segment type

◆ SYSTEM_SEGMENT_TYPE_IDT

#define SYSTEM_SEGMENT_TYPE_IDT   0x02

IDT segment type

◆ SYSTEM_SEGMENT_TYPE_TSS_A

#define SYSTEM_SEGMENT_TYPE_TSS_A   0x09

Active TSS segment type

◆ SYSTEM_SEGMENT_TYPE_TSS_B

#define SYSTEM_SEGMENT_TYPE_TSS_B   0x0B

Busy TSS segment type

Function Documentation

◆ descriptor_build_ap_descriptors_register()

uint8_t descriptor_build_ap_descriptors_register ( void  )

builds gdt and tss for application processor

Returns
0 at success.

◆ descriptor_build_gdt_register()

uint8_t descriptor_build_gdt_register ( void  )

builds a default gdt

Returns
0 at success.

◆ descriptor_build_idt_register()

uint8_t descriptor_build_idt_register ( void  )

builds a default idt

Returns
0 at success.