?? process.h
字號:
#ifndef _I386_PROCESS_
#define _I386_PROCESS_
#include <type.h>
//實模式中斷使用的寄存器,抱歉我只把需要的保存起來。
//如果其它的寄存器被改變,可能導致系統出錯。
typedef struct RMRegs{
t_32 intNo;
t_16 ds;
t_16 es;
t_32 esi;
t_32 edi;
t_32 ebx;
t_32 edx;
t_32 ecx;
t_32 eax;
}RMRegs, *PRMRegs;
/* 段描述符 */
typedef struct tagSegDesc /* 共 8 個字節 */
{
t_16 limit_low; /* Limit */
t_16 base_low; /* Base */
t_8 base_mid; /* Base */
t_8 attr1; /* P(1) DPL(2) DT(1) TYPE(4) */
t_8 limit_high_attr2; /* G(1) D(1) 0(1) AVL(1) LimitHigh(4) */
t_8 base_high; /* Base */
}SegDesc, *PSegDesc;
typedef struct TSS {
t_32 back_link;
t_32 esp0; /* stack pointer to use during interrupt */
t_32 ss0; /* " segment " " " " */
t_32 esp1;
t_32 ss1;
t_32 esp2;
t_32 ss2;
t_32 cr3;
t_32 eip;
t_32 flags;
t_32 eax, ecx ,edx, ebx;
t_32 esp;
t_32 ebp;
t_32 esi;
t_32 edi;
t_32 es;
t_32 cs;
t_32 ss;
t_32 ds;
t_32 fs;
t_32 gs;
t_32 ldt;
t_16 trap;
t_16 iobase; /* I/O位圖基址大于或等于TSS段界限,就表示沒有I/O許可位圖 */
/*t_8 iomap[2];*/
}TSS, *PTSS;
/* 門描述符 */
typedef struct GateDesc
{
t_16 offset_low; /* Offset Low */
t_16 selector; /* Selector */
t_8 dcount; /* 該字段只在調用門描述符中有效。
如果在利用調用門調用子程序時引起特權級的轉換和堆棧的改變,需要將外層堆棧中的參數復制到內層堆棧。
該雙字計數字段就是用于說明這種情況發生時,要復制的雙字參數的數量。 */
t_8 attr; /* P(1) DPL(2) DT(1) TYPE(4) */
t_16 offset_high; /* Offset High */
}GateDesc, *PGateDesc;
/* GDT 描述符指針結構 */
typedef struct DescPtr {
t_16 limit __attribute__((packed));
t_32 addr __attribute__((packed));
} *PDescPtr, DescPtr ;
//實模式中斷使用的寄存器,抱歉我只把需要的保存起來。
//如果其它的寄存器被改變,可能導致系統出錯。
typedef struct IntRegs{
t_16 ds;
t_16 es;
t_16 si;
t_16 di;
t_16 bx;
t_16 dx;
t_16 cx;
t_16 ax;
}*PIntRegs, IntRegs;
typedef struct _REGS
{
unsigned int gs, fs, es, ds;
unsigned int edi, esi, ebp, kesp, ebx, edx, ecx, eax;
unsigned int int_no, err_code;
unsigned int eip, cs, eflags, esp, ss;
}Regs, *PRegs; //19*4=76 Bytes
typedef struct tagProcessContext{
unsigned int gs, fs, es, ds, ss;
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
unsigned int eflags, cs, eip;
}ProcessContext, *PProcessContext;
#define REGSLEN sizeof(Regs)
#define GET_PROCESS_REGS(p) ((PRegs)((t_32)p+PROCESS_SIZE-REGSLEN) )
/* 描述符類型值說明 */
#define DA_32 0x4000 /* 32 位段 */
#define DA_LIMIT_4K 0x8000 /* 段界限粒度為 4K 字節 */
#define DA_DPL0 0x00 /* DPL = 0 */
#define DA_DPL1 0x20 /* DPL = 1 */
#define DA_DPL2 0x40 /* DPL = 2 */
#define DA_DPL3 0x60 /* DPL = 3 */
/* 存儲段描述符類型值說明 */
#define DA_DR 0x90 /* 存在的只讀數據段類型值 */
#define DA_DRW 0x92 /* 存在的可讀寫數據段屬性值 */
#define DA_DRWA 0x93 /* 存在的已訪問可讀寫數據段類型值 */
#define DA_C 0x98 /* 存在的只執行代碼段屬性值 */
#define DA_CR 0x9A /* 存在的可執行可讀代碼段屬性值 */
#define DA_CCO 0x9C /* 存在的只執行一致代碼段屬性值 */
#define DA_CCOR 0x9E /* 存在的可執行可讀一致代碼段屬性值 */
/* 系統段描述符類型值說明 */
#define DA_LDT 0x82 /* 局部描述符表段類型值 */
#define DA_TaskGate 0x85 /* 任務門類型值 */
#define DA_386TSS 0x89 /* 可用 386 任務狀態段類型值 */
#define DA_386CGate 0x8C /* 386 調用門類型值 */
#define DA_386IGate 0x8E /* 386 中斷門類型值 */
#define DA_386TGate 0x8F /* 386 陷阱門類型值 */
/* 選擇子類型值說明 */
/* 其中, SA_ : Selector Attribute */
#define SA_RPL_MASK 0xFFFC
#define SA_RPL0 0
#define SA_RPL1 1
#define SA_RPL2 2
#define SA_RPL3 3
#define SA_TI_MASK 0xFFFB
#define SA_TIG 0
#define SA_TIL 4
#define sti() __asm__ __volatile__ ("sti")
#define cli() __asm__ __volatile__ ("cli")
// 全局函數的聲明
void SetGate( UINT vector, UCHAR desc_type, PVOID handle );
void SetGDTDesc(UCHAR vector, ULONG base, ULONG limit, UINT attribute);
void SetIDTDesc(UCHAR vector, UCHAR desc_type,PVOID handler );
void SetLDTDesc(SegDesc *pDesc, ULONG base, ULONG limit, UINT attribute);
void ChangeIDTCS( UINT seg ); //for process
#endif //_I386_PROCESS_
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -