Subversion Repositories Kolibri OS

Rev

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

Rev 3545 Rev 3556
Line 261... Line 261...
261
        dd      SOCKET_get_opt  ; 9
261
        dd      SOCKET_get_opt  ; 9
262
        dd      SOCKET_pair     ; 10
262
        dd      SOCKET_pair     ; 10
263
  .number = ($ - .table) / 4 - 1
263
  .number = ($ - .table) / 4 - 1
Line 264... Line 264...
264
 
264
 
265
s_error:
265
s_error:
266
        DEBUGF  2,"SOCKET: error\n"
266
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET: error\n"
Line 267... Line 267...
267
        mov     dword [esp+32], -1
267
        mov     dword [esp+32], -1
Line 268... Line 268...
268
 
268
 
Line 279... Line 279...
279
;
279
;
280
;-----------------------------------------------------------------
280
;-----------------------------------------------------------------
281
align 4
281
align 4
282
SOCKET_open:
282
SOCKET_open:
Line 283... Line 283...
283
 
283
 
Line 284... Line 284...
284
        DEBUGF  2,"SOCKET_open: domain=%u type=%u protocol=%x ", ecx, edx, esi
284
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_open: domain=%u type=%u protocol=%x ", ecx, edx, esi
285
 
285
 
286
        push    ecx edx esi
286
        push    ecx edx esi
287
        call    SOCKET_alloc
287
        call    SOCKET_alloc
Line 288... Line 288...
288
        pop     esi edx ecx
288
        pop     esi edx ecx
289
        jz      s_error
289
        jz      s_error
Line 290... Line 290...
290
 
290
 
291
        mov     [esp+32], edi                   ; return socketnumber
291
        mov     [esp+32], edi                   ; return socketnumber
292
        DEBUGF  2,"socknum=%u\n", edi
292
        DEBUGF  DEBUG_NETWORK_VERBOSE, "socknum=%u\n", edi
293
 
293
 
Line 319... Line 319...
319
 
319
 
320
        cmp     esi, PPP_PROTO_ETHERNET
320
        cmp     esi, PPP_PROTO_ETHERNET
Line 321... Line 321...
321
        je      .pppoe
321
        je      .pppoe
322
 
322
 
323
  .no_ppp:
323
  .no_ppp:
Line 324... Line 324...
324
        DEBUGF  2,"Unknown socket family/protocol\n"
324
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_open: Unknown socket family/protocol\n"
325
        ret
325
        ret
326
 
326
 
Line 392... Line 392...
392
;
392
;
393
;-----------------------------------------------------------------
393
;-----------------------------------------------------------------
394
align 4
394
align 4
395
SOCKET_bind:
395
SOCKET_bind:
Line 396... Line 396...
396
 
396
 
Line 397... Line 397...
397
        DEBUGF  2,"SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
397
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
398
 
398
 
Line 399... Line 399...
399
        call    SOCKET_num_to_ptr
399
        call    SOCKET_num_to_ptr
Line 442... Line 442...
442
 
442
 
443
        mov     bx, [edx + 2]                   ; Now fill in the local port if it's still available
443
        mov     bx, [edx + 2]                   ; Now fill in the local port if it's still available
444
        call    SOCKET_check_port
444
        call    SOCKET_check_port
Line 445... Line 445...
445
        jz      s_error                         ; ZF is set by socket_check_port, on error
445
        jz      s_error                         ; ZF is set by socket_check_port, on error
446
 
446
 
447
        DEBUGF  1,"SOCKET_bind: local ip=%u.%u.%u.%u\n",\
