xref: /minix3/minix/kernel/arch/i386/include/archconst.h (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc 
2*433d6423SLionel Sambuc #ifndef _I386_ACONST_H
3*433d6423SLionel Sambuc #define _I386_ACONST_H 1
4*433d6423SLionel Sambuc 
5*433d6423SLionel Sambuc #include <machine/interrupt.h>
6*433d6423SLionel Sambuc #include <machine/memory.h>
7*433d6423SLionel Sambuc 
8*433d6423SLionel Sambuc /* Constants for protected mode. */
9*433d6423SLionel Sambuc 
10*433d6423SLionel Sambuc /* Table sizes. */
11*433d6423SLionel Sambuc #define IDT_SIZE 256	/* the table is set to it's maximal size */
12*433d6423SLionel Sambuc 
13*433d6423SLionel Sambuc /* GDT layout (SYSENTER/SYSEXIT compliant) */
14*433d6423SLionel Sambuc #define KERN_CS_INDEX        1
15*433d6423SLionel Sambuc #define KERN_DS_INDEX        2
16*433d6423SLionel Sambuc #define USER_CS_INDEX        3
17*433d6423SLionel Sambuc #define USER_DS_INDEX        4
18*433d6423SLionel Sambuc #define LDT_INDEX            5
19*433d6423SLionel Sambuc #define TSS_INDEX_FIRST      6
20*433d6423SLionel Sambuc #define TSS_INDEX(cpu)       (TSS_INDEX_FIRST + (cpu)) /* per cpu kernel tss */
21*433d6423SLionel Sambuc #define GDT_SIZE             (TSS_INDEX(CONFIG_MAX_CPUS))	/* LDT descriptor */
22*433d6423SLionel Sambuc 
23*433d6423SLionel Sambuc #define SEG_SELECTOR(i)          ((i)*8)
24*433d6423SLionel Sambuc #define KERN_CS_SELECTOR SEG_SELECTOR(KERN_CS_INDEX)
25*433d6423SLionel Sambuc #define KERN_DS_SELECTOR SEG_SELECTOR(KERN_DS_INDEX)
26*433d6423SLionel Sambuc #define USER_CS_SELECTOR (SEG_SELECTOR(USER_CS_INDEX) | USER_PRIVILEGE)
27*433d6423SLionel Sambuc #define USER_DS_SELECTOR (SEG_SELECTOR(USER_DS_INDEX) | USER_PRIVILEGE)
28*433d6423SLionel Sambuc #define LDT_SELECTOR SEG_SELECTOR(LDT_INDEX)
29*433d6423SLionel Sambuc #define TSS_SELECTOR(cpu)	SEG_SELECTOR(TSS_INDEX(cpu))
30*433d6423SLionel Sambuc 
31*433d6423SLionel Sambuc #define DESC_SIZE	8
32*433d6423SLionel Sambuc 
33*433d6423SLionel Sambuc /* Privileges. */
34*433d6423SLionel Sambuc #define INTR_PRIVILEGE       0	/* kernel and interrupt handlers */
35*433d6423SLionel Sambuc #define USER_PRIVILEGE       3	/* servers and user processes */
36*433d6423SLionel Sambuc #define RPL_MASK             0x03	/* bits in selector RPL */
37*433d6423SLionel Sambuc 
38*433d6423SLionel Sambuc /* 286 hardware constants. */
39*433d6423SLionel Sambuc 
40*433d6423SLionel Sambuc /* Exception vector numbers. */
41*433d6423SLionel Sambuc #define BOUNDS_VECTOR        5	/* bounds check failed */
42*433d6423SLionel Sambuc #define INVAL_OP_VECTOR      6	/* invalid opcode */
43*433d6423SLionel Sambuc #define COPROC_NOT_VECTOR    7	/* coprocessor not available */
44*433d6423SLionel Sambuc #define DOUBLE_FAULT_VECTOR  8
45*433d6423SLionel Sambuc #define COPROC_SEG_VECTOR    9	/* coprocessor segment overrun */
46*433d6423SLionel Sambuc #define INVAL_TSS_VECTOR    10	/* invalid TSS */
47*433d6423SLionel Sambuc #define SEG_NOT_VECTOR      11	/* segment not present */
48*433d6423SLionel Sambuc #define STACK_FAULT_VECTOR  12	/* stack exception */
49*433d6423SLionel Sambuc #define PROTECTION_VECTOR   13	/* general protection */
50*433d6423SLionel Sambuc 
51*433d6423SLionel Sambuc /* Selector bits. */
52*433d6423SLionel Sambuc #define TI                0x04	/* table indicator */
53*433d6423SLionel Sambuc #define RPL               0x03	/* requester privilege level */
54*433d6423SLionel Sambuc 
55*433d6423SLionel Sambuc /* Base and limit sizes and shifts. */
56*433d6423SLionel Sambuc #define BASE_MIDDLE_SHIFT   16	/* shift for base --> base_middle */
57*433d6423SLionel Sambuc 
58*433d6423SLionel Sambuc /* Access-byte and type-byte bits. */
59*433d6423SLionel Sambuc #define PRESENT           0x80	/* set for descriptor present */
60*433d6423SLionel Sambuc #define DPL               0x60	/* descriptor privilege level mask */
61*433d6423SLionel Sambuc #define DPL_SHIFT            5
62*433d6423SLionel Sambuc #define SEGMENT           0x10	/* set for segment-type descriptors */
63*433d6423SLionel Sambuc 
64*433d6423SLionel Sambuc /* Access-byte bits. */
65*433d6423SLionel Sambuc #define EXECUTABLE        0x08	/* set for executable segment */
66*433d6423SLionel Sambuc #define CONFORMING        0x04	/* set for conforming segment if executable */
67*433d6423SLionel Sambuc #define EXPAND_DOWN       0x04	/* set for expand-down segment if !executable*/
68*433d6423SLionel Sambuc #define READABLE          0x02	/* set for readable segment if executable */
69*433d6423SLionel Sambuc #define WRITEABLE         0x02	/* set for writeable segment if !executable */
70*433d6423SLionel Sambuc #define TSS_BUSY          0x02	/* set if TSS descriptor is busy */
71*433d6423SLionel Sambuc #define ACCESSED          0x01	/* set if segment accessed */
72*433d6423SLionel Sambuc 
73*433d6423SLionel Sambuc /* Special descriptor types. */
74*433d6423SLionel Sambuc #define AVL_286_TSS          1	/* available 286 TSS */
75*433d6423SLionel Sambuc #define LDT                  2	/* local descriptor table */
76*433d6423SLionel Sambuc #define BUSY_286_TSS         3	/* set transparently to the software */
77*433d6423SLionel Sambuc #define CALL_286_GATE        4	/* not used */
78*433d6423SLionel Sambuc #define TASK_GATE            5	/* only used by debugger */
79*433d6423SLionel Sambuc #define INT_286_GATE         6	/* interrupt gate, used for all vectors */
80*433d6423SLionel Sambuc #define TRAP_286_GATE        7	/* not used */
81*433d6423SLionel Sambuc 
82*433d6423SLionel Sambuc #define INT_GATE_TYPE	(INT_286_GATE | DESC_386_BIT)
83*433d6423SLionel Sambuc #define TSS_TYPE	(AVL_286_TSS  | DESC_386_BIT)
84*433d6423SLionel Sambuc 
85*433d6423SLionel Sambuc 
86*433d6423SLionel Sambuc /* Extra 386 hardware constants. */
87*433d6423SLionel Sambuc 
88*433d6423SLionel Sambuc /* Exception vector numbers. */
89*433d6423SLionel Sambuc #define PAGE_FAULT_VECTOR   14
90*433d6423SLionel Sambuc #define COPROC_ERR_VECTOR   16	/* coprocessor error */
91*433d6423SLionel Sambuc #define ALIGNMENT_CHECK_VECTOR	17
92*433d6423SLionel Sambuc #define MACHINE_CHECK_VECTOR	18
93*433d6423SLionel Sambuc #define SIMD_EXCEPTION_VECTOR	19     /* SIMD Floating-Point Exception (#XM) */
94*433d6423SLionel Sambuc 
95*433d6423SLionel Sambuc /* Descriptor structure offsets. */
96*433d6423SLionel Sambuc #define DESC_GRANULARITY     6	/* to granularity byte */
97*433d6423SLionel Sambuc #define DESC_BASE_HIGH       7	/* to base_high */
98*433d6423SLionel Sambuc 
99*433d6423SLionel Sambuc /* Type-byte bits. */
100*433d6423SLionel Sambuc #define DESC_386_BIT  0x08 /* 386 types are obtained by ORing with this */
101*433d6423SLionel Sambuc 				/* LDT's and TASK_GATE's don't need it */
102*433d6423SLionel Sambuc 
103*433d6423SLionel Sambuc /* Base and limit sizes and shifts. */
104*433d6423SLionel Sambuc #define BASE_HIGH_SHIFT     24  /* shift for base --> base_high */
105*433d6423SLionel Sambuc #define BYTE_GRAN_MAX   0xFFFFFL   /* maximum size for byte granular segment */
106*433d6423SLionel Sambuc #define GRANULARITY_SHIFT   16  /* shift for limit --> granularity */
107*433d6423SLionel Sambuc #define OFFSET_HIGH_SHIFT   16  /* shift for (gate) offset --> offset_high */
108*433d6423SLionel Sambuc #define PAGE_GRAN_SHIFT     12  /* extra shift for page granular limits */
109*433d6423SLionel Sambuc 
110*433d6423SLionel Sambuc /* Granularity byte. */
111*433d6423SLionel Sambuc #define GRANULAR  	  0x80	/* set for 4K granularilty */
112*433d6423SLionel Sambuc #define DEFAULT   	  0x40	/* set for 32-bit defaults (executable seg) */
113*433d6423SLionel Sambuc #define BIG       	  0x40	/* set for "BIG" (expand-down seg) */
114*433d6423SLionel Sambuc #define AVL        	  0x10	/* 0 for available */
115*433d6423SLionel Sambuc #define LIMIT_HIGH   	  0x0F	/* mask for high bits of limit */
116*433d6423SLionel Sambuc 
117*433d6423SLionel Sambuc /* Program stack words and masks. */
118*433d6423SLionel Sambuc #define INIT_PSW      0x0200    /* initial psw */
119*433d6423SLionel Sambuc #define INIT_TASK_PSW 0x1200    /* initial psw for tasks (with IOPL 1) */
120*433d6423SLionel Sambuc #define TRACEBIT      0x0100    /* OR this with psw in proc[] for tracing */
121*433d6423SLionel Sambuc #define SETPSW(rp, new)         /* permits only certain bits to be set */ \
122*433d6423SLionel Sambuc         ((rp)->p_reg.psw = ((rp)->p_reg.psw & ~0xCD5) | ((new) & 0xCD5))
123*433d6423SLionel Sambuc #define IF_MASK 0x00000200
124*433d6423SLionel Sambuc #define IOPL_MASK 0x003000
125*433d6423SLionel Sambuc 
126*433d6423SLionel Sambuc #define INTEL_CPUID_GEN_EBX	0x756e6547 /* ASCII value of "Genu" */
127*433d6423SLionel Sambuc #define INTEL_CPUID_GEN_EDX	0x49656e69 /* ASCII value of "ineI" */
128*433d6423SLionel Sambuc #define INTEL_CPUID_GEN_ECX	0x6c65746e /* ASCII value of "ntel" */
129*433d6423SLionel Sambuc 
130*433d6423SLionel Sambuc #define AMD_CPUID_GEN_EBX	0x68747541 /* ASCII value of "Auth" */
131*433d6423SLionel Sambuc #define AMD_CPUID_GEN_EDX	0x69746e65 /* ASCII value of "enti" */
132*433d6423SLionel Sambuc #define AMD_CPUID_GEN_ECX	0x444d4163 /* ASCII value of "cAMD" */
133*433d6423SLionel Sambuc 
134*433d6423SLionel Sambuc #define CPU_VENDOR_INTEL	0
135*433d6423SLionel Sambuc #define CPU_VENDOR_AMD		2
136*433d6423SLionel Sambuc #define CPU_VENDOR_UNKNOWN	0xff
137*433d6423SLionel Sambuc 
138*433d6423SLionel Sambuc /* fpu context should be saved in 16-byte aligned memory */
139*433d6423SLionel Sambuc #define FPUALIGN		16
140*433d6423SLionel Sambuc 
141*433d6423SLionel Sambuc /* Poweroff 16-bit code address */
142*433d6423SLionel Sambuc #define BIOS_POWEROFF_ENTRY 0x1000
143*433d6423SLionel Sambuc 
144*433d6423SLionel Sambuc 
145*433d6423SLionel Sambuc /*
146*433d6423SLionel Sambuc  * defines how many bytes are reserved at the top of the kernel stack for global
147*433d6423SLionel Sambuc  * information like currently scheduled process or current cpu id
148*433d6423SLionel Sambuc  */
149*433d6423SLionel Sambuc #define X86_STACK_TOP_RESERVED	(2 * sizeof(reg_t))
150*433d6423SLionel Sambuc 
151*433d6423SLionel Sambuc #define PG_ALLOCATEME ((phys_bytes)-1)
152*433d6423SLionel Sambuc 
153*433d6423SLionel Sambuc /* MSRs */
154*433d6423SLionel Sambuc #define INTEL_MSR_PERFMON_CRT0         0xc1
155*433d6423SLionel Sambuc #define INTEL_MSR_SYSENTER_CS         0x174
156*433d6423SLionel Sambuc #define INTEL_MSR_SYSENTER_ESP        0x175
157*433d6423SLionel Sambuc #define INTEL_MSR_SYSENTER_EIP        0x176
158*433d6423SLionel Sambuc #define INTEL_MSR_PERFMON_SEL0        0x186
159*433d6423SLionel Sambuc 
160*433d6423SLionel Sambuc #define INTEL_MSR_PERFMON_SEL0_ENABLE (1 << 22)
161*433d6423SLionel Sambuc 
162*433d6423SLionel Sambuc #define AMD_EFER_SCE		(1L << 0) /* SYSCALL/SYSRET enabled */
163*433d6423SLionel Sambuc #define AMD_MSR_EFER		0xC0000080	/* extended features msr */
164*433d6423SLionel Sambuc #define AMD_MSR_STAR		0xC0000081	/* SYSCALL params msr */
165*433d6423SLionel Sambuc 
166*433d6423SLionel Sambuc /* trap styles recorded on kernel entry and exit */
167*433d6423SLionel Sambuc #define KTS_NONE	1 /* invalid */
168*433d6423SLionel Sambuc #define KTS_INT_HARD	2 /* exception / hard interrupt */
169*433d6423SLionel Sambuc #define KTS_INT_ORIG	3 /* soft interrupt from libc */
170*433d6423SLionel Sambuc #define KTS_INT_UM	4 /* soft interrupt from usermapped code */
171*433d6423SLionel Sambuc #define KTS_FULLCONTEXT	5 /* must restore full context */
172*433d6423SLionel Sambuc #define KTS_SYSENTER	6 /* SYSENTER instruction (usermapped) */
173*433d6423SLionel Sambuc #define KTS_SYSCALL	7 /* SYSCALL instruction (usermapped) */
174*433d6423SLionel Sambuc 
175*433d6423SLionel Sambuc #endif /* _I386_ACONST_H */
176