[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
gdt.c File Reference
#include "userprog/gdt.h"
#include <debug.h>
#include "userprog/tss.h"
#include "threads/mmu.h"
#include "threads/palloc.h"
#include "threads/vaddr.h"
#include "intrinsic.h"
Include dependency graph for gdt.c:

Classes

struct  segment_desc
 
struct  segment_descriptor64
 

Macros

#define SEG64(type, base, lim, dpl)
 

Functions

void gdt_init (void)
 

Variables

static struct segment_desc gdt [SEL_CNT]
 
struct desc_ptr gdt_ds
 

Macro Definition Documentation

◆ SEG64

#define SEG64 (   type,
  base,
  lim,
  dpl 
)
Value:
(struct segment_desc) \
{ ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (unsigned) (lim) >> 28, 0, 1, 0, 1, \
(unsigned) (base) >> 24 }
Definition: gdt.c:24
unsigned dpl
Definition: gdt.c:30
unsigned type
Definition: gdt.c:28

Function Documentation

◆ gdt_init()

void gdt_init ( void  )
83 {
84 /* Initialize GDT. */
85 struct segment_descriptor64 *tss_desc =
86 (struct segment_descriptor64 *) &gdt[SEL_TSS >> 3];
87 struct task_state *tss = tss_get ();
88
89 *tss_desc = (struct segment_descriptor64) {
90 .lim_15_0 = (uint64_t) (sizeof (struct task_state)) & 0xffff,
91 .base_15_0 = (uint64_t) (tss) & 0xffff,
92 .base_23_16 = ((uint64_t) (tss) >> 16) & 0xff,
93 .type = 0x9,
94 .s = 0,
95 .dpl = 0,
96 .p = 1,
97 .lim_19_16 = ((uint64_t)(sizeof (struct task_state)) >> 16) & 0xf,
98 .avl = 0,
99 .rsv1 = 0,
100 .g = 0,
101 .base_31_24 = ((uint64_t)(tss) >> 24) & 0xff,
102 .base_63_32 = ((uint64_t)(tss) >> 32) & 0xffffffff,
103 .res1 = 0,
104 .clear = 0,
105 .res2 = 0
106 };
107
108 lgdt (&gdt_ds);
109 /* reload segment registers */
110 asm volatile("movw %%ax, %%gs" :: "a" (SEL_UDSEG));
111 asm volatile("movw %%ax, %%fs" :: "a" (0));
112 asm volatile("movw %%ax, %%es" :: "a" (SEL_KDSEG));
113 asm volatile("movw %%ax, %%ds" :: "a" (SEL_KDSEG));
114 asm volatile("movw %%ax, %%ss" :: "a" (SEL_KDSEG));
115 asm volatile("pushq %%rbx\n"
116 "movabs $1f, %%rax\n"
117 "pushq %%rax\n"
118 "lretq\n"
119 "1:\n" :: "b" (SEL_KCSEG):"cc","memory");
120 /* Kill the local descriptor table */
121 lldt (0);
122}
static struct segment_desc gdt[SEL_CNT]
Definition: gdt.c:64
struct desc_ptr gdt_ds
Definition: gdt.c:75
#define SEL_KDSEG
Definition: loader.h:37
#define SEL_KCSEG
Definition: loader.h:36
#define SEL_UDSEG
Definition: loader.h:38
#define SEL_TSS
Definition: loader.h:40
unsigned long long int uint64_t
Definition: stdint.h:29
Definition: gdt.c:40
uint32_t base_63_32
Definition: gdt.c:53
unsigned base_23_16
Definition: gdt.c:43
unsigned base_15_0
Definition: gdt.c:42
unsigned lim_15_0
Definition: gdt.c:41
Definition: tss.h:7
struct task_state * tss
Definition: tss.c:49
struct task_state * tss_get(void)
Definition: tss.c:63
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ gdt

struct segment_desc gdt[SEL_CNT]
static
Initial value:
= {
[SEL_NULL >> 3] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
[SEL_KCSEG >> 3] = SEG64 (0xa, 0x0, 0xffffffff, 0),
[SEL_KDSEG >> 3] = SEG64 (0x2, 0x0, 0xffffffff, 0),
[SEL_UDSEG >> 3] = SEG64 (0x2, 0x0, 0xffffffff, 3),
[SEL_UCSEG >> 3] = SEG64 (0xa, 0x0, 0xffffffff, 3),
[SEL_TSS >> 3] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
[6] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
[7] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
#define SEG64(type, base, lim, dpl)
Definition: gdt.c:59
#define SEL_NULL
Definition: loader.h:35
#define SEL_UCSEG
Definition: loader.h:39

◆ gdt_ds

struct desc_ptr gdt_ds
Initial value:
= {
.size = sizeof(gdt) - 1,
}
uint64_t address
Definition: mmu.h:1