OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Sep 20, 2020 5:50 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Who could help me and coreect errors?
PostPosted: Tue Jan 25, 2011 7:24 am 
Offline
Member
Member

Joined: Fri Nov 19, 2010 6:54 pm
Posts: 70
I want to learn call gate,and I write codes,but when it run,it is down,
who could help me?Thanks.
Look:
Code:
;----------------------------------------------
JUMP16  MACRO   selector, offsetv
        DB      0EAH           
        DW      offsetv       
        DW      selector       
        ENDM
;---------------------------------------------
CALL16  MACRO   selector, offsetv
        DB      9AH             
        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
GDTSEG SEGMENT PARA USE16
GDT LABEL BYTE
DUMMY DESCRIPTOR <>
;
DEMOTSS DESCRIPTOR <104,DEMOTSSSEG,,89H,>
DEMOTSS_SEL = DEMOTSS - GDT
;
DEMOLDTD DESCRIPTOR <DEMOLDTLEN-1,DEMOLDTSEG, , 82H,>
DEMOLDT_SEL = DEMOLDTD - GDT
;
TEMPCODE DESCRIPTOR <0FFFFH,TEMPCODESEG, ,98H, >
TEMPCODE_SEL = TEMPCODE - GDT

GDTLEN = $-GDT
GDTSEG ENDS

;----------------------------------------------------------
;LDT
DEMOLDTSEG SEGMENT PARA USE16
DEMOLDT LABEL BYTE
;
DEMOSTACK0 DESCRIPTOR <DEMOSTACK0LEN-1, DEMOSTACK0SEG, , 92H , >
DEMOSTACK0_SEL = (DEMOSTACK0 - DEMOLDT) + 04H
;
DEMOSTACK1 DESCRIPTOR <DEMOSTACK1LEN-1, DEMOSTACK1SEG, , 92H + 20H, >
DEMOSTACK1_SEL = (DEMOSTACK1-DEMOLDT) + 04H + 01H
;
DEMOSTACK3 DESCRIPTOR <DEMOSTACK3LEN -1, DEMOSTACK3SEG, , 92H + 60H, >
DEMOSTACK3_SEL = DEMOSTACK3-DEMOLDT + 04H + 03H
;
DEMOCODE DESCRIPTOR <DEMOCODELEN-1, DEMOCODESEG, , 98H + 60H, >
DEMOCODE_SEL = (DEMOCODE-DEMOLDT) + 04H + 03H
;
T32CODE DESCRIPTOR <T32CODELEN-1, T32CODESEG, , 98H , >
T32CODE_SEL = (T32CODE-DEMOLDT) + 04H
;
TOT32GATEA GATE <T32Begin,T32CODE_SEL, 0, 8CH,>
TOT32A_SEL = (TOT32GATEA-DEMOLDT) + 04H
;
TOT32GATEB GATE <T32End,T32CODE_SEL, 0, 8CH + 60H, 0>
TOT32B_SEL = (TOT32GATEB-DEMOLDT) + 04H
;
DEMOLDTLEN = $ - DEMOLDT
DEMOLDTSEG ENDS
;----------------------------------------------------------
;TSS
DEMOTSSSEG SEGMENT PARA USE16
DD 0
DW DEMOSTACK0LEN,0
DW DEMOSTACK0_SEL,0
DW DEMOSTACK1LEN,0
DW DEMOSTACK1_SEL,0
DD ?
DW ?, 0
DD 0
DD ?
DD ?
DD ?
DD ?
DD ?
DD ?
DD ?
DD ?
DD ?
DD ?
DW ?, 0
DW ?, 0
DW ?, 0
DW ?, 0
DW ?, 0
DW ?, 0
DW DEMOLDT_SEL, 0
DW 0
DW $ + 2
DB 0FFH
DEMOTSSSEG ENDS
;----------------------------------------------------------
DEMOSTACK0SEG SEGMENT PARA USE16
   DEMOSTACK0LEN = 512
   DB DEMOSTACK0LEN DUP(0)
