Clubcos  0.0.0
Clubcos - Clubc Operating System
 모두 데이타 구조 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 매크로 페이지들
gdt.h
이 파일의 문서화 페이지로 가기
1 // Copyright (c) 2014, 임경현 (dlarudgus20)
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
32 #ifndef GDT_H_
33 #define GDT_H_
34 
35 #include <stddef.h>
36 #include <stdint.h>
37 
38 #include "memory_map.h"
39 
41 #define NULL_SEGMENT 0
42 
43 #define KERNEL_DATA_SEGMENT (1 * 8)
44 
45 #define KERNEL_CODE_SEGMENT (2 * 8)
46 
56 #define MAKE_GDT_TYPE1(SegmentType,S,DPL,P) \
57  ((((P) << 7) & 0x80) | (((DPL) << 5) & 0x60) | (((S) << 4) & 0x10) | ((SegmentType) & 0x0f))
58 
65 #define MAKE_DATA_SEGMENT(expdown,writable) \
66  (((((expdown) << 2) & 0x04) | (((writable) << 1) & 0x02)) & 0x06)
67 
73 #define MAKE_CODE_SEGMENT(conforming,readable) \
74  ((((((conforming) << 2) & 0x04) | (((readable) << 1) & 0x02)) | 0x08) & 0x0e)
75 
77 #define DATA_SEGMENT_TYPE MAKE_DATA_SEGMENT(0,1)
78 
79 #define CODE_SEGMENT_TYPE MAKE_CODE_SEGMENT(0,1)
80 
82 typedef uint8_t GdtType1;
84 typedef uint8_t GdtType2;
85 
89 typedef struct tagGdt
90 {
92 
93  uint8_t Address_16_23;
94 
95  union
96  {
97  struct
98  {
99  unsigned SegmentType:4, S:1, DPL:2, P:1;
100  };
102  };
103 
104  union
105  {
106  struct
107  {
108  unsigned Size_16_19:4;
109  unsigned AVL:1, reserved:1, D:1, G:1;
110  };
112  };
113 
114  uint8_t Address_24_32;
115 } Gdt;
116 
118 static Gdt * const g_pGdtTable = (Gdt *)GDT_TABLE_ADDRESS;
119 
127 void ckGdtInit(Gdt *pGdt, uint32_t address, uint32_t size, GdtType1 type1);
128 
133 static inline void ckGdtInitNull(Gdt *pGdt)
134 {
135  ((int *)pGdt)[1] = ((int *)pGdt)[0] = 0;
136 }
137 
141 void ckGdtLoad(uint16_t size, Gdt *address);
142 
146 void ckGdtTableInitialize(void);
147 
148 #endif /* GDT_H_ */
unsigned reserved
Definition: gdt.h:109
unsigned G
Definition: gdt.h:109
#define GDT_TABLE_ADDRESS
GDT 테이블의 선형 주소입니다.
Definition: memory_map.h:62
unsigned P
Definition: gdt.h:99
uint8_t Address_24_32
Definition: gdt.h:114
unsigned S
Definition: gdt.h:99
uint8_t GdtType2
Gdt 구조체를 참조하십시오.
Definition: gdt.h:84
uint16_t Size_0_15
Definition: gdt.h:91
unsigned DPL
Definition: gdt.h:99
unsigned Size_16_19
Definition: gdt.h:108
unsigned AVL
Definition: gdt.h:109
void ckGdtLoad(uint16_t size, Gdt *address)
lgdt 명령어로 GDT 테이블을 로드합니다.
GDT를 나타내는 구조체입니다.
Definition: gdt.h:89
void ckGdtInit(Gdt *pGdt, uint32_t address, uint32_t size, GdtType1 type1)
Gdt 구조체를 초기화합니다.
Definition: gdt.c:63
unsigned D
Definition: gdt.h:109
GdtType2 type2
Definition: gdt.h:111
void ckGdtTableInitialize(void)
GDT 테이블을 초기화합니다.
Definition: gdt.c:36
GdtType1 type1
Definition: gdt.h:101
uint16_t Address_0_15
Definition: gdt.h:91
struct tagGdt Gdt
GDT를 나타내는 구조체입니다.
unsigned SegmentType
Definition: gdt.h:99
uint8_t GdtType1
Gdt 구조체를 참조하십시오.
Definition: gdt.h:82
uint8_t Address_16_23
Definition: gdt.h:93