home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 7.ddi / EXAMPLES / GRAPHICS / REAL.ASM < prev   
Encoding:
Assembly Source File  |  1991-02-04  |  5.3 KB  |  201 lines

  1.     .386r
  2. ;
  3. ;    real.asm - Real mode assembler code for gserver
  4. ;
  5. ;************************************************************************/
  6. ;*    Copyright (C) 1986-1988 Phar Lap Software, Inc.            */
  7. ;*    Unpublished - rights reserved under the Copyright Laws of the    */
  8. ;*    United States.  Use, duplication, or disclosure by the         */
  9. ;*    Government is subject to restrictions as set forth in         */
  10. ;*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  11. ;*    Computer Software clause at 252.227-7013.            */
  12. ;*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  13. ;************************************************************************/
  14.  
  15.  
  16.     extrn    _gserver:far,_exit:far
  17.  
  18.     assume    cs:codeseg
  19.  
  20. codeseg    segment public byte 'code'
  21.  
  22.  
  23. ;
  24. ;    Variables used by this assembly language code
  25. ;
  26.  
  27. dssave    dw    ?        ; Real mode DS register
  28. sssave    dw    ?        ; Real mode SS register
  29. essave    dw    ?        ; Real mode ES register
  30. spsave    dw    ?        ; Real mode SP register
  31. bpsave    dw    ?        ; Real mode BP register
  32.  
  33. realpsp    dw    ?        ; Real mode PSP pointer
  34. protpsp    dw    ?        ; Protected mode PSP pointer
  35.  
  36. spsave2 dw    ?        ; SP register provided by DOS-Extender
  37. sssave2    dw    ?        ; SS register provided by DOS-Extender
  38.  
  39. reptr    dd    _reenter    ; Far pointer to _reenter
  40.  
  41. ;
  42. ;    protret - Return from real mode back to protected mode
  43. ;
  44. ;    This routine is called by the real mode server when
  45. ;    initialization of the server has been completed.  It returns
  46. ;    to the protected mode code which loaded the real mode server.
  47. ;    It returns by calling the 386|DOS-Extender protected mode
  48. ;    call function.  The address of this function as well as the
  49. ;    protected mode return address are taken from the parameter
  50. ;    block that is passed into the real mode server as the command
  51. ;    tail by the protected mode code.
  52. ;
  53.  
  54.     public    _protret
  55.  
  56. _protret proc    far
  57.  
  58. ;    First, the real mode PSP segment pointer, the real mode segment
  59. ;    registers, and the real mode stack are saved for future calls
  60. ;    to the real mode server.
  61.  
  62.     mov    ah,62h        ; Get the address of the PSP into ES.
  63.     int    21h        ;
  64.     mov    es,bx        ;
  65.  
  66.     mov    realpsp,bx    ; Save the real mode PSP pointer.
  67.  
  68.     mov    dssave,ds    ; Save the current real mode registers.
  69.     mov    sssave,ss    ;
  70.     mov    essave,es    ;
  71.     mov    bpsave,bp    ;
  72.     mov    ax,sp        ;
  73.     sub    ax,20h        ;
  74.     mov    spsave,ax    ;
  75.  
  76. ;     The following sanity check is done to make sure that the
  77. ;    we were called by a protected mode program
  78.  
  79.     mov    al,es:80h    ; Branch if the length of the command
  80.     cmp    al,12        ;    tail is not 12.
  81.     jne    #err        ;
  82.  
  83. ;    Save the segment address of the protected mode PSP for future
  84. ;    calls into the real mode code.
  85.  
  86.     mov    ax,es:8bh    ; Save the protected mode PSP.
  87.     mov    protpsp,ax    ;
  88.  
  89. ;    Return to protected mode via 386|DOS-Extender
  90.  
  91.     sub    ax,ax        ; Zero the parameter block pointer on
  92.     push    ax        ;    the stack.
  93.     push    ax        ;
  94.  
  95.     mov    ax,es:89h    ; Push the prot mode CS onto
  96.     push    ax        ;    the stack.
  97.  
  98.     mov    ax,es:87h    ; Push the protected mode return address
  99.     push    ax        ;    onto the stack.
  100.     mov    ax,es:85h    ;
  101.     push    ax        ;
  102.  
  103.     mov    eax,reptr    ; Load a far pointer to the re-enter routine
  104.                 ;    into EAX.
  105.  
  106.     call    es:(dword ptr 81h) ; Call back into protected mode.
  107.  
  108. ;    When the protected mode code returns to this point, it wants us
  109. ;    to exit.
  110.  
  111. ;    Switch to the real mode PSP so that MS-DOS is all happy.
  112.  
  113.     mov    ah,50h        ; Restore the real mode PSP.
  114.     mov    bx,realpsp    ;
  115.     int    21h        ;
  116.  
  117. ;    Call the C exit routine to terminate and go back to protected mode
  118. ;    forever.
  119.  
  120.     push    0        ; Call the C exit routine.
  121.     call    _exit        ;
  122.  
  123.  
  124. ;    Fatal error handler.
  125.  
  126. #err:    mov    dx,offset #errmsg; Output a fatal error message.
  127.     push    cs        ;
  128.     pop    ds        ;
  129.     mov    ah,9h        ;
  130.     int    21h        ;
  131.  
  132.     mov    ax,4c01h    ; Abort.
  133.     int    21h        ;
  134.  
  135. #errmsg    db    'Fatal error: Bad call to real mode server.',0dh,0ah,'$'
  136.  
  137. _protret endp
  138.  
  139.  
  140. ;
  141. ;    _reenter - Re-enter point for real mode
  142. ;
  143. ;    This routine is called from protected mode.  Its job is
  144. ;    to restore the real mode segment registers, stack, and PSP
  145. ;    and then to call the server.
  146. ;
  147.  
  148.     public    _reenter
  149.  
  150. _reenter proc    far
  151.  
  152. ;    First load the segment:offset address of the communcations buffer
  153. ;    into EDX.  We do this now because the address is on the stack and
  154. ;    we are about to switch stacks.
  155.  
  156.     mov    bp,sp        ; Load from the stack, the far pointer to 
  157.     mov    edx,4[bp]    ;    communications buffer into EDX.
  158.  
  159. ;    Now switch stacks and restore the real mode segment registers.
  160.  
  161.     mov    spsave2,sp    ; Save the stack pointer (SS:SP) given to us 
  162.     mov    sssave2,ss    ;    by 386|DOS-Extender.
  163.  
  164.     mov    ds,dssave    ; Restore the real mode registers and switch
  165.     mov    es,essave    ;    stacks.
  166.     mov    ss,sssave    ;
  167.     mov    sp,spsave    ;
  168.     mov    bp,bpsave    ;
  169.  
  170. ;    Switch to the real mode PSP so that MS-DOS is all happy.
  171.  
  172.     mov    ah,50h        ; Restore the real mode PSP.
  173.     mov    bx,realpsp    ;
  174.     int    21h        ;
  175.  
  176. ;    Call the server with the address of the commuications buffer
  177. ;    pushed onto the stack as an argument
  178.  
  179.     push    edx        ; Call the graphics server.
  180.     call    _gserver    ;
  181.  
  182. ;    Switch back to the protected mode PSP so that MS-DOS stays happy
  183.  
  184.     mov    ah,50h        ; Switch back to the protected mode PSP.
  185.     mov    bx,protpsp    ;
  186.     int    21h        ;
  187.  
  188. ;    Switch back to the stack provided by 386|DOS-Extender and then
  189. ;    return back to the caller that is running in protected mode.
  190.  
  191.     mov    ss,sssave2    ; Switch back to the stack provided by
  192.     mov    sp,spsave2    ;    386|DOS-Extender.
  193.  
  194.     ret            ; Return back to protected mode caller.
  195.  
  196. _reenter endp
  197.  
  198. codeseg    ends
  199.  
  200.     end
  201.