missing "SEG_BIG" flag in data segments (desc_seg())
[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
8 #define SEG_ACCESSED    0x00000100
9 #define SEG_PRESENT             0x00008000
10 #define SEG_AVL                 0x00100000
11 #define SEG_GRAN                0x00800000
12
13 /* data segment type flags */
14 #define SEG_WR                  0x00000200
15 #define SEG_EXPDN               0x00000400
16 #define SEG_BIG                 0x00400000
17 /* code segment type flags */
18 #define SEG_RD                  0x00000200
19 #define SEG_CONFORM             0x00000400
20 #define SEG_DEF                 0x00400000
21
22
23 #define GATE_TYPE_INTR  0x0e00
24 #define GATE_TYPE_TRAP  0x0f00
25 #define GATE_PRESENT    0x8000
26
27
28 void desc_seg(struct desc *desc, int type, uint32_t base, uint32_t limit, int dpl)
29 {
30         static uint32_t segtype[] = { 0, SEG_TYPE_CODE, SEG_TYPE_DATA, SEG_TYPE_TSS };
31
32         if(type == SEG_NULL) {
33                 desc->d[0] = desc->d[1] = 0;
34                 return;
35         }
36
37         desc->d[0] = (limit & 0xffff) | (base << 16);
38         desc->d[1] = ((base >> 16) & 0xff) | (type << 8) | SEG_PRESENT | (dpl << 13) | segtype[type];
39         desc->d[1] |= (base & 0xff000000) | (limit & 0xf0000) | SEG_GRAN | SEG_DEF | SEG_RD;
40 }
41
42
43
44 void desc_intr(struct desc *desc, int type, uint16_t sel, uint32_t offs, int dpl)
45 {
46         uint32_t gate_type[] = { GATE_TYPE_INTR, GATE_TYPE_TRAP };
47
48         desc->d[0] = (offs & 0xffff) | ((uint32_t)sel << 16);
49         desc->d[1] = (offs & 0xffff0000) | GATE_PRESENT | (dpl << 13) | gate_type[type];
50 }