447
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_bind: local ip=%u.%u.%u.%u\n",\
Line 448... Line 448...
448
        [eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\
448
        [eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\
449
        [eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1
449
        [eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1
Line 465... Line 465...
465
;
465
;
466
;-----------------------------------------------------------------
466
;-----------------------------------------------------------------
467
align 4
467
align 4
468
SOCKET_connect:
468
SOCKET_connect:
Line 469... Line 469...
469
 
469
 
Line 470... Line 470...
470
        DEBUGF  2,"SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
470
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
471
 
471
 
Line 472... Line 472...
472
        call    SOCKET_num_to_ptr
472
        call    SOCKET_num_to_ptr
Line 614... Line 614...
614
;
614
;
615
;-----------------------------------------------------------------
615
;-----------------------------------------------------------------
616
align 4
616
align 4
617
SOCKET_listen:
617
SOCKET_listen:
Line 618... Line 618...
618
 
618
 
Line 619... Line 619...
619
        DEBUGF  2,"SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
619
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
620
 
620
 
Line 621... Line 621...
621
        call    SOCKET_num_to_ptr
621
        call    SOCKET_num_to_ptr
Line 666... Line 666...
666
;
666
;
667
;-----------------------------------------------------------------
667
;-----------------------------------------------------------------
668
align 4
668
align 4
669
SOCKET_accept:
669
SOCKET_accept:
Line 670... Line 670...
670
 
670
 
Line 671... Line 671...
671
        DEBUGF  2,"SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
671
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
672
 
672
 
Line 673... Line 673...
673
        call    SOCKET_num_to_ptr
673
        call    SOCKET_num_to_ptr
Line 716... Line 716...
716
;
716
;
717
;-----------------------------------------------------------------
717
;-----------------------------------------------------------------
718
align 4
718
align 4
719
SOCKET_close:
719
SOCKET_close:
Line 720... Line 720...
720
 
720
 
Line 721... Line 721...
721
        DEBUGF  2,"SOCKET_close: socknum=%u\n", ecx
721
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_close: socknum=%u\n", ecx
722
 
722
 
Line 723... Line 723...
723
        call    SOCKET_num_to_ptr
723
        call    SOCKET_num_to_ptr
Line 765... Line 765...
765
;
765
;
766
;-----------------------------------------------------------------
766
;-----------------------------------------------------------------
767
align 4
767
align 4
768
SOCKET_receive:
768
SOCKET_receive:
Line 769... Line 769...
769
 
769
 
Line 770... Line 770...
770
        DEBUGF  2,"SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
770
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
771
 
771
 
Line 772... Line 772...
772
        call    SOCKET_num_to_ptr
772
        call    SOCKET_num_to_ptr
Line 773... Line 773...
773
        jz      s_error
773
        jz      s_error
774
 
774
 
Line 775... Line 775...
775
        jmp     [eax + SOCKET.rcv_proc]
775
        jmp     [eax + SOCKET.rcv_proc]
Line 776... Line 776...
776
 
776
 
777
 
777
 
Line 778... Line 778...
778
align 4
778
align 4
779
SOCKET_receive_dgram:
779
SOCKET_receive_dgram:
Line 780... Line 780...
780
 
780
 
781
        DEBUGF  1,"SOCKET_receive: DGRAM\n"
781
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: DGRAM\n"
Line 782... Line 782...
782
 
782
 
783
        mov     ebx, esi
783
        mov     ebx, esi
Line 784... Line 784...
784
        mov     edi, edx                                        ; addr to buffer
784
        mov     edi, edx                                        ; addr to buffer
785
 
785
 
786
  .loop:
786
  .loop:
787
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block      ; destroys esi and ecx
787
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block      ; destroys esi and ecx
Line 788... Line 788...
788
 
788
 
789
        mov     ecx, [esi + socket_queue_entry.data_size]
789
        mov     ecx, [esi + socket_queue_entry.data_size]
790
        DEBUGF  1,"SOCKET_receive: %u bytes data\n", ecx
790
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: %u bytes data\n", ecx
Line 814... Line 814...
814
        call    kernel_free                                     ; remove the packet
814
        call    kernel_free                                     ; remove the packet
815
        ret
815
        ret
Line 816... Line 816...
816
 
816
 
Line 817... Line 817...
817
  .too_small:
817
  .too_small:
818
 
818
 
Line 819... Line 819...
819
        DEBUGF  2,"SOCKET_receive: Buffer too small\n"
819
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: Buffer too small\n"
820
        jmp     s_error
820
        jmp     s_error
821
 
821
 
Line 844... Line 844...
844
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
844
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
Line 845... Line 845...
845
 
845
 
846
align 4
846
align 4
Line 847... Line 847...
847
SOCKET_receive_stream:
847
SOCKET_receive_stream:
Line 848... Line 848...
848
 
848
 
849
        DEBUGF  1,"SOCKET_receive: STREAM\n"
849
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: STREAM\n"
850
 
850
 
851
        mov     ebx, edi
851
        mov     ebx, edi
Line 900... Line 900...
900
;
900
;
901
;-----------------------------------------------------------------
901
;-----------------------------------------------------------------
902
align 4
902
align 4
903
SOCKET_send:
903
SOCKET_send:
Line 904... Line 904...
904
 
904
 
Line 905... Line 905...
905
        DEBUGF  2,"SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
905
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
906
 
906
 
Line 907... Line 907...
907
        call    SOCKET_num_to_ptr
907
        call    SOCKET_num_to_ptr
Line 914... Line 914...
914
 
914
 
915
 
915
 
Line 916... Line 916...
916
align 4
916
align 4
Line 917... Line 917...
917
SOCKET_send_udp:
917
SOCKET_send_udp:
918
 
918
 
919
        DEBUGF  1,"SOCKET_send: UDP\n"
919
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: UDP\n"
920
 
920
 
Line 926... Line 926...
926
 
926
 
927
 
927
 
Line 928... Line 928...
928
align 4
928
align 4
Line 929... Line 929...
929
SOCKET_send_tcp:
929
SOCKET_send_tcp:
930
 
930
 
931
        DEBUGF  1,"SOCKET_send: TCP\n"
931
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: TCP\n"
932
 
932
 
Line 942... Line 942...
942
 
942
 
943
 
943
 
Line 944... Line 944...
944
align 4
944
align 4
Line 945... Line 945...
945
SOCKET_send_ip:
945
SOCKET_send_ip:
946
 
946
 
947
        DEBUGF  1,"SOCKET_send: IPv4\n"
947
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: IPv4\n"
948
 
948
 
Line 954... Line 954...
954
 
954
 
955
 
955
 
Line 956... Line 956...
956
align 4
956
align 4
Line 957... Line 957...
957
SOCKET_send_icmp:
957
SOCKET_send_icmp:
958
 
958
 
959
        DEBUGF  1,"SOCKET_send: ICMP\n"
959
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: ICMP\n"
960
 
960
 
Line 966... Line 966...
966
 
966
 
967
 
967
 
Line 968... Line 968...
968
align 4
968
align 4
Line 969... Line 969...
969
SOCKET_send_pppoe:
969
SOCKET_send_pppoe:
970
 
970
 
Line 971... Line 971...
971
        DEBUGF  1,"SOCKET_send: PPPoE\n"
971
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: PPPoE\n"
Line 996... Line 996...
996
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local_
996
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local_
Line 997... Line 997...
997
 
997
 
998
align 4
998
align 4
Line 999... Line 999...
999
SOCKET_send_local_:
999
SOCKET_send_local_:
Line 1000... Line 1000...
1000
 
1000
 
1001
        DEBUGF  1,"SOCKET_send: LOCAL\n"
1001
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: LOCAL\n"
1002
 
1002
 
1003
        ; get the other side's socket and check if it still exists
1003
        ; get the other side's socket and check if it still exists
Line 1035... Line 1035...
1035
;
1035
;
1036
;-----------------------------------------------------------------
1036
;-----------------------------------------------------------------
1037
align 4
1037
align 4
1038
SOCKET_get_opt:
1038
SOCKET_get_opt:
Line 1039... Line 1039...
1039
 
1039
 
Line 1040... Line 1040...
1040
        DEBUGF  2,"SOCKET_get_opt\n"
1040
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_get_opt\n"
1041
 
1041
 
Line 1042... Line 1042...
1042
        call    SOCKET_num_to_ptr
1042
        call    SOCKET_num_to_ptr
Line 1085... Line 1085...
1085
;
1085
;
1086
;-----------------------------------------------------------------
1086
;-----------------------------------------------------------------
1087
align 4
1087
align 4
1088
SOCKET_set_opt:
1088
SOCKET_set_opt:
Line 1089... Line 1089...
1089
 
1089
 
Line 1090... Line 1090...
1090
        DEBUGF  2,"SOCKET_set_opt\n"
1090
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_set_opt\n"
1091
 
1091
 
Line 1092... Line 1092...
1092
        call    SOCKET_num_to_ptr
1092
        call    SOCKET_num_to_ptr
Line 1114... Line 1114...
1114
        mov     edx, [NET_DRV_LIST + 4*edx]
1114
        mov     edx, [NET_DRV_LIST + 4*edx]
1115
        test    edx, edx
1115
        test    edx, edx
1116
        jz      s_error
1116
        jz      s_error
1117
        mov     [eax + SOCKET.device], edx
1117
        mov     [eax + SOCKET.device], edx
Line 1118... Line 1118...
1118
 
1118
 
Line 1119... Line 1119...
1119
        DEBUGF  1,"SOCKET_set_opt: Bound socket %x to device %x\n",eax, edx
1119
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_set_opt: Bound socket %x to device %x\n",eax, edx
1120
 
1120
 
Line 1121... Line 1121...
1121
        mov     dword [esp+32], 0       ; success!
1121
        mov     dword [esp+32], 0       ; success!
Line 1156... Line 1156...
1156
;
1156
;
1157
;-----------------------------------------------------------------
1157
;-----------------------------------------------------------------
1158
align 4
1158
align 4
1159
SOCKET_pair:
1159
SOCKET_pair:
Line 1160... Line 1160...
1160
 
1160
 
Line 1161... Line 1161...
1161
        DEBUGF  2,"SOCKET_pair\n"
1161
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_pair\n"
1162
 
1162
 
1163
        call    SOCKET_alloc
1163
        call    SOCKET_alloc
Line 1215... Line 1215...
1215
;  OUT: -1 on error
1215
;  OUT: -1 on error
1216
;-----------------------------------------------------------------
1216
;-----------------------------------------------------------------
1217
align 4
1217
align 4
1218
SOCKET_debug:
1218
SOCKET_debug:
Line 1219... Line 1219...
1219
 
1219
 
Line 1220... Line 1220...
1220
        DEBUGF  1,"SOCKET_debug\n"
1220
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_debug\n"
Line 1221... Line 1221...
1221
 
1221
 
1222
        mov     edi, edx
1222
        mov     edi, edx
Line 1264... Line 1264...
1264
;
1264
;
1265
;-----------------------------------------------------------------
1265
;-----------------------------------------------------------------
1266
align 4
1266
align 4
1267
SOCKET_find_port:
1267
SOCKET_find_port:
Line 1268... Line 1268...
1268
 
1268
 
Line 1269... Line 1269...
1269
        DEBUGF  2,"SOCKET_find_port\n"
1269
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_find_port\n"
Line 1270... Line 1270...
1270
 
1270
 
1271
        push    ebx esi ecx
1271
        push    ebx esi ecx
Line 1325... Line 1325...
1325
;
1325
;
1326
;-----------------------------------------------------------------
1326
;-----------------------------------------------------------------
1327
align 4
1327
align 4
1328
SOCKET_check_port:
1328
SOCKET_check_port:
Line 1329... Line 1329...
1329
 
1329
 
Line 1330... Line 1330...
1330
        DEBUGF  2,"SOCKET_check_port: "
1330
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_check_port: "
1331
 
1331
 
1332
        mov     ecx, [eax + SOCKET.Protocol]
1332
        mov     ecx, [eax + SOCKET.Protocol]
Line 1345... Line 1345...
1345
        jne     .next_socket
1345
        jne     .next_socket
Line 1346... Line 1346...
1346
 
1346
 
1347
        cmp     [esi + UDP_SOCKET.LocalPort], bx
1347
        cmp     [esi + UDP_SOCKET.LocalPort], bx
Line 1348... Line 1348...
1348
        jne     .next_socket
1348
        jne     .next_socket
1349
 
1349
 
Line 1350... Line 1350...
1350
        DEBUGF  2,"local port %x already in use\n", bx  ; FIXME: find a way to print big endian values with debugf
1350
        DEBUGF  DEBUG_NETWORK_VERBOSE, "local port %x already in use\n", bx  ; FIXME: find a way to print big endian values with debugf
1351
        ret
1351
        ret
1352
 
1352
 
1353
  .port_ok:
1353
  .port_ok:
1354
        DEBUGF  2,"local port %x is free\n", bx         ; FIXME: find a way to print big endian values with debugf
1354
        DEBUGF  DEBUG_NETWORK_VERBOSE, "local port %x is free\n", bx         ; FIXME: find a way to print big endian values with debugf
Line 1376... Line 1376...
1376
;
1376
;
1377
;-----------------------------------------------------------------
1377
;-----------------------------------------------------------------
1378
align 4
1378
align 4
1379
SOCKET_input:
1379
SOCKET_input:
Line 1380... Line 1380...
1380
 
1380
 
Line 1381... Line 1381...
1381
        DEBUGF  2,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx
1381
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx
1382
 
1382
 
1383
        mov     [esp+4], ecx
1383
        mov     [esp+4], ecx
Line 1384... Line 1384...
1384
        push    esi
1384
        push    esi
Line 1385... Line 1385...
1385
        mov     esi, esp
1385
        mov     esi, esp
1386
 
1386
 
Line 1387... Line 1387...
1387
        add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full
1387
        add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full
1388
 
1388
 
1389
        DEBUGF  1,"SOCKET_input: success\n"
1389
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_input: success\n"
1390
        add     esp, sizeof.socket_queue_entry
1390
        add     esp, sizeof.socket_queue_entry
Line 1391... Line 1391...
1391
 
1391
 
Line 1392... Line 1392...
1392
        pusha
1392
        pusha
1393
        lea     ecx, [eax + SOCKET.mutex]
1393
        lea     ecx, [eax + SOCKET.mutex]
Line 1394... Line 1394...
1394
        call    mutex_unlock
1394
        call    mutex_unlock
1395
        popa
1395
        popa
1396
 
1396
 
1397
        jmp     SOCKET_notify
1397
        jmp     SOCKET_notify
Line 1422... Line 1422...
1422
 
1422
 
1423
        push    edx
1423
        push    edx
1424
        stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW
1424
        stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW
Line 1425... Line 1425...
1425
        pop     edx
1425
        pop     edx
Line 1426... Line 1426...
1426
 
1426
 
1427
        DEBUGF  1,"SOCKET_ring_created: %x\n", eax
1427
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_created: %x\n", eax
1428
 
1428
 
1429
        pusha
1429
        pusha
Line 1456... Line 1456...
1456
;
1456
;
1457
;-----------------------------------------------------------------
1457
;-----------------------------------------------------------------
1458
align 4
1458
align 4
1459
SOCKET_ring_write:
1459
SOCKET_ring_write:
Line 1460... Line 1460...
1460
 
1460
 
Line 1461... Line 1461...
1461
        DEBUGF  1,"SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx
1461
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx
1462
 
1462
 
1463
; lock mutex
1463
; lock mutex
1464
        pusha
1464
        pusha
Line 1472... Line 1472...
1472
        cmp     ecx, edi
1472
        cmp     ecx, edi
1473
        jbe     .copy
1473
        jbe     .copy
1474
        mov     ecx, edi
1474
        mov     ecx, edi
1475
  .copy:
1475
  .copy:
1476
        mov     edi, [eax + RING_BUFFER.write_ptr]
1476
        mov     edi, [eax + RING_BUFFER.write_ptr]
1477
        DEBUGF  2,"SOCKET_ring_write: %u bytes from %x to %x\n", ecx, esi, edi
1477
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_write: %u bytes from %x to %x\n", ecx, esi, edi
Line 1478... Line 1478...
1478
 
1478
 
1479
; update write ptr
1479
; update write ptr
1480
        push    edi
1480
        push    edi
1481
        add     edi, ecx
1481
        add     edi, ecx
Line 1530... Line 1530...
1530
;
1530
;
1531
;-----------------------------------------------------------------
1531
;-----------------------------------------------------------------
1532
align 4
1532
align 4
1533
SOCKET_ring_read:
1533
SOCKET_ring_read:
Line 1534... Line 1534...
1534
 
1534
 
Line 1535... Line 1535...
1535
        DEBUGF  1,"SOCKET_ring_read: ringbuff=%x ptr=%x size=%u offset=%x\n", eax, edi, ecx, edx
1535
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_read: ringbuff=%x ptr=%x size=%u offset=%x\n", eax, edi, ecx, edx
1536
 
1536
 
1537
        pusha
1537
        pusha
1538
        lea     ecx, [eax + RING_BUFFER.mutex]
1538
        lea     ecx, [eax + RING_BUFFER.mutex]
Line 1553... Line 1553...
1553
 
1553
 
1554
        cmp     ecx, edx
1554
        cmp     ecx, edx
Line 1555... Line 1555...
1555
        ja      .less_data
1555
        ja      .less_data
1556
 
1556
 
1557
  .copy:
1557
  .copy:
1558
        DEBUGF  2,"SOCKET_ring_read: %u bytes from %x to %x\n", ecx, esi, edi
1558
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_read: %u bytes from %x to %x\n", ecx, esi, edi
1559
        push    ecx
1559
        push    ecx
1560
        shr     ecx, 1
1560
        shr     ecx, 1
1561
        jnc     .nb
1561
        jnc     .nb
Line 1576... Line 1576...
1576
        pusha
1576
        pusha
1577
        lea     ecx, [eax + RING_BUFFER.mutex]
1577
        lea     ecx, [eax + RING_BUFFER.mutex]
1578
        call    mutex_unlock                                    ; TODO: check what registers this function actually destroys
1578
        call    mutex_unlock                                    ; TODO: check what registers this function actually destroys
1579
        popa
1579
        popa
Line 1580... Line 1580...
1580
 
1580
 
1581
        DEBUGF  1,"SOCKET_ring_read: no data at all!\n"
1581
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_read: no data at all!\n"
1582
        xor     ecx, ecx
1582
        xor     ecx, ecx
Line 1583... Line 1583...
1583
        ret
1583
        ret
1584
 
1584
 
Line 1600... Line 1600...
1600
;
1600
;
1601
;-----------------------------------------------------------------
1601
;-----------------------------------------------------------------
1602
align 4
1602
align 4
1603
SOCKET_ring_free:
1603
SOCKET_ring_free:
Line 1604... Line 1604...
1604
 
1604
 
Line 1605... Line 1605...
1605
        DEBUGF  1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax
1605
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax
1606
 
1606
 
1607
        push    eax ecx
1607
        push    eax ecx
1608
        lea     ecx, [eax + RING_BUFFER.mutex]
1608
        lea     ecx, [eax + RING_BUFFER.mutex]
Line 1625... Line 1625...
1625
        pop     ecx eax
1625
        pop     ecx eax
Line 1626... Line 1626...
1626
 
1626
 
Line 1627... Line 1627...
1627
        ret
1627
        ret
1628
 
1628
 
1629
  .error:       ; we could free all available bytes, but that would be stupid, i guess..
1629
  .error:       ; we could free all available bytes, but that would be stupid, i guess..
Line 1630... Line 1630...
1630
        DEBUGF  1,"SOCKET_ring_free: buffer=%x error!\n", eax
1630
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_free: buffer=%x error!\n", eax
1631
        add     [eax + RING_BUFFER.size], ecx
1631
        add     [eax + RING_BUFFER.size], ecx
1632
 
1632
 
Line 1650... Line 1650...
1650
;
1650
;
1651
;-----------------------------------------------------------------
1651
;-----------------------------------------------------------------
1652
align 4
1652
align 4
1653
SOCKET_block:
1653
SOCKET_block:
Line 1654... Line 1654...
1654
 
1654
 
Line 1655... Line 1655...
1655
        DEBUGF  1,"SOCKET_block: %x\n", eax
1655
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: %x\n", eax
1656
 
1656
 
Line 1657... Line 1657...
1657
        pushf
1657
        pushf
Line 1665... Line 1665...
1665
        mov     edx, [TASK_BASE]
1665
        mov     edx, [TASK_BASE]
1666
        mov     [edx + TASKDATA.state], 1               ; Suspended
1666
        mov     [edx + TASKDATA.state], 1               ; Suspended
Line 1667... Line 1667...
1667
 
1667
 
1668
        ; Remember the thread ID so we can wake it up again
1668
        ; Remember the thread ID so we can wake it up again
1669
        mov     edx, [edx + TASKDATA.pid]
1669
        mov     edx, [edx + TASKDATA.pid]
1670
        DEBUGF  1,"SOCKET_block: suspending thread: %u\n", edx
1670
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: suspending thread: %u\n", edx
1671
        mov     [eax + SOCKET.TID], edx
1671
        mov     [eax + SOCKET.TID], edx
Line 1672... Line 1672...
1672
        pop     edx
1672
        pop     edx
1673
 
1673
 
Line 1674... Line 1674...
1674
        call    change_task
1674
        call    change_task
Line 1675... Line 1675...
1675
        popf
1675
        popf
Line 1676... Line 1676...
1676
 
1676
 
Line 1690... Line 1690...
1690
;
1690
;
1691
;-----------------------------------------------------------------
1691
;-----------------------------------------------------------------
1692
align 4
1692
align 4
1693
SOCKET_notify:
1693
SOCKET_notify:
Line 1694... Line 1694...
1694
 
1694
 
Line 1695... Line 1695...
1695
        DEBUGF  1,"SOCKET_notify: %x\n", eax
1695
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: %x\n", eax
1696
 
1696
 
Line 1697... Line 1697...
1697
        call    SOCKET_check
1697
        call    SOCKET_check
Line 1726... Line 1726...
1726
 
1726
 
1727
  .found_pid:
1727
  .found_pid:
1728
        shl     ecx, 8
1728
        shl     ecx, 8
Line 1729... Line 1729...
1729
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
1729
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
Line 1730... Line 1730...
1730
 
1730
 
Line 1731... Line 1731...
1731
        DEBUGF  1,"SOCKET_notify: Raised a network event!\n"
1731
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: Raised a network event!\n"
1732
 
1732
 
Line 1754... Line 1754...
1754
        jmp     .error
1754
        jmp     .error
1755
  .found:
1755
  .found:
Line 1756... Line 1756...
1756
 
1756
 
1757
        ; Run the thread
1757
        ; Run the thread
1758
        mov     [esi + TASKDATA.state], 0       ; Running
1758
        mov     [esi + TASKDATA.state], 0       ; Running
Line 1759... Line 1759...
1759
        DEBUGF  1,"SOCKET_notify: Unblocked socket!\n"
1759
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: Unblocked socket!\n"
1760
 
1760
 
Line 1761... Line 1761...
1761
  .done:
1761
  .done:
Line 1783... Line 1783...
1783
SOCKET_alloc:
1783
SOCKET_alloc:
Line 1784... Line 1784...
1784
 
1784
 
Line 1785... Line 1785...
1785
        push    ebx
1785
        push    ebx
1786
 
1786
 
1787
        stdcall kernel_alloc, SOCKETBUFFSIZE
1787
        stdcall kernel_alloc, SOCKETBUFFSIZE
1788
        DEBUGF  1, "SOCKET_alloc: ptr=%x\n", eax
1788
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_alloc: ptr=%x\n", eax
Line 1789... Line 1789...
1789
        or      eax, eax
1789
        or      eax, eax
1790
        jz      .exit
1790
        jz      .exit
Line 1819... Line 1819...
1819
        jmp     .next_socket_number
1819
        jmp     .next_socket_number
Line 1820... Line 1820...
1820
 
1820
 
1821
  .last_socket:
1821
  .last_socket:
1822
        mov     [last_socket_num], edi
1822
        mov     [last_socket_num], edi
1823
        mov     [eax + SOCKET.Number], edi
1823
        mov     [eax + SOCKET.Number], edi
Line 1824... Line 1824...
1824
        DEBUGF  1, "SOCKET_alloc: number=%u\n", edi
1824
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_alloc: number=%u\n", edi
1825
 
1825
 
1826
; Fill in PID
1826
; Fill in PID
1827
        mov     ebx, [TASK_BASE]
1827
        mov     ebx, [TASK_BASE]
Line 1876... Line 1876...
1876
;
1876
;
1877
;----------------------------------------------------
1877
;----------------------------------------------------
1878
align 4
1878
align 4
1879
SOCKET_free:
1879
SOCKET_free:
Line 1880... Line 1880...
1880
 
1880
 
Line 1881... Line 1881...
1881
        DEBUGF  1, "SOCKET_free: %x\n", eax
1881
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: %x\n", eax
1882
 
1882
 
Line 1883... Line 1883...
1883
        call    SOCKET_check
1883
        call    SOCKET_check
Line 1904... Line 1904...
1904
 
1904
 
1905
        push    eax                             ; this will be passed to kernel_free
1905
        push    eax                             ; this will be passed to kernel_free
1906
        mov     ebx, [eax + SOCKET.NextPtr]
1906
        mov     ebx, [eax + SOCKET.NextPtr]
Line 1907... Line 1907...
1907
        mov     eax, [eax + SOCKET.PrevPtr]
1907
        mov     eax, [eax + SOCKET.PrevPtr]
Line 1908... Line 1908...
1908
 
1908
 
1909
        DEBUGF  1, "SOCKET_free: linking socket %x to socket %x\n", eax, ebx
1909
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: linking socket %x to socket %x\n", eax, ebx
1910
 
1910
 
1911
        test    eax, eax
1911
        test    eax, eax
Line 1919... Line 1919...
1919
       @@:
1919
       @@:
Line 1920... Line 1920...
1920
 
1920
 
1921
        call    kernel_free
1921
        call    kernel_free
Line 1922... Line 1922...
1922
        pop     ebx
1922
        pop     ebx
Line 1923... Line 1923...
1923
 
1923
 
1924
        DEBUGF  1, "SOCKET_free: success!\n"
1924
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
Line 1925... Line 1925...
1925
 
1925
 
Line 1937... Line 1937...
1937
;
1937
;
1938
;-----------------------------------
1938
;-----------------------------------
1939
align 4
1939
align 4
1940
SOCKET_fork:
1940
SOCKET_fork:
Line 1941... Line 1941...
1941
 
1941
 
Line 1942... Line 1942...
1942
        DEBUGF  1,"SOCKET_fork: %x\n", ebx
1942
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_fork: %x\n", ebx
1943
 
1943
 
1944
; Exit if backlog queue is full
1944
; Exit if backlog queue is full
1945
        mov     eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size]
1945
        mov     eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size]
Line 1969... Line 1969...
1969
        ret
1969
        ret
Line 1970... Line 1970...
1970
 
1970
 
1971
  .fail2:
1971
  .fail2:
1972
        add     esp, 4+4+4
1972
        add     esp, 4+4+4
1973
  .fail:
1973
  .fail:
1974
        DEBUGF  1,"SOCKET_fork: failed\n"
1974
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_fork: failed\n"
1975
        xor     eax, eax
1975
        xor     eax, eax
Line 1976... Line 1976...
1976
        ret
1976
        ret
Line 1988... Line 1988...
1988
;
1988
;
1989
;---------------------------------------------------
1989
;---------------------------------------------------
1990
align 4
1990
align 4
1991
SOCKET_num_to_ptr:
1991
SOCKET_num_to_ptr:
Line 1992... Line 1992...
1992
 
1992
 
Line 1993... Line 1993...
1993
        DEBUGF  1,"SOCKET_num_to_ptr: num=%u ", ecx
1993
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_num_to_ptr: num=%u ", ecx
Line 1994... Line 1994...
1994
 
1994
 
1995
        mov     eax, net_sockets
1995
        mov     eax, net_sockets
Line 2001... Line 2001...
2001
        cmp     [eax + SOCKET.Number], ecx
2001
        cmp     [eax + SOCKET.Number], ecx
2002
        jne     .next_socket
2002
        jne     .next_socket
Line 2003... Line 2003...
2003
 
2003
 
Line 2004... Line 2004...
2004
        test    eax, eax
2004
        test    eax, eax
2005
 
2005
 
Line 2006... Line 2006...
2006
        DEBUGF  1,"ptr=%x\n", eax
2006
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ptr=%x\n", eax
2007
        ret
2007
        ret
2008
 
2008
 
Line 2009... Line 2009...
2009
  .error:
2009
  .error:
2010
        DEBUGF  1,"not found\n", eax
2010
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_nuto_ptr: not found\n", eax
Line 2023... Line 2023...
2023
;
2023
;
2024
;---------------------------------------------------
2024
;---------------------------------------------------
2025
align 4
2025
align 4
2026
SOCKET_ptr_to_num:
2026
SOCKET_ptr_to_num:
Line 2027... Line 2027...
2027
 
2027
 
Line 2028... Line 2028...
2028
        DEBUGF  1,"SOCKET_ptr_to_num: ptr=%x ", eax
2028
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ptr_to_num: ptr=%x ", eax
2029
 
2029
 
Line 2030... Line 2030...
2030
        call    SOCKET_check
2030
        call    SOCKET_check
Line 2031... Line 2031...
2031
        jz      .error
2031
        jz      .error
2032
 
2032
 
Line 2033... Line 2033...
2033
        mov     eax, [eax + SOCKET.Number]
2033
        mov     eax, [eax + SOCKET.Number]
2034
 
2034
 
2035
        DEBUGF  1,"num=%u\n", eax
2035
        DEBUGF  DEBUG_NETWORK_VERBOSE, "num=%u\n", eax
Line 2036... Line 2036...
2036
        ret
2036
        ret
2037
 
2037
 
Line 2052... Line 2052...
2052
;
2052
;
2053
;---------------------------------------------------
2053
;---------------------------------------------------
2054
align 4
2054
align 4
2055
SOCKET_check:
2055
SOCKET_check:
Line 2056... Line 2056...
2056
 
2056
 
Line 2057... Line 2057...
2057
        DEBUGF  1,"SOCKET_check: %x\n", eax
2057
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax
2058
 
2058
 
Line 2059... Line 2059...
2059
        push    ebx
2059
        push    ebx
Line 2086... Line 2086...
2086
;
2086
;
2087
;---------------------------------------------------
2087
;---------------------------------------------------
2088
align 4
2088
align 4
2089
SOCKET_check_owner:
2089
SOCKET_check_owner:
Line 2090... Line 2090...
2090
 
2090
 
Line 2091... Line 2091...
2091
        DEBUGF  1,"SOCKET_check_owner: %x\n", eax
2091
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_check_owner: %x\n", eax
2092
 
2092
 
2093
        push    ebx
2093
        push    ebx
2094
        mov     ebx, [TASK_BASE]
2094
        mov     ebx, [TASK_BASE]
Line 2114... Line 2114...
2114
;
2114
;
2115
;------------------------------------------------------
2115
;------------------------------------------------------
2116
align 4
2116
align 4
2117
SOCKET_process_end:
2117
SOCKET_process_end:
Line 2118... Line 2118...
2118
 
2118
 
Line 2119... Line 2119...
2119
        DEBUGF  1, "SOCKET_process_end: %x\n", edx
2119
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_process_end: %x\n", edx
2120
 
2120
 
Line 2121... Line 2121...
2121
        push    ebx
2121
        push    ebx
Line 2128... Line 2128...
2128
        jz      .done
2128
        jz      .done
Line 2129... Line 2129...
2129
 
2129
 
2130
        cmp     [ebx + SOCKET.PID], edx
2130
        cmp     [ebx + SOCKET.PID], edx
Line 2131... Line 2131...
2131
        jne     .next_socket
2131
        jne     .next_socket
Line 2132... Line 2132...
2132
 
2132
 
2133
        DEBUGF  1, "SOCKET_process_end: killing socket %x\n", ebx
2133
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_process_end: killing socket %x\n", ebx
2134
 
2134
 
2135
        mov     [ebx + SOCKET.PID], 0
2135
        mov     [ebx + SOCKET.PID], 0
Line 2158... Line 2158...
2158
;-----------------------------------------------------------------
2158
;-----------------------------------------------------------------
Line 2159... Line 2159...
2159
 
2159
 
2160
align 4
2160
align 4
Line 2161... Line 2161...
2161
SOCKET_is_connecting:
2161
SOCKET_is_connecting:
Line 2162... Line 2162...
2162
 
2162
 
2163
        DEBUGF  1,"SOCKET_is_connecting: %x\n", eax
2163
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_connecting: %x\n", eax
Line 2164... Line 2164...
2164
 
2164
 
Line 2179... Line 2179...
2179
;-----------------------------------------------------------------
2179
;-----------------------------------------------------------------
Line 2180... Line 2180...
2180
 
2180
 
2181
align 4
2181
align 4
Line 2182... Line 2182...
2182
SOCKET_is_connected:
2182
SOCKET_is_connected:
Line 2183... Line 2183...
2183
 
2183
 
2184
        DEBUGF  1,"SOCKET_is_connected: %x\n", eax
2184
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_connected: %x\n", eax
Line 2185... Line 2185...
2185
 
2185
 
Line 2201... Line 2201...
2201
;-----------------------------------------------------------------
2201
;-----------------------------------------------------------------
Line 2202... Line 2202...
2202
 
2202
 
2203
align 4
2203
align 4
Line 2204... Line 2204...
2204
SOCKET_is_disconnecting:
2204
SOCKET_is_disconnecting:
Line 2205... Line 2205...
2205
 
2205
 
2206
        DEBUGF  1,"SOCKET_is_disconnecting: %x\n", eax
2206
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnecting: %x\n", eax
Line 2207... Line 2207...
2207
 
2207
 
Line 2222... Line 2222...
2222
;-----------------------------------------------------------------
2222
;-----------------------------------------------------------------
Line 2223... Line 2223...
2223
 
2223
 
2224
align 4
2224
align 4
Line 2225... Line 2225...
2225
SOCKET_is_disconnected:
2225
SOCKET_is_disconnected:
Line 2226... Line 2226...
2226
 
2226
 
2227
        DEBUGF  1,"SOCKET_is_disconnected: %x\n", eax
2227
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnected: %x\n", eax
Line 2228... Line 2228...
2228
 
2228
 
Line 2255... Line 2255...
2255
;-----------------------------------------------------------------
2255
;-----------------------------------------------------------------
Line 2256... Line 2256...
2256
 
2256
 
2257
align 4
2257
align 4
Line 2258... Line 2258...
2258
SOCKET_cant_recv_more:
2258
SOCKET_cant_recv_more:
Line 2259... Line 2259...
2259
 
2259
 
Line 2260... Line 2260...
2260
        DEBUGF  1,"SOCKET_cant_recv_more: %x\n", eax
2260
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_cant_recv_more: %x\n", eax
Line 2275... Line 2275...
2275
;-----------------------------------------------------------------
2275
;-----------------------------------------------------------------
Line 2276... Line 2276...
2276
 
2276
 
2277
align 4
2277
align 4
Line 2278... Line 2278...
2278
SOCKET_cant_send_more:
2278
SOCKET_cant_send_more:
Line 2279... Line 2279...
2279
 
2279
 
Line 2280... Line 2280...
2280
        DEBUGF  1,"SOCKET_cant_send_more: %x\n", eax
2280
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_cant_send_more: %x\n", eax
2281
 
2281