Pip
Architecture-dependent parts of Pip: MAL, IAL and boot
Data Structures | Macros | Typedefs | Functions | Variables
gdt.h File Reference

Include file for GDT configuration. More...

#include <stdint.h>
#include "maldefines.h"

Go to the source code of this file.

Data Structures

struct  segment_descriptor_s
 Meant to be written inside the GDT. Provides the processor with the size and location of a segment, as well as access control and status information. More...
 
struct  callgate_descriptor_s
 A callgate descriptor for the GDT/LDT Intel 64 and IA-32 Architectures Software Developer's Manual - Vol. 3a - Sec. 5.8.3 and Fig. 5.8. More...
 
struct  tss_descriptor_s
 
union  gdt_entry
 
struct  gdt_ptr
 Pointer to the GDT. More...
 
struct  tss_s
 Task State Segment structure . More...
 

Macros

#define GRANULARITY_1   0
 
#define GRANULARITY_4096   1
 
#define SEG_DATA_READONLY_EXPANDUP_TYPE   0b0000
 
#define SEG_DATA_READWRITE_EXPANDUP_TYPE   0b0010
 
#define SEG_DATA_READONLY_EXPANDDOWN_TYPE   0b0100
 
#define SEG_DATA_READWRITE_EXPANDDOWN_TYPE   0b0110
 
#define SEG_CODE_EXECONLY_NONCONFORMING_TYPE   0b1000
 
#define SEG_CODE_EXECREAD_NONCONFORMING_TYPE   0b1010
 
#define SEG_CODE_EXECONLY_CONFORMING_TYPE   0b1100
 
#define SEG_CODE_EXECREAD_CONFORMING_TYPE   0b1110
 
#define GDT_CALLGATE_TYPE   0b1100
 
#define GDT_TSS_INACTIVE_TYPE   0b1001
 
#define GDT_TSS_BUSY_TYPE   0b1011
 

Typedefs

typedef struct segment_descriptor_s segment_descriptor_t
 
typedef struct callgate_descriptor_s callgate_descriptor_t
 
typedef struct tss_descriptor_s tss_descriptor_t
 
typedef union gdt_entry gdt_entry_t
 
typedef struct tss_s tss_t
 

Functions

struct gdt_ptr __attribute__ ((packed))
 
void gdt_init ()
 Installs the GDT into the CPU. More...
 
void setKernelStack (uint32_t stack)
 Updates the kernel stack address into the TSS. More...
 

Variables

unsigned short limit
 Address limit. More...
 
unsigned int base
 Base address. More...
 
unsigned prev_tss
 Pointer to the previous TSS entry (updated on a task switch) More...
 
unsigned reserved0
 
unsigned esp0
 Kernel-mode ESP (static) More...
 
unsigned ss0
 Kernel-mode stack segment (static) More...
 
unsigned reserved1
 
unsigned esp1
 Ring-1 ESP (static) More...
 
unsigned ss1
 Ring-1 stack segment (static) More...
 
unsigned reserved2
 
unsigned esp2
 Ring-2 ESP (static) More...
 
unsigned ss2
 Ring-2 stack segment (static) More...
 
unsigned reserved3
 
unsigned cr3
 Page directory address (static) More...
 
unsigned eip
 Execution pointer (prior to task switch) More...
 
unsigned eflags
 CPU flags (prior to task switch) More...
 
unsigned eax
 General register EAX (prior to task switch) More...
 
unsigned ecx
 General register ECX (prior to task switch) More...
 
unsigned edx
 General register EDX (prior to task switch) More...
 
unsigned ebx
 General register EBX (prior to task switch) More...
 
unsigned esp
 User-mode ESP (prior to task switch) More...
 
unsigned ebp
 User-mode EBP (prior to task switch) More...
 
unsigned esi
 General register ESI (prior to task switch) More...
 
unsigned edi
 General register EDI (prior to task switch) More...
 
unsigned es
 Segment selector ES (prior to task switch) More...
 
unsigned reserved4
 
unsigned cs
 Segment selector CS (prior to task switch) More...
 
unsigned reserved5
 
unsigned ss
 Segment selector SS (prior to task switch) More...
 
unsigned reserved6
 
unsigned ds
 Segment selector DS (prior to task switch) More...
 
unsigned reserved7
 
unsigned fs
 Segment selector FS (prior to task switch) More...
 
unsigned reserved8
 
unsigned gs
 Segment selector GS (prior to task switch) More...
 
unsigned reserved9
 
unsigned ldt
 Pointer to the LDT (static) More...
 
unsigned reserved10
 
unsigned trap
 Flag to raise an exception when a task switch to this task occurs (static) More...
 
unsigned reserved11
 
unsigned iomap_base
 IOMMU base. More...
 
tss_t tss
 Generic TSS for userland-to-kernel switch. More...
 

Detailed Description

Include file for GDT configuration.

Macro Definition Documentation

◆ GDT_CALLGATE_TYPE

#define GDT_CALLGATE_TYPE   0b1100

◆ GDT_TSS_BUSY_TYPE

#define GDT_TSS_BUSY_TYPE   0b1011

◆ GDT_TSS_INACTIVE_TYPE

