IBNOS
Classes | Macros | Functions | Variables
Global / Interrupt Descriptor Table

Classes

struct  GDTTable
 
struct  GDTEntry
 
struct  IDTTable
 
struct  IDTEntry
 

Macros

#define INTJMP_ENTRY_SIZE   8
 
#define INTJMP_ENTRY_MASK   7
 
#define INTJMP_ENTRY_BITS   3
 
#define KERNEL_IDLE_BEGIN   ((uint32_t)&__kernelIdleBegin)
 
#define KERNEL_IDLE_END   ((uint32_t)&__kernelIdleEnd)
 
#define KERNELSTACK_SIZE   PAGE_SIZE
 

Functions

void __attribute__ ((cdecl))
 
void gdtInit ()
 Initializes the GDT, task registers, and sets up everything required for multiprocessing. More...
 
struct GDTEntrygdtGetFreeEntry ()
 Get a free entry in the GDT. More...
 
uint32_t gdtGetEntryOffset (struct GDTEntry *entry, uint32_t ring)
 Determines the offset of a GDT entry. More...
 
void gdtEntrySetAddress (struct GDTEntry *entry, uint32_t address)
 Helper function to set the address inside a GDTEntry. More...
 
void gdtEntrySetLimit (struct GDTEntry *entry, uint64_t length)
 Helper function to set the length inside a GDTEntry. More...
 
void gdtReleaseEntry (struct GDTEntry *entry)
 Mark a GDTEntry as free. More...
 
uint32_t tssRunUsermodeThread (struct thread *t)
 Run a thread. More...
 
struct GDTTable __attribute__ ((packed))
 

Variables

void * kernelStack
 
void * intJmpTable_kernel
 
void * intJmpTable_user
 
struct GDTEntrycodeRing0
 
struct GDTEntrydataRing0
 
struct GDTEntrycodeRing3
 
struct GDTEntrydataRing3
 
struct GDTEntrykernelTask
 
struct GDTEntryusermodeTask
 
uint32_t __kernelIdleBegin
 
uint32_t __kernelIdleEnd
 

GDT Privileges

#define GDT_CPL_MASK   3
 
#define GDT_CPL_RING0   0
 
#define GDT_CPL_RING3   3
 

Interrupt types

For more information take a look at http://wiki.osdev.org/Interrupt_Descriptor_Table

#define INT_TYPE_TASK32   0x5
 
#define INT_TYPE_INT16   0x6
 
#define INT_TYPE_TRAP16   0x7
 
#define INT_TYPE_INT32   0xE
 
#define INT_TYPE_TRAP32   0xF
 

GDT Size

#define GDT_MAX_SIZE   0x10000
 
#define GDT_MAX_PAGES   ((GDT_MAX_SIZE + PAGE_MASK) >> PAGE_BITS)
 
#define GDT_MAX_COUNT   (GDT_MAX_SIZE / sizeof(struct GDTEntry))
 

IDT Size

#define IDT_MAX_SIZE   PAGE_SIZE
 
#define IDT_MAX_COUNT   256
 

Detailed Description

Macro Definition Documentation

◆ GDT_CPL_MASK

#define GDT_CPL_MASK   3

Number of bits needed to store the privelege level

Definition at line 45 of file gdt.h.

◆ GDT_CPL_RING0

#define GDT_CPL_RING0   0

Ring 0

Definition at line 46 of file gdt.h.

◆ GDT_CPL_RING3

#define GDT_CPL_RING3   3

Ring 3

Definition at line 47 of file gdt.h.

◆ GDT_MAX_COUNT

#define GDT_MAX_COUNT   (GDT_MAX_SIZE / sizeof(struct GDTEntry))

Maximum number of entries in the GDT

Definition at line 76 of file gdt.h.

◆ GDT_MAX_PAGES

#define GDT_MAX_PAGES   ((GDT_MAX_SIZE + PAGE_MASK) >> PAGE_BITS)

Number of pages occupied by the GDT

Definition at line 74 of file gdt.h.

◆ GDT_MAX_SIZE

#define GDT_MAX_SIZE   0x10000

Size of the Global Descriptor Table

Definition at line 72 of file gdt.h.

◆ IDT_MAX_COUNT

#define IDT_MAX_COUNT   256

Number of entries in the IDT

Definition at line 86 of file gdt.h.

◆ IDT_MAX_SIZE

#define IDT_MAX_SIZE   PAGE_SIZE

Size of the Interrupt Descriptor Table

Definition at line 84 of file gdt.h.

◆ INT_TYPE_INT16

#define INT_TYPE_INT16   0x6

Identifies a 16 bit Interrupt Task

Definition at line 56 of file gdt.h.

◆ INT_TYPE_INT32

#define INT_TYPE_INT32   0xE

Identifies a 32 bit standard Interrupt

Definition at line 58 of file gdt.h.

◆ INT_TYPE_TASK32

#define INT_TYPE_TASK32   0x5

Identifies a 32 bit Interrupt Task

Definition at line 55 of file gdt.h.

◆ INT_TYPE_TRAP16

#define INT_TYPE_TRAP16   0x7

Identifies a 16 bit Interrupt Trap

Definition at line 57 of file gdt.h.

◆ INT_TYPE_TRAP32

#define INT_TYPE_TRAP32   0xF

Identifies a 32 bit Interrupt Trap

Definition at line 59 of file gdt.h.

◆ INTJMP_ENTRY_BITS

#define INTJMP_ENTRY_BITS   3

Definition at line 74 of file gdt.c.

◆ INTJMP_ENTRY_MASK

#define INTJMP_ENTRY_MASK   7

Definition at line 73 of file gdt.c.

◆ INTJMP_ENTRY_SIZE

#define INTJMP_ENTRY_SIZE   8

Definition at line 72 of file gdt.c.

◆ KERNEL_IDLE_BEGIN

#define KERNEL_IDLE_BEGIN   ((uint32_t)&__kernelIdleBegin)

Definition at line 79 of file gdt.c.

◆ KERNEL_IDLE_END

#define KERNEL_IDLE_END   ((uint32_t)&__kernelIdleEnd)

Definition at line 80 of file gdt.c.

◆ KERNELSTACK_SIZE

#define KERNELSTACK_SIZE   PAGE_SIZE

Size of the ring0 kernel stack which is mapped into each process

Definition at line 65 of file gdt.h.

Function Documentation

◆ __attribute__() [1/2]

void __attribute__ ( (cdecl)  )

Definition at line 103 of file gdt.c.

◆ __attribute__() [2/2]

struct GDTTable __attribute__ ( (packed)  )

◆ gdtEntrySetAddress()

void gdtEntrySetAddress ( struct GDTEntry entry,
uint32_t  address 
)

Helper function to set the address inside a GDTEntry.

The address value is split across 3 attributes inside the GDTEntry structure (GDTEntry::address1, GDTEntry::address2, GDTEntry::address3). This functions should make it easier to set this value.

Parameters
[in]entryThe entry which should be altered
[in]addressThe address which should be set

Definition at line 557 of file gdt.c.

◆ gdtEntrySetLimit()

void gdtEntrySetLimit ( struct GDTEntry entry,
uint64_t  length 
)

Helper function to set the length inside a GDTEntry.

The length value or to be more precise the limit (length - 1) is split across 2 attributes inside the GDTEntry structure (GDTEntry::limit1, GDTEntry::limit2). All these fields can only save a value with a maximum of 20 bits. To store a length with a higher value (for example for a segment covering the whole address space), the value can be stored as pages. The function will automatically set the GDTEntry::granularity bit to identify the limit as page count.

Warning
If the length exceeds 1 megabyte, it must be a multiple of of the page size or an assertion will be hit.
Parameters
[in]entryThe entry which should be altered
[in]lengthThe length which should be set

Definition at line 582 of file gdt.c.

◆ gdtGetEntryOffset()

uint32_t gdtGetEntryOffset ( struct GDTEntry entry,
uint32_t  ring 
)

Determines the offset of a GDT entry.

This functions calculates the offset of an entry relative to the base address of the GDT. This CPU always uses offsets to identify an entry, so that the absolute address of an entry is only useful for changing it. These offsets are for example required to specify a segment as value in a segment register (CS, DS, SS, ...) or an task inside the task register. The CPU also stores the needed privilege level (ring) inside such a register. To simplify your work, this function will embed the ring passed as parameter.

Parameters
[in]entryThe entry for which you want to get the offset
[in]ringThe ring which is required to access the segment
Returns
Offset of the entry + the ring level

Definition at line 537 of file gdt.c.

◆ gdtGetFreeEntry()

struct GDTEntry * gdtGetFreeEntry ( )

Get a free entry in the GDT.

Returns
Pointer to the free GDT entry

Definition at line 503 of file gdt.c.

◆ gdtInit()

void gdtInit ( )

Initializes the GDT, task registers, and sets up everything required for multiprocessing.

Definition at line 432 of file gdt.c.

◆ gdtReleaseEntry()

void gdtReleaseEntry ( struct GDTEntry entry)

Mark a GDTEntry as free.

This function is used to mark a GDT entry to be used for other purposes. You are not allowed to access the entry any more after releasing it.

Parameters
[in]entryThe entry to release

Definition at line 612 of file gdt.c.

◆ tssRunUsermodeThread()

uint32_t tssRunUsermodeThread ( struct thread t)

Run a thread.

This function loads the saved thread context inside a hardware task and starts it.

Parameters
[in]tA pointer to a thread structure containing the tss context
Returns
Reason why the execution was interrupted, usually one of the Interrupt return values

Definition at line 628 of file gdt.c.

Variable Documentation

◆ __kernelIdleBegin

uint32_t __kernelIdleBegin

◆ __kernelIdleEnd

uint32_t __kernelIdleEnd

◆ codeRing0

struct GDTEntry* codeRing0

Definition at line 63 of file gdt.c.

◆ codeRing3

struct GDTEntry* codeRing3

Definition at line 65 of file gdt.c.

◆ dataRing0

struct GDTEntry* dataRing0

Definition at line 64 of file gdt.c.

◆ dataRing3

struct GDTEntry* dataRing3

Definition at line 66 of file gdt.c.

◆ intJmpTable_kernel

void* intJmpTable_kernel

Definition at line 53 of file gdt.c.

◆ intJmpTable_user

void* intJmpTable_user

Definition at line 54 of file gdt.c.

◆ kernelStack

void* kernelStack

Definition at line 42 of file gdt.c.

◆ kernelTask

struct GDTEntry* kernelTask

Definition at line 69 of file gdt.c.

◆ usermodeTask

struct GDTEntry* usermodeTask

Definition at line 70 of file gdt.c.