home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / utils / amd-udi / udi / dostip.asm < prev    next >
Encoding:
Assembly Source File  |  1993-12-23  |  10.5 KB  |  399 lines

  1. ;******************************************************************************
  2. ;* Copyright 1991 Advanced Micro Devices, Inc.
  3. ;*
  4. ;* This software is the property of Advanced Micro Devices, Inc  (AMD)  which
  5. ;* specifically  grants the user the right to modify, use and distribute this
  6. ;* software provided this notice is not removed or altered.  All other rights
  7. ;* are reserved by AMD.
  8. ;*
  9. ;* AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
  10. ;* SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
  11. ;* DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
  12. ;* USE OF THIS SOFTWARE.
  13. ;*
  14. ;* Comments about this software should be directed to udi@amd.com. If access
  15. ;* to electronic mail isn't available, send mail to:
  16. ;*
  17. ;* Advanced Micro Devices, Inc.
  18. ;* 29K Support Products
  19. ;* Mail Stop 573
  20. ;* 5900 E. Ben White Blvd.
  21. ;* Austin, TX 78741
  22. ;* 800-292-9263
  23. ;*****************************************************************************
  24. ;*       $Id: dostip.asm,v 1.2 1993/12/23 04:44:45 cassidy Exp $
  25. ;*     $Id: @(#)dostip.asm    2.7, AMD
  26. ;******************************************************************************
  27. ;*/
  28.  
  29. IFNDEF DOS386
  30.     DOSSEG
  31.     .MODEL    LARGE
  32.     PUBLIC    _UDIASMConnect
  33.     PUBLIC    _UDIASMDisconnect
  34.     EXTRN    _UDICDisconnect:FAR
  35.     EXTRN    _UDICConnect:FAR
  36.     .CODE
  37. ELSE
  38. ;
  39. ; Segment ordering and attributes for DOS386.  We make sure the
  40. ; real mode code and data comes first.  The real and
  41. ; prot mode data are together so they can be grouped.
  42. ;
  43.  
  44. rmcode    segment byte public use16
  45. ; We need to mark the first byte in rmcode to figure the real segment value
  46.     public   rmcode_firstbyte
  47. rmcode_firstbyte    label byte
  48.  
  49. rmcode    ends
  50. rmdata    segment dword public use16
  51. rmdata    ends
  52. pmdata    segment dword public use32
  53. pmdata    ends
  54. pmcode    segment byte public use32
  55. pmcode    ends
  56. dgroup    group    rmdata,pmdata
  57.  
  58.  
  59.  
  60. rmcode segment        ; _UDIASMDisconnect will be in rmcode segment
  61.  
  62. ENDIF
  63.  
  64.  
  65.     INCLUDE udidos.ah        ; TermStruct Definitions from DFE
  66.  
  67. _UDIASMDisconnect    LABEL   FAR
  68. ;
  69. ; Save off important stuff in structure whose address
  70. ; is given as third parameter to this function.
  71.     mov    bx, sp
  72.     les    bx, ss:8[bx]
  73.     mov    es:[bx].sss, ss
  74.     mov    es:[bx].ssp, sp
  75.     mov    es:[bx].ssi, si
  76.     mov    es:[bx].sdi, di
  77.     mov    es:[bx].sbp, bp
  78.     mov    es:[bx].sds, ds
  79.  
  80. IFNDEF DOS386
  81.     jmp    _UDICDisconnect        ; real mode, just jump to the C routine
  82. ELSE
  83.     jmp    rm_UDIDisconnect    ; DOS386, jump to the real mode stub
  84. ENDIF
  85.  
  86. _UDIASMConnect    LABEL   FAR
  87. ;
  88. ; Save off important stuff in structure whose address
  89. ; is given as third parameter to this function.
  90.     mov    bx, sp
  91.     les    bx, ss:12[bx]
  92.     mov    es:[bx].sss, ss
  93.     mov    es:[bx].ssp, sp
  94.     mov    es:[bx].ssi, si
  95.     mov    es:[bx].sdi, di
  96.     mov    es:[bx].sbp, bp
  97.     mov    es:[bx].sds, ds
  98. IFNDEF DOS386
  99.     jmp    _UDICConnect        ; real mode, just jump to the C routine
  100. ELSE
  101.     jmp    rm_UDIConnect        ; DOS386, jump to the real mode stub
  102. ENDIF
  103.  
  104. IFDEF DOS386
  105.     ; Note: the rest of this file is just DOS386 support
  106.  
  107. rmcode ends
  108.  
  109. ;
  110. ; Data that needs to be accessed in both real
  111. ; mode and protected mode
  112. ;
  113. rmdata    segment
  114.  
  115.     public code_selector, data_selector, call_prot
  116.     public    segregblock
  117.     ; these get filled in by protected mode startup code
  118. code_selector  DW ?
  119. data_selector  DW ?
  120. call_prot    DD ?
  121. segregblock    DW ?    ; ds value    ; seg reg block filled in at startup time
  122.         DW ?    ; es value
  123.         DW ?    ; fs value
  124.         DW ?    ; gs value
  125.  
  126.     public TIPName
  127. TIPName        DB  256 DUP(?)
  128.  
  129.     public TIPVecRec
  130. TIPVecRec    DB  0,0,0,0    ; will get filled in by main
  131.          DD  0        ; next ptr
  132.         DD  0        ; prev ptr
  133.         DD  TIPName    ; exeName
  134.                 ; the other entries get added by the udi_table macro below
  135. TIPVecRecEnd    LABEL BYTE
  136.  
  137. rmdata    ends
  138.  
  139.  
  140.  
  141.  
  142. ;
  143. ; Data that is only accessed in prot mode
  144. ;
  145.     extrn  conventional_memory:DWORD    ; set up by dx_map_physical
  146.     extrn  stack_table: DWORD        ; set up by C-level code.
  147.  
  148. pmdata   segment
  149. dos386glue_table LABEL DWORD    ; so we can reference it later in the udi_table macro
  150.                 ; the entries get added by the udi_table macro below
  151. pmdata   ends
  152.  
  153.  
  154.  
  155. ;; The udi_table macro does three things
  156. ;;    1) generates real mode entry point for each UDI function
  157. ;;       This code just sets an index in bl and jumps to rm_common
  158. ;;    2) adds an entry into the TIPVecRec to point to the above real mode entry point
  159. ;;    3) adds an entry into the dos386glue_table table which is used by the prot.mode stub
  160. ;;       to call the actual C glue routine.
  161.  
  162. udi_table    MACRO   UDIProcName,val
  163. rmcode segment
  164.     public    rm_&UDIProcName
  165. rm_&UDIProcName LABEL NEAR
  166.     mov    bl, val        ;; bl will indicate which UDI Proc was called
  167.     jmp    short rm_common
  168. rmcode  ends
  169.  
  170. rmdata segment
  171.     ORG    TIPVecRec + 16 + 4*val    ;; Entry in TIPVecRec (+16 for first 4 fields)
  172.     IF    val EQ 0
  173.     DD    _UDIASMConnect        ;; special case for Connect
  174.     ELSE
  175.     IF    val EQ 1
  176.     DD    _UDIASMDisconnect    ;; special case for Disconnect
  177.     ELSE
  178.     DD    rm_&UDIProcName        ;; normal entry is rm_ stub
  179.     ENDIF
  180.     ENDIF
  181. rmdata ends
  182.  
  183. pmdata segment
  184.     EXTRN    d386_&UDIProcName:NEAR
  185.     ORG    dos386glue_table + 4*val    ;; this builds the jump table that pmstub uses
  186.     DD    d386_&UDIProcName
  187. pmdata ends
  188.  
  189.     ENDM
  190.  
  191.     udi_table   UDIConnect,0
  192.     udi_table   UDIDisconnect,1
  193.         udi_table   UDISetCurrentConnection,2
  194.         udi_table   UDICapabilities,3
  195.         udi_table   UDIGetErrorMsg,4
  196.         udi_table   UDIGetTargetConfig,5
  197.         udi_table   UDICreateProcess,6
  198.         udi_table   UDISetCurrentProcess,7
  199.         udi_table   UDIDestroyProcess,8
  200.         udi_table   UDIInitializeProcess,9
  201.         udi_table   UDIRead,10
  202.         udi_table   UDIWrite,11
  203.         udi_table   UDICopy,12
  204.         udi_table   UDIExecute,13
  205.         udi_table   UDIStep,14
  206.         udi_table   UDIStop,15
  207.         udi_table   UDIWait,16
  208.         udi_table   UDISetBreakpoint,17
  209.         udi_table   UDIQueryBreakpoint,18
  210.         udi_table   UDIClearBreakpoint,19
  211.         udi_table   UDIGetStdout,20
  212.         udi_table   UDIGetStderr,21
  213.         udi_table   UDIPutStdin,22
  214.         udi_table   UDIStdinMode,23
  215.         udi_table   UDIPutTrans,24
  216.         udi_table   UDIGetTrans,25
  217.         udi_table   UDITransMode,26
  218.  
  219.  
  220. rmcode  segment
  221.     ASSUME    nothing, CS:rmcode    ; all we know is that CS=rmcode
  222.  
  223.  
  224.     ; Common real mode stub code
  225.     ; bl is an index indicating which UDI function was called
  226.     ; we need to switch to protected mode (ebx will be passed thru unchanged)
  227. rm_common  PROC FAR        ; UDI always called as far (real mode)
  228.     push    ds        ; save ds
  229.     push    bp        ; and save bp
  230.     push    si        ; and si, di
  231.     push    di
  232.                 ; note: if anything else gets pushed here, you must
  233.                 ; change the MSCPARAMS macro in dos386c.c
  234.     push    cs
  235.     pop    ds        ; set ds = cs
  236.     ASSUME ds:dgroup
  237.     ; to switch to protected mode, we push a dword ptr to a block which
  238.     ; contains the protected mode segment registers to use
  239.     ; and we push the 48-bit protected address of pmstub
  240.     ; then we call the call_prot routine which was returned by dx_rmlink_get
  241.  
  242.     push    cs        ; segment of seg reg block
  243.     lea    ax, segregblock
  244.     push    ax        ; offset of seg reg block
  245.        push    code_selector
  246.     lea    eax, pmstub
  247.     push    eax
  248.     call    call_prot
  249.     add    sp, 10        ; unpop all things we pushed
  250.                 ; ax return code from prot mode passed thru
  251.     
  252.     pop    di        ; unpop di,si saved earlier
  253.     pop    si
  254.     pop    bp        ; unpop the BP we saved earlier
  255.     pop    ds        ; unpop the DS we saved earlier
  256.     ret             ; will do a FAR (real mode) ret to DFE
  257.  
  258. rm_common  ENDP
  259.  
  260. rmcode  ends
  261.  
  262.     
  263.     
  264.  
  265. pmcode segment
  266.  
  267. pmstub proc far
  268.     ; at this point ss:sp -> far return (DF) back to dos-extender
  269.     ;           sp+6     a word of 0
  270.     ;          sp+8     the pushed DS (of rmstub)
  271.     ;          sp+10  parameters
  272.     ; we pop the far return and save it away
  273.     ; then we call the real application procedure (the params still on stack)
  274.     ASSUME CS:pmcode, DS:dgroup
  275.     ; first let's switch ss:esp so that ss = ds
  276.     ; (it will still point to the same physical memory location)
  277.     ; (we'll save the old ss:esp on the stack in case they're needed)
  278.     mov    dx, ss
  279.     mov     ecx, esp
  280.     ; at this point, ecx contains the physical 32-bit address of sp
  281.     ; (selector 60h's offset mapped directly to 1meg physical memory)
  282.  
  283.     mov    eax, conventional_memory
  284.     cmp    eax, 0        ; if conventional memory not mapped take other path
  285.     je    short conv_mem_unmapped
  286.  
  287.           ; This is the code that is not DPMI compatible
  288.         ; we add the ofst of beggining of conventional memory to esp
  289.         ; to make it SS_DATA relative and then use data_selector as the SS
  290.         ; thus no stack switch is necessary, we just remap the old stack
  291.     add    eax, ecx    ; this adds esp to conventional_memory
  292.     mov    ss, data_selector
  293.     mov    esp, eax
  294.     jmp    short got_ss_sp
  295.         ; now ss:esp points to same place as before but using different segment
  296.  
  297.  
  298. conv_mem_unmapped:
  299.            ; This code is DPMI compatible
  300.            ; we actually switch to a new stack that is in the TIPs DS
  301.            ; the number and size of these stacks was allocated at startup time.
  302.     lea    eax, stack_table
  303. chk_stack:
  304.     cmp    dword ptr [eax], 0
  305.     je    short no_stack    ; stack pointer of 0 means end of table
  306.     mov    esi, dword ptr [eax]    ; get stack pointer
  307.     cmp    dword ptr [esi+4], 0    ; is it marked free?
  308.     je    short take_stack
  309.     add    eax, 4        ; to next stack entry in table
  310.     jmp    chk_stack
  311.  
  312. no_stack:
  313.     mov    eax, 25        ; IPC Limitation error
  314.     ret
  315.  
  316. take_stack:
  317.     mov    dword ptr [esi+4], 0ffffffffh    ; mark stack in use
  318.     mov    ss, data_selector
  319.     mov    esp, esi    ; get stack pointer from table
  320.                 ; now we have ss = ds, so we can go to C level.
  321.  
  322. got_ss_sp:
  323.     ; push the old ss:esp on the stack
  324.     push    edx        ; old ss (need to push as full 32-bit for C convention)
  325.     push    ecx        ; old esp
  326.  
  327.     ; bl still contains the UDIProcedure Index (which was set up by the rm stub)
  328.     ; use this to get to the correct dos386glue_table routine 
  329.     xor    bh, bh
  330.     shl    bx,1        ; *4 for indexing into DD array
  331.     shl    bx,1
  332.     call    dos386glue_table[bx]
  333.     ; on return, we just need to restore the old ss:esp
  334.     pop    ecx
  335.     pop    edx
  336.  
  337.     cmp    conventional_memory, 0    ; if we had switched stacks
  338.     jne    short no_stack_clear
  339.     mov    dword ptr [esp+4], 0    ; clear the stack in use indicator
  340.  
  341. no_stack_clear:
  342.                 ; this code is identical whether we switched stacks or not
  343.                 ; we just restore the old ss:sp and return
  344.     mov    ss, dx
  345.     mov    esp, ecx
  346.                 ; the stack should look as it did when we entered
  347.                 ; so we just do a far ret
  348.     ret
  349. pmstub endp
  350.  
  351.  
  352.     public    GetCS
  353. GetCS    PROC NEAR
  354.     mov    ax, cs
  355.     ret
  356. GetCS    ENDP
  357.  
  358.     public    GetDS
  359. GetDS    PROC NEAR
  360.     mov    ax, ds
  361.     ret
  362. GetDS    ENDP
  363.  
  364.  
  365.     public    _exp_return
  366.     extrn    _top:dword
  367.  
  368. _exp_return PROC FAR
  369.     ; set the stack pointer back to its initial state as left by dfe
  370.     ; (leave the ss unchanged)
  371.     ; then do a far ret which will get us back to the dfe.
  372.     ; (which will then restore its own stack).
  373.     mov    ebp, esp
  374.     mov    eax, [ebp+4]    ; errcode
  375.     mov    ecx, _top
  376.     add    ecx, 2
  377.     mov    esp, ecx
  378.     ret
  379. _exp_return ENDP
  380.  
  381. pmcode ends
  382.  
  383.  
  384. rmdata   segment
  385. ;
  386. ; Symbol marking end of real mode code & data,
  387. ; used at link time to specify the real mode
  388. ; code & data size
  389. ;
  390.     public    end_real
  391. end_real label    byte
  392. rmdata   ends
  393.  
  394.  
  395.  
  396. ENDIF    ; end of DOS386 conditional code
  397.  
  398.     END
  399.