00001
00002
00003
00004
00005 #define FL_CF 0x00000001 // Carry Flag
00006 #define FL_PF 0x00000004 // Parity Flag
00007 #define FL_AF 0x00000010 // Auxiliary carry Flag
00008 #define FL_ZF 0x00000040 // Zero Flag
00009 #define FL_SF 0x00000080 // Sign Flag
00010 #define FL_TF 0x00000100 // Trap Flag
00011 #define FL_IF 0x00000200 // Interrupt Enable
00012 #define FL_DF 0x00000400 // Direction Flag
00013 #define FL_OF 0x00000800 // Overflow Flag
00014 #define FL_IOPL_MASK 0x00003000 // I/O Privilege Level bitmask
00015 #define FL_IOPL_0 0x00000000 // IOPL == 0
00016 #define FL_IOPL_1 0x00001000 // IOPL == 1
00017 #define FL_IOPL_2 0x00002000 // IOPL == 2
00018 #define FL_IOPL_3 0x00003000 // IOPL == 3
00019 #define FL_NT 0x00004000 // Nested Task
00020 #define FL_RF 0x00010000 // Resume Flag
00021 #define FL_VM 0x00020000 // Virtual 8086 mode
00022 #define FL_AC 0x00040000 // Alignment Check
00023 #define FL_VIF 0x00080000 // Virtual Interrupt Flag
00024 #define FL_VIP 0x00100000 // Virtual Interrupt Pending
00025 #define FL_ID 0x00200000 // ID flag
00026
00027
00028 struct segdesc {
00029 uint lim_15_0 : 16;
00030 uint base_15_0 : 16;
00031 uint base_23_16 : 8;
00032 uint type : 4;
00033 uint s : 1;
00034 uint dpl : 2;
00035 uint p : 1;
00036 uint lim_19_16 : 4;
00037 uint avl : 1;
00038 uint rsv1 : 1;
00039 uint db : 1;
00040 uint g : 1;
00041 uint base_31_24 : 8;
00042 };
00043
00044
00045 #define SEG(type, base, lim, dpl) (struct segdesc) \
00046 { ((lim) >> 12) & 0xffff, (uint)(base) & 0xffff, \
00047 ((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \
00048 (uint)(lim) >> 28, 0, 0, 1, 1, (uint)(base) >> 24 }
00049
00050 #define SEG16(type, base, lim, dpl) (struct segdesc) \
00051 { (lim) & 0xffff, (uint)(base) & 0xffff, \
00052 ((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \
00053 (uint)(lim) >> 16, 0, 0, 1, 0, (uint)(base) >> 24 }
00054
00055 #define DPL_USER 0x3 // User DPL
00056
00057
00058 #define STA_X 0x8 // Executable segment
00059 #define STA_E 0x4 // Expand down (non-executable segments)
00060 #define STA_C 0x4 // Conforming code segment (executable only)
00061 #define STA_W 0x2 // Writeable (non-executable segments)
00062 #define STA_R 0x2 // Readable (executable segments)
00063 #define STA_A 0x1 // Accessed
00064
00065
00066 #define STS_T16A 0x1 // Available 16-bit TSS
00067 #define STS_LDT 0x2 // Local Descriptor Table
00068 #define STS_T16B 0x3 // Busy 16-bit TSS
00069 #define STS_CG16 0x4 // 16-bit Call Gate
00070 #define STS_TG 0x5 // Task Gate / Coum Transmitions
00071 #define STS_IG16 0x6 // 16-bit Interrupt Gate
00072 #define STS_TG16 0x7 // 16-bit Trap Gate
00073 #define STS_T32A 0x9 // Available 32-bit TSS
00074 #define STS_T32B 0xB // Busy 32-bit TSS
00075 #define STS_CG32 0xC // 32-bit Call Gate
00076 #define STS_IG32 0xE // 32-bit Interrupt Gate
00077 #define STS_TG32 0xF // 32-bit Trap Gate
00078
00079
00080 struct taskstate {
00081 uint link;
00082 uint esp0;
00083 ushort ss0;
00084 ushort padding1;
00085 uint *esp1;
00086 ushort ss1;
00087 ushort padding2;
00088 uint *esp2;
00089 ushort ss2;
00090 ushort padding3;
00091 void *cr3;
00092 uint *eip;
00093 uint eflags;
00094 uint eax;
00095 uint ecx;
00096 uint edx;
00097 uint ebx;
00098 uint *esp;
00099 uint *ebp;
00100 uint esi;
00101 uint edi;
00102 ushort es;
00103 ushort padding4;
00104 ushort cs;
00105 ushort padding5;
00106 ushort ss;
00107 ushort padding6;
00108 ushort ds;
00109 ushort padding7;
00110 ushort fs;
00111 ushort padding8;
00112 ushort gs;
00113 ushort padding9;
00114 ushort ldt;
00115 ushort padding10;
00116 ushort t;
00117 ushort iomb;
00118 };
00119
00120
00121 struct gatedesc {
00122 uint off_15_0 : 16;
00123 uint cs : 16;
00124 uint args : 5;
00125 uint rsv1 : 3;
00126 uint type : 4;
00127 uint s : 1;
00128 uint dpl : 2;
00129 uint p : 1;
00130 uint off_31_16 : 16;
00131 };
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 #define SETGATE(gate, istrap, sel, off, d) \
00142 { \
00143 (gate).off_15_0 = (uint) (off) & 0xffff; \
00144 (gate).cs = (sel); \
00145 (gate).args = 0; \
00146 (gate).rsv1 = 0; \
00147 (gate).type = (istrap) ? STS_TG32 : STS_IG32; \
00148 (gate).s = 0; \
00149 (gate).dpl = (d); \
00150 (gate).p = 1; \
00151 (gate).off_31_16 = (uint) (off) >> 16; \
00152 }
00153