Subversion Repositories Kolibri OS

Rev

Rev 5363 | Rev 6011 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5363 Rev 5522
Line 12... Line 12...
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 16... Line 16...
16
 
16
 
Line 17... Line 17...
17
$Revision: 5363 $
17
$Revision: 5522 $
18
 
18
 
Line 19... Line 19...
19
ETH_FRAME_MINIMUM       = 60
19
ETH_FRAME_MINIMUM       = 60
Line 31... Line 31...
31
 
31
 
Line 32... Line 32...
32
        mac             dp ?
32
        mac             dp ?
Line 33... Line -...
33
 
-
 
34
ends
-
 
35
 
-
 
36
struct  ETH_queue_entry
-
 
37
 
-
 
38
        device          dd ?
-
 
39
        packet          dd ?
-
 
40
        size            dd ?
-
 
41
 
33
 
42
ends
34
ends
Line 43... Line 35...
43
 
35
 
-
 
36
iglobal
-
 
37
align 4
-
 
38
 
-
 
39
        ETH_BROADCAST   dp 0xffffffffffff
-
 
40
 
-
 
41
        ETH_frame_queued        dd 0    ; Number of queued frames
44
iglobal
42
 
Line 45... Line 43...
45
align 4
43
        ETH_frame_head          dd ETH_frame_head       ; Pointer to next frame in the linked list
46
 
44
        ETH_frame_tail          dd ETH_frame_head       ; Pointer to last frame in the linked list
47
        ETH_BROADCAST   dp  0xffffffffffff
45
 
48
endg
-
 
49
 
46
endg
Line 50... Line 47...
50
uglobal
47
 
Line 51... Line -...
51
align 4
-
 
52
        ETH_input_event dd ?
-
 
53
        ETH_queue       rd (ETH_QUEUE_SIZE*sizeof.ETH_queue_entry + sizeof.queue)/4
48
uglobal
54
endg
49
align 4
55
 
50
        ETH_input_event dd ?
