Subversion Repositories Kolibri OS

Rev

Rev 1206 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1206 Rev 1241
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  ETHERNET.INC                                                   ;;
6
;;  ETHERNET.INC                                                   ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  Ethernet network layer for KolibriOS                           ;;
8
;;  Ethernet network layer for KolibriOS                           ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
11
;;                                                                 ;;
11
;;                                                                 ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
 
16
 
17
$Revision: 1206 $
17
$Revision: 1241 $
18
 
18
 
19
MAX_ETH_DEVICES 	equ MAX_NET_DEVICES
19
MAX_ETH_DEVICES 	equ MAX_NET_DEVICES
20
ETH_QUEUE_SIZE		equ 16
20
ETH_QUEUE_SIZE		equ 16
21
 
21
 
22
struct	ETH_FRAME
22
struct	ETH_FRAME
23
	.DstMAC 	dp  ?  ; destination MAC-address [6 bytes]
23
	.DstMAC 	dp  ?  ; destination MAC-address [6 bytes]
24
	.SrcMAC 	dp  ?  ; source MAC-address [6 bytes]
24
	.SrcMAC 	dp  ?  ; source MAC-address [6 bytes]
25
	.Type		dw  ?  ; type of the upper-layer protocol [2 bytes]
25
	.Type		dw  ?  ; type of the upper-layer protocol [2 bytes]
26
	.Data:		       ; data [46-1500 bytes]
26
	.Data:		       ; data [46-1500 bytes]
27
ends
27
ends
28
 
28
 
29
struct	ETH_DEVICE
29
struct	ETH_DEVICE
30
	.unload 	dd ?
30
	.unload 	dd ?
31
	.reset		dd ?
31
	.reset		dd ?
32
	.transmit	dd ?
32
	.transmit	dd ?
33
	.set_MAC	dd ?
33
	.set_MAC	dd ?
34
	.get_MAC	dd ?
34
	.get_MAC	dd ?
35
	.set_mode	dd ?
35
	.set_mode	dd ?
36
	.get_mode	dd ?
36
	.get_mode	dd ?
37
 
37
 
38
	.bytes_tx	dq ?
38
	.bytes_tx	dq ?
39
	.bytes_rx	dq ?
39
	.bytes_rx	dq ?
40
	.packets_tx	dd ?
40
	.packets_tx	dd ?
41
	.packets_rx	dd ?
41
	.packets_rx	dd ?
42
	.mode		dd ?  ; This dword contains cable status (10mbit/100mbit, full/half duplex, auto negotiation or not,..)
42
	.mode		dd ?  ; This dword contains cable status (10mbit/100mbit, full/half duplex, auto negotiation or not,..)
43
	.name		dd ?
43
	.name		dd ?
44
	.mac		dp ?
44
	.mac		dp ?
45
ends			      ; the rest of the device struct depends on the type of device
45
ends			      ; the rest of the device struct depends on the type of device
46
 
46
 
47
 
47
 
48
align 4
48
align 4
49
iglobal
49
iglobal
50
 
50
 
51
	ETH_BROADCAST	dp  0xffffffffffff
51
	ETH_BROADCAST	dp  0xffffffffffff
52
endg
52
endg
53
 
53
 
54
align 4
54
align 4
55
uglobal
55
uglobal
56
 
56
 
57
	ETH_RUNNING	dd  ?
57
	ETH_RUNNING	dd  ?
58
	ETH_DRV_LIST	rd  MAX_ETH_DEVICES
58
	ETH_DRV_LIST	rd  MAX_ETH_DEVICES
59
	ETH_IN_QUEUE	rd  3*ETH_QUEUE_SIZE+3
59
	ETH_IN_QUEUE	rd  3*ETH_QUEUE_SIZE+3
60
	ETH_OUT_QUEUE	rd  3*ETH_QUEUE_SIZE+3
60
	ETH_OUT_QUEUE	rd  3*ETH_QUEUE_SIZE+3
61
endg
61
endg
62
 
62
 
63
 
63
 
