Page 1 of 1

Who could help me about calling gate

Posted: Mon Apr 25, 2011 7:28 pm
by leetow2003
I define a calling gate in GDT that it indicate a process,
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

Re: Who could help me about calling gate

Posted: Mon Apr 25, 2011 11:05 pm
by Combuster
I suppose your CLI thread hasn't taught you yet to read bochs messages and the manuals? Please do so.

I briefly went through your code - I couldn't find any information on what you are doing to cause the crash, where the crash actually happens, there is not even one line of meaningful comments. Which means you are making it too difficult for me to fix your problem.

Re: Who could help me about calling gate

Posted: Tue Apr 26, 2011 12:09 am
by Yargh
First: Exception handlers. If you had them your computer wouldn't be restarting, and you would know the cause and address of your problem. The address + objdump = you know where the problem is in your code.
Second: You don't have to put a comment on every whitespace line. They make it annoying to read through. Whitespace lines are ignored by the assembler, and having them doesn't change anything.