Source to include/mach/machreg.h
0001 #ifndef _MACHREG_H
0002 #define _MACHREG_H
0003 /*
0004 * machreg.h
0005 * Register definitions for i386
0006 */
0007 #include <sys/types.h>
0008 #include <sys/param.h>
0009
0010 /*
0011 * This is what is added to a user's stack when an event is
0012 * delivered.
0013 */
0014 struct evframe {
0015 char ev_event[EVLEN]; /* Event delivered */
0016 ulong ev_previp; /* Previous IP */
0017 };
0018
0019 /*
0020 * This is the shape of the kernel stack after taking an interrupt
0021 * or exception. For machine traps which don't provide an error
0022 * code, we push a 0 ourselves. "traptype" is from sys/trap.h.
0023 * edi..eax are in pushal format.
0024 */
0025 struct trapframe {
0026 ulong esds;
0027 ulong edi, esi, ebp, espdummy, ebx, edx, ecx, eax;
0028 ulong traptype;
0029 ulong errcode;
0030 ulong eip, ecs;
0031 ulong eflags;
0032 ulong esp, ess;
0033 };
0034 #define NREG (sizeof(struct trapframe) / sizeof(ulong))
0035
0036 /*
0037 * When the registers are pushed with the "pusha" instruction, this
0038 * is the resulting format.
0039 */
0040 struct pushaframe {
0041 ulong edi, esi, ebp, esp, ebx, edx, ecx, eax;
0042 };
0043
0044 /*
0045 * Tell if given descriptor is from user mode
0046 */
0047 #define USERMODE(tf) ((tf)->ecs & 0x3)
0048
0049 /*
0050 * Bits in eflags
0051 */
0052 #define F_CF 0x00000001 /* carry */
0053 #define F_PF 0x00000004 /* parity */
0054 #define F_AF 0x00000010 /* BCD stuff */
0055 #define F_ZF 0x00000040 /* zero */
0056 #define F_SF 0x00000080 /* sign */
0057 #define F_TF 0x00000100 /* single step */
0058 #define F_IF 0x00000200 /* interrupts */
0059 #define F_DF 0x00000400 /* direction */
0060 #define F_OF 0x00000800 /* overflow */
0061 #define F_IOPL 0x00003000 /* IO privilege level */
0062 #define F_NT 0x00004000 /* nested task */
0063 #define F_RF 0x00010000 /* resume flag */
0064 #define F_VM 0x00020000 /* virtual 8086 */
0065
0066 /*
0067 * Bits in errcode when handling page fault
0068 */
0069 #define EC_KERNEL 4 /* Fault from kernel mode */
0070 #define EC_WRITE 2 /* Access was a write */
0071 #define EC_PROT 1 /* Page valid, but access modes wrong */
0072
0073 #ifdef PROC_DEBUG
0074 /*
0075 * This stuff is only needed in the context of proc.h, and only
0076 * then when process debugging is configured.
0077 *
0078 * WARNING: locore.s knows about this struct, so don't fiddle it
0079 * until you've looked at how locore.s uses it.
0080 */
0081 struct dbg_regs {
0082 ulong dr[4]; /* DR0..3--linear addr to break on */
0083 ulong dr7; /* Debug control register */
0084 };
0085 #endif /* PROC_DEBUG */
0086
0087 /*
0088 * Buffer for saving FPU state - matches the layout used by frestor
0089 */
0090 struct fpu {
0091 ulong ocw, osw, otw, oip, ocs, ooo, oos, ost[20];
0092 };
0093
0094 /*
0095 * Bits in CR0
0096 */
0097 #define BIT(x) (1 << (x))
0098 #define CR0_PE BIT(0) /* Protection enable */
0099 #define CR0_MP BIT(1) /* Math processor present */
0100 #define CR0_EM BIT(2) /* Emulate FP--trap on FP instruction */
0101 #define CR0_TS BIT(3) /* Task switched flag */
0102 #define CR0_ET BIT(4) /* Extension type--387 DX presence */
0103 #define CR0_NE BIT(5) /* Numeric Error--allow traps on numeric errors */
0104 #define CR0_WP BIT(16) /* Write protect--ring 0 honors RO PTE's */
0105 #define CR0_AM BIT(18) /* Alignment--trap on unaligned refs */
0106 #define CR0_NW BIT(29) /* Not write-through--inhibit write-through */
0107 #define CR0_CD BIT(30) /* Cache disable */
0108 #define CR0_PG BIT(31) /* Paging--use PTEs/CR3 */
0109
0110 #ifdef KERNEL
0111 extern void fpu_enable(struct fpu *), fpu_disable(struct fpu *),
0112 fpu_maskexcep(void);
0113 extern int fpu_detected(void);
0114 #endif /* KERNEL */
0115
0116 #endif /* _MACHREG_H */