|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
下面这段代码,本意是跳入LDT的,但是执行会不断的循环,稍微跟了一下,发现out 0x92,al这句,执行会跳回起始地址,很郁闷!这句以前可没有错过,先留存,以后有时间在耐心看吧!
org 0x100
jmp LABEL_BEGIN
LABEL_GDT dw 0,0,0,0
LABEL_DESC_CODE32 dw SegCode32Len - 1,0,0x9800,0x0040
LABEL_DESC_VIDEO dw 0xffff,0x8000,0x920b,0x0040
LABEL_DESC_LDT dw LdtLen - 1,0,0x8200,0x0040
GdtLen equ $ - LABEL_GDT
GdtPtr dw GdtLen - 1
dd 0
SelectorCode32 equ LABEL_DESC_CODE32 - LABEL_GDT
SelectorVideo equ LABEL_DESC_VIDEO - LABEL_GDT
SelectorLdt equ LABEL_DESC_LDT - LABEL_GDT
LABEL_LDT:
LABEL_DESC_CODEA dw SegCodeALen - 1,0,0x9800,0x0040
LdtLen equ $ - LABEL_LDT
SelectorCodeA equ LABEL_DESC_CODEA - LABEL_LDT + 4
LABEL_BEGIN:
mov ax,cs
mov ds,ax
mov ss,ax
mov sp,0x100
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_SEG_CODE32
mov [LABEL_DESC_CODE32 + 2],ax
shr eax,16
mov [LABEL_DESC_CODE32 + 4],al
mov [LABEL_DESC_CODE32 + 7],ah
; Code32 Segment Init
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_GDT
mov [GdtPtr + 2],eax
; GDT init
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_LDT
mov [LABEL_DESC_LDT + 2],ax
shr eax,16
mov [LABEL_DESC_LDT + 4],al
mov [LABEL_DESC_LDT + 7],ah
; Ldt(GDT)
xor eax,eax
mov ax,cs
shl eax,4
add eax,LABEL_SEG_CODEA
mov [LABEL_DESC_CODEA + 2],ax
shr eax,16
mov [LABEL_DESC_CODEA + 4],al
mov [LABEL_DESC_CODEA + 7],ah
; Ldt init
lgdt [GdtPtr]
cli
in al,0x92
or al,1
out 0x92,al
mov eax,cr0
or al,2
mov cr0,eax
jmp dword SelectorCode32:0
[bits 32]
[section text]
LABEL_SEG_CODE32:
mov ax,SelectorVideo
mov gs,ax
mov al,'P'
mov ah,0xc
mov [gs:0],ax
mov ax,SelectorLdt
lldt ax
jmp dword SelectorCodeA:0
SegCode32Len equ $ - LABEL_SEG_CODE32
LABEL_SEG_CODEA:
mov al,'L'
mov ah,0xc
mov [gs:4],ax
jmp $
SegCodeALen equ $ - LABEL_SEG_CODEA
|
|