d02c5fc2decbaa06fd6acae5660424d1fb3c7c1f
[3sys] / sys1 / kern / src / desc.c
1 #include "desc.h"
2
3 #define SEG_TYPE_SYSTEM 0
4 #define SEG_TYPE_CODE   0x00001800
5 #define SEG_TYPE_DATA   0x00001000
6 #define SEG_TYPE_TSS    0x00000100
7 #define SEG_TYPE_INTR   0x00000e00
8 #define SEG_TYPE_TRAP   0x00000f00
9
10 #define SEG_ACCESSED    0x00000100
11 #define SEG_PRESENT             0x00008000
12 #define SEG_AVL                 0x00100000
13 #define SEG_GRAN                0x00800000
14
15 /* data segment type flags */
16 #define SEG_WR                  0x00000200
17 #define SEG_EXPDN               0x00000400
18 #define SEG_BIG                 0x00400000
19 /* code segment type flags */
20 #define SEG_RD                  0x00000200
21 #define SEG_CONFORM             0x00000400
22 #define SEG_DEF                 0x00400000
23
24
25 void desc_seg(struct desc *desc, int type, uint32_t base, uint32_t limit, int dpl)
26 {
27         if(type == SEG_NULL) {
28                 desc->d[0] = desc->d[1] = 0;
29                 return;
30         }
31
32         desc->d[0] = (limit & 0xffff) | (base << 16);
33         desc->d[1] = ((base >> 16) & 0xff) | (type << 8) | SEG_PRESENT | (dpl << 13);
34         desc->d[1] |= (base & 0xff000000) | (limit & 0xf0000) | SEG_AVL | SEG_GRAN;
35
36         switch(type) {
37         case SEG_CODE:
38                 desc->d[1] |= (3 << 11) | SEG_DEF | SEG_RD;
39                 break;
40
41         case SEG_DATA:
42                 desc->d[1] |= (2 << 11) | SEG_WR;
43                 break;
44         }
45 }