Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;          GNU GENERAL PUBLIC LICENSE                             ;;
  7. ;;             Version 2, June 1991                                ;;
  8. ;;                                                                 ;;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.  
  11. include 'pci.inc'
  12. include 'mii.inc'
  13.  
  14. ; Kernel variables
  15.  
  16.         PAGESIZE        = 4096
  17.         PG_SW           = 0x003
  18.         PG_NOCACHE      = 0x018
  19.  
  20.  
  21. ; network driver types
  22.  
  23.         NET_TYPE_ETH    = 1
  24.         NET_TYPE_SLIP   = 2
  25.  
  26. ; link state
  27.  
  28.         ETH_LINK_DOWN   = 0             ; Link is down
  29.         ETH_LINK_UNKOWN = 1b            ; There could be an active link
  30.         ETH_LINK_FD     = 10b           ; full duplex flag
  31.         ETH_LINK_10M    = 100b          ; 10 mbit
  32.         ETH_LINK_100M   = 1000b         ; 100 mbit
  33.         ETH_LINK_1G     = 10000b        ; gigabit
  34.  
  35.  
  36.         LAST_IO = 0
  37. macro   set_io addr {
  38.  
  39.         if      addr = 0
  40.         mov     edx, [device.io_addr]
  41.         else if addr = LAST_IO
  42.         else
  43.         add     edx, addr - LAST_IO
  44.         end if
  45.  
  46.         LAST_IO = addr
  47. }
  48.  
  49. macro   allocate_and_clear dest, size, err {
  50.  
  51. ; We need to allocate at least 8 pages, if we want a continuous memory in ram
  52.         push    edx
  53.     if (size < 8*4096) & (size > 4096)
  54.         stdcall KernelAlloc, 8*4096
  55.     else
  56.         stdcall KernelAlloc, size
  57.     end if
  58.         pop     edx
  59.  
  60.         test    eax, eax
  61.         jz      err
  62.         mov     dest, eax               ; Save the address to it into the device struct
  63.         mov     edi, eax                ; look at last part of code!
  64.  
  65. ; Release the unused pages (if any)
  66.     if (size < 8*4096) & (size > 4096)
  67.         add     eax, (size/4096+1)*4096
  68.         mov     ecx, 8-(size/4096+1)
  69.         push    edx
  70.         call    ReleasePages
  71.         pop     edx
  72.     end if
  73.  
  74. ; Clear the allocated buffer
  75.         mov     ecx, size/4             ; divide by 4 because of DWORD
  76.         xor     eax, eax
  77.         rep     stosd
  78.  
  79. }
  80.  
  81. struc   IOCTL {
  82.         .handle         dd ?
  83.         .io_code        dd ?
  84.         .input          dd ?
  85.         .inp_size       dd ?
  86.         .output         dd ?
  87.         .out_size       dd ?
  88. }
  89.  
  90. virtual at edx
  91.   IOCTL IOCTL
  92. end virtual
  93.  
  94.  
  95. if used null_op
  96. align 4
  97. null_op:
  98.         or      eax, -1
  99.         ret
  100.  
  101. end if
  102.  
  103.  
  104. macro   GetRealAddr {             ; input and output is eax
  105.  
  106.         push    ax
  107.         call    GetPgAddr
  108.         and     word[esp], PAGESIZE - 1
  109.         or      ax, word[esp]
  110.         inc     esp
  111.         inc     esp
  112.  
  113. }
  114.  
  115. macro   NET_DEVICE {
  116.  
  117.         .type           dd ?    ; Type field
  118.         .mtu            dd ?    ; Maximal Transmission Unit
  119.         .name           dd ?    ; Ptr to 0 terminated string
  120.  
  121.         .unload         dd ?    ; Ptrs to driver functions
  122.         .reset          dd ?    ;
  123.         .transmit       dd ?    ;
  124.  
  125.         .bytes_tx       dq ?    ; Statistics, updated by the driver
  126.         .bytes_rx       dq ?    ;
  127.         .packets_tx     dd ?    ;
  128.         .packets_rx     dd ?    ;
  129.  
  130.         .state          dd ?    ; link state (0 = no link)
  131.         .hwacc          dd ?    ; bitmask stating enabled HW accelerations
  132.  
  133.         .end:
  134. }
  135.  
  136.  
  137. macro   ETH_DEVICE {
  138.         NET_DEVICE
  139.  
  140.         .mac            dp ?
  141.                         dw ?    ; qword alignment
  142.  
  143. }
  144.  
  145.  
  146.  
  147. macro   SLIP_DEVICE {
  148.         NET_DEVICE
  149.  
  150. }