64
;-----------------------------------------------
64
;-----------------------------------------------
65
;
65
;
66
; ETH_init
66
; ETH_init
67
;
67
;
68
;  This function resets all ethernet variables
68
;  This function resets all ethernet variables
69
;
69
;
70
;  IN:  /
70
;  IN:  /
71
;  OUT: /
71
;  OUT: /
72
;
72
;
73
;-----------------------------------------------
73
;-----------------------------------------------
74
 
74
 
75
align 4
75
align 4
76
ETH_init:
76
ETH_init:
77
 
77
 
78
	xor	eax, eax
78
	xor	eax, eax
79
	mov	edi, ETH_RUNNING
79
	mov	edi, ETH_RUNNING
80
	mov	ecx, (1+MAX_ETH_DEVICES)
80
	mov	ecx, (1+MAX_ETH_DEVICES)
81
	rep	stosd
81
	rep	stosd
82
 
82
 
83
	mov	dword [ETH_IN_QUEUE], ETH_QUEUE_SIZE
83
	mov	dword [ETH_IN_QUEUE], ETH_QUEUE_SIZE
84
	mov	dword [ETH_IN_QUEUE+4], ETH_IN_QUEUE + queue.data
84
	mov	dword [ETH_IN_QUEUE+4], ETH_IN_QUEUE + queue.data
85
	mov	dword [ETH_IN_QUEUE+8], ETH_IN_QUEUE + queue.data
85
	mov	dword [ETH_IN_QUEUE+8], ETH_IN_QUEUE + queue.data
86
 
86
 
87
	mov	dword [ETH_OUT_QUEUE], ETH_QUEUE_SIZE
87
	mov	dword [ETH_OUT_QUEUE], ETH_QUEUE_SIZE
88
	mov	dword [ETH_OUT_QUEUE+4], ETH_OUT_QUEUE + queue.data
88
	mov	dword [ETH_OUT_QUEUE+4], ETH_OUT_QUEUE + queue.data
89
	mov	dword [ETH_OUT_QUEUE+8], ETH_OUT_QUEUE + queue.data
89
	mov	dword [ETH_OUT_QUEUE+8], ETH_OUT_QUEUE + queue.data
90
 
90
 
91
	ret
91
	ret
92
 
92
 
93
 
93
 
94
;---------------------------------------------------------
94
;---------------------------------------------------------
95
;
95
;
96
; ETH_Add_Device:
96
; ETH_Add_Device:
97
;
97
;
98
;  This function is called by ethernet drivers,
98
;  This function is called by ethernet drivers,
99
;  to register each running ethernet device to the kernel
99
;  to register each running ethernet device to the kernel
100
;
100
;
101
;  IN:  Pointer to device structure in ebx
101
;  IN:  Pointer to device structure in ebx
102
;  OUT: Device num in eax, -1 on error
102
;  OUT: Device num in eax, -1 on error
103
;
103
;
104
;---------------------------------------------------------
104
;---------------------------------------------------------
105
 
105
 
106
align 4
106
align 4
107
ETH_Add_Device:
107
ETH_Add_Device:
108
 
108
 
109
	DEBUGF	1,"ETH_Add_Device: %x ", ebx
109
	DEBUGF	1,"ETH_Add_Device: %x ", ebx
110
 
110
 
111
	mov	eax, [ETH_RUNNING]
111
	mov	eax, [ETH_RUNNING]
112
	cmp	eax, MAX_ETH_DEVICES
112
	cmp	eax, MAX_ETH_DEVICES
113
	jge	.error
113
	jge	.error
114
 
114
 
115
	test	eax, eax
115
	test	eax, eax
116
	jnz	.notfirst
116
	jnz	.notfirst
117
	mov	dword [ETH_IN_QUEUE], eax
117
	mov	dword [ETH_IN_QUEUE], eax
118
	mov	dword [ETH_OUT_QUEUE], eax
118
	mov	dword [ETH_OUT_QUEUE], eax
119
      .notfirst:
119
      .notfirst:
120
 
120
 
121
	mov	eax, ebx
121
	mov	eax, ebx
122
	mov	ecx, MAX_ETH_DEVICES	  ; We need to check whole list because a device may be removed without re-organizing list
122
	mov	ecx, MAX_ETH_DEVICES	  ; We need to check whole list because a device may be removed without re-organizing list
