asm.h

// 用來定義段描述符的宏 

//
// assembler macros to create x86 segments
//

// 定義了一個空段描述符 

#define SEG_NULLASM                                             \
        .word 0, 0;                                             \
        .byte 0, 0, 0, 0

//  以type,base,lim爲參數定義一個段描述符, 其中的0xC0=(1100)2, 其
//  中的第一個1對應於段描述符中的G位,置1表示段界限以4KB爲單位
//  第二個1對應於段描述符的D位,置1表示這是一個保護模式下的段描述符
//  具體的關於段描述符的格式定義在mmu.h中 
 
// The 0xC0 means the limit is in 4096-byte units
// and (for executable segments) 32-bit mode.
#define SEG_ASM(type,base,lim)                                  \
        .word (((lim) >> 12) & 0xffff), ((base) & 0xffff);      \
        .byte (((base) >> 16) & 0xff), (0x90 | (type)),         \
                (0xC0 | (((lim) >> 28) & 0xf)), (((base) >> 24) & 0xff)

//  可執行段 
#define STA_X     0x8       // Executable segment
//  非可執行段 
#define STA_E     0x4       // Expand down (non-executable segments)
//  只能執行的段 
#define STA_C     0x4       // Conforming code segment (executable only)
//  可寫段但是不能執行的段 
#define STA_W     0x2       // Writeable (non-executable segments)
//  可讀可執行的段 
#define STA_R     0x2       // Readable (executable segments)
//  表明描述符是否已被訪問;把選擇字裝入段寄存器時,該位被標記爲1 
#define STA_A     0x1       // Accessed



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章