source: branches/minix3-book/kernel/protect.h@ 12

Last change on this file since 12 was 4, checked in by Mattia Monga, 14 years ago

Importazione sorgenti libro

File size: 5.7 KB
Line 
1/* Constants for protected mode. */
2
3/* Table sizes. */
4#define GDT_SIZE (FIRST_LDT_INDEX + NR_TASKS + NR_PROCS)
5 /* spec. and LDT's */
6#define IDT_SIZE (IRQ8_VECTOR + 8) /* only up to the highest vector */
7#define LDT_SIZE (2 + NR_REMOTE_SEGS) /* CS, DS and remote segments */
8
9/* Fixed global descriptors. 1 to 7 are prescribed by the BIOS. */
10#define GDT_INDEX 1 /* GDT descriptor */
11#define IDT_INDEX 2 /* IDT descriptor */
12#define DS_INDEX 3 /* kernel DS */
13#define ES_INDEX 4 /* kernel ES (386: flag 4 Gb at startup) */
14#define SS_INDEX 5 /* kernel SS (386: monitor SS at startup) */
15#define CS_INDEX 6 /* kernel CS */
16#define MON_CS_INDEX 7 /* temp for BIOS (386: monitor CS at startup) */
17#define TSS_INDEX 8 /* kernel TSS */
18#define DS_286_INDEX 9 /* scratch 16-bit source segment */
19#define ES_286_INDEX 10 /* scratch 16-bit destination segment */
20#define A_INDEX 11 /* 64K memory segment at A0000 */
21#define B_INDEX 12 /* 64K memory segment at B0000 */
22#define C_INDEX 13 /* 64K memory segment at C0000 */
23#define D_INDEX 14 /* 64K memory segment at D0000 */
24#define FIRST_LDT_INDEX 15 /* rest of descriptors are LDT's */
25
26#define GDT_SELECTOR 0x08 /* (GDT_INDEX * DESC_SIZE) bad for asld */
27#define IDT_SELECTOR 0x10 /* (IDT_INDEX * DESC_SIZE) */
28#define DS_SELECTOR 0x18 /* (DS_INDEX * DESC_SIZE) */
29#define ES_SELECTOR 0x20 /* (ES_INDEX * DESC_SIZE) */
30#define FLAT_DS_SELECTOR 0x21 /* less privileged ES */
31#define SS_SELECTOR 0x28 /* (SS_INDEX * DESC_SIZE) */
32#define CS_SELECTOR 0x30 /* (CS_INDEX * DESC_SIZE) */
33#define MON_CS_SELECTOR 0x38 /* (MON_CS_INDEX * DESC_SIZE) */
34#define TSS_SELECTOR 0x40 /* (TSS_INDEX * DESC_SIZE) */
35#define DS_286_SELECTOR 0x49 /* (DS_286_INDEX*DESC_SIZE+TASK_PRIVILEGE) */
36#define ES_286_SELECTOR 0x51 /* (ES_286_INDEX*DESC_SIZE+TASK_PRIVILEGE) */
37
38/* Fixed local descriptors. */
39#define CS_LDT_INDEX 0 /* process CS */
40#define DS_LDT_INDEX 1 /* process DS=ES=FS=GS=SS */
41#define EXTRA_LDT_INDEX 2 /* first of the extra LDT entries */
42
43/* Privileges. */
44#define INTR_PRIVILEGE 0 /* kernel and interrupt handlers */
45#define TASK_PRIVILEGE 1 /* kernel tasks */
46#define USER_PRIVILEGE 3 /* servers and user processes */
47
48/* 286 hardware constants. */
49
50/* Exception vector numbers. */
51#define BOUNDS_VECTOR 5 /* bounds check failed */
52#define INVAL_OP_VECTOR 6 /* invalid opcode */
53#define COPROC_NOT_VECTOR 7 /* coprocessor not available */
54#define DOUBLE_FAULT_VECTOR 8
55#define COPROC_SEG_VECTOR 9 /* coprocessor segment overrun */
56#define INVAL_TSS_VECTOR 10 /* invalid TSS */
57#define SEG_NOT_VECTOR 11 /* segment not present */
58#define STACK_FAULT_VECTOR 12 /* stack exception */
59#define PROTECTION_VECTOR 13 /* general protection */
60
61/* Selector bits. */
62#define TI 0x04 /* table indicator */
63#define RPL 0x03 /* requester privilege level */
64
65/* Descriptor structure offsets. */
66#define DESC_BASE 2 /* to base_low */
67#define DESC_BASE_MIDDLE 4 /* to base_middle */
68#define DESC_ACCESS 5 /* to access byte */
69#define DESC_SIZE 8 /* sizeof (struct segdesc_s) */
70
71/* Base and limit sizes and shifts. */
72#define BASE_MIDDLE_SHIFT 16 /* shift for base --> base_middle */
73
74/* Access-byte and type-byte bits. */
75#define PRESENT 0x80 /* set for descriptor present */
76#define DPL 0x60 /* descriptor privilege level mask */
77#define DPL_SHIFT 5
78#define SEGMENT 0x10 /* set for segment-type descriptors */
79
80/* Access-byte bits. */
81#define EXECUTABLE 0x08 /* set for executable segment */
82#define CONFORMING 0x04 /* set for conforming segment if executable */
83#define EXPAND_DOWN 0x04 /* set for expand-down segment if !executable*/
84#define READABLE 0x02 /* set for readable segment if executable */
85#define WRITEABLE 0x02 /* set for writeable segment if !executable */
86#define TSS_BUSY 0x02 /* set if TSS descriptor is busy */
87#define ACCESSED 0x01 /* set if segment accessed */
88
89/* Special descriptor types. */
90#define AVL_286_TSS 1 /* available 286 TSS */
91#define LDT 2 /* local descriptor table */
92#define BUSY_286_TSS 3 /* set transparently to the software */
93#define CALL_286_GATE 4 /* not used */
94#define TASK_GATE 5 /* only used by debugger */
95#define INT_286_GATE 6 /* interrupt gate, used for all vectors */
96#define TRAP_286_GATE 7 /* not used */
97
98/* Extra 386 hardware constants. */
99
100/* Exception vector numbers. */
101#define PAGE_FAULT_VECTOR 14
102#define COPROC_ERR_VECTOR 16 /* coprocessor error */
103
104/* Descriptor structure offsets. */
105#define DESC_GRANULARITY 6 /* to granularity byte */
106#define DESC_BASE_HIGH 7 /* to base_high */
107
108/* Base and limit sizes and shifts. */
109#define BASE_HIGH_SHIFT 24 /* shift for base --> base_high */
110#define BYTE_GRAN_MAX 0xFFFFFL /* maximum size for byte granular segment */
111#define GRANULARITY_SHIFT 16 /* shift for limit --> granularity */
112#define OFFSET_HIGH_SHIFT 16 /* shift for (gate) offset --> offset_high */
113#define PAGE_GRAN_SHIFT 12 /* extra shift for page granular limits */
114
115/* Type-byte bits. */
116#define DESC_386_BIT 0x08 /* 386 types are obtained by ORing with this */
117 /* LDT's and TASK_GATE's don't need it */
118
119/* Granularity byte. */
120#define GRANULAR 0x80 /* set for 4K granularilty */
121#define DEFAULT 0x40 /* set for 32-bit defaults (executable seg) */
122#define BIG 0x40 /* set for "BIG" (expand-down seg) */
123#define AVL 0x10 /* 0 for available */
124#define LIMIT_HIGH 0x0F /* mask for high bits of limit */
Note: See TracBrowser for help on using the repository browser.