123
	mov	edi, ETH_DRV_LIST
123
	mov	edi, ETH_DRV_LIST
124
 
124
 
125
	cld
125
	cld
126
	repne	scasd			  ; See if device is already in the list
126
	repne	scasd			  ; See if device is already in the list
127
	jz	.error
127
	jz	.error
128
 
128
 
129
	xor	eax, eax
129
	xor	eax, eax
130
	mov	ecx, MAX_ETH_DEVICES
130
	mov	ecx, MAX_ETH_DEVICES
131
	mov	edi, ETH_DRV_LIST
131
	mov	edi, ETH_DRV_LIST
132
 
132
 
133
	repne	scasd			  ; Find empty spot in the list
133
	repne	scasd			  ; Find empty spot in the list
134
	jnz	.error
134
	jnz	.error
135
 
135
 
136
	sub	edi, 4
136
	sub	edi, 4
137
	mov	[edi], ebx		  ; add device to list
137
	mov	[edi], ebx		  ; add device to list
138
 
138
 
139
	sub	edi, ETH_DRV_LIST	  ; edi = 4*device num       Calculate device number in eax
139
	sub	edi, ETH_DRV_LIST	  ; edi = 4*device num       Calculate device number in eax
140
	mov	eax, edi		  ; edx = 4*device num
140
	mov	eax, edi		  ; edx = 4*device num
141
	shr	eax, 2
141
	shr	eax, 2
142
 
142
 
143
	inc	[ETH_RUNNING]		  ; Indicate that one more ethernet device is up and running
143
	inc	[ETH_RUNNING]		  ; Indicate that one more ethernet device is up and running
144
 
144
 
145
	DEBUGF	1,"- succes: %u\n",eax
145
	DEBUGF	1,"- succes: %u\n",eax
146
	ret
146
	ret
147
 
147
 
148
       .error:
148
       .error:
149
	or	eax, -1
149
	or	eax, -1
150
	DEBUGF	1,"- fail\n"
150
	DEBUGF	1,"- fail\n"
151
 
151
 
152
	ret
152
	ret
153
 
153
 
154
 
154
 
155
 
155
 
156
 
156
 
157
;--------------------------------
157
;--------------------------------
158
;
158
;
159
; ETH_Remove_Device:
159
; ETH_Remove_Device:
160
;
160
;
161
;  This function is called by ethernet drivers,
161
;  This function is called by ethernet drivers,
162
;  to unregister ethernet devices from the kernel
162
;  to unregister ethernet devices from the kernel
163
;
163
;
164
;  IN:  Pointer to device structure in ebx
164
;  IN:  Pointer to device structure in ebx
165
;  OUT: eax: -1 on error
165
;  OUT: eax: -1 on error
166
;
166
;
167
;--------------------------------
167
;--------------------------------
168
 
168
 
169
align 4
169
align 4
170
ETH_Remove_Device:
170
ETH_Remove_Device:
171
 
171
 
172
	cmp	[ETH_RUNNING], 0
172
	cmp	[ETH_RUNNING], 0
173
	je	.error
173
	je	.error
174
 
174
 
175
	mov	eax, ebx
175
	mov	eax, ebx
176
	mov	ecx, MAX_ETH_DEVICES
176
	mov	ecx, MAX_ETH_DEVICES
177
	mov	edi, ETH_DRV_LIST
177
	mov	edi, ETH_DRV_LIST
178
 
178
 
179
	repne	scasd
179
	repne	scasd
180
	jnz	.error
180
	jnz	.error
181
 
181
 
182
	xor	eax, eax
182
	xor	eax, eax
183
	mov	dword [edi-4], eax
183
	mov	dword [edi-4], eax
184
 
184
 
185
	dec	[ETH_RUNNING]
185
	dec	[ETH_RUNNING]
186
	jnz	.notlast
186
	jnz	.notlast
187
 
187
 
188
	mov	dword [ETH_IN_QUEUE], ETH_QUEUE_SIZE
188
	mov	dword [ETH_IN_QUEUE], ETH_QUEUE_SIZE
189
	mov	dword [ETH_OUT_QUEUE], ETH_QUEUE_SIZE
