Subversion Repositories Kolibri OS

Rev

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