when I call this gate,My PC always restart,Look:
Code: Select all
CALL16 MACRO selector, offsetv
DB 9AH
DW offsetv
DW selector
ENDM
;=====================
jump macro selector,offsetv
db 0eah
dw offsetv
dw selector
endm
descriptor struc
limitl dw 0
basel dw 0
basem db 0
attributes dw 0
baseh db 0
descriptor ends
pdesc struc
limit dw 0
base dd 0
pdesc ends
gate struc
offsetl dw 0
selector dw 0
dcount db 0
gtype db 0
offseth dw 0
gate ends
;========================
.386P
;GDT
dseg segment use16
gdt label byte
dummy descriptor <>
;
code descriptor <0ffffh,,,98h,>
code_sel =code-gdt
;
stack descriptor <0ffffh,,,92h,>
stack_sel=stack-gdt
;
codec descriptor<codeclen-1,,,98h,>
codec_sel =codec-gdt
;
codecgate gate<offset cstart,codec_sel,0,8ch,0>
codecgate_sel = codecgate-gdt
;
gdtlen =$-gdt
;
vgdtr pdesc <gdtlen-1,>
;
dseg ends
;=====================
stackseg segment use16 stack
dw 512 dup(0)
stackseg ends
codecseg segment use16
assume cs:codecseg
cstart proc far
;========= I write only instruction retf
retf
cstart endp
codeclen =$-cstart
codecseg ends
;
cseg segment use16
assume cs:cseg, ds:dseg
start:
mov ax,dseg
mov ds,ax
;
mov bx,16
mul bx
add ax,offset gdt
adc dx,0
mov word ptr vgdtr.base,ax
mov word ptr vgdtr.base+2,dx
;
mov ax,cs
mul bx
mov code.basel,ax
mov code.basem,dl
mov code.baseh,dh
;
mov ax,codecseg
mul bx
mov codec.basel,ax
mov codec.basem,dl
mov codec.baseh,dh
;
mov ax,stackseg
mul bx
mov stack.basel,ax
mov stack.basem,dl
mov stack.baseh,dh
;
mov ax,dseg
mov ds,ax
lgdt fword ptr vgdtr
;
cli ;
mov eax,cr0
or eax,1
mov cr0,eax
;
jump <code_sel>,<offset virtual>
;
virtual:
CALL16 codecgate_sel,0 ;===============
;
mov eax,cr0
and eax,0fffffffeh
mov cr0,eax
;
jump <seg real>,<offset real>
;
real:
sti
mov ax,4c00h
int 21h
;
cseg ends
end start