189
	mov	dword [ETH_OUT_QUEUE], ETH_QUEUE_SIZE
190
 
190
 
191
       .notlast:
191
       .notlast:
192
 
192
 
193
	ret
193
	ret
194
 
194
 
195
       .error:
195
       .error:
196
	or	eax, -1
196
	or	eax, -1
197
 
197
 
198
	ret
198
	ret
199
 
199
 
200
 
200
 
201
 
201
 
202
;-------------------------------------------------------------
202
;-------------------------------------------------------------
203
;
203
;
204
; ETH_Receiver:
204
; ETH_Receiver:
205
;
205
;
206
;  This function is called by ethernet drivers,
206
;  This function is called by ethernet drivers,
207
;  It pushes the received ethernet packets onto the eth_in_queue
207
;  It pushes the received ethernet packets onto the eth_in_queue
208
;
208
;
209
;  IN:  Pointer to buffer in [esp], size of buffer in [esp-4], pointer to eth_device in ebx
209
;  IN:  Pointer to buffer in [esp], size of buffer in [esp-4], pointer to eth_device in ebx
210
;  OUT: /
210
;  OUT: /
211
;
211
;
212
;-------------------------------------------------------------
212
;-------------------------------------------------------------
213
 
213
 
214
align 4
214
align 4
215
ETH_Receiver:
215
ETH_Receiver:
216
	DEBUGF	1,"ETH_Receiver \n"
216
	DEBUGF	1,"ETH_Receiver \n"
217
 
217
 
218
	add_to_queue ETH_IN_QUEUE, ETH_QUEUE_SIZE, .gohome
218
	add_to_queue ETH_IN_QUEUE, ETH_QUEUE_SIZE, .gohome
219
 
219
 
220
  .gohome:
220
  .gohome:
221
	ret
221
	ret
222
 
222
 
223
 
223
 
224
 
224
 
225
 
225
 
226
 
226
 
