%include "F:\虚拟机\玩转文件\pm.inc"
org 0100h
jmp Code16
[SECTION .Gdtdes]
LABLE_GDT :Descriptor 0,0,0
LABEL_DESC_NORMAL:Descriptor 0, 0ffffh,92h;
LABLE_CODE32 :Descriptor 0,SEGCODE32-1,4098H;
LABLE_DATA32 :Descriptor 0,SEGDATA32-1,92H;
LABEL_DESC_VIDEO :Descriptor 0B8000h,0ffffh, 92H;
LABLE_CODE16 :Descriptor 0,0ffffh,98H;
LABLE_STACK :Descriptor 0,TopofStack,4093H;
LABLE_CALL_GATE: Gate seclectorcode32,Ulen,0,8ch;;调用门描述符
LABLE_LDT :Descriptor 0,LDTLen-1,82H;
GdtLen equ $-LABLE_GDT
GdtPtr dw GdtLen-1
dd 0
SelectorNormal equ LABEL_DESC_NORMAL - LABLE_GDT
seclectorcode32 equ LABLE_CODE32 - LABLE_GDT
seclectorcode16 equ LABLE_CODE16 - LABLE_GDT
seclectordata32 equ LABLE_DATA32 - LABLE_GDT
SelectorVideo equ LABEL_DESC_VIDEO - LABLE_GDT
seclectorstack equ LABLE_STACK - LABLE_GDT
seclectorLDT equ LABLE_LDT - LABLE_GDT
Selectorcallgate equ LABLE_CALL_GATE-LABLE_GDT;---------;调用门选择子
[SECTION .data]
ALIGN 32 ;
[BITS 32]
Data32 db "In protect model Now.LYHL",0;--------------------30
DataF equ Data32 - $$
Data16 db "In real model Now.LYHL ",0
DataN equ Data16 - $$
SEGDATA32 equ $-Data32
[SECTION .stack];------------------------------34+2+2
ALIGN 32
[BITS 32]
Stack:
times 512 db 0
TopofStack equ $-Stack-1
[SECTION .ccode16]
ALIGN 32
[BITS 16];----------------------------------43
Code16:
MOV AX,CS
MOV DS,AX
mov es,ax
mov [ww+3],ax
XOR EAX,EAX
;--------------------------------------------50
mov ax,cs
SHL EAX,4
ADD EAX,Data32
mov [LABLE_DATA32+2],ax
shr eax,16
mov [LABLE_DATA32+4],al
mov [LABLE_DATA32+7],ah
;---------------------58
XOR EAX,EAX
mov ax,cs
SHL EAX,4
ADD EAX,Code32
mov [LABLE_CODE32+2],ax
shr eax,16
mov [LABLE_CODE32+4],al;---------------------65
mov [LABLE_CODE32+7],ah
;----------------------------------------67
XOR EAX,EAX
mov ax,cs
SHL EAX,4
ADD EAX,MCode16
mov [LABLE_CODE16+2],ax
shr eax,16
mov [LABLE_CODE16+4],al
mov [LABLE_CODE16+7],ah
;-------------------------------------------77
XOR EAX,EAX
mov ax,cs
SHL EAX,4
ADD EAX,Stack
mov [LABLE_STACK+2],ax
shr eax,16
mov [LABLE_STACK+4],al;--------------84
mov [LABLE_STACK+7],ah
;---------------------------------86
mov ax,cs
SHL EAX,4
ADD EAX,LDT_LDT
mov [LABLE_LDT+2],ax
shr eax,16
mov [LABLE_LDT+4],al
mov [LABLE_LDT+7],ah
mov ax,cs
SHL EAX,4
ADD EAX,Cjum
mov [LDT_CODE32+2],ax
shr eax,16
mov [LDT_CODE32+4],al
mov [LDT_CODE32+7],ah
xor eax,eax
mov ax,ds
shl eax,4
add eax,LABLE_GDT;---------------99+9
mov dword [GdtPtr+2],eax
lgdt [GdtPtr]
cli
;;----------------------------------95
in al,92h
or al,00000010b
out 92h,al
mov eax,cr0;--------------------------------100
or eax,1
mov cr0,eax
jmp dword seclectorcode32:0
LABEL_REAL:
mov ax,cs
mov ds, ax
mov es, ax
mov ss, ax
;--------------------------------------------111
IN AL,92H
AND AL,11111101b
OUT 92H,AL
sti;
mov ax,0B800h
mov es,ax
mov cx,10
mov edi,(80*5+5)*2
mov ah,0Ch
mov esi,Data16
sv: ;----------------------------125
mov al,[ds:esi]
test al,al
jz ddos
mov [es:edi],ax
inc esi
add edi,2
;-------------------------------------------------133
jmp sv
ddos:
MOV AX,4C00H
INT 21H
[SECTION .code32]
ALIGN 32
[BITS 32]
Code32:
;------------------------------------------144
xor eax,eax
mov ax,seclectordata32
mov ds,ax
xor edi,edi
mov edi,(80*10+0)*2
xor esi,esi
mov esi,DataF
;------------------------------------------153
mov ax,seclectorstack
mov ss,ax
mov esp,TopofStack
mov ax,SelectorVideo
mov gs,ax
mov ah,0Ch
xy:
mov al,[esi]
test al,al;-----------164
jz qq
mov [gs:edi],ax
inc esi
add edi,2
;--------------------------------------169
jmp xy
qq:
mov ax,seclectorLDT
lldt ax
jmp LDTseclectorLDT:0
Mjup:
jmp seclectorcode16:0
UseofStack:
push edi
push gs
push ax
push cx
mov edi,(80*20+0)*2
xor ecx,ecx
mov cx,10
kk: ;-----------------------------------------181+1+2+1
mov al,6
mov [gs:edi],ax;
add edi,2
loop kk
pop cx
pop ax
pop gs
pop edi
retf
Ulen equ UseofStack-Code32
Mojup equ Mjup-Code32
SEGCODE32 equ $ - Code32
[SECTION .code16]
ALIGN 32
[BITS 16]
MCode16:
mov ax,SelectorNormal
mov ds,ax;---------------------199+2+1+1
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov eax,cr0
and al,11111110b
mov cr0,eax
ww:
jmp 0:LABEL_REAL
[SECTION .Ldtdes];****************************************234
ALIGN 32
LDT_LDT:
LDT_CODE32 :Descriptor 0,LCode32-1,4098h
LDTLen equ $-LDT_LDT
LDTseclectorLDT equ LDT_CODE32-LDT_LDT+4;***********************240
[SECTION .LdtCode32]
ALIGN 32
[BITS 32]
Cjum:
mov ax,SelectorVideo
mov gs,ax
mov ah,0Ch
;call seclectorcode32:Ulen
call Selectorcallgate:0;;;;;;;;;;;;;;;;;;;利用调用门进入目标段
jmp seclectorcode32:Mojup
Cojum equ Cjum-$$
LCode32 equ $-Cjum