summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap/msdos/ndis_0.asm
blob: 2990985fee30387baf4a78995d2b9a66d4a9c400 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
PAGE 60,132
NAME NDIS_0

ifdef DOSX
  .386
  _TEXT   SEGMENT PUBLIC DWORD USE16 'CODE'
  _TEXT   ENDS
  _DATA   SEGMENT PUBLIC DWORD USE16 'CODE'
  _DATA   ENDS
  _TEXT32 SEGMENT PUBLIC BYTE  USE32 'CODE'
  _TEXT32 ENDS
  CB_DSEG EQU <CS>                          ; DOSX is tiny-model
  D_SEG   EQU <_TEXT SEGMENT>
  D_END   EQU <_TEXT ENDS>
  ASSUME  CS:_TEXT,DS:_TEXT

  PUSHREGS equ <pushad>
  POPREGS  equ <popad>

  PUBPROC macro name
          align 4
          public @&name
          @&name label near
          endm
else
  .286
  _TEXT   SEGMENT PUBLIC DWORD 'CODE'
  _TEXT   ENDS
  _DATA   SEGMENT PUBLIC DWORD 'DATA'
  _DATA   ENDS
  CB_DSEG EQU <SEG _DATA>                   ; 16bit is small/large model
  D_SEG   EQU <_DATA SEGMENT>
  D_END   EQU <_DATA ENDS>
  ASSUME  CS:_TEXT,DS:_DATA

  PUSHREGS equ <pusha>
  POPREGS  equ <popa>

  PUBPROC  macro name
           public _&name
           _&name label far
           endm
endif

;-------------------------------------------

D_SEG

D_END


_TEXT SEGMENT

EXTRN _NdisSystemRequest      : near
EXTRN _NdisRequestConfirm     : near
EXTRN _NdisTransmitConfirm    : near
EXTRN _NdisReceiveLookahead   : near
EXTRN _NdisIndicationComplete : near
EXTRN _NdisReceiveChain       : near
EXTRN _NdisStatusProc         : near
EXTRN _NdisAllocStack         : near
EXTRN _NdisFreeStack          : near

;
; *ALL* interrupt threads come through this macro.
;
CALLBACK macro callbackProc, argsSize

     pushf
     PUSHREGS                ;; Save the registers

     push es
     push ds
     mov  ax,CB_DSEG         ;; Load DS
     mov  ds,ax
     call _NdisAllocStack    ;; Get and install a stack.

     mov  bx,ss              ;; Save off the old stack in other regs
     mov  cx,sp
     mov  ss,dx              ;; Install the new one
     mov  sp,ax
     push bx                 ;; Save the old one on to the new stack
     push cx
     sub  sp,&argsSize       ;; Allocate space for arguments on the stack

     mov  ax,ss              ;; Set up the destination for the move
     mov  es,ax
     mov  di,sp
     mov  ds,bx              ;; Set up the source for the move.
     mov  si,cx
     add  si,4+6+32

     mov  cx,&argsSize       ;; Move the arguments to the stack.
     shr  cx,1
     cld
     rep  movsw

     mov  ax,CB_DSEG         ;; Set my data segment again.
     mov  ds,ax

     call &callbackProc      ;; Call the real callback.
     pop  di                 ;; Pop off the old stack
     pop  si
     mov  bx,ss              ;; Save off the current allocated stack.
     mov  cx,sp
     mov  ss,si              ;; Restore the old stack
     mov  sp,di
     push ax                 ;; Save the return code
     push bx                 ;; Free the stack. Push the pointer to it
     push cx
     call _NdisFreeStack
     add  sp,4
     pop  ax                 ;; Get the return code back
     add  di,32              ;; Get a pointer to ax on the stack
     mov  word ptr ss:[di],ax
     pop  ds
     pop  es

     POPREGS
     popf
endm

;
; Define all of the callbacks for the NDIS procs.
;

PUBPROC systemRequestGlue
CALLBACK _NdisSystemRequest,14
RETF

PUBPROC requestConfirmGlue
CALLBACK _NdisRequestConfirm,12
RETF

PUBPROC transmitConfirmGlue
CALLBACK _NdisTransmitConfirm,10
RETF

PUBPROC receiveLookaheadGlue
CALLBACK _NdisReceiveLookahead,16
RETF

PUBPROC indicationCompleteGlue
CALLBACK _NdisIndicationComplete,4
RETF

PUBPROC receiveChainGlue
CALLBACK _NdisReceiveChain,16
RETF

PUBPROC statusGlue
CALLBACK _NdisStatusProc,12
RETF

;
; int FAR NdisGetLinkage (int handle, char *data, int size);
;

ifdef DOSX
  PUBPROC NdisGetLinkage
          push ebx
          mov ebx, [esp+8]              ; device handle
          mov eax, 4402h                ; IOCTRL read function
          mov edx, [esp+12]             ; DS:EDX -> result data
          mov ecx, [esp+16]             ; ECX = length
          int 21h
          pop ebx
          jc  @fail
          xor eax, eax
  @fail:  ret

else
  PUBPROC NdisGetLinkage
          enter 0, 0
          mov bx, [bp+6]
          mov ax, 4402h
          mov dx, [bp+8]
          mov cx, [bp+12]
          int 21h
          jc  @fail
          xor ax, ax
  @fail:  leave
          retf
endif

ENDS

END
OpenPOWER on IntegriCloud