Subversion Repositories Kolibri OS

Rev

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