POK(kernelpart)
gdt.h File Reference
#include <types.h>

Go to the source code of this file.

Data Structures

struct  __attribute__

Macros

#define GDT_CORE_CODE_SEGMENT   1
#define GDT_CORE_DATA_SEGMENT   2
#define GDT_TSS_SEGMENT   3
#define GDT_PARTITION_CODE_SEGMENT(partition_id)   (4 + 2 * partition_id)
#define GDT_PARTITION_DATA_SEGMENT(partition_id)   (4 + 2 * partition_id + 1)
#define GDT_BUILD_SELECTOR(seg, local, rpl)   ((seg << 3) | ((local & 0x1) << 2) | (rpl & 0x3))

Typedefs

typedef enum e_gdte_type e_gdte_type

Enumerations

enum  e_gdte_type { GDTE_CODE = 0xB, GDTE_DATA = 0x3, GDTE_TSS = 0x9 }

Functions

pok_ret_t pok_gdt_init ()
int pok_tss_init ()
void tss_set_esp0 (uint32_t esp0)
void gdt_set_segment (uint16_t index, uint32_t base_address, uint32_t limit, e_gdte_type t, int dpl)
void gdt_set_system (uint16_t index, uint32_t base_address, uint32_t limit, e_gdte_type t, int dpl)
void gdt_enable (uint16_t index)
void gdt_disable (uint16_t index)

Macro Definition Documentation

#define GDT_BUILD_SELECTOR (   seg,
  local,
  rpl 
)    ((seg << 3) | ((local & 0x1) << 2) | (rpl & 0x3))

Definition at line 52 of file gdt.h.

#define GDT_CORE_CODE_SEGMENT   1

Definition at line 45 of file gdt.h.

#define GDT_CORE_DATA_SEGMENT   2

Definition at line 46 of file gdt.h.

#define GDT_PARTITION_CODE_SEGMENT (   partition_id)    (4 + 2 * partition_id)

Definition at line 49 of file gdt.h.

#define GDT_PARTITION_DATA_SEGMENT (   partition_id)    (4 + 2 * partition_id + 1)

Definition at line 50 of file gdt.h.

#define GDT_TSS_SEGMENT   3

Definition at line 47 of file gdt.h.


Typedef Documentation

typedef enum e_gdte_type e_gdte_type

Enumeration Type Documentation

Enumerator:
GDTE_CODE 
GDTE_DATA 
GDTE_TSS 

Definition at line 23 of file gdt.h.

{
GDTE_CODE = 0xB,
GDTE_DATA = 0x3,
GDTE_TSS = 0x9

Function Documentation

void gdt_disable ( uint16_t  index)

Definition at line 155 of file gdt.c.

{
pok_gdt[index].present = 0;
}
void gdt_enable ( uint16_t  index)

Definition at line 150 of file gdt.c.

{
pok_gdt[index].present = 1;
}
void gdt_set_segment ( uint16_t  index,
uint32_t  base_address,
uint32_t  limit,
e_gdte_type  t,
int  dpl 
)

Definition at line 99 of file gdt.c.

{
if (limit > (1 << 20)) /* 4K granularity */
{
pok_gdt[index].limit_low = (limit >> 12) & 0xFFFF;
pok_gdt[index].limit_high = (limit >> 28) & 0xF;
pok_gdt[index].granularity = 1;
}
else /* 1B granularity */
{
pok_gdt[index].limit_low = limit & 0xFFFF;
pok_gdt[index].limit_high = (limit >> 16) & 0xFF;
pok_gdt[index].granularity = 0;
}
pok_gdt[index].base_low = base_address & 0xFFFFFF;
pok_gdt[index].base_high = (base_address >> 24) & 0xFF;
pok_gdt[index].type = t & 0xF;
pok_gdt[index].dpl = dpl & 0x3;
pok_gdt[index].s = 1; /* Segment is data/code type */
pok_gdt[index].present = 1;
pok_gdt[index].available = 0;
pok_gdt[index].op_size = 1; /* We work on 32 bits segments */
}
void gdt_set_system ( uint16_t  index,
uint32_t  base_address,
uint32_t  limit,
e_gdte_type  t,
int  dpl 
)

Definition at line 130 of file gdt.c.

{
pok_gdt[index].limit_low = limit & 0xFFFF;
pok_gdt[index].limit_high = (limit >> 16) & 0xFF;
pok_gdt[index].base_low = base_address & 0xFFFFFF;
pok_gdt[index].base_high = (base_address >> 24) & 0xFF;
pok_gdt[index].type = t & 0xF;
pok_gdt[index].dpl = dpl & 0x3;
pok_gdt[index].s = 0; /* Segment is system type */
pok_gdt[index].present = 1;
pok_gdt[index].available = 0;
pok_gdt[index].op_size = 0;
}
pok_ret_t pok_gdt_init ( )

Definition at line 41 of file gdt.c.

{
sysdesc_t sysdesc;
/* Set null descriptor and clear table */
memset(pok_gdt, 0, sizeof (gdt_entry_t) * GDT_SIZE);
/* Set kernel descriptors */
/* Load GDT */
sysdesc.limit = sizeof (pok_gdt);
sysdesc.base = (uint32_t)pok_gdt;
asm ("lgdt %0"
:
: "m" (sysdesc));
/* Reload Segments */
asm ("ljmp %0, $1f \n"
"1: \n"
"mov %1, %%ax \n"
"mov %%ax, %%ds \n"
"mov %%ax, %%es \n"
"mov %%ax, %%fs \n"
"mov %%ax, %%gs \n"
"mov %%ax, %%ss \n"
:
: "i" (GDT_CORE_CODE_SEGMENT << 3),
: "eax");
return (POK_ERRNO_OK);
}
int pok_tss_init ( )

Definition at line 79 of file gdt.c.

{
memset(&pok_tss, 0, sizeof (tss_t));
sizeof (tss_t), GDTE_TSS, 0);
asm ("ltr %0" : :"m"(sel));
return (POK_ERRNO_OK);
}
void tss_set_esp0 ( uint32_t  esp0)

Definition at line 94 of file gdt.c.

{
pok_tss.esp0 = esp0;
}