DEMOSTACK0SEG ENDS
;----------------------------------------------------------
DEMOSTACK1SEG SEGMENT PARA USE16
   DEMOSTACK1LEN = 512
   DB DEMOSTACK1LEN DUP(0)
DEMOSTACK1SEG ENDS
;----------------------------------------------------------
DEMOSTACK3SEG SEGMENT PARA USE16
   DEMOSTACK3LEN = 512
   DB DEMOSTACK3LEN DUP(0)
DEMOSTACK3SEG ENDS
;----------------------------------------------------------

;----------------------------------------------------------
DEMOCODESEG SEGMENT PARA USE16
      ASSUME CS:DEMOCODESEG
DEMOBEGIN:
    CALL16 TOT32B_SEL, 0
DEMOCODELEN = $ - DEMOBEGIN
DEMOCODESEG ENDS
;----------------------------------------------------------

T32CODESEG SEGMENT PARA USE16   
         ASSUME CS:T32CODESEG
T32BEGIN:
     ;
     MOV AX, DEMOSTACK0_SEL
     MOV SS, AX
     MOV ESP, DEMOSTACK0LEN
     ;
     PUSH DWORD PTR DEMOSTACK3_SEL
     PUSH DWORD PTR DEMOSTACK3LEN
     ;
     PUSH DWORD PTR DEMOCODE_SEL
     PUSH OFFSET DEMOBEGIN
     ;
     RETF
T32END:
    JUMP16 TEMPCODE_SEL, <OFFSET TOREAL>
T32CODELEN = $ - T32BEGIN
T32CODESEG ENDS
;----------------------------------------------------------
TEMPCODESEG SEGMENT PARA USE16
            ASSUME CS:TEMPCODESEG
VIRTUAL:
      ;Load TR
      MOV AX, DEMOTSS_SEL
      LTR AX
      ;Load LDTR
      MOV BX, DEMOLDT_SEL
      LLDT BX
      ;
      JUMP16 TOT32A_SEL, 0
TOREAL:
     ;
     MOV EAX, CR0
     AND AX, 0FFFEH
     MOV CR0, EAX
     JUMP16 <SEG REAL>, <OFFSET REAL>
TEMPCODELEN = $ - VIRTUAL
TEMPCODESEG ENDS
;----------------------------------------------------------
RDATASEG SEGMENT PARA USE16
         VGDTR PDESC <GDTLEN-1, >
RDATASEG ENDS
;----------------------------------------------------------
RCODESEG SEGMENT PARA USE16
         ASSUME CS:RCODESEG