#define GDT_TSS_INACTIVE_TYPE   0b1001

◆ GRANULARITY_1

#define GRANULARITY_1   0

◆ GRANULARITY_4096

#define GRANULARITY_4096   1

◆ SEG_CODE_EXECONLY_CONFORMING_TYPE

#define SEG_CODE_EXECONLY_CONFORMING_TYPE   0b1100

◆ SEG_CODE_EXECONLY_NONCONFORMING_TYPE

#define SEG_CODE_EXECONLY_NONCONFORMING_TYPE   0b1000

◆ SEG_CODE_EXECREAD_CONFORMING_TYPE

#define SEG_CODE_EXECREAD_CONFORMING_TYPE   0b1110

◆ SEG_CODE_EXECREAD_NONCONFORMING_TYPE

#define SEG_CODE_EXECREAD_NONCONFORMING_TYPE   0b1010

◆ SEG_DATA_READONLY_EXPANDDOWN_TYPE

#define SEG_DATA_READONLY_EXPANDDOWN_TYPE   0b0100

◆ SEG_DATA_READONLY_EXPANDUP_TYPE

#define SEG_DATA_READONLY_EXPANDUP_TYPE   0b0000

All the different types of segments entries Last bit of the type is written every time the segment is accessed, and can be cleared for debug purposes and virtual memory management (according to Intel's doc).

Intel 64 and IA-32 Architectures Software Developer's Manual - Vol. 3a - Sec. 3.5 and Fig. 3-8

◆ SEG_DATA_READWRITE_EXPANDDOWN_TYPE

#define SEG_DATA_READWRITE_EXPANDDOWN_TYPE   0b0110

◆ SEG_DATA_READWRITE_EXPANDUP_TYPE

#define SEG_DATA_READWRITE_EXPANDUP_TYPE   0b0010

Typedef Documentation

◆ callgate_descriptor_t

◆ gdt_entry_t

typedef union gdt_entry gdt_entry_t

◆ segment_descriptor_t

◆ tss_descriptor_t

◆ tss_t

typedef struct tss_s tss_t

Function Documentation

◆ __attribute__()

struct gdt_ptr __attribute__ ( (packed)  )

◆ gdt_init()

void gdt_init ( )

Installs the GDT into the CPU.

Callgate setup (Syscalls)

◆ setKernelStack()

void setKernelStack ( uint32_t  stack)

Updates the kernel stack address into the TSS.

Parameters
stackThe stack address

Variable Documentation

◆ base

unsigned int base

Base address.

◆ cr3

unsigned cr3

Page directory address (static)

◆ cs

unsigned cs

Segment selector CS (prior to task switch)

◆ ds

unsigned ds

Segment selector DS (prior to task switch)

◆ eax

unsigned eax

General register EAX (prior to task switch)

◆ ebp

unsigned ebp

User-mode EBP (prior to task switch)

◆ ebx

unsigned ebx

General register EBX (prior to task switch)

◆ ecx

unsigned ecx

General register ECX (prior to task switch)

◆ edi

unsigned edi

General register EDI (prior to task switch)

◆ edx

unsigned edx

General register EDX (prior to task switch)

◆ eflags

unsigned eflags

CPU flags (prior to task switch)

◆ eip

unsigned eip

Execution pointer (prior to task switch)

◆ es

unsigned es

Segment selector ES (prior to task switch)

◆ esi

unsigned esi

General register ESI (prior to task switch)

◆ esp

unsigned esp

User-mode ESP (prior to task switch)

◆ esp0

unsigned esp0

Kernel-mode ESP (static)

◆ esp1

unsigned esp1

Ring-1 ESP (static)

◆ esp2

unsigned esp2

Ring-2 ESP (static)

◆ fs

unsigned fs

Segment selector FS (prior to task switch)

◆ gs

unsigned gs

Segment selector GS (prior to task switch)

◆ iomap_base

unsigned iomap_base

IOMMU base.

◆ ldt

unsigned ldt

Pointer to the LDT (static)

◆ limit

unsigned short limit

Address limit.

◆ prev_tss

unsigned prev_tss

Pointer to the previous TSS entry (updated on a task switch)

◆ reserved0

unsigned reserved0

◆ reserved1

unsigned reserved1

◆ reserved10

unsigned reserved10

◆ reserved11

unsigned reserved11

◆ reserved2

unsigned reserved2

◆ reserved3

unsigned reserved3

◆ reserved4

unsigned reserved4

◆ reserved5

unsigned reserved5

◆ reserved6

unsigned reserved6

◆ reserved7

unsigned reserved7

◆ reserved8

unsigned reserved8

◆ reserved9

unsigned reserved9

◆ ss

unsigned ss

Segment selector SS (prior to task switch)

◆ ss0

unsigned ss0

Kernel-mode stack segment (static)

◆ ss1

unsigned ss1

Ring-1 stack segment (static)

◆ ss2

unsigned ss2

Ring-2 stack segment (static)

◆ trap

unsigned trap

Flag to raise an exception when a task switch to this task occurs (static)

◆ tss

tss_t tss

Generic TSS for userland-to-kernel switch.