增加LDT任务描述任务
已有 219 次阅读2012-4-6 18:33
1.增加一个32位的代码段
; CodeA (LDT, 32 位代码段)
[SECTION .la]
ALIGN 32
[BITS 32]
LABEL_CODE_A:
mov ax, SelectorVideo
mov gs, ax
mov di, 160 * 10 + 10 * 2
mov ah, 0C
mov al, 'Y'
mov [gs:di], ax
jmp SelectorCode16:0
CodeALen equ $ - LABEL_CODE_A
; END of [SECTION .la]
2.增加一个段,内容是LDT描述符表
[SECTION .ldt]
ALIGN 32
LABEL_LDT:;
LABEL_LDT_DESC_CODEA: Descriptor 0, CodeALen - 1, DA_C + DA_32 ;CODE, 32位
LDT_LEN equ $ - LABEL_LDT
; LDT 选择子
SelectorLDTCodeA equ $ - LABEL_LDT + SA_TIL
; END of [SECTION .la]
3. 在GDT中增加一个描述符,用以描述这个LDT
LABEL_DESC_LDT: Descriptor 0, LDT_LEN - 1, DA_LDT ; LDT
4.增加新添的描述符初始化代码
; 初始化 LDT 描述符
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_LDT
mov word [LABEL_DESC_LDT + 2], ax
shr eax,16
mov byte [LABEL_DESC_LDT + 4], al
mov byte [LABEL_DESC_LDT + 7], ah
;初始化 LDT 中的描述符
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_CODE_A
mov word [LABEL_LDT_DESC_CODEA + 2], ax
shr eax,16
mov byte [LABEL_LDT_DESC_CODEA + 4], al
mov byte [LABEL_LDT_DESC_CODEA + 7], ah
5. 使用lldt加载ldtptr,用jmp跳转等指令方式运行
; Load LDT
mov ax, SelectorLDT
lldt ax
jmp SelectorLDTCodeA:0 ; 跳入局部任务