START:
        ;Set GDT Segment
        ASSUME  DS:GDTSEG 
        MOV     AX,GDTSEG
        MOV     DS,AX
   ;
   MOV     BX,16
        MOV     AX,DEMOTSSSEG 
        MUL     BX
        MOV     DEMOTSS.BASEL,AX
        MOV     DEMOTSS.BASEM,DL
        MOV     DEMOTSS.BASEH,DH
        ;
        MOV     AX,DEMOLDTSEG
        MUL     BX
        MOV     DEMOLDTD.BASEL,AX
        MOV     DEMOLDTD.BASEM,DL
        MOV     DEMOLDTD.BASEH,DH
        ;
        MOV     AX,TEMPCODESEG
        MUL     BX
        MOV     TEMPCODE.BASEL,AX
        MOV     TEMPCODE.BASEM,DL
        MOV     TEMPCODE.BASEH,DH
   ;Set LDT Segment
        ASSUME  DS:DEMOLDTSEG
        MOV     AX,DEMOLDTSEG
        MOV     DS,AX
        MOV     BX,16
        MOV     AX,DEMOSTACK0SEG   
        MUL     BX
        MOV     DEMOSTACK0.BASEL,AX
        MOV     DEMOSTACK0.BASEM,DL
        MOV     DEMOSTACK0.BASEH,DH
        ;
        MOV     AX,DEMOSTACK1SEG   
        MUL     BX
        MOV     DEMOSTACK1.BASEL,AX
        MOV     DEMOSTACK1.BASEM,DL
        MOV     DEMOSTACK1.BASEH,DH
   ;
   MOV     AX,DEMOSTACK3SEG   
        MUL     BX
        MOV     DEMOSTACK3.BASEL,AX
        MOV     DEMOSTACK3.BASEM,DL
        MOV     DEMOSTACK3.BASEH,DH
   ;
        MOV     AX,DEMOCODESEG 
        MUL     BX
        MOV     DEMOCODE.BASEL,AX
        MOV     DEMOCODE.BASEM,DL
        MOV     DEMOCODE.BASEH,DH
        ;
        MOV     AX,T32CODESEG 
        MUL     BX
        MOV     T32CODE.BASEL,AX
        MOV     T32CODE.BASEM,DL
        MOV     T32CODE.BASEH,DH
        ;
        ASSUME  DS:RDATASEG
        MOV     AX, RDATASEG
        MOV     DS, AX
   MOV     BX,16
        MOV     AX,GDTSEG
        MUL     BX
        MOV     WORD PTR VGDTR.BASE,AX
        MOV     WORD PTR VGDTR.BASE+2,DX
        LGDT    FWORD PTR VGDTR
        CLI
        ;
   call ea20           
        MOV     EAX,CR0
        OR      EAX,1
        MOV     CR0,EAX
        ;
       JUMP16 TEMPCODE_SEL, <OFFSET VIRTUAL>
REAL:
       STI
       call da20
       MOV AX, 4C00H
       INT 21H
;-----------------------------------
ea20        proc  near
            push  ax
            in    al,92h
            or    al,2
            out   92h,al
            pop   ax
            ret
ea20        endp
;
;
da20        proc near
            push  ax
            in    al,92h
            and   al,0fdh     ;0fdh=not 20h
            out   92h,al
            pop   ax
            ret
da20        endp
;-------------------------------------
RCODESEG ENDS
END START


EDIT: Brendan added some code tags..


Top
 Profile  
 
 Post subject: Re: Who could help me and coreect errors?
PostPosted: Tue Jan 25, 2011 7:59 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9287
Location: On the balcony, watching the Swedish Chef
Use code tags, and "does not work" is not a valid description.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Who could help me and coreect errors?
PostPosted: Tue Jan 25, 2011 8:17 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7466
Location: Germany
  • Comment your code. Comments tell other people what you think each piece of code does, which makes it easier to tell if a strange piece of code is a bug or just an unexpected approach to things. This applies to all coding, not just code you prepare for a forum posting.
  • Ease up on the CAPS LOCK. Most people on the 'net consider ALL UPPERCASE to be the equivalent of "shouting", and most programmers consider lowercase to be easier to read.
  • As Combuster said, you should have followed (read?) the forum rules, or have payed attention to the input page, and you would have found the [ code ] tags that would have made your code much easier to read (as well as pointing out the rest of what I am writing right now, too).
  • Typos, bad grammar and bad punctuation can happen, but they do add to the impression of carelessness, which does not increase your chances of getting a helpful reply.
  • "When it run,it is down" is not a valid error description. At the very least:
    • What was your command line for the assembler?
    • How did you try to run it? (Floppy image? HD image? CD image? USB stick? QEMU? Bochs? Real hardware?)
    • What was the exact behaviour? (Hung? Reboot?)
  • And last, but not least, try to apply Solar's Machete. Try to verify your assumptions. Try to find out where exactly your code stops working.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: Who could help me and coreect errors?
PostPosted: Tue Jan 25, 2011 1:51 pm 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 674
The new IP, CS, SP and SS should all be word-sized, since you are performing a 16-bit RETF.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], thewrongchristian and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group