Subversion Repositories Kolibri OS

Rev

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