home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / tcpiptk / r0lib32 / dd.asm < prev    next >
Assembly Source File  |  1999-05-11  |  7KB  |  253 lines

  1.  
  2. .SEQ   ;Use the segments in the order listed
  3. .286p
  4.  
  5. jmp32   macro   target
  6.                 db      066h                    ; operand size prefix
  7.                 jmp     flat:target
  8. endm
  9.  
  10. extrn   _init16_c:far                           ;16bit initialization code (in init16.c)
  11.  
  12. ;group the segments into the correct order
  13. DGROUP  group NULL, _DATA, CONST, FAR_BSS, _BSS, LAST_D
  14.  
  15. NULL            SEGMENT WORD PUBLIC 'BEGDATA'
  16.  
  17. ;Device driver header
  18. public  dev_header
  19. dev_header      equ     $
  20. ptr_to_next     dd      0ffffffffh      ;loadable
  21. device_attr     dw      0C880h          ;option bits
  22. offst           dw      MAINSEG:STRATEGY
  23. offst1          dw      MAINSEG:IDC
  24. dev_name        db      'TEST$    '     ;device name
  25. res2            dw      4 dup(0)
  26. ;--------end of header
  27.  
  28. public __acrtused
  29. __acrtused      dw      0               ;C .OBJ files want one. They never use it.
  30.  
  31. public _gdtrtab                         ; will be passed to sgdt instruction
  32. _gdtrtab        db      8 dup(0)
  33.  
  34. public _myds
  35. _myds           dw      ?
  36.  
  37. public _devhelp
  38. _devhelp        dd      ?
  39.  
  40. public mixed                            ;this variable is used to facilitate switching between
  41. mixed           dw      init16          ;the 16bit init code and the 32bit strategy code
  42.  
  43. NULL            ENDS
  44.  
  45. _DATA           SEGMENT WORD PUBLIC 'DATA'
  46. _DATA           ENDS
  47.  
  48. CONST           SEGMENT WORD PUBLIC 'CONST'
  49. CONST           ENDS
  50.  
  51. FAR_BSS         SEGMENT WORD PUBLIC 'FAR_BSS'
  52. FAR_BSS         ENDS
  53.  
  54. _BSS            SEGMENT WORD PUBLIC 'BSS'
  55. _BSS            ENDS
  56.  
  57. LAST_D          SEGMENT WORD PUBLIC 'LAST_DATA'
  58. public          _last_d
  59. _last_d         equ     $
  60. LAST_D          ends
  61.  
  62. extrn Dos32FlatDS:abs
  63.  
  64. ;==========================================
  65. ; Entry point to Strategy routine
  66. ;==========================================
  67.  
  68. MAINSEG         SEGMENT WORD PUBLIC 'CODE'
  69. assume          cs:MAINSEG, ds:DGROUP, es:nothing
  70.  
  71. STRATEGY        proc    far
  72.                 push    es      ; es:bx is a pointer to an lpreq structure
  73.                 push    bx
  74.                 jmp     mixed
  75. mixed_ret:
  76.                 pop     bx
  77.                 pop     es
  78.                 ret
  79. STRATEGY        endp
  80.  
  81.  
  82. public  _setjmp32
  83. _setjmp32       proc    far
  84.                 ;(called from init16.c)
  85.                 ;this tells the STRATEGY function to jump to strategy1632 next time
  86.                 push    bx
  87.                 mov     bx, OFFSET mixed
  88.                 mov     [bx], OFFSET MAINSEG:strategy1632
  89.                 pop     bx
  90.                 ret
  91. _setjmp32       endp
  92.  
  93.  
  94. init16:         call    _initmyds
  95.                 call    _init16_c
  96.                 jmp     mixed_ret
  97.  
  98.  
  99. strategy1632:
  100.                 push    ds
  101.                 push    es              ;Save the ES as in 32 bit DS should equal ES
  102.                 mov     ax, Dos32FlatDS
  103.                 mov     ds,ax
  104.                 mov     es,ax           ;Added because this is what the /Gv would have done
  105.                 jmp32   strategy32      ;jmp to the 32bit code segment
  106. strategy3216:   pop     es
  107.                 pop     ds
  108.                 jmp     mixed_ret
  109.  
  110.  
  111. ;used in .c file
  112. _GetDosVarLinearPtr proc public
  113.                 push    bp
  114.                 push    bx
  115.                 mov     bp, sp
  116.                 mov     al, 09h         ; The reserved index=9 to get ptr to the kernel DOSTABLE struct.
  117.                 mov     dl, 24h         ; DevHlp_GetDosVar
  118.                 call    [_devhelp]
  119.                 jc      mygetdosvarerror
  120.                 ; Now we have        AX: Selector BX: Offset
  121.                 mov     dx, ax
  122.                 mov     ax, bx
  123.                 pop     bx
  124.                 pop     bp
  125.                 ret                     ; Return the EAX which is linear pointer to TABLE
  126. mygetdosvarerror:
  127.                 mov     ax, 0
  128.                 mov     dx, 0
  129.                 pop     bx
  130.                 pop     bp
  131.                 ret
  132. _GetDosVarLinearPtr endp
  133.  
  134.  
  135. IDC             proc    far
  136.                 ret
  137. IDC             endp
  138.  
  139.  
  140. public _initmyds
  141. _initmyds proc far
  142.                 mov     ax, ds
  143.                 mov     _myds, ax
  144.                 ret
  145. _initmyds endp
  146.  
  147.  
  148.  
  149. thunk3216devhelp16:
  150.         call    [_devhelp]              ; 16-bit DevHelp call from 16-bit code
  151.                                         ; callee params are as they were
  152.         jmp     flat:thunk1632devhelp32 ; go back to the 32-bit generic stub
  153.  
  154. MAINSEG ends
  155.  
  156. .386
  157. CODE32          SEGMENT DWORD USE32 PUBLIC 'CODE'
  158. assume ds:flat, cs:CODE32
  159.  
  160. extrn   strategy32_c:near                       ; 32bit C strategy function
  161. extrn   seltoflat:near                          ; in driver.c
  162. extrn   _ptkssbase:dword                        ; in init16.c
  163.  
  164.  
  165. public int3break
  166. int3break       proc
  167.                 int     3
  168.                 ret
  169. int3break       endp
  170.  
  171.  
  172. strategy32:     sgdt    byte ptr _gdtrtab       ; find the start of the gdt table
  173.                 push    ss:[esp+4]              ; push 4 bytes of 16:16 address
  174.                 call    seltoflat
  175.                 add     esp,4                   ; clean-up stack
  176.                 mov     edx, eax
  177.                 or      eax, 0
  178.                 jz      sanityfailed
  179.  
  180.                 push    eax
  181.                 call    strategy32_c
  182.                 add     esp,4
  183. sanityfailed:
  184.                 jmp     far ptr strategy3216    ; jump back to 16_bit code
  185.  
  186.  
  187.  
  188. ;virt2lin(16:16 virt address) and returns the linear address in eax register
  189. public virt2lin
  190. virt2lin proc
  191.                 push    ebp
  192.                 mov     ebp,esp
  193.  
  194.                 mov     ax, ss:[ebp+10]                 ; selector
  195.                 push    esi
  196.                 xor     esi, esi
  197.                 mov     si, ss:[ebp+8]                  ; selector
  198.                 mov     dl, 5bh                         ; devhlp_virt2lin
  199.                 call    devhelp32
  200.                 jc      virt2linerror
  201.                 pop     esi
  202.                 pop     ebp
  203.                 ret
  204.  
  205. virt2linerror:
  206.                 xor     eax, eax
  207.                 pop     esi
  208.                 pop     ebp
  209.                 ret
  210. virt2lin endp
  211.  
  212.  
  213. retss proc public
  214.                 mov     eax, ss
  215.                 ret
  216. retss endp
  217.  
  218.  
  219. sstods proc public
  220.                 mov     eax, dword ptr _ptkssbase
  221.                 or      eax, 0
  222.                 jz      sstodsexit
  223.                 mov     eax, dword ptr [eax]
  224. sstodsexit:
  225.                 ret
  226. sstods          endp
  227.  
  228.  
  229. devhelp32       proc public
  230.         push    ds
  231.         push    eax
  232.         mov     ax, _myds
  233.         mov     ds, ax
  234.         pop     eax
  235.         jmp     far ptr thunk3216devhelp16      ; jump to  16-bit code
  236.  
  237. thunk1632devhelp32:
  238.                 pop     ds
  239.                 ret
  240. devhelp32       endp
  241.  
  242.  
  243. CODE32          ENDS
  244.  
  245.  
  246. _TEXT           SEGMENT WORD PUBLIC 'CODE'
  247. _TEXT           ENDS
  248.  
  249.  
  250. END_TEXT        SEGMENT WORD PUBLIC 'CODE'
  251. END_TEXT        ENDS
  252. END
  253.