Subversion Repositories Kolibri OS

Rev

Rev 2887 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2886 hidnplayr 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1472 hidnplayr 10
 
2886 hidnplayr 11
include 'bus/pci.inc'
1472 hidnplayr 12
 
1556 hidnplayr 13
; Kernel variables
1472 hidnplayr 14
 
2887 hidnplayr 15
        PAGESIZE        = 4096
16
        PG_SW           = 0x003
2935 hidnplayr 17
        PG_NOCACHE      = 0x018
1472 hidnplayr 18
 
1556 hidnplayr 19
 
1514 hidnplayr 20
; network driver types
1472 hidnplayr 21
 
2887 hidnplayr 22
        NET_TYPE_ETH    = 1
23
        NET_TYPE_SLIP   = 2
1514 hidnplayr 24
 
25
 
2886 hidnplayr 26
        LAST_IO = 0
2887 hidnplayr 27
macro   set_io addr {
1514 hidnplayr 28
 
2886 hidnplayr 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
1472 hidnplayr 35
 
2886 hidnplayr 36
        LAST_IO = addr
1472 hidnplayr 37
}
38
 
2887 hidnplayr 39
macro   allocate_and_clear dest, size, err {
1472 hidnplayr 40
 
41
; We need to allocate at least 8 pages, if we want a continuous memory in ram
2886 hidnplayr 42
        push    edx
1472 hidnplayr 43
    if (size < 8*4096) & (size > 4096)
2886 hidnplayr 44
        stdcall KernelAlloc, 8*4096
1472 hidnplayr 45
    else
2886 hidnplayr 46
        stdcall KernelAlloc, size
1472 hidnplayr 47
    end if
2886 hidnplayr 48
        pop     edx
1521 hidnplayr 49
 
2886 hidnplayr 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!
1472 hidnplayr 54
 
55
; Release the unused pages (if any)
56
    if (size < 8*4096) & (size > 4096)
2886 hidnplayr 57
        add     eax, (size/4096+1)*4096
58
        mov     ecx, 8-(size/4096+1)
59
        push    edx
60
        call    ReleasePages
61
        pop     edx
1472 hidnplayr 62
    end if
63
 
64
; Clear the allocated buffer
2886 hidnplayr 65
        mov     ecx, size/4             ; divide by 4 because of DWORD
66
        xor     eax, eax
67
        rep     stosd
1472 hidnplayr 68
 
69
}
70
 
2887 hidnplayr 71
struc   IOCTL {
72
        .handle         dd ?
73
        .io_code        dd ?
74
        .input          dd ?
75
        .inp_size       dd ?
76
        .output         dd ?
77
        .out_size       dd ?
1472 hidnplayr 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:
2886 hidnplayr 88
        or      eax, -1
89
        ret
1472 hidnplayr 90
 
91
end if
92
 
93
 
2887 hidnplayr 94
macro   GetRealAddr {             ; input and output is eax
1472 hidnplayr 95
 
2886 hidnplayr 96
        push    ax
97
        call    GetPgAddr
98
        and     word[esp], PAGESIZE - 1
99
        or      ax, word[esp]
100
        inc     esp
101
        inc     esp
1472 hidnplayr 102
 
1492 hidnplayr 103
}
104
 
2887 hidnplayr 105
macro   NET_DEVICE {
1519 hidnplayr 106
 
2886 hidnplayr 107
        .type           dd ?    ; Type field
108
        .mtu            dd ?    ; Maximal Transmission Unit
109
        .name           dd ?    ; Ptr to 0 terminated string
1519 hidnplayr 110
 
2886 hidnplayr 111
        .unload         dd ?    ; Ptrs to driver functions
112
        .reset          dd ?    ;
113
        .transmit       dd ?    ;
1519 hidnplayr 114
 
2886 hidnplayr 115
        .bytes_tx       dq ?    ; Statistics, updated by the driver
116
        .bytes_rx       dq ?    ;
117
        .packets_tx     dd ?    ;
118
        .packets_rx     dd ?    ;
1519 hidnplayr 119
 
2886 hidnplayr 120
        .end:
1514 hidnplayr 121
}
1492 hidnplayr 122
 
1529 hidnplayr 123
 
2887 hidnplayr 124
macro   ETH_DEVICE {
125
        NET_DEVICE
1519 hidnplayr 126
 
2886 hidnplayr 127
        .set_mode       dd ?
128
        .get_mode       dd ?
1519 hidnplayr 129
 
2886 hidnplayr 130
        .set_MAC        dd ?
131
        .get_MAC        dd ?
1519 hidnplayr 132
 
2886 hidnplayr 133
        .mode           dd ?
134
        .mac            dp ?
135
                        dp ?    ; qword alignment
1519 hidnplayr 136
 
1492 hidnplayr 137
}
138
 
1502 hidnplayr 139
 
140
 
2887 hidnplayr 141
macro   SLIP_DEVICE {
2886 hidnplayr 142
        NET_DEVICE
1519 hidnplayr 143
 
2886 hidnplayr 144
        .set_mode       dd ?
145
        .get_mode       dd ?
1519 hidnplayr 146
 
2886 hidnplayr 147
        .mode           dd ?
1519 hidnplayr 148
 
1529 hidnplayr 149
}