POK(kernelpart)
gdt.c File Reference
#include <libc.h>
#include <types.h>
#include <errno.h>
#include "gdt.h"
#include "sysdesc.h"
#include "tss.h"

Go to the source code of this file.

Macros

#define POK_CONFIG_NB_THREADS   0
#define POK_CONFIG_NB_PARTITIONS   0
#define GDT_SIZE   256

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)

Variables

gdt_entry_t pok_gdt [GDT_SIZE]
tss_t pok_tss

Macro Definition Documentation

#define GDT_SIZE   256

Definition at line 35 of file gdt.c.

#define POK_CONFIG_NB_PARTITIONS   0

Definition at line 32 of file gdt.c.

#define POK_CONFIG_NB_THREADS   0

Definition at line 28 of file gdt.c.


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;
}

Variable Documentation

gdt_entry_t pok_gdt[GDT_SIZE]

Definition at line 37 of file gdt.c.

tss_t pok_tss

Definition at line 39 of file gdt.c.