56
macro   ETH_init {
51
endg
57
 
52
 
Line 70... Line 65...
70
;-----------------------------------------------------------------
65
;-----------------------------------------------------------------
71
;
66
;
72
; ETH_input
67
; ETH_input
73
;
68
;
74
;  This function is called by ethernet drivers,
69
;  This function is called by ethernet drivers,
75
;  It pushes the received ethernet packets onto the eth_in_queue
70
;  It pushes the received ethernet packets onto the ethernet input queue
76
;
71
;
77
;  IN:   [esp]  = Pointer to buffer
72
;  IN:  [esp] = Pointer to buffer
78
;       [esp+4] = size of buffer
-
 
79
;         ebx   = pointer to eth_device
-
 
-
 
73
;
80
;  OUT: /
74
;  OUT: /
81
;
75
;
82
;-----------------------------------------------------------------
76
;-----------------------------------------------------------------
83
align 4
77
align 4
84
ETH_input:
78
ETH_input:
Line 85... Line 79...
85
 
79
 
-
 
80
        pop     eax
-
 
81
        pushf
-
 
82
        cli
-
 
83
 
86
        push    ebx
84
        cmp     [ETH_frame_queued], ETH_QUEUE_SIZE
-
 
85
        jae     .full
-
 
86
        inc     [ETH_frame_queued]
-
 
87
 
-
 
88
; Add frame to the end of the linked list
Line 87... Line 89...
87
        mov     esi, esp
89
        mov     [eax + NET_BUFF.NextPtr], ETH_frame_head
88
 
90
 
Line -... Line 91...
-
 
91
        mov     ebx, [ETH_frame_tail]
-
 
92
        mov     [eax + NET_BUFF.PrevPtr], ebx
-
 
93
 
-
 
94
        mov     [ETH_frame_tail], eax
-
 
95
        mov     [ebx + NET_BUFF.NextPtr], eax
-
 
96
 
89
        add_to_queue ETH_queue, ETH_QUEUE_SIZE, sizeof.ETH_queue_entry, .fail
97
        popf
90
        add     esp, sizeof.ETH_queue_entry
98
 
91
 
99
; Now queue an event to process it
92
        xor     edx, edx
100
        xor     edx, edx
93
        mov     eax, [ETH_input_event]
101
        mov     eax, [ETH_input_event]
Line 94... Line 102...
94
        mov     ebx, [eax + EVENT.id]
102
        mov     ebx, [eax + EVENT.id]
Line 95... Line 103...
95
        xor     esi, esi
103
        xor     esi, esi
96
        call    raise_event
104
        call    raise_event
97
 
-
 
98
        ret
105
 
99
 
106
        ret
100
  .fail:
107
 
101
        DEBUGF  DEBUG_NETWORK_ERROR, "ETH incoming queue is full, discarding packet!\n"
-
 
102
 
108
  .full:
Line 114... Line 120...
114
 
120
 
115
        xor     esi, esi
121
        xor     esi, esi
116
        mov     ecx, MANUAL_DESTROY
122
        mov     ecx, MANUAL_DESTROY
117
        call    create_event
123
        call    create_event
118
        mov     [ETH_input_event], eax
124
        mov     [ETH_input_event], eax
119
 
125
        pushf
-
 
126
  .wait:
120
  .wait:
127
        popf
121
        mov     eax, [ETH_input_event]
128
        mov     eax, [ETH_input_event]
122
        mov     ebx, [eax + EVENT.id]
129
        mov     ebx, [eax + EVENT.id]
Line 123... Line 130...
123
        call    wait_event
130
        call    wait_event
-
 
131
 
-
 
132
  .loop:
124
 
133
        pushf
-
 
134
        cli
-
 
135
        cmp     [ETH_frame_queued], 0
-
 
136
        je      .wait
Line 125... Line 137...
125
  .loop:
137
 
126
        get_from_queue ETH_queue, ETH_QUEUE_SIZE, sizeof.ETH_queue_entry, .wait
138
        dec     [ETH_frame_queued]
127
 
-
 
Line 128... Line 139...
128
        mov     eax, [esi + ETH_queue_entry.packet]
139
 
-
 
140
        mov     esi, [ETH_frame_head]
-
 
141
        mov     ebx, [esi + NET_BUFF.NextPtr]
-
 
142
 
-
 
143
        mov     [ETH_frame_head], ebx
-
 
144
        mov     [ebx + NET_BUFF.PrevPtr], ETH_frame_head
129
        mov     ecx, [esi + ETH_queue_entry.size]
145
 
-
 
146
        popf
-
 
147
 
-
 
148
        mov     eax, [esi + NET_BUFF.offset]
-
 
149
        add     eax, esi
-
 
150
        mov     ecx, [esi + NET_BUFF.length]
Line 130... Line 151...
130
        mov     ebx, [esi + ETH_queue_entry.device]
151
        mov     ebx, [esi + NET_BUFF.device]
131
 
152
 
132
        pushd   .loop   ; return address
153
        pushd   .loop           ; return address for protocol handler
Line -... Line 154...
-
 
154
        push    esi             ; keep pointer to NET_BUFF on stack
133
        push    ecx eax
155
 
134
 
156
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ETH_input: size=%u\n", ecx
Line -... Line 157...
-
 
157
        sub     ecx, sizeof.ETH_header
135
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ETH_input: size=%u\n", ecx
158
        jb      .dump
136
        sub     ecx, sizeof.ETH_header
159
 
Line 137... Line 160...
137
        jb      .dump
160
; Set registers for protocol handlers
138
 
161
        lea     edx, [eax + sizeof.ETH_header]
Line 156... Line 179...
156
 
179
 
Line 157... Line 180...
157
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ETH_input: Unknown packet type=%x\n", ax
180
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ETH_input: Unknown packet type=%x\n", ax
158
 
181
 
159
  .dump:
182
  .dump:
160
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ETH_input: dumping\n"
-
 
161
        call    NET_packet_free
183
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ETH_input: dumping\n"
Line 162... Line 184...
162
        add     esp, 4
184
        call    NET_BUFF_free
163
        ret
185
        ret
164
 
186
 
Line 169... Line 191...
169
; IN:  ax = protocol
191
; IN:  ax = protocol
170
;     ebx = device ptr
192
;     ebx = device ptr
171
;     ecx = payload size
193
;     ecx = payload size
172
;     edx = pointer to destination mac
194
;     edx = pointer to destination mac
173
;
195
;
174
; OUT: eax = start of ethernet frame / 0 on error
196
; OUT: eax = start of net frame / 0 on error
175
;      ebx = device ptr
197
;      ebx = device ptr
176
;      ecx = payload size
198
;      ecx = payload size
177
;      edx = ethernet frame size
-
 
178
;      edi = start of ethernet payload
199
;      edi = start of payload
179
;
200
;
180
;-----------------------------------------------------------------
201
;-----------------------------------------------------------------
181
align 4
202
align 4
182
ETH_output:
203
ETH_output:
Line 187... Line 208...
187
        ja      .exit
208
        ja      .exit
Line 188... Line 209...
188
 
209
 
189
        push    ecx
210
        push    ecx
Line 190... Line 211...
190
        push    ax edx
211
        push    ax edx
191
 
212
 
192
        add     ecx, sizeof.ETH_header
213
        add     ecx, sizeof.ETH_header + NET_BUFF.data
193
        stdcall kernel_alloc, ecx
214
        stdcall NET_BUFF_alloc, ecx
-
 
215
        test    eax, eax
194
        test    eax, eax
216
        jz      .out_of_ram
-
 
217
        mov     [eax + NET_BUFF.type], NET_BUFF_ETH
-
 
218
        mov     [eax + NET_BUFF.device], ebx
Line 195... Line 219...
195
        jz      .out_of_ram
219
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
196
        mov     edi, eax
220
        lea     edi, [eax + NET_BUFF.data]
197
 
221
 
198
        pop     esi
222
        pop     esi
199
        movsd
223
        movsd
200
        movsw
224
        movsw
201
        lea     esi, [ebx + ETH_DEVICE.mac]
225
        lea     esi, [ebx + ETH_DEVICE.mac]
202
        movsd
226
        movsd
Line 203... Line 227...
203
        movsw
227
        movsw
204
        pop     ax
228
        pop     ax
205
        stosw
-
 
Line -... Line 229...
-
 
229
        stosw
206
 
230
 
207
        lea     eax, [edi - sizeof.ETH_header]  ; Set eax to buffer start
231
        lea     eax, [edi - sizeof.ETH_header - NET_BUFF.data]  ; Set eax to buffer start
208
        pop     ecx
232
        pop     ecx
-
 
233
 
209
        lea     edx, [ecx + sizeof.ETH_header]  ; Set edx to complete buffer size
234
        lea     edx, [ecx + sizeof.ETH_header]  ; Set edx to complete buffer size
210
 
235
        cmp     edx, ETH_FRAME_MINIMUM
Line 211... Line 236...
211
        cmp     edx, ETH_FRAME_MINIMUM
236
        jbe     .adjust_size
212
        jbe     .adjust_size
237
  .done:
Line 270... Line 295...
270
 
295
 
271
 
296
 
272
  .read_mac:
297
  .read_mac:
273
        movzx   ebx, word [eax + ETH_DEVICE.mac]
298
        movzx   ebx, word [eax + ETH_DEVICE.mac]
274
        mov     eax, dword [eax + ETH_DEVICE.mac + 2]
299
        mov     eax, dword [eax + ETH_DEVICE.mac + 2]