Rev 6476 | Rev 7679 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6476 | Rev 7678 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2019. 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 | ;; STACK.INC ;; |
6 | ;; STACK.INC ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; TCP/IP stack for KolibriOS ;; |
8 | ;; TCP/IP stack for KolibriOS ;; |
Line 19... | Line 19... | ||
19 | ;; GNU GENERAL PUBLIC LICENSE ;; |
19 | ;; GNU GENERAL PUBLIC LICENSE ;; |
20 | ;; Version 2, June 1991 ;; |
20 | ;; Version 2, June 1991 ;; |
21 | ;; ;; |
21 | ;; ;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 23... | Line 23... | ||
23 | 23 | ||
Line 24... | Line 24... | ||
24 | $Revision: 6476 $ |
24 | $Revision: 7678 $ |
25 | 25 | ||
26 | uglobal |
26 | uglobal |
27 | net_10ms dd ? |
27 | net_10ms dd ? |
Line 249... | Line 249... | ||
249 | 249 | ||
250 | 250 | ||
Line 251... | Line 251... | ||
251 | uglobal |
251 | uglobal |
252 | align 4 |
252 | align 4 |
Line 253... | Line 253... | ||
253 | 253 | ||
254 | NET_RUNNING dd ? |
254 | net_running dd ? |
Line 255... | Line 255... | ||
255 | NET_DRV_LIST rd NET_DEVICES_MAX |
255 | net_drv_list rd NET_DEVICES_MAX |
Line 274... | Line 274... | ||
274 | ; allocate network buffers |
274 | ; allocate network buffers |
275 | stdcall kernel_alloc, NET_BUFFER_SIZE*NET_BUFFERS |
275 | stdcall kernel_alloc, NET_BUFFER_SIZE*NET_BUFFERS |
276 | test eax, eax |
276 | test eax, eax |
277 | jz .fail |
277 | jz .fail |
Line 278... | Line 278... | ||
278 | 278 | ||
279 | mov edi, NET_BUFFS_FREE |
279 | mov edi, net_buffs_free |
280 | mov ecx, NET_BUFFERS |
280 | mov ecx, NET_BUFFERS |
281 | cld |
281 | cld |
282 | .loop: |
282 | .loop: |
283 | stosd |
283 | stosd |
284 | add eax, NET_BUFFER_SIZE |
284 | add eax, NET_BUFFER_SIZE |
285 | dec ecx |
285 | dec ecx |
Line 286... | Line 286... | ||
286 | jnz .loop |
286 | jnz .loop |
287 | 287 | ||
Line 288... | Line 288... | ||
288 | mov eax, NET_BUFFS_FREE |
288 | mov eax, net_buffs_free |
289 | stosd |
289 | stosd |
290 | 290 | ||
291 | ; Init the network drivers list |
291 | ; Init the network drivers list |
292 | xor eax, eax |
292 | xor eax, eax |
Line 293... | Line 293... | ||
293 | mov edi, NET_RUNNING |
293 | mov edi, net_running |
Line 344... | Line 344... | ||
344 | mov eax, [timer_ticks] |
344 | mov eax, [timer_ticks] |
345 | cmp eax, [net_10ms] |
345 | cmp eax, [net_10ms] |
346 | je .exit |
346 | je .exit |
347 | mov [net_10ms], eax |
347 | mov [net_10ms], eax |
Line 348... | Line 348... | ||
348 | 348 | ||
349 | cmp [NET_RUNNING], 0 |
349 | cmp [net_running], 0 |
Line 350... | Line 350... | ||
350 | je .exit |
350 | je .exit |
351 | 351 | ||
Line 376... | Line 376... | ||
376 | cmp [buffersize], NET_BUFFER_SIZE |
376 | cmp [buffersize], NET_BUFFER_SIZE |
377 | ja .too_large |
377 | ja .too_large |
Line 378... | Line 378... | ||
378 | 378 | ||
Line 379... | Line 379... | ||
379 | spin_lock_irqsave |
379 | spin_lock_irqsave |
380 | 380 | ||
381 | mov eax, [NET_BUFFS_FREE.current] |
381 | mov eax, [net_buffs_free.current] |
382 | cmp eax, NET_BUFFS_FREE+NET_BUFFERS*4 |
382 | cmp eax, net_buffs_free+NET_BUFFERS*4 |
383 | jae .out_of_mem |
383 | jae .out_of_mem |
Line 384... | Line 384... | ||
384 | mov eax, [eax] |
384 | mov eax, [eax] |
Line 385... | Line 385... | ||
385 | add [NET_BUFFS_FREE.current], 4 |
385 | add [net_buffs_free.current], 4 |
386 | 386 | ||
Line 408... | Line 408... | ||
408 | 408 | ||
Line 409... | Line 409... | ||
409 | DEBUGF DEBUG_NETWORK_VERBOSE, "net_buff_free: 0x%x\n", [buffer] |
409 | DEBUGF DEBUG_NETWORK_VERBOSE, "net_buff_free: 0x%x\n", [buffer] |
Line 410... | Line 410... | ||
410 | 410 | ||
411 | spin_lock_irqsave |
411 | spin_lock_irqsave |
412 | 412 | ||
413 | sub [NET_BUFFS_FREE.current], 4 |
413 | sub [net_buffs_free.current], 4 |
Line 414... | Line 414... | ||
414 | mov eax, [NET_BUFFS_FREE.current] |
414 | mov eax, [net_buffs_free.current] |
Line 458... | Line 458... | ||
458 | align 4 |
458 | align 4 |
459 | net_add_device: |
459 | net_add_device: |
Line 460... | Line 460... | ||
460 | 460 | ||
Line 461... | Line 461... | ||
461 | DEBUGF DEBUG_NETWORK_VERBOSE, "net_add_device: %x\n", ebx ;;; TODO: use mutex to lock net device list |
461 | DEBUGF DEBUG_NETWORK_VERBOSE, "net_add_device: %x\n", ebx ;;; TODO: use mutex to lock net device list |
462 | 462 | ||
Line 463... | Line 463... | ||
463 | cmp [NET_RUNNING], NET_DEVICES_MAX |
463 | cmp [net_running], NET_DEVICES_MAX |
464 | jae .error |
464 | jae .error |
465 | 465 | ||
466 | ;---------------------------------- |
466 | ;---------------------------------- |
467 | ; Check if device is already listed |
467 | ; Check if device is already listed |
Line 468... | Line 468... | ||
468 | mov eax, ebx |
468 | mov eax, ebx |
469 | mov ecx, NET_DEVICES_MAX ; We need to check whole list because a device may be removed without re-organizing list |
469 | mov ecx, NET_DEVICES_MAX ; We need to check whole list because a device may be removed without re-organizing list |
Line 470... | Line 470... | ||
470 | mov edi, NET_DRV_LIST |
470 | mov edi, net_drv_list |
471 | 471 | ||
472 | repne scasd ; See if device is already in the list |
472 | repne scasd ; See if device is already in the list |
473 | jz .error |
473 | jz .error |
474 | 474 | ||
Line 475... | Line 475... | ||
475 | ;---------------------------- |
475 | ;---------------------------- |
476 | ; Find empty slot in the list |
476 | ; Find empty slot in the list |
Line 477... | Line 477... | ||
477 | xor eax, eax |
477 | xor eax, eax |
Line 486... | Line 486... | ||
486 | ;----------------------------- |
486 | ;----------------------------- |
487 | ; Add device to the found slot |
487 | ; Add device to the found slot |
488 | mov [edi], ebx ; add device to list |
488 | mov [edi], ebx ; add device to list |
Line 489... | Line 489... | ||
489 | 489 | ||
490 | mov eax, edi ; Calculate device number in eax |
490 | mov eax, edi ; Calculate device number in eax |
491 | sub eax, NET_DRV_LIST |
491 | sub eax, net_drv_list |
Line 492... | Line 492... | ||
492 | shr eax, 2 |
492 | shr eax, 2 |
Line 493... | Line 493... | ||
493 | 493 | ||
Line 494... | Line 494... | ||
494 | inc [NET_RUNNING] ; Indicate that one more network device is up and running |
494 | inc [net_running] ; Indicate that one more network device is up and running |
495 | 495 | ||
Line 515... | Line 515... | ||
515 | ; ; |
515 | ; ; |
516 | ;-----------------------------------------------------------------; |
516 | ;-----------------------------------------------------------------; |
517 | align 4 |
517 | align 4 |
518 | net_remove_device: |
518 | net_remove_device: |
Line 519... | Line 519... | ||
519 | 519 | ||
520 | cmp [NET_RUNNING], 0 |
520 | cmp [net_running], 0 |
Line 521... | Line 521... | ||
521 | je .error |
521 | je .error |
522 | 522 | ||
Line 523... | Line 523... | ||
523 | ;---------------------------- |
523 | ;---------------------------- |
524 | ; Find the driver in the list |
524 | ; Find the driver in the list |
525 | 525 | ||
Line 526... | Line 526... | ||
526 | mov eax, ebx |
526 | mov eax, ebx |
527 | mov ecx, NET_DEVICES_MAX |
527 | mov ecx, NET_DEVICES_MAX |
Line 528... | Line 528... | ||
528 | mov edi, NET_DRV_LIST |
528 | mov edi, net_drv_list |
529 | 529 | ||
Line 530... | Line 530... | ||
530 | repne scasd |
530 | repne scasd |
531 | jnz .error |
531 | jnz .error |
532 | 532 | ||
Line 533... | Line 533... | ||
533 | ;------------------------ |
533 | ;------------------------ |
Line 534... | Line 534... | ||
534 | ; Remove it from the list |
534 | ; Remove it from the list |
535 | 535 | ||
Line 573... | Line 573... | ||
573 | test ebx, ebx |
573 | test ebx, ebx |
574 | jz .fail |
574 | jz .fail |
Line 575... | Line 575... | ||
575 | 575 | ||
576 | push ecx |
576 | push ecx |
577 | mov ecx, NET_DEVICES_MAX |
577 | mov ecx, NET_DEVICES_MAX |
578 | mov edi, NET_DRV_LIST |
578 | mov edi, net_drv_list |
579 | .loop: |
579 | .loop: |
580 | cmp ebx, [edi] |
580 | cmp ebx, [edi] |
581 | je .found |
581 | je .found |
582 | add edi, 4 |
582 | add edi, 4 |
Line 587... | Line 587... | ||
587 | .fail: |
587 | .fail: |
588 | or edi, -1 |
588 | or edi, -1 |
589 | ret |
589 | ret |
Line 590... | Line 590... | ||
590 | 590 | ||
591 | .found: |
591 | .found: |
592 | sub edi, NET_DRV_LIST |
592 | sub edi, net_drv_list |
593 | pop ecx |
593 | pop ecx |
Line 594... | Line 594... | ||
594 | ret |
594 | ret |
595 | 595 | ||
Line 715... | Line 715... | ||
715 | sys_network: |
715 | sys_network: |
Line 716... | Line 716... | ||
716 | 716 | ||
717 | cmp bl, 255 |
717 | cmp bl, 255 |
Line 718... | Line 718... | ||
718 | jne @f |
718 | jne @f |
719 | 719 | ||
720 | mov eax, [NET_RUNNING] |
720 | mov eax, [net_running] |
Line 721... | Line 721... | ||
721 | mov [esp+32], eax |
721 | mov [esp+32], eax |
722 | ret |
722 | ret |
Line 727... | Line 727... | ||
727 | 727 | ||
728 | mov esi, ebx |
728 | mov esi, ebx |
729 | and esi, 0x0000ff00 |
729 | and esi, 0x0000ff00 |
Line 730... | Line 730... | ||
730 | shr esi, 6 |
730 | shr esi, 6 |
731 | 731 | ||
Line 732... | Line 732... | ||
732 | cmp dword[esi + NET_DRV_LIST], 0 ; check if driver is running |
732 | cmp dword[esi + net_drv_list], 0 ; check if driver is running |
Line 733... | Line 733... | ||
733 | je .doesnt_exist |
733 | je .doesnt_exist |
734 | 734 | ||
735 | mov eax, [esi + NET_DRV_LIST] |
735 | mov eax, [esi + net_drv_list] |
736 | 736 | ||
Line 838... | Line 838... | ||
838 | jae .doesnt_exist |
838 | jae .doesnt_exist |
Line 839... | Line 839... | ||
839 | 839 | ||
840 | mov esi, ebx |
840 | mov esi, ebx |
841 | and esi, 0x0000ff00 |
841 | and esi, 0x0000ff00 |
842 | shr esi, 6 ; now we have the device num * 4 in esi |
842 | shr esi, 6 ; now we have the device num * 4 in esi |
843 | cmp [esi + NET_DRV_LIST], 0 ; check if driver is running |
843 | cmp [esi + net_drv_list], 0 ; check if driver is running |
Line 844... | Line 844... | ||
844 | je .doesnt_exist |
844 | je .doesnt_exist |
Line 845... | Line 845... | ||
845 | 845 |