227
;-------------------------------------------------------------
227
;-------------------------------------------------------------
228
;
228
;
229
; ETH_Handler:
229
; ETH_Handler:
230
;
230
;
231
;  Handles all queued eth packets (called from kernel's main_loop)
231
;  Handles all queued eth packets (called from kernel's main_loop)
232
;
232
;
233
;  IN:  /
233
;  IN:  /
234
;  OUT: /
234
;  OUT: /
235
;
235
;
236
;-------------------------------------------------------------
236
;-------------------------------------------------------------
237
 
237
 
238
align 4
238
align 4
239
ETH_handler:
239
ETH_handler:
240
 
240
 
241
	get_from_queue ETH_IN_QUEUE, ETH_QUEUE_SIZE, .gohome
241
	get_from_queue ETH_IN_QUEUE, ETH_QUEUE_SIZE, .gohome
242
 
242
 
243
	DEBUGF	1,"ETH_Handler - size: %u\n", ecx
243
	DEBUGF	1,"ETH_Handler - size: %u\n", ecx
244
	cmp	ecx, 60    ; check packet length
244
	cmp	ecx, 60    ; check packet length
245
	jl	.dump
245
	jl	.dump
246
	sub	ecx, ETH_FRAME.Data
246
	sub	ecx, ETH_FRAME.Data
247
 
247
 
248
	lea	edx, [eax + ETH_FRAME.Data]
248
	lea	edx, [eax + ETH_FRAME.Data]
249
	mov	ax , [eax + ETH_FRAME.Type]
249
	mov	ax , [eax + ETH_FRAME.Type]
250
 
250
 
251
	cmp	ax, ETHER_IPv4
251
	cmp	ax, ETHER_IPv4
252
	je	IPv4_handler
252
	je	IPv4_handler
253
 
253
 
254
	cmp	ax, ETHER_ARP
254
	cmp	ax, ETHER_ARP
255
	je	ARP_handler
255
	je	ARP_handler
256
 
256
 
257
	DEBUGF	1,"Unknown ethernet packet type %x\n", ax
257
	DEBUGF	1,"Unknown ethernet packet type %x\n", ax
258
 
258
 
259
  .dump:
259
  .dump:
260
	DEBUGF	1,"Dumping packet\n"
260
	DEBUGF	1,"Dumping packet\n"
261
	call	kernel_free
261
	call	kernel_free
262
	add	esp, 4
262
	add	esp, 4
263
 
263
 
264
  .gohome:
264
  .gohome:
265
	ret				; return 1. to get more from queue / 2. to caller
265
	ret				; return 1. to get more from queue / 2. to caller
266
 
266
 
267
 
267
 
268
 
268
 
269
;-----------------------------------------------------------------
269
;-----------------------------------------------------------------
270
;
270
;
271
; ETH_Sender:
271
; ETH_Sender:
272
;
272
;
273
;  This function sends an ethernet packet to the correct driver.
273
;  This function sends an ethernet packet to the correct driver.
274
;
274
;
275
;  IN:  Pointer to buffer in [esp]
275
;  IN:  Pointer to buffer in [esp]
276
;       size of buffer in [esp+4]
276
;       size of buffer in [esp+4]
277
;       pointer to device struct in ebx
277
;       pointer to device struct in ebx
278
;  OUT: /
278
;  OUT: /
279
;
279
;
280
;-----------------------------------------------------------------
280
;-----------------------------------------------------------------
281
 
281
 
282
align 4
282
align 4
283
ETH_Sender:
283
ETH_Sender:
284
	DEBUGF	1,"ETH_Sender \n"
284
	DEBUGF	1,"ETH_Sender \n"
285
 
285
 
286
	add_to_queue ETH_OUT_QUEUE, ETH_QUEUE_SIZE, .gohome
286
	add_to_queue ETH_OUT_QUEUE, ETH_QUEUE_SIZE, .gohome
287
 
287
 
288
  .gohome:
288
  .gohome:
289
	ret
289
	ret
290
 
290
 
291
 
291
 
292
align 4
292
align 4
293
ETH_send_queued:
293
ETH_send_queued:
294
 
294
 
295
	get_from_queue ETH_OUT_QUEUE, ETH_QUEUE_SIZE, .gohome
295
	get_from_queue ETH_OUT_QUEUE, ETH_QUEUE_SIZE, .gohome
296
 
296
 
297
	call	ETH_struc2dev		 ; convert struct ptr to device num (this way we know if driver is still mounted)
297
	call	ETH_struc2dev		 ; convert struct ptr to device num (this way we know if driver is still mounted)
298
	cmp	edi, -1
298
	cmp	edi, -1
299
	je	.fail
299
	je	.fail
300
 
300
 
301
	DEBUGF 1,"ETH_Sender - device: %u\n", edi
301
	DEBUGF 1,"ETH_Sender - device: %u\n", edi
302
 
302
 
303
	jmp	[ebx+ETH_DEVICE.transmit]
303
	jmp	[ebx+ETH_DEVICE.transmit]
304
 
304
 
305
     .fail:
305
     .fail:
306
	call	kernel_free
306
	call	kernel_free
307
	add	esp, 4 ; pop (balance stack)
307
	add	esp, 4 ; pop (balance stack)
308
	DEBUGF 1,"ETH_Sender - fail\n"
308
	DEBUGF 1,"ETH_Sender - fail\n"
309
     .gohome:
309
     .gohome:
310
	ret
310
	ret
311
 
311
 
312
;---------------------------------------------------------------------------
312
;---------------------------------------------------------------------------
313
;
313
;
314
; ETH_struc2dev
314
; ETH_struc2dev
315
;
315
;
316
; IN: pointer to device struct in ebx
316
; IN: pointer to device struct in ebx
317
;
317
;
318
; OUT: edi is -1 on error, device number otherwise
318
; OUT: edi is -1 on error, device number otherwise
319
;
319
;
320
;---------------------------------------------------------------------------
320
;---------------------------------------------------------------------------
321
 
321
 
322
align 4
322
align 4
323
ETH_struc2dev:
323
ETH_struc2dev:
324
	push	eax ecx
324
	push	eax ecx
325
 
325
 
326
	mov	eax, ebx
326
	mov	eax, ebx
327
	mov	ecx, MAX_ETH_DEVICES
327
	mov	ecx, MAX_ETH_DEVICES
328
	mov	edi, ETH_DRV_LIST
328
	mov	edi, ETH_DRV_LIST
329
 
329
 
330
	repne	scasd
330
	repne	scasd
331
	jnz	.error
331
	jnz	.error
332
 
332
 
333
	sub	edi, ETH_DRV_LIST+4
333
	sub	edi, ETH_DRV_LIST+4
334
	shr	edi, 2
334
	shr	edi, 2
335
 
335
 
336
	pop	ecx eax
336
	pop	ecx eax
337
	ret
337
	ret
338
  .error:
338
  .error:
339
	or	edi, -1
339
	or	edi, -1
340
	pop	ecx eax
340
	pop	ecx eax
341
 
341
 
342
	ret
342
	ret
343
 
343
 
344
 
344
 
345
;---------------------------------------------------------------------------
345
;---------------------------------------------------------------------------
346
;
346
;
347
; ETH_create_Packet
347
; ETH_create_Packet
348
;
348
;
349
; IN: pointer to source mac in eax
349
; IN: pointer to source mac in eax
350
;     pointer to destination mac in ebx
350
;     pointer to destination mac in ebx
351
;     packet size in ecx
351
;     packet size in ecx
352
;     device number in edx
352
;     device number in edx
353
;     protocol in di
353
;     protocol in di
354
;
354
;
355
; OUT: edi is -1 on error, pointer to buffer otherwise
355
; OUT: edi is -1 on error, pointer to buffer otherwise
356
;      eax points to buffer start
356
;      eax points to buffer start
357
;      ebx is pointer to device structure
357
;      ebx is pointer to device structure
358
;      ecx is unchanged (packet size of embedded data)
358
;      ecx is unchanged (packet size of embedded data)
359
;      edx is size of complete buffer
359
;      edx is size of complete buffer
360
;      esi points to procedure wich needs to be called to send packet
360
;      esi points to procedure wich needs to be called to send packet
361
;
361
;
362
;---------------------------------------------------------------------------
362
;---------------------------------------------------------------------------
363
 
363
 
364
align 4
364
align 4
365
ETH_create_Packet:
365
ETH_create_Packet:
366
 
366
 
367
	DEBUGF 1,"Creating Ethernet Packet (size=%u): \n", ecx
367
	DEBUGF 1,"Creating Ethernet Packet (size=%u): \n", ecx
368
 
368
 
369
	cmp	ecx, 1500
369
	cmp	ecx, 1500
370
	jg	.exit
370
	jg	.exit
371
 
371
 
372
	push	ecx di eax ebx edx
372
	push	ecx di eax ebx edx
373
 
373
 
374
	add	ecx, ETH_FRAME.Data
374
	add	ecx, ETH_FRAME.Data
375
	push	ecx
375
	push	ecx
376
	push	ecx
376
	push	ecx
377
	call	kernel_alloc
377
	call	kernel_alloc
378
	test	eax, eax
378
	test	eax, eax
379
	jz	.pop_exit
379
	jz	.pop_exit
380
 
380
 
381
	pop	ecx
381
	pop	ecx
382
	pop	edx
382
	pop	edx
383
 
383
 
384
	mov	edi, eax
384
	mov	edi, eax
385
	pop	esi
385
	pop	esi
386
	movsd
386
	movsd
387
	movsw
387
	movsw
388
	pop	esi
388
	pop	esi
389
	movsd
389
	movsd
390
	movsw
390
	movsw
391
	pop	ax
391
	pop	ax
392
	stosw
392
	stosw
393
 
393
 
394
	lea	eax, [edi - ETH_FRAME.Data]  ; Set eax to buffer start
394
	lea	eax, [edi - ETH_FRAME.Data]  ; Set eax to buffer start
395
	mov	edx, ecx		     ; Set ebx to complete buffer size
395
	mov	edx, ecx		     ; Set ebx to complete buffer size
396
	pop	ecx
396
	pop	ecx
397
	mov	esi, ETH_Sender
397
	mov	esi, ETH_Sender
398
 
398
 
399
	xor	ebx, ebx			;;;; TODO: Fixme
399
	xor	ebx, ebx			;;;; TODO: Fixme
400
	mov	ebx, [ETH_DRV_LIST + ebx]
400
	mov	ebx, [ETH_DRV_LIST + ebx]
401
 
401
 
402
	cmp	edx, 46 + ETH_FRAME.Data    ; If data size is less then 46, add padding bytes
402
	cmp	edx, 46 + ETH_FRAME.Data    ; If data size is less then 46, add padding bytes
403
	jg	.continue
403
	jg	.continue
404
	mov	edx, 46 + ETH_FRAME.Data
404
	mov	edx, 46 + ETH_FRAME.Data
405
       .continue:
405
       .continue:
406
 
406
 
407
	DEBUGF 1,"done: %x size:%u device:%x\n", eax, edx, ebx
407
	DEBUGF 1,"done: %x size:%u device:%x\n", eax, edx, ebx
408
	ret
408
	ret
409
 
409
 
410
  .pop_exit:
410
  .pop_exit:
411
	DEBUGF 1,"Out of ram space!!\n"
411
	DEBUGF 1,"Out of ram space!!\n"
412
	add	esp, 18
412
	add	esp, 18
413
	or	edi,-1
413
	or	edi,-1
414
	ret
414
	ret
415
 
415
 
416
  .exit:
416
  .exit:
417
	DEBUGF 1,"Packet too large!\n"
417
	DEBUGF 1,"Packet too large!\n"
418
	or	edi, -1
418
	or	edi, -1
419
	ret
419
	ret
420
 
420
 
421
 
421
 
422
 
422
 
423
;---------------------------------------------------------------------------
423
;---------------------------------------------------------------------------
424
;
424
;
425
; ETH_API
425
; ETH_API
426
;
426
;
427
; This function is called by system function 75
427
; This function is called by system function 75
428
;
428
;
429
; IN:  subfunction number in bl
429
; IN:  subfunction number in bl
430
;      device number in bh
430
;      device number in bh
431
;      ecx, edx, .. depends on subfunction
431
;      ecx, edx, .. depends on subfunction
432
;
432
;
433
; OUT:
433
; OUT:
434
;
434
;
435
;---------------------------------------------------------------------------
435
;---------------------------------------------------------------------------
436
 
436
 
437
align 4
437
align 4
438
ETH_API:
438
ETH_API:
439
 
439
 
440
	movzx	eax, bh
440
	movzx	eax, bh
441
	shl	eax, 2
441
	shl	eax, 2
442
 
442
 
443
	test	bl, bl
443
	test	bl, bl
444
	jz	.packets_tx	; 0
444
	jz	.packets_tx	; 0
445
	dec	bl
445
	dec	bl
446
	jz	.packets_rx	; 1
446
	jz	.packets_rx	; 1
447
	dec	bl
447
	dec	bl
448
	jz	.bytes_tx	; 2
448
	jz	.bytes_tx	; 2
449
	dec	bl
449
	dec	bl
450
	jz	.bytes_rx	; 3
450
	jz	.bytes_rx	; 3
451
	dec	bl
451
	dec	bl
452
	jz	.read_mac	; 4
452
	jz	.read_mac	; 4
453
	dec	bl
453
	dec	bl
454
	jz	.write_mac	; 5
454
	jz	.write_mac	; 5
455
	dec	bl
455
	dec	bl
456
	jz	.in_queue	; 6
456
	jz	.in_queue	; 6
457
	dec	bl
457
	dec	bl
458
	jz	.out_queue	; 7
458
	jz	.out_queue	; 7
459
 
459
 
460
.error:
460
.error:
461
	mov	eax, -1
461
	mov	eax, -1
462
	ret
462
	ret
463
 
463
 
464
.packets_tx:
464
.packets_tx:
465
	add	eax, ETH_DRV_LIST
465
	add	eax, ETH_DRV_LIST
466
	mov	eax, dword [eax]
466
	mov	eax, dword [eax]
467
	mov	eax, dword [eax + ETH_DEVICE.packets_tx]
467
	mov	eax, dword [eax + ETH_DEVICE.packets_tx]
468
 
468
 
469
	ret
469
	ret
470
 
470
 
471
.packets_rx:
471
.packets_rx:
472
	add	eax, ETH_DRV_LIST
472
	add	eax, ETH_DRV_LIST
473
	mov	eax, dword [eax]
473
	mov	eax, dword [eax]
474
	mov	eax, dword [eax + ETH_DEVICE.packets_rx]
474
	mov	eax, dword [eax + ETH_DEVICE.packets_rx]
475
	ret
475
	ret
476
 
476
 
477
.bytes_tx:
477
.bytes_tx:
478
	add	eax, ETH_DRV_LIST
478
	add	eax, ETH_DRV_LIST
479
	mov	eax, dword [eax]
479
	mov	eax, dword [eax]
480
	mov	eax, dword [eax + ETH_DEVICE.bytes_tx + 4]
480
	mov	ebx, dword [eax + ETH_DEVICE.bytes_tx + 4]
481
	mov	eax, dword [eax + ETH_DEVICE.bytes_tx]
481
	mov	eax, dword [eax + ETH_DEVICE.bytes_tx]
482
	mov	[esp+20+4], ebx 			; TODO: fix this ugly code
482
	mov	[esp+20+4], ebx 			; TODO: fix this ugly code
483
	ret
483
	ret
484
 
484
 
485
.bytes_rx:
485
.bytes_rx:
486
	add	eax, ETH_DRV_LIST
486
	add	eax, ETH_DRV_LIST
487
	mov	eax, dword [eax]
487
	mov	eax, dword [eax]
488
	mov	ebx, dword [eax + ETH_DEVICE.bytes_rx + 4]
488
	mov	ebx, dword [eax + ETH_DEVICE.bytes_rx + 4]
489
	mov	eax, dword [eax + ETH_DEVICE.bytes_rx]
489
	mov	eax, dword [eax + ETH_DEVICE.bytes_rx]
490
	mov	[esp+20+4], ebx 			; TODO: fix this ugly code
490
	mov	[esp+20+4], ebx 			; TODO: fix this ugly code
491
	ret
491
	ret
492
 
492
 
493
 
493
 
494
.read_mac:
494
.read_mac:
495
	add	eax, ETH_DRV_LIST
495
	add	eax, ETH_DRV_LIST
496
	mov	eax, [eax]
496
	mov	eax, [eax]
497
;        push    eax
497
;        push    eax
498
;        call    dword [eax + ETH_DEVICE.get_MAC]
498
;        call    dword [eax + ETH_DEVICE.get_MAC]
499
;        pop     eax
499
;        pop     eax
500
	movzx	ebx, word [eax + ETH_DEVICE.mac]
500
	movzx	ebx, word [eax + ETH_DEVICE.mac]
501
	mov	eax, dword [eax + ETH_DEVICE.mac + 2]
501
	mov	eax, dword [eax + ETH_DEVICE.mac + 2]
502
	mov	[esp+20+4], ebx 			; TODO: fix this ugly code
502
	mov	[esp+20+4], ebx 			; TODO: fix this ugly code
503
	ret
503
	ret
504
 
504
 
505
.write_mac:
505
.write_mac:
506
	push	ecx
506
	push	ecx
507
	push	dx
507
	push	dx
508
	add	eax, ETH_DRV_LIST
508
	add	eax, ETH_DRV_LIST
509
	mov	eax, [eax]
509
	mov	eax, [eax]
510
	mov	eax, dword [eax + ETH_DEVICE.set_MAC]
510
	mov	eax, dword [eax + ETH_DEVICE.set_MAC]
511
	call	eax
511
	call	eax
512
	ret
512
	ret
513
 
513
 
514
.in_queue:
514
.in_queue:
515
	add	eax, ETH_IN_QUEUE
515
	add	eax, ETH_IN_QUEUE
516
	mov	eax, [eax + queue.size]
516
	mov	eax, [eax + queue.size]
517
	ret
517
	ret
518
 
518
 
519
.out_queue:
519
.out_queue:
520
	add	eax, ETH_OUT_QUEUE
520
	add	eax, ETH_OUT_QUEUE
521
	mov	eax, [eax + queue.size]
521
	mov	eax, [eax + queue.size]
522
	ret
522
	ret