Rev 4974 | Rev 5074 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4974 | Rev 5005 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; RTL8029/ne2000 driver for KolibriOS ;; |
6 | ;; RTL8029/ne2000 driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; based on RTL8029.asm driver for menuetos ;; |
8 | ;; based on RTL8029.asm driver for menuetos ;; |
9 | ;; and realtek8029.asm for SolarOS by Eugen Brasoveanu ;; |
9 | ;; and realtek8029.asm for SolarOS by Eugen Brasoveanu ;; |
10 | ;; ;; |
10 | ;; ;; |
11 | ;; Written by hidnplayr@kolibrios.org ;; |
11 | ;; Written by hidnplayr@kolibrios.org ;; |
12 | ;; with help from CleverMouse ;; |
12 | ;; with help from CleverMouse ;; |
13 | ;; ;; |
13 | ;; ;; |
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
15 | ;; Version 2, June 1991 ;; |
15 | ;; Version 2, June 1991 ;; |
16 | ;; ;; |
16 | ;; ;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
18 | 18 | ||
- | 19 | format PE DLL native |
|
19 | format MS COFF |
20 | entry START |
20 | 21 | ||
- | 22 | CURRENT_API = 0x0200 |
|
21 | API_VERSION = 0x01000100 |
23 | COMPATIBLE_API = 0x0100 |
22 | DRIVER_VERSION = 5 |
24 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
23 | 25 | ||
24 | MAX_DEVICES = 16 |
26 | MAX_DEVICES = 16 |
25 | 27 | ||
26 | DEBUG = 1 |
28 | DEBUG = 1 |
27 | __DEBUG__ = 1 |
29 | __DEBUG__ = 1 |
28 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
30 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
- | 31 | ||
- | 32 | section '.flat' readable writable executable |
|
29 | 33 | ||
30 | include '../struct.inc' |
34 | include '../struct.inc' |
31 | include '../macros.inc' |
35 | include '../macros.inc' |
32 | include '../proc32.inc' |
36 | include '../proc32.inc' |
33 | include '../imports.inc' |
- | |
34 | include '../fdo.inc' |
37 | include '../fdo.inc' |
35 | include '../netdrv.inc' |
38 | include '../netdrv_pe.inc' |
36 | - | ||
37 | virtual at ebx |
- | |
38 | - | ||
39 | device: |
- | |
40 | - | ||
41 | ETH_DEVICE |
- | |
42 | - | ||
43 | .io_addr dd ? |
- | |
44 | .irq_line db ? |
- | |
45 | .pci_bus dd ? |
39 | |
46 | .pci_dev dd ? |
40 | struct device ETH_DEVICE |
- | 41 | ||
- | 42 | io_addr dd ? |
|
47 | 43 | irq_line db ? |
|
48 | .flags db ? |
- | |
49 | .vendor db ? |
- | |
50 | - | ||
51 | .memsize db ? |
44 | pci_bus dd ? |
52 | .rx_start db ? |
45 | pci_dev dd ? |
53 | .tx_start db ? |
46 | |
- | 47 | flags db ? |
|
- | 48 | vendor db ? |
|
- | 49 | ||
- | 50 | memsize db ? |
|
54 | .bmem dd ? |
51 | rx_start db ? |
55 | .rmem dd ? |
- | |
56 | - | ||
57 | .size = $ - device |
- | |
58 | - | ||
59 | end virtual |
- | |
60 | 52 | tx_start db ? |
|
61 | 53 | bmem dd ? |
|
62 | public START |
54 | rmem dd ? |
63 | public service_proc |
55 | |
64 | public version |
56 | ends |
65 | 57 | ||
66 | P0_COMMAND = 0x00 |
58 | P0_COMMAND = 0x00 |
67 | P0_PSTART = 0x01 |
59 | P0_PSTART = 0x01 |
68 | P0_PSTOP = 0x02 |
60 | P0_PSTOP = 0x02 |
69 | P0_BOUND = 0x03 |
61 | P0_BOUND = 0x03 |
70 | P0_TSR = 0x04 |
62 | P0_TSR = 0x04 |
71 | P0_TPSR = 0x04 |
63 | P0_TPSR = 0x04 |
72 | P0_TBCR0 = 0x05 |
64 | P0_TBCR0 = 0x05 |
73 | P0_TBCR1 = 0x06 |
65 | P0_TBCR1 = 0x06 |
74 | P0_ISR = 0x07 |
66 | P0_ISR = 0x07 |
75 | P0_RSAR0 = 0x08 |
67 | P0_RSAR0 = 0x08 |
76 | P0_RSAR1 = 0x09 |
68 | P0_RSAR1 = 0x09 |
77 | P0_RBCR0 = 0x0A |
69 | P0_RBCR0 = 0x0A |
78 | P0_RBCR1 = 0x0B |
70 | P0_RBCR1 = 0x0B |
79 | P0_RSR = 0x0C |
71 | P0_RSR = 0x0C |
80 | P0_RCR = 0x0C |
72 | P0_RCR = 0x0C |
81 | P0_TCR = 0x0D |
73 | P0_TCR = 0x0D |
82 | P0_DCR = 0x0E |
74 | P0_DCR = 0x0E |
83 | P0_IMR = 0x0F |
75 | P0_IMR = 0x0F |
84 | 76 | ||
85 | P1_COMMAND = 0x00 |
77 | P1_COMMAND = 0x00 |
86 | P1_PAR0 = 0x01 |
78 | P1_PAR0 = 0x01 |
87 | P1_PAR1 = 0x02 |
79 | P1_PAR1 = 0x02 |
88 | P1_PAR2 = 0x03 |
80 | P1_PAR2 = 0x03 |
89 | P1_PAR3 = 0x04 |
81 | P1_PAR3 = 0x04 |
90 | P1_PAR4 = 0x05 |
82 | P1_PAR4 = 0x05 |
91 | P1_PAR5 = 0x06 |
83 | P1_PAR5 = 0x06 |
92 | P1_CURR = 0x07 |
84 | P1_CURR = 0x07 |
93 | P1_MAR0 = 0x08 |
85 | P1_MAR0 = 0x08 |
94 | 86 | ||
95 | CMD_PS0 = 0x00 ; Page 0 select |
87 | CMD_PS0 = 0x00 ; Page 0 select |
96 | CMD_PS1 = 0x40 ; Page 1 select |
88 | CMD_PS1 = 0x40 ; Page 1 select |
97 | CMD_PS2 = 0x80 ; Page 2 select |
89 | CMD_PS2 = 0x80 ; Page 2 select |
98 | CMD_RD2 = 0x20 ; Remote DMA control |
90 | CMD_RD2 = 0x20 ; Remote DMA control |
99 | CMD_RD1 = 0x10 |
91 | CMD_RD1 = 0x10 |
100 | CMD_RD0 = 0x08 |
92 | CMD_RD0 = 0x08 |
101 | CMD_TXP = 0x04 ; transmit packet |
93 | CMD_TXP = 0x04 ; transmit packet |
102 | CMD_STA = 0x02 ; start |
94 | CMD_STA = 0x02 ; start |
103 | CMD_STP = 0x01 ; stop |
95 | CMD_STP = 0x01 ; stop |
104 | 96 | ||
105 | CMD_RDMA_READ = 001b shl 3 |
97 | CMD_RDMA_READ = 001b shl 3 |
106 | CMD_RDMA_WRITE = 010b shl 3 |
98 | CMD_RDMA_WRITE = 010b shl 3 |
107 | CMD_RDMA_SEND_PACKET = 011b shl 3 |
99 | CMD_RDMA_SEND_PACKET = 011b shl 3 |
108 | CMD_RDMA_ABORT = 100b shl 3 ; really is 1xx, Abort/Complete Remote DMA |
100 | CMD_RDMA_ABORT = 100b shl 3 ; really is 1xx, Abort/Complete Remote DMA |
109 | ; RDMA_MASK = 111b shl 3 ; internal, mask |
101 | ; RDMA_MASK = 111b shl 3 ; internal, mask |
110 | 102 | ||
111 | RCR_MON = 0x20 ; monitor mode |
103 | RCR_MON = 0x20 ; monitor mode |
112 | 104 | ||
113 | DCR_FT1 = 0x40 |
105 | DCR_FT1 = 0x40 |
114 | DCR_LS = 0x08 ; Loopback select |
106 | DCR_LS = 0x08 ; Loopback select |
115 | DCR_WTS = 0x01 ; Word transfer select |
107 | DCR_WTS = 0x01 ; Word transfer select |
116 | 108 | ||
117 | ISR_PRX = 0x01 ; successful recv |
109 | ISR_PRX = 0x01 ; successful recv |
118 | ISR_PTX = 0x02 ; successful xmit |
110 | ISR_PTX = 0x02 ; successful xmit |
119 | ISR_RXE = 0x04 ; receive error |
111 | ISR_RXE = 0x04 ; receive error |
120 | ISR_TXE = 0x08 ; transmit error |
112 | ISR_TXE = 0x08 ; transmit error |
121 | ISR_OVW = 0x10 ; Overflow |
113 | ISR_OVW = 0x10 ; Overflow |
122 | ISR_CNT = 0x20 ; Counter overflow |
114 | ISR_CNT = 0x20 ; Counter overflow |
123 | ISR_RDC = 0x40 ; Remote DMA complete |
115 | ISR_RDC = 0x40 ; Remote DMA complete |
124 | ISR_RST = 0x80 ; reset |
116 | ISR_RST = 0x80 ; reset |
125 | 117 | ||
126 | IRQ_MASK = ISR_PRX ;+ ISR_PTX ;+ ISR_RDC + ISR_PTX + ISR_TXE |
118 | IRQ_MASK = ISR_PRX ;+ ISR_PTX ;+ ISR_RDC + ISR_PTX + ISR_TXE |
127 | 119 | ||
128 | RSTAT_PRX = 1 shl 0 ; successful recv |
120 | RSTAT_PRX = 1 shl 0 ; successful recv |
129 | RSTAT_CRC = 1 shl 1 ; CRC error |
121 | RSTAT_CRC = 1 shl 1 ; CRC error |
130 | RSTAT_FAE = 1 shl 2 ; Frame alignment error |
122 | RSTAT_FAE = 1 shl 2 ; Frame alignment error |
131 | RSTAT_OVER = 1 shl 3 ; FIFO overrun |
123 | RSTAT_OVER = 1 shl 3 ; FIFO overrun |
132 | 124 | ||
133 | TXBUF_SIZE = 6 |
125 | TXBUF_SIZE = 6 |
134 | RXBUF_END = 32 |
126 | RXBUF_END = 32 |
135 | PAGE_SIZE = 256 |
127 | PAGE_SIZE = 256 |
136 | 128 | ||
137 | ETH_ZLEN = 60 |
129 | ETH_ZLEN = 60 |
138 | ETH_FRAME_LEN = 1514 |
130 | ETH_FRAME_LEN = 1514 |
139 | 131 | ||
140 | FLAG_PIO = 1 shl 0 |
132 | FLAG_PIO = 1 shl 0 |
141 | FLAG_16BIT = 1 shl 1 |
133 | FLAG_16BIT = 1 shl 1 |
142 | 134 | ||
143 | VENDOR_NONE = 0 |
135 | VENDOR_NONE = 0 |
144 | VENDOR_WD = 1 |
136 | VENDOR_WD = 1 |
145 | VENDOR_NOVELL = 2 |
137 | VENDOR_NOVELL = 2 |
146 | VENDOR_3COM = 3 |
138 | VENDOR_3COM = 3 |
147 | 139 | ||
148 | NE_ASIC = 0x10 |
140 | NE_ASIC = 0x10 |
149 | NE_RESET = 0x0F ; Used to reset card |
141 | NE_RESET = 0x0F ; Used to reset card |
150 | NE_DATA = 0x00 ; Used to read/write NIC mem |
142 | NE_DATA = 0x00 ; Used to read/write NIC mem |
151 | 143 | ||
152 | MEM_8k = 32 |
144 | MEM_8k = 32 |
153 | MEM_16k = 64 |
145 | MEM_16k = 64 |
154 | MEM_32k = 128 |
146 | MEM_32k = 128 |
155 | 147 | ||
156 | ISA_MAX_ADDR = 0x400 |
148 | ISA_MAX_ADDR = 0x400 |
157 | 149 | ||
158 | 150 | ||
- | 151 | ||
- | 152 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
- | 153 | ;; ;; |
|
- | 154 | ;; proc START ;; |
|
159 | 155 | ;; ;; |
|
- | 156 | ;; (standard driver proc) ;; |
|
160 | section '.flat' code readable align 16 |
- | |
161 | - | ||
162 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | |
163 | ;; |
- | |
164 | ;; proc START |
157 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
165 | ;; |
158 | |
166 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
159 | proc START c, reason:dword, cmdline:dword |
167 | - | ||
168 | align 4 |
- | |
169 | proc START stdcall, state:dword |
- | |
170 | 160 | ||
171 | cmp [state], 1 |
161 | cmp [reason], DRV_ENTRY |
172 | jne .exit |
162 | jne .fail |
- | 163 | ||
173 | .entry: |
164 | DEBUGF 2,"Loading driver\n" |
174 | DEBUGF 1, "Loading driver\n" |
- | |
175 | stdcall RegService, my_service, service_proc |
165 | invoke RegService, my_service, service_proc |
176 | ret |
166 | ret |
177 | .fail: |
167 | |
178 | .exit: |
168 | .fail: |
179 | xor eax, eax |
169 | xor eax, eax |
180 | ret |
170 | ret |
181 | 171 | ||
182 | endp |
172 | endp |
183 | 173 | ||
184 | 174 | ||
185 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
175 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
186 | ;; |
176 | ;; ;; |
- | 177 | ;; proc SERVICE_PROC ;; |
|
187 | ;; proc SERVICE_PROC |
178 | ;; ;; |
188 | ;; |
179 | ;; (standard driver proc) ;; |
189 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
180 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
190 | 181 | ||
191 | align 4 |
182 | align 4 |
192 | proc service_proc stdcall, ioctl:dword |
183 | proc service_proc stdcall, ioctl:dword |
193 | 184 | ||
194 | mov edx, [ioctl] |
185 | mov edx, [ioctl] |
195 | mov eax, [edx + IOCTL.io_code] |
186 | mov eax, [edx + IOCTL.io_code] |
196 | 187 | ||
197 | ;------------------------------------------------------ |
188 | ;------------------------------------------------------ |
198 | ;--------------- |
189 | ;--------------- |
199 | cmp eax, 0 ;SRV_GETVERSION |
190 | cmp eax, 0 ;SRV_GETVERSION |
200 | jne @F ;--------------- |
191 | jne @F ;--------------- |
201 | 192 | ||
202 | cmp [edx + IOCTL.out_size], 4 |
193 | cmp [edx + IOCTL.out_size], 4 |
203 | jb .fail |
194 | jb .fail |
204 | mov eax, [edx + IOCTL.output] |
195 | mov eax, [edx + IOCTL.output] |
205 | mov [eax], dword API_VERSION |
196 | mov [eax], dword API_VERSION |
206 | 197 | ||
207 | xor eax, eax |
198 | xor eax, eax |
208 | ret |
199 | ret |
209 | 200 | ||
210 | ;------------------------------------------------------ |
201 | ;------------------------------------------------------ |
211 | @@: ;--------- |
202 | @@: ;--------- |
212 | cmp eax, 1 ;SRV_HOOK |
203 | cmp eax, 1 ;SRV_HOOK |
213 | jne @F ;--------- |
204 | jne @F ;--------- |
214 | 205 | ||
215 | DEBUGF 1, "Checking if device is already listed..\n" |
206 | DEBUGF 1, "Checking if device is already listed..\n" |
216 | 207 | ||
217 | mov eax, [edx + IOCTL.input] |
208 | mov eax, [edx + IOCTL.input] |
218 | 209 | ||
219 | cmp [edx + IOCTL.inp_size], 3 |
210 | cmp [edx + IOCTL.inp_size], 3 |
220 | jb .fail |
211 | jb .fail |
221 | cmp byte [eax], 1 |
212 | cmp byte [eax], 1 |
222 | je .pci |
213 | je .pci |
223 | 214 | ||
224 | cmp [edx + IOCTL.inp_size], 4 |
215 | cmp [edx + IOCTL.inp_size], 4 |
225 | jb .fail |
216 | jb .fail |
226 | cmp byte [eax], 0 |
217 | cmp byte [eax], 0 |
227 | je .isa |
218 | je .isa |
228 | 219 | ||
229 | jmp .fail |
220 | jmp .fail |
230 | 221 | ||
231 | .pci: |
222 | .pci: |
232 | 223 | ||
233 | ; check if the device is already listed |
224 | ; check if the device is already listed |
234 | 225 | ||
235 | mov esi, device_list |
226 | mov esi, device_list |
236 | mov ecx, [devices] |
227 | mov ecx, [devices] |
237 | test ecx, ecx |
228 | test ecx, ecx |
238 | jz .firstdevice_pci |
229 | jz .firstdevice_pci |
239 | 230 | ||
240 | mov ax, [eax+1] ; get the pci bus and device numbers |
231 | mov ax, [eax+1] ; get the pci bus and device numbers |
241 | .nextdevice: |
232 | .nextdevice: |
242 | mov ebx, [esi] |
233 | mov ebx, [esi] |
243 | cmp al, byte[device.pci_bus] |
234 | cmp al, byte[ebx + device.pci_bus] |
244 | jne @f |
235 | jne @f |
245 | cmp ah, byte[device.pci_dev] |
236 | cmp ah, byte[ebx + device.pci_dev] |
246 | je .find_devicenum ; Device is already loaded, let's find it's device number |
237 | je .find_devicenum ; Device is already loaded, let's find it's device number |
247 | @@: |
238 | @@: |
248 | add esi, 4 |
239 | add esi, 4 |
249 | loop .nextdevice |
240 | loop .nextdevice |
250 | 241 | ||
251 | .firstdevice_pci: |
242 | .firstdevice_pci: |
252 | call create_new_struct |
243 | call create_new_struct |
253 | 244 | ||
254 | mov eax, [edx + IOCTL.input] |
245 | mov eax, [edx + IOCTL.input] |
255 | movzx ecx, byte[eax+1] |
246 | movzx ecx, byte[eax+1] |
256 | mov [device.pci_bus], ecx |
247 | mov [ebx + device.pci_bus], ecx |
257 | movzx ecx, byte[eax+2] |
248 | movzx ecx, byte[eax+2] |
258 | mov [device.pci_dev], ecx |
249 | mov [ebx + device.pci_dev], ecx |
259 | 250 | ||
260 | ; Now, it's time to find the base io addres of the PCI device |
251 | ; Now, it's time to find the base io addres of the PCI device |
- | 252 | ||
261 | 253 | stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev] |
|
262 | PCI_find_io |
254 | mov [ebx + device.io_addr], eax |
263 | 255 | ||
264 | ; We've found the io address, find IRQ now |
256 | ; We've found the io address, find IRQ now |
- | 257 | ||
265 | 258 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
|
266 | PCI_find_irq |
- | |
267 | 259 | mov [ebx + device.irq_line], al |
|
268 | jmp .hook |
260 | jmp .hook |
269 | 261 | ||
270 | .isa: |
262 | .isa: |
271 | mov esi, device_list |
263 | mov esi, device_list |
272 | mov ecx, [devices] |
264 | mov ecx, [devices] |
273 | test ecx, ecx |
265 | test ecx, ecx |
274 | jz .firstdevice_isa |
266 | jz .firstdevice_isa |
275 | movzx edi, word [eax+1] |
267 | movzx edi, word [eax+1] |
276 | mov al, [eax+3] |
268 | mov al, [eax+3] |
277 | .nextdevice_isa: |
269 | .nextdevice_isa: |
278 | mov ebx, [esi] |
270 | mov ebx, [esi] |
279 | cmp edi, [device.io_addr] |
271 | cmp edi, [ebx + device.io_addr] |
280 | jne .maybenext |
272 | jne .maybenext |
281 | cmp al, [device.irq_line] |
273 | cmp al, [ebx + device.irq_line] |
282 | je find_device_num |
274 | je find_device_num |
283 | .maybenext: |
275 | .maybenext: |
284 | add esi, 4 |
276 | add esi, 4 |
285 | loop .nextdevice_isa |
277 | loop .nextdevice_isa |
286 | 278 | ||
287 | 279 | ||
288 | 280 | ||
289 | .firstdevice_isa: |
281 | .firstdevice_isa: |
290 | call create_new_struct |
282 | call create_new_struct |
291 | 283 | ||
292 | mov eax, [edx + IOCTL.input] |
284 | mov eax, [edx + IOCTL.input] |
293 | movzx ecx, word[eax+1] |
285 | movzx ecx, word[eax+1] |
294 | mov [device.io_addr], ecx |
286 | mov [ebx + device.io_addr], ecx |
295 | mov cl, [eax+3] |
287 | mov cl, [eax+3] |
296 | mov [device.irq_line], cl |
288 | mov [ebx + device.irq_line], cl |
297 | 289 | ||
298 | .hook: |
- | |
299 | 290 | .hook: |
|
300 | DEBUGF 1, "Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
291 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
301 | [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 |
292 | [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:8 |
302 | 293 | ||
303 | call probe ; this function will output in eax |
294 | call probe ; this function will output in eax |
304 | test eax, eax |
295 | test eax, eax |
305 | jnz .err ; If an error occured, exit |
296 | jnz .err ; If an error occured, exit |
- | 297 | ||
- | 298 | DEBUGF 2,"Initialised OK\n" |
|
306 | 299 | ||
307 | mov eax, [devices] |
300 | mov eax, [devices] |
308 | mov [device_list+4*eax], ebx |
301 | mov [device_list+4*eax], ebx |
309 | inc [devices] |
302 | inc [devices] |
310 | 303 | ||
311 | mov [device.type], NET_TYPE_ETH |
304 | mov [ebx + device.type], NET_TYPE_ETH |
312 | call NetRegDev |
305 | invoke NetRegDev |
313 | 306 | ||
314 | cmp eax, -1 |
307 | cmp eax, -1 |
315 | jz .err |
308 | jz .err |
316 | ret |
309 | ret |
317 | 310 | ||
318 | 311 | ||
319 | ; If the device was already loaded, find the device number and return it in eax |
312 | ; If the device was already loaded, find the device number and return it in eax |
320 | 313 | ||
321 | .find_devicenum: |
314 | .find_devicenum: |
322 | DEBUGF 1, "Trying to find device number of already registered device\n" |
315 | DEBUGF 1, "Trying to find device number of already registered device\n" |
323 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
316 | invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
324 | ; into a device number in edi |
317 | ; into a device number in edi |
325 | mov eax, edi ; Application wants it in eax instead |
318 | mov eax, edi ; Application wants it in eax instead |
326 | DEBUGF 1, "Kernel says: %u\n", eax |
319 | DEBUGF 1, "Kernel says: %u\n", eax |
327 | ret |
320 | ret |
328 | 321 | ||
329 | .err: |
322 | .err: |
330 | DEBUGF 2, "Failed, removing device structure\n" |
323 | DEBUGF 2, "Failed, removing device structure\n" |
331 | stdcall KernelFree, ebx |
324 | invoke KernelFree, ebx |
332 | 325 | ||
333 | jmp .fail |
326 | jmp .fail |
334 | 327 | ||
335 | ;------------------------------------------------------ |
328 | ;------------------------------------------------------ |
336 | @@: |
329 | @@: |
337 | .fail: |
330 | .fail: |
338 | or eax, -1 |
331 | or eax, -1 |
339 | ret |
332 | ret |
340 | 333 | ||
341 | ;------------------------------------------------------ |
334 | ;------------------------------------------------------ |
342 | endp |
335 | endp |
343 | 336 | ||
344 | 337 | ||
345 | create_new_struct: |
338 | create_new_struct: |
346 | 339 | ||
347 | cmp [devices], MAX_DEVICES |
340 | cmp [devices], MAX_DEVICES |
348 | jae .fail |
341 | jae .fail |
349 | 342 | ||
350 | allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure |
343 | allocate_and_clear ebx, sizeof.device, .fail ; Allocate the buffer for device structure |
351 | 344 | ||
352 | mov [device.reset], reset |
345 | mov [ebx + device.reset], reset |
353 | mov [device.transmit], transmit |
346 | mov [ebx + device.transmit], transmit |
354 | mov [device.unload], unload |
347 | mov [ebx + device.unload], unload |
355 | mov [device.name], my_service |
348 | mov [ebx + device.name], my_service |
356 | 349 | ||
357 | ret |
350 | ret |
358 | 351 | ||
359 | .fail: |
352 | .fail: |
360 | add esp, 4 ; return to caller of 'hook' |
353 | add esp, 4 ; return to caller of 'hook' |
361 | or eax, -1 |
354 | or eax, -1 |
362 | ret |
355 | ret |
363 | 356 | ||
364 | find_device_num: |
357 | find_device_num: |
365 | 358 | ||
366 | DEBUGF 1, "Trying to find device number of already registered device\n" |
359 | DEBUGF 1, "Trying to find device number of already registered device\n" |
367 | mov ebx, eax |
360 | mov ebx, eax |
368 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
361 | invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
369 | ; into a device number in edi |
362 | ; into a device number in edi |
370 | mov eax, edi ; Application wants it in eax instead |
363 | mov eax, edi ; Application wants it in eax instead |
371 | DEBUGF 1, "Kernel says: %u\n", eax |
364 | DEBUGF 1, "Kernel says: %u\n", eax |
372 | ret |
365 | ret |
373 | 366 | ||
374 | 367 | ||
375 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
368 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
376 | ;; ;; |
369 | ;; ;; |
377 | ;; Actual Hardware dependent code starts here ;; |
370 | ;; Actual Hardware dependent code starts here ;; |
378 | ;; ;; |
371 | ;; ;; |
379 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
372 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
380 | 373 | ||
381 | 374 | ||
382 | unload: ; TODO |
375 | unload: ; TODO |
383 | or eax, -1 |
376 | or eax, -1 |
384 | ret |
377 | ret |
385 | 378 | ||
386 | 379 | ||
387 | 380 | ||
388 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
381 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
389 | ;; |
382 | ;; |
390 | ;; probe: enables the device and clears the rx buffer |
383 | ;; probe: enables the device and clears the rx buffer |
391 | ;; |
384 | ;; |
392 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
385 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
393 | 386 | ||
394 | probe: |
387 | probe: |
395 | mov [device.vendor], VENDOR_NONE |
388 | mov [ebx + device.vendor], VENDOR_NONE |
396 | mov [device.bmem], 0 |
389 | mov [ebx + device.bmem], 0 |
397 | 390 | ||
398 | DEBUGF 1, "Trying 16-bit mode\n" |
391 | DEBUGF 1, "Trying 16-bit mode\n" |
399 | 392 | ||
400 | mov [device.flags], FLAG_16BIT + FLAG_PIO |
393 | mov [ebx + device.flags], FLAG_16BIT + FLAG_PIO |
401 | mov [device.memsize], MEM_32k |
394 | mov [ebx + device.memsize], MEM_32k |
402 | mov [device.tx_start], 64 |
395 | mov [ebx + device.tx_start], 64 |
403 | mov [device.rx_start], TXBUF_SIZE + 64 |
396 | mov [ebx + device.rx_start], TXBUF_SIZE + 64 |
404 | 397 | ||
405 | set_io 0 |
398 | set_io [ebx + device.io_addr], 0 |
406 | set_io P0_DCR |
399 | set_io [ebx + device.io_addr], P0_DCR |
407 | mov al, DCR_WTS + DCR_FT1 + DCR_LS ; word transfer select + |
400 | mov al, DCR_WTS + DCR_FT1 + DCR_LS ; word transfer select + |
408 | out dx, al |
401 | out dx, al |
409 | 402 | ||
410 | set_io P0_PSTART |
403 | set_io [ebx + device.io_addr], P0_PSTART |
411 | mov al, MEM_16k |
404 | mov al, MEM_16k |
412 | out dx, al |
405 | out dx, al |
413 | 406 | ||
414 | set_io P0_PSTOP |
407 | set_io [ebx + device.io_addr], P0_PSTOP |
415 | mov al, MEM_32k |
408 | mov al, MEM_32k |
416 | out dx, al |
409 | out dx, al |
417 | 410 | ||
418 | mov esi, my_service |
411 | mov esi, my_service |
419 | mov di, 16384 |
412 | mov di, 16384 |
420 | mov cx, 14 |
413 | mov cx, 14 |
421 | call PIO_write |
414 | call PIO_write |
422 | 415 | ||
423 | mov si, 16384 |
416 | mov si, 16384 |
424 | mov cx, 14 |
417 | mov cx, 14 |
425 | sub esp, 16 |
418 | sub esp, 16 |
426 | mov edi, esp |
419 | mov edi, esp |
427 | call PIO_read |
420 | call PIO_read |
428 | 421 | ||
429 | mov esi, esp |
422 | mov esi, esp |
430 | add esp, 16 |
423 | add esp, 16 |
431 | mov edi, my_service |
424 | mov edi, my_service |
432 | mov ecx, 13 |
425 | mov ecx, 13 |
433 | repe cmpsb |
426 | repe cmpsb |
434 | je ep_set_vendor |
427 | je ep_set_vendor |
435 | 428 | ||
436 | DEBUGF 1, "16-bit mode failed\n" |
429 | DEBUGF 1, "16-bit mode failed\n" |
437 | DEBUGF 1, "Trying 8-bit mode\n" |
430 | DEBUGF 1, "Trying 8-bit mode\n" |
438 | 431 | ||
439 | mov [device.flags], FLAG_PIO |
432 | mov [ebx + device.flags], FLAG_PIO |
440 | mov [device.memsize], MEM_16k |
433 | mov [ebx + device.memsize], MEM_16k |
441 | mov [device.tx_start], 32 |
434 | mov [ebx + device.tx_start], 32 |
442 | mov [device.rx_start], TXBUF_SIZE + 32 |
435 | mov [ebx + device.rx_start], TXBUF_SIZE + 32 |
443 | 436 | ||
444 | set_io NE_ASIC + NE_RESET |
437 | set_io [ebx + device.io_addr], NE_ASIC + NE_RESET |
445 | in al, dx |
438 | in al, dx |
446 | out dx, al |
439 | out dx, al |
447 | 440 | ||
448 | in al, 0x84 |
441 | in al, 0x84 |
449 | 442 | ||
450 | set_io P0_COMMAND |
443 | set_io [ebx + device.io_addr], P0_COMMAND |
451 | mov al, CMD_RD2 + CMD_STP |
444 | mov al, CMD_RD2 + CMD_STP |
452 | out dx, al |
445 | out dx, al |
453 | 446 | ||
454 | set_io P0_RCR |
447 | set_io [ebx + device.io_addr], P0_RCR |
455 | mov al, RCR_MON |
448 | mov al, RCR_MON |
456 | out dx, al |
449 | out dx, al |
457 | 450 | ||
458 | set_io P0_DCR |
451 | set_io [ebx + device.io_addr], P0_DCR |
459 | mov al, DCR_FT1 + DCR_LS |
452 | mov al, DCR_FT1 + DCR_LS |
460 | out dx, al |
453 | out dx, al |
461 | 454 | ||
462 | set_io P0_PSTART |
455 | set_io [ebx + device.io_addr], P0_PSTART |
463 | mov al, MEM_8k |
456 | mov al, MEM_8k |
464 | out dx, al |
457 | out dx, al |
465 | 458 | ||
466 | set_io P0_PSTOP |
459 | set_io [ebx + device.io_addr], P0_PSTOP |
467 | mov al, MEM_16k |
460 | mov al, MEM_16k |
468 | out dx, al |
461 | out dx, al |
469 | 462 | ||
470 | mov esi, my_service |
463 | mov esi, my_service |
471 | mov di, 8192 |
464 | mov di, 8192 |
472 | mov cx, 14 |
465 | mov cx, 14 |
473 | call PIO_write |
466 | call PIO_write |
474 | 467 | ||
475 | mov si, 8192 |
468 | mov si, 8192 |
476 | mov cx, 14 |
469 | mov cx, 14 |
477 | sub esp, 16 |
470 | sub esp, 16 |
478 | mov edi, esp |
471 | mov edi, esp |
479 | call PIO_read |
472 | call PIO_read |
480 | 473 | ||
481 | mov esi, my_service |
474 | mov esi, my_service |
482 | mov edi, esp |
475 | mov edi, esp |
483 | add esp, 16 |
476 | add esp, 16 |
484 | mov ecx, 13 |
477 | mov ecx, 13 |
485 | repe cmpsb |
478 | repe cmpsb |
486 | je ep_set_vendor |
479 | je ep_set_vendor |
487 | 480 | ||
488 | DEBUGF 2, "This is not a valid ne2000 device!\n" |
481 | DEBUGF 2, "This is not a valid ne2000 device!\n" |
489 | or eax, -1 |
482 | or eax, -1 |
490 | ret |
483 | ret |
491 | 484 | ||
492 | 485 | ||
493 | ep_set_vendor: |
486 | ep_set_vendor: |
494 | 487 | ||
495 | DEBUGF 1, "Mode ok\n" |
488 | DEBUGF 1, "Mode ok\n" |
496 | 489 | ||
497 | cmp [device.io_addr], ISA_MAX_ADDR |
490 | cmp [ebx + device.io_addr], ISA_MAX_ADDR |
498 | jbe .isa |
491 | jbe .isa |
499 | 492 | ||
500 | DEBUGF 1, "Card is using PCI bus\n" |
493 | DEBUGF 1, "Card is using PCI bus\n" |
501 | 494 | ||
502 | mov [device.vendor], VENDOR_NOVELL ;;; FIXME |
495 | mov [ebx + device.vendor], VENDOR_NOVELL ;;; FIXME |
503 | jmp ep_check_have_vendor |
496 | jmp ep_check_have_vendor |
504 | 497 | ||
505 | .isa: |
498 | .isa: |
506 | DEBUGF 1, "Card is using ISA bus\n" |
499 | DEBUGF 1, "Card is using ISA bus\n" |
507 | 500 | ||
508 | mov [device.vendor], VENDOR_NOVELL |
501 | mov [ebx + device.vendor], VENDOR_NOVELL |
509 | 502 | ||
510 | ep_check_have_vendor: |
503 | ep_check_have_vendor: |
511 | 504 | ||
512 | 505 | ||
513 | mov al, [device.vendor] |
506 | mov al, [ebx + device.vendor] |
514 | cmp al, VENDOR_NONE |
507 | cmp al, VENDOR_NONE |
515 | ; je exit |
508 | ; je exit |
516 | 509 | ||
517 | cmp al, VENDOR_3COM |
510 | cmp al, VENDOR_3COM |
518 | je reset |
511 | je reset |
519 | 512 | ||
520 | mov eax, [device.bmem] |
513 | mov eax, [ebx + device.bmem] |
521 | mov [device.rmem], eax |
514 | mov [ebx + device.rmem], eax |
522 | 515 | ||
523 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
516 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
524 | ;; |
517 | ;; |
525 | ;; reset: Place the chip into a virgin state |
518 | ;; reset: Place the chip into a virgin state |
526 | ;; |
519 | ;; |
527 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
520 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
528 | 521 | ||
529 | reset: |
522 | reset: |
530 | DEBUGF 1, "Resetting device\n" |
523 | DEBUGF 1, "Resetting device\n" |
531 | 524 | ||
532 | ; attach int handler |
525 | ; attach int handler |
533 | movzx eax, [device.irq_line] |
526 | movzx eax, [ebx + device.irq_line] |
534 | DEBUGF 1, "Attaching int handler to irq %x\n", eax:1 |
527 | DEBUGF 1, "Attaching int handler to irq %x\n", eax:1 |
535 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
528 | invoke AttachIntHandler, eax, int_handler, ebx |
536 | test eax, eax |
529 | test eax, eax |
537 | jnz @f |
530 | jnz @f |
538 | DEBUGF 2, "Could not attach int handler!\n" |
531 | DEBUGF 2, "Could not attach int handler!\n" |
539 | ; or eax, -1 |
532 | or eax, -1 |
540 | ; ret |
533 | ret |
541 | @@: |
534 | @@: |
542 | 535 | ||
543 | ; Stop card + DMA |
536 | ; Stop card + DMA |
544 | set_io 0 |
537 | set_io [ebx + device.io_addr], 0 |
545 | ; set_io P0_COMMAND |
538 | ; set_io [ebx + device.io_addr], P0_COMMAND |
546 | mov al, CMD_PS0 + CMD_RDMA_ABORT + CMD_STP |
539 | mov al, CMD_PS0 + CMD_RDMA_ABORT + CMD_STP |
547 | out dx, al |
540 | out dx, al |
548 | 541 | ||
549 | ; initialize DCR |
542 | ; initialize DCR |
550 | set_io P0_DCR |
543 | set_io [ebx + device.io_addr], P0_DCR |
551 | mov al, DCR_FT1 + DCR_LS |
544 | mov al, DCR_FT1 + DCR_LS |
552 | test [device.flags], FLAG_16BIT |
545 | test [ebx + device.flags], FLAG_16BIT |
553 | jz @f |
546 | jz @f |
554 | or al, DCR_WTS ; word transfer select |
547 | or al, DCR_WTS ; word transfer select |
555 | @@: |
548 | @@: |
556 | out dx, al |
549 | out dx, al |
557 | 550 | ||
558 | ; clear remote bytes count |
551 | ; clear remote bytes count |
559 | set_io P0_RBCR0 |
552 | set_io [ebx + device.io_addr], P0_RBCR0 |
560 | xor al, al |
553 | xor al, al |
561 | out dx, al |
554 | out dx, al |
562 | 555 | ||
563 | set_io P0_RBCR1 |
556 | set_io [ebx + device.io_addr], P0_RBCR1 |
564 | out dx, al |
557 | out dx, al |
565 | 558 | ||
566 | ; initialize Receive configuration register (until all init is done) |
559 | ; initialize Receive configuration register (until all init is done) |
567 | set_io P0_RCR |
560 | set_io [ebx + device.io_addr], P0_RCR |
568 | mov al, 0x20 ; monitor mode |
561 | mov al, 0x20 ; monitor mode |
569 | out dx, al |
562 | out dx, al |
570 | 563 | ||
571 | ; transmit configuration register to monitor mode (until all ini is done) |
564 | ; transmit configuration register to monitor mode (until all ini is done) |
572 | set_io P0_TCR |
565 | set_io [ebx + device.io_addr], P0_TCR |
573 | mov al, 2 ; internal loopback |
566 | mov al, 2 ; internal loopback |
574 | out dx, al |
567 | out dx, al |
575 | 568 | ||
576 | ; clear interupt status |
569 | ; clear interupt status |
577 | set_io P0_ISR |
570 | set_io [ebx + device.io_addr], P0_ISR |
578 | mov al, 0xff |
571 | mov al, 0xff |
579 | out dx, al |
572 | out dx, al |
580 | 573 | ||
581 | ; clear IRQ mask ;;;;; CHECKME ;;;;; |
574 | ; clear IRQ mask ;;;;; CHECKME ;;;;; |
582 | set_io P0_IMR |
575 | set_io [ebx + device.io_addr], P0_IMR |
583 | xor al, al |
576 | xor al, al |
584 | out dx, al |
577 | out dx, al |
585 | 578 | ||
586 | ; set transmit pointer |
579 | ; set transmit pointer |
587 | set_io P0_TPSR |
580 | set_io [ebx + device.io_addr], P0_TPSR |
588 | mov al, [device.tx_start] |
581 | mov al, [ebx + device.tx_start] |
589 | out dx, al |
582 | out dx, al |
590 | 583 | ||
591 | ; set pagestart pointer |
584 | ; set pagestart pointer |
592 | set_io P0_PSTART |
585 | set_io [ebx + device.io_addr], P0_PSTART |
593 | mov al, [device.rx_start] |
586 | mov al, [ebx + device.rx_start] |
594 | out dx, al |
587 | out dx, al |
595 | 588 | ||
596 | ; set pagestop pointer |
589 | ; set pagestop pointer |
597 | set_io P0_PSTOP |
590 | set_io [ebx + device.io_addr], P0_PSTOP |
598 | mov al, [device.memsize] |
591 | mov al, [ebx + device.memsize] |
599 | out dx, al |
592 | out dx, al |
600 | 593 | ||
601 | ; set boundary pointer |
594 | ; set boundary pointer |
602 | set_io P0_BOUND |
595 | set_io [ebx + device.io_addr], P0_BOUND |
603 | mov al, [device.memsize] |
596 | mov al, [ebx + device.memsize] |
604 | dec al |
597 | dec al |
605 | out dx, al |
598 | out dx, al |
606 | 599 | ||
607 | ; set curr pointer |
600 | ; set curr pointer |
608 | set_io P0_COMMAND |
601 | set_io [ebx + device.io_addr], P0_COMMAND |
609 | mov al, CMD_PS1 ;+ CMD_RD2 + CMD_STP ; page 1, stop mode |
602 | mov al, CMD_PS1 ;+ CMD_RD2 + CMD_STP ; page 1, stop mode |
610 | out dx, al |
603 | out dx, al |
611 | 604 | ||
612 | set_io P1_CURR |
605 | set_io [ebx + device.io_addr], P1_CURR |
613 | mov al, [device.rx_start] |
606 | mov al, [ebx + device.rx_start] |
614 | out dx, al |
607 | out dx, al |
615 | 608 | ||
616 | set_io P0_COMMAND |
609 | set_io [ebx + device.io_addr], P0_COMMAND |
617 | mov al, CMD_PS0 ;+ CMD_RD2 + CMD_STA ; go to page 0, start mode |
610 | mov al, CMD_PS0 ;+ CMD_RD2 + CMD_STA ; go to page 0, start mode |
618 | out dx, al |
611 | out dx, al |
619 | 612 | ||
620 | ; Read MAC address and set it to registers |
613 | ; Read MAC address and set it to registers |
621 | call read_mac |
614 | call read_mac |
622 | push .macret |
615 | push .macret |
623 | sub esp, 6 |
616 | sub esp, 6 |
624 | lea esi, [device.mac] |
617 | lea esi, [ebx + device.mac] |
625 | mov edi, esp |
618 | mov edi, esp |
626 | movsd |
619 | movsd |
627 | movsw |
620 | movsw |
628 | jmp write_mac |
621 | jmp write_mac |
629 | .macret: |
622 | .macret: |
630 | 623 | ||
631 | ; set IRQ mask |
624 | ; set IRQ mask |
632 | set_io 0 |
625 | set_io [ebx + device.io_addr], 0 |
633 | set_io P0_IMR |
626 | set_io [ebx + device.io_addr], P0_IMR |
634 | mov al, IRQ_MASK |
627 | mov al, IRQ_MASK |
635 | out dx, al |
628 | out dx, al |
636 | 629 | ||
637 | ; start mode |
630 | ; start mode |
638 | set_io P0_COMMAND |
631 | set_io [ebx + device.io_addr], P0_COMMAND |
639 | mov al, CMD_STA |
632 | mov al, CMD_STA |
640 | out dx, al |
633 | out dx, al |
641 | 634 | ||
642 | ; clear transmit control register |
635 | ; clear transmit control register |
643 | set_io P0_TCR |
636 | set_io [ebx + device.io_addr], P0_TCR |
644 | xor al, al ; no loopback |
637 | xor al, al ; no loopback |
645 | out dx, al |
638 | out dx, al |
646 | 639 | ||
647 | ; set receive control register ;;;; |
640 | ; set receive control register ;;;; |
648 | set_io P0_RCR |
641 | set_io [ebx + device.io_addr], P0_RCR |
649 | mov al, 4 ; accept broadcast |
642 | mov al, 4 ; accept broadcast |
650 | out dx, al |
643 | out dx, al |
651 | 644 | ||
652 | ; clear packet/byte counters |
645 | ; clear packet/byte counters |
653 | xor eax, eax |
646 | xor eax, eax |
654 | lea edi, [device.bytes_tx] |
647 | lea edi, [ebx + device.bytes_tx] |
655 | mov ecx, 6 |
648 | mov ecx, 6 |
656 | rep stosd |
649 | rep stosd |
657 | 650 | ||
658 | ; Set the mtu, kernel will be able to send now |
651 | ; Set the mtu, kernel will be able to send now |
659 | mov [device.mtu], ETH_FRAME_LEN |
652 | mov [ebx + device.mtu], ETH_FRAME_LEN |
660 | 653 | ||
661 | ; Set link state to unknown |
654 | ; Set link state to unknown |
662 | mov [device.state], ETH_LINK_UNKOWN |
655 | mov [ebx + device.state], ETH_LINK_UNKNOWN |
663 | 656 | ||
664 | ; Indicate that we have successfully reset the card |
657 | ; Indicate that we have successfully reset the card |
665 | xor eax, eax |
658 | xor eax, eax |
666 | DEBUGF 1, "Done!\n" |
659 | DEBUGF 1, "Done!\n" |
667 | 660 | ||
668 | ret |
661 | ret |
669 | 662 | ||
670 | 663 | ||
671 | 664 | ||
672 | ;*************************************************************************** |
665 | ;*************************************************************************** |
673 | ; Function |
666 | ; Function |
674 | ; transmit |
667 | ; transmit |
675 | ; buffer in [esp+4], size in [esp+8], pointer to device struct in ebx |
668 | ; buffer in [esp+4], size in [esp+8], pointer to device struct in ebx |
676 | ;*************************************************************************** |
669 | ;*************************************************************************** |
- | 670 | ||
- | 671 | proc transmit stdcall buffer_ptr, buffer_size |
|
677 | 672 | ||
678 | align 4 |
673 | pushf |
679 | transmit: |
674 | cli |
680 | 675 | ||
681 | mov esi, [esp + 4] |
676 | mov esi, [buffer_ptr] |
682 | mov ecx, [esp + 8] |
677 | mov ecx, [buffer_size] |
683 | DEBUGF 1, "Transmitting packet, buffer:%x, size:%u\n",esi, ecx |
678 | DEBUGF 1, "Transmitting packet, buffer:%x, size:%u\n", esi, ecx |
684 | DEBUGF 1, "To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
679 | DEBUGF 1, "To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
685 | [esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2,[esi+6]:2,[esi+7]:2,[esi+8]:2,[esi+9]:2,[esi+10]:2,[esi+11]:2,[esi+13]:2,[esi+12]:2 |
680 | [esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2,[esi+6]:2,[esi+7]:2,[esi+8]:2,[esi+9]:2,[esi+10]:2,[esi+11]:2,[esi+13]:2,[esi+12]:2 |
686 | 681 | ||
687 | cmp ecx, ETH_FRAME_LEN |
682 | cmp ecx, ETH_FRAME_LEN |
688 | ja .err ; packet is too long |
683 | ja .err ; packet is too long |
689 | cmp ecx, ETH_ZLEN |
684 | cmp ecx, ETH_ZLEN |
690 | jb .err ; packet is too short |
685 | jb .err ; packet is too short |
691 | 686 | ||
692 | movzx edi, [device.tx_start] |
687 | movzx edi, [ebx + device.tx_start] |
693 | shl edi, 8 |
688 | shl edi, 8 |
694 | push cx |
689 | push cx |
695 | call PIO_write |
690 | call PIO_write |
696 | pop cx |
691 | pop cx |
697 | 692 | ||
698 | set_io 0 |
693 | set_io [ebx + device.io_addr], 0 |
699 | ; set_io P0_COMMAND |
694 | ; set_io [ebx + device.io_addr], P0_COMMAND |
700 | mov al, CMD_PS0 + CMD_RD2 + CMD_STA |
695 | mov al, CMD_PS0 + CMD_RD2 + CMD_STA |
701 | out dx, al |
696 | out dx, al |
702 | 697 | ||
703 | set_io P0_TPSR |
698 | set_io [ebx + device.io_addr], P0_TPSR |
704 | mov al, [device.tx_start] |
699 | mov al, [ebx + device.tx_start] |
705 | out dx, al |
700 | out dx, al |
706 | 701 | ||
707 | set_io P0_TBCR0 |
702 | set_io [ebx + device.io_addr], P0_TBCR0 |
708 | mov al, cl |
703 | mov al, cl |
709 | out dx, al |
704 | out dx, al |
710 | 705 | ||
711 | set_io P0_TBCR1 |
706 | set_io [ebx + device.io_addr], P0_TBCR1 |
712 | mov al, ch |
707 | mov al, ch |
713 | out dx, al |
708 | out dx, al |
714 | 709 | ||
715 | set_io P0_COMMAND |
710 | set_io [ebx + device.io_addr], P0_COMMAND |
716 | mov al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA |
711 | mov al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA |
717 | out dx, al |
712 | out dx, al |
718 | 713 | ||
719 | DEBUGF 1, "Packet Sent!\n" |
714 | DEBUGF 1, "Packet Sent!\n" |
720 | 715 | ||
721 | inc [device.packets_tx] |
716 | inc [ebx + device.packets_tx] |
722 | mov eax, [esp + 8] ; Get packet size in eax |
- | |
723 | 717 | mov eax, [buffer_size] |
|
724 | add dword [device.bytes_tx], eax |
718 | add dword[ebx + device.bytes_tx], eax |
725 | adc dword [device.bytes_tx + 4], 0 |
719 | adc dword[ebx + device.bytes_tx + 4], 0 |
- | 720 | ||
726 | 721 | invoke KernelFree, [buffer_ptr] |
|
727 | stdcall KernelFree, [esp+4] |
722 | popf |
728 | xor eax, eax |
723 | xor eax, eax |
729 | ret 8 |
724 | ret |
730 | 725 | ||
731 | .err: |
726 | .err: |
732 | DEBUGF 2, "Transmit error!\n" |
727 | DEBUGF 2, "Transmit error!\n" |
733 | stdcall KernelFree, [esp+4] |
728 | invoke KernelFree, [buffer_ptr] |
- | 729 | popf |
|
734 | or eax, -1 |
730 | or eax, -1 |
735 | ret 8 |
731 | ret |
- | 732 | ||
- | 733 | endp |
|
736 | 734 | ||
737 | 735 | ||
738 | 736 | ||
739 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
737 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
740 | ; |
738 | ; |
741 | ; Interrupt handler |
739 | ; Interrupt handler |
742 | ; |
740 | ; |
743 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
741 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
744 | 742 | ||
745 | align 4 |
743 | align 4 |
746 | int_handler: |
744 | int_handler: |
747 | 745 | ||
748 | push ebx esi edi |
746 | push ebx esi edi |
749 | - | ||
750 | DEBUGF 1, "INT\n" |
747 | DEBUGF 1, "INT\n" |
751 | 748 | ||
752 | ; find pointer of device wich made INT occur |
749 | ; find pointer of device wich made INT occur |
753 | 750 | ||
754 | mov ecx, [devices] |
751 | mov ecx, [devices] |
755 | test ecx, ecx |
752 | test ecx, ecx |
756 | jz .nothing |
753 | jz .nothing |
757 | mov esi, device_list |
754 | mov esi, device_list |
758 | .nextdevice: |
755 | .nextdevice: |
759 | mov ebx, [esi] |
756 | mov ebx, [esi] |
760 | 757 | ||
761 | set_io 0 |
758 | set_io [ebx + device.io_addr], 0 |
762 | ; set_io P0_COMMAND |
759 | ; set_io [ebx + device.io_addr], P0_COMMAND |
763 | mov al, CMD_PS0 |
760 | mov al, CMD_PS0 |
764 | out dx, al |
761 | out dx, al |
765 | 762 | ||
766 | set_io P0_ISR |
763 | set_io [ebx + device.io_addr], P0_ISR |
767 | in al, dx |
764 | in al, dx |
768 | test al, al |
765 | test al, al |
769 | jnz .got_it |
766 | jnz .got_it |
770 | .continue: |
767 | .continue: |
771 | add esi, 4 |
768 | add esi, 4 |
772 | dec ecx |
769 | dec ecx |
773 | jnz .nextdevice |
770 | jnz .nextdevice |
774 | .nothing: |
771 | .nothing: |
775 | pop edi esi ebx |
772 | pop edi esi ebx |
776 | xor eax, eax |
773 | xor eax, eax |
777 | 774 | ||
778 | ret |
775 | ret |
779 | 776 | ||
780 | .got_it: |
777 | .got_it: |
781 | - | ||
782 | DEBUGF 1, "Device=%x status=%x\n", ebx, eax:2 |
778 | DEBUGF 1, "Device=%x status=%x\n", ebx, eax:2 |
783 | 779 | ||
784 | push ebx |
780 | push ebx |
785 | 781 | .rx_loop: |
|
786 | test al, ISR_PRX ; packet received ok ? |
782 | test al, ISR_PRX ; packet received ok ? |
787 | jz .no_rx |
783 | jz .no_rx |
788 | - | ||
789 | test [device.flags], FLAG_PIO |
784 | test [ebx + device.flags], FLAG_PIO |
790 | jz .no_rx ; FIXME: Only PIO mode supported for now |
785 | jz .no_rx ; FIXME: Only PIO mode supported for now |
791 | - | ||
792 | ; |
- | |
793 | - | ||
794 | pushd .no_rx |
- | |
795 | 786 | ||
796 | ; allocate a buffer |
- | |
797 | 787 | ; allocate a buffer |
|
798 | stdcall KernelAlloc, ETH_FRAME_LEN |
788 | invoke KernelAlloc, ETH_FRAME_LEN |
799 | test eax, eax |
789 | test eax, eax |
- | 790 | jz .rx_fail_2 |
|
- | 791 | ||
800 | jz .fail_2 |
792 | ; Push return address and packet ptr to stack |
- | 793 | pushd .no_rx |
|
801 | pushd 0 |
794 | pushd 0 ; Reserve some space for the packet size |
802 | push eax |
795 | push eax |
803 | 796 | ||
804 | ; read offset for current packet from device |
797 | ; read offset for current packet from device |
805 | - | ||
806 | set_io 0 |
798 | set_io [ebx + device.io_addr], 0 |
807 | set_io P0_BOUND ; boundary ptr is offset to next packet we need to read. |
799 | set_io [ebx + device.io_addr], P0_BOUND ; boundary ptr is offset to next packet we need to read. |
808 | in al, dx |
800 | in al, dx |
809 | inc al |
801 | inc al |
810 | - | ||
811 | cmp al, [device.memsize] |
802 | cmp al, [ebx + device.memsize] |
812 | jb @f |
803 | jb @f |
813 | mov al, [device.rx_start] |
804 | mov al, [ebx + device.rx_start] |
814 | @@: |
805 | @@: |
815 | mov ch, al |
806 | mov ch, al |
816 | 807 | ||
817 | set_io P0_COMMAND |
808 | set_io [ebx + device.io_addr], P0_COMMAND |
818 | mov al, CMD_PS1 |
809 | mov al, CMD_PS1 |
819 | out dx, al |
- | |
820 | 810 | out dx, al |
|
821 | set_io P1_CURR |
811 | set_io [ebx + device.io_addr], P1_CURR |
822 | in al, dx ; get current page in cl |
812 | in al, dx ; get current page in cl |
823 | mov cl, al |
813 | mov cl, al |
824 | 814 | ||
825 | set_io P1_COMMAND |
815 | set_io [ebx + device.io_addr], P1_COMMAND |
826 | mov al, CMD_PS0 |
816 | mov al, CMD_PS0 |
827 | out dx, al |
817 | out dx, al |
828 | 818 | ||
829 | cmp cl, [device.memsize] |
819 | cmp cl, [ebx + device.memsize] |
830 | jb @f |
820 | jb @f |
831 | mov cl, [device.rx_start] |
821 | mov cl, [ebx + device.rx_start] |
832 | @@: |
822 | @@: |
833 | 823 | ||
834 | cmp cl, ch |
824 | cmp cl, ch |
835 | je .fail |
825 | je .rx_fail |
836 | - | ||
837 | movzx esi, ch ; we are using 256 byte pages |
826 | movzx esi, ch ; we are using 256 byte pages |
838 | shl esi, 8 ; esi now holds the offset for current packet |
827 | shl esi, 8 ; esi now holds the offset for current packet |
839 | 828 | ||
840 | ; Get packet header in eax |
- | |
841 | 829 | ; Get packet header in ecx |
|
842 | sub esp, 4 ; reserve 4 bytes on stack to put packet header in |
830 | push ecx ; reserve 4 bytes on stack to put packet header in |
843 | mov edi, esp |
831 | mov edi, esp |
844 | mov cx, 4 |
832 | mov cx, 4 |
845 | call PIO_read |
833 | call PIO_read |
846 | - | ||
847 | mov ecx, [esp] ; ecx now contains packet header |
834 | mov ecx, [esp] |
848 | 835 | ||
849 | ; check if packet is ok |
- | |
850 | 836 | ; check if packet is ok |
|
851 | test ecx, RSTAT_PRX |
837 | test ecx, RSTAT_PRX |
852 | jz .fail_3 |
838 | jz .rx_fail_3 |
853 | - | ||
854 | ; calculate packet length in ecx |
839 | |
855 | 840 | ; calculate packet length in ecx |
|
856 | shr ecx, 16 |
841 | shr ecx, 16 |
857 | sub ecx, 4 ; CRC doesnt count as data byte |
842 | sub ecx, 4 ; CRC doesnt count as data byte |
858 | mov [esp + 4 + 4], ecx |
- | |
859 | 843 | mov [esp + 8], ecx |
|
860 | ; check if packet size is ok |
844 | |
861 | 845 | ; check if packet size is ok |
|
862 | cmp ecx, ETH_ZLEN |
846 | cmp ecx, ETH_ZLEN |
863 | jb .fail_3 |
847 | jb .rx_fail_3 |
864 | cmp ecx, ETH_FRAME_LEN |
- | |
865 | ja .fail_3 |
848 | cmp ecx, ETH_FRAME_LEN |
866 | - | ||
867 | ; update stats |
849 | ja .rx_fail_3 |
868 | 850 | ||
869 | DEBUGF 1, "Received %u bytes\n", ecx |
851 | ; update stats |
870 | 852 | DEBUGF 1, "Received %u bytes\n", ecx |
|
871 | add dword[device.bytes_rx], ecx |
- | |
872 | adc dword[device.bytes_rx + 4], 0 |
853 | add dword[ebx + device.bytes_rx], ecx |
873 | inc [device.packets_rx] |
854 | adc dword[ebx + device.bytes_rx + 4], 0 |
874 | 855 | inc [ebx + device.packets_rx] |
|
875 | ; update read and write pointers |
856 | |
876 | 857 | ; update read and write pointers |
|
877 | add esi, 4 |
858 | add esi, 4 |
878 | mov edi, [esp + 4] |
859 | mov edi, [esp + 4] |
879 | 860 | ||
880 | ; now check if we can read all data at once (if we cross the end boundary, we need to wrap back to the beginning) |
861 | ; now check if we can read all data at once (if we cross the end boundary, we need to wrap back to the beginning) |
881 | - | ||
882 | xor eax, eax |
862 | xor eax, eax |
883 | mov ah, [device.memsize] |
863 | mov ah, [ebx + device.memsize] |
884 | sub eax, esi |
864 | sub eax, esi |
885 | cmp ecx, eax ; eax = number of bytes till end of buffer, ecx = bytes we need to read |
865 | cmp ecx, eax ; eax = number of bytes till end of buffer, ecx = bytes we need to read |
886 | jbe .no_wrap |
866 | jbe .no_wrap |
887 | 867 | ||
888 | ; Read first part |
868 | ; Read first part |
889 | - | ||
890 | sub ecx, eax |
869 | sub ecx, eax |
891 | push ecx |
870 | push ecx |
892 | mov ecx, eax |
871 | mov ecx, eax |
893 | - | ||
894 | call PIO_read ; Read the data |
872 | call PIO_read ; Read the data |
895 | 873 | ||
896 | ; update pointers |
- | |
897 | 874 | ; update pointers for second read |
|
898 | add edi, ecx |
875 | add edi, ecx |
899 | pop ecx |
- | |
900 | 876 | pop ecx |
|
901 | movzx esi, [device.rx_start] |
877 | movzx esi, [ebx + device.rx_start] |
902 | shl esi, 8 |
878 | shl esi, 8 |
903 | 879 | ||
904 | ; now read second part (or only part) |
880 | ; now read second part (or only part) |
905 | - | ||
906 | .no_wrap: |
881 | .no_wrap: |
907 | call PIO_read ; Read the data |
882 | call PIO_read ; Read the data |
908 | 883 | ||
909 | ; update boundary pointer |
884 | ; update boundary pointer |
910 | - | ||
911 | pop eax |
885 | pop eax |
912 | mov al, ah |
886 | mov al, ah |
913 | cmp al, [device.rx_start] |
887 | cmp al, [ebx + device.rx_start] |
914 | jne @f |
888 | jne @f |
915 | mov al, [device.memsize] |
889 | mov al, [ebx + device.memsize] |
916 | @@: |
890 | @@: |
917 | - | ||
918 | set_io 0 |
891 | set_io [ebx + device.io_addr], 0 |
919 | set_io P0_BOUND |
892 | set_io [ebx + device.io_addr], P0_BOUND |
920 | dec al |
893 | dec al |
921 | out dx, al |
894 | out dx, al |
922 | 895 | ||
923 | ; now send the data to the kernel |
896 | ; now send the data to the kernel |
- | 897 | jmp [Eth_input] |
|
924 | - | ||
925 | jmp Eth_input |
- | |
926 | 898 | ||
927 | .fail_3: |
899 | .rx_fail_3: |
928 | add esp, 4 |
900 | add esp, 4 |
929 | .fail: |
901 | .rx_fail: |
930 | add esp, 8 |
902 | add esp, 12 |
931 | .fail_2: |
- | |
932 | - | ||
- | 903 | .rx_fail_2: |
|
933 | 904 | DEBUGF 2, "Error on receive\n" |
|
934 | .no_rx: |
905 | .no_rx: |
935 | pop ebx |
906 | pop ebx |
936 | DEBUGF 1, "done\n" |
907 | DEBUGF 1, "done\n" |
937 | 908 | ||
938 | set_io 0 |
909 | set_io [ebx + device.io_addr], 0 |
939 | set_io P0_ISR |
910 | set_io [ebx + device.io_addr], P0_ISR |
940 | mov al, 0xff |
911 | mov al, 0xff |
941 | out dx, al |
912 | out dx, al |
942 | 913 | ||
943 | pop edi esi ebx |
914 | pop edi esi ebx |
944 | 915 | ||
945 | ret |
916 | ret |
946 | 917 | ||
947 | - | ||
948 | - | ||
949 | - | ||
950 | 918 | ||
951 | ;;;;;;;;;;;;;;;;;;;;;;; |
919 | ;;;;;;;;;;;;;;;;;;;;;;; |
952 | ;; ;; |
920 | ;; ;; |
953 | ;; Write MAC address ;; |
921 | ;; Write MAC address ;; |
954 | ;; ;; |
922 | ;; ;; |
955 | ;;;;;;;;;;;;;;;;;;;;;;; |
923 | ;;;;;;;;;;;;;;;;;;;;;;; |
956 | 924 | ||
957 | align 4 |
925 | align 4 |
958 | write_mac: ; in: mac on stack (6 bytes) |
926 | write_mac: ; in: mac on stack (6 bytes) |
959 | 927 | ||
960 | DEBUGF 1, "Writing MAC\n" |
928 | DEBUGF 1, "Writing MAC\n" |
961 | 929 | ||
962 | set_io 0 |
930 | set_io [ebx + device.io_addr], 0 |
963 | mov al, CMD_PS1; + CMD_RD2 + CMD_STP |
931 | mov al, CMD_PS1; + CMD_RD2 + CMD_STP |
964 | out dx, al |
932 | out dx, al |
965 | 933 | ||
966 | set_io P1_PAR0 |
934 | set_io [ebx + device.io_addr], P1_PAR0 |
967 | mov esi, esp |
935 | mov esi, esp |
968 | mov cx, 6 |
936 | mov cx, 6 |
969 | @@: |
937 | @@: |
970 | lodsb |
938 | lodsb |
971 | out dx, al |
939 | out dx, al |
972 | inc dx |
940 | inc dx |
973 | loopw @r |
941 | loopw @r |
974 | 942 | ||
975 | add esp, 6 |
943 | add esp, 6 |
976 | 944 | ||
977 | ; Notice this procedure does not ret, but continues to read_mac instead. |
945 | ; Notice this procedure does not ret, but continues to read_mac instead. |
978 | 946 | ||
979 | ;;;;;;;;;;;;;;;;;;;;;; |
947 | ;;;;;;;;;;;;;;;;;;;;;; |
980 | ;; ;; |
948 | ;; ;; |
981 | ;; Read MAC address ;; |
949 | ;; Read MAC address ;; |
982 | ;; ;; |
950 | ;; ;; |
983 | ;;;;;;;;;;;;;;;;;;;;;; |
951 | ;;;;;;;;;;;;;;;;;;;;;; |
984 | 952 | ||
985 | read_mac: |
953 | read_mac: |
986 | 954 | ||
987 | DEBUGF 1, "Reading MAC\n" |
955 | DEBUGF 1, "Reading MAC\n" |
988 | 956 | ||
989 | xor esi, esi |
957 | xor esi, esi |
990 | mov cx, 16 |
958 | mov cx, 16 |
991 | sub esp, 16 |
959 | sub esp, 16 |
992 | mov edi, esp |
960 | mov edi, esp |
993 | call PIO_read |
961 | call PIO_read |
994 | 962 | ||
995 | mov esi, esp |
963 | mov esi, esp |
996 | add esp, 16 |
964 | add esp, 16 |
997 | lea edi, [device.mac] |
965 | lea edi, [ebx + device.mac] |
998 | mov ecx, 6 |
966 | mov ecx, 6 |
999 | .loop: |
967 | .loop: |
1000 | movsb |
968 | movsb |
1001 | test [device.flags], FLAG_16BIT |
969 | test [ebx + device.flags], FLAG_16BIT |
1002 | jz .8bit |
970 | jz .8bit |
1003 | inc esi |
971 | inc esi |
1004 | .8bit: |
972 | .8bit: |
1005 | loop .loop |
973 | loop .loop |
1006 | - | ||
1007 | DEBUGF 1, "MAC=%x-%x-%x-%x-%x-%x\n",\ |
974 | DEBUGF 1, "MAC=%x-%x-%x-%x-%x-%x\n",\ |
1008 | [device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 |
975 | [ebx + device.mac]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,[ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2 |
1009 | 976 | ||
1010 | ret |
977 | ret |
1011 | 978 | ||
1012 | 979 | ||
1013 | ;*************************************************************************** |
980 | ;*************************************************************************** |
1014 | ; |
981 | ; |
1015 | ; PIO_read |
982 | ; PIO_read |
1016 | ; |
983 | ; |
1017 | ; Description |
984 | ; Description |
1018 | ; Read a frame from the ethernet card via Programmed I/O |
985 | ; Read a frame from the ethernet card via Programmed I/O |
1019 | ; src in si |
986 | ; src in si |
1020 | ; cnt in cx |
987 | ; cnt in cx |
1021 | ; dst in edi |
988 | ; dst in edi |
1022 | ;*************************************************************************** |
989 | ;*************************************************************************** |
1023 | PIO_read: |
990 | PIO_read: |
1024 | 991 | ||
1025 | DEBUGF 1, "PIO Read from %x to %x, %u bytes ", si, edi, cx |
992 | DEBUGF 1, "PIO Read from %x to %x, %u bytes ", si, edi, cx |
1026 | 993 | ||
1027 | ; start DMA |
994 | ; stop DMA + start |
1028 | set_io 0 |
995 | set_io [ebx + device.io_addr], 0 |
1029 | ; set_io P0_COMMAND |
996 | ; set_io [ebx + device.io_addr], P0_COMMAND |
1030 | mov al, CMD_RD2 + CMD_STA |
997 | mov al, CMD_RD2 + CMD_STA |
1031 | out dx, al |
998 | out dx, al |
- | 999 | ||
- | 1000 | ; Request confirmation of end of DMA transfer |
|
- | 1001 | set_io [ebx + device.io_addr], P0_ISR |
|
- | 1002 | mov al, ISR_RDC |
|
- | 1003 | out dx, al |
|
1032 | 1004 | ||
1033 | ; set length of data we're interested in |
1005 | ; set length of data we're interested in |
1034 | set_io P0_RBCR0 |
1006 | set_io [ebx + device.io_addr], P0_RBCR0 |
1035 | mov al, cl |
1007 | mov al, cl |
1036 | out dx, al |
- | |
1037 | 1008 | out dx, al |
|
1038 | set_io P0_RBCR1 |
1009 | set_io [ebx + device.io_addr], P0_RBCR1 |
1039 | mov al, ch |
1010 | mov al, ch |
1040 | out dx, al |
1011 | out dx, al |
1041 | 1012 | ||
1042 | ; set offset of what we want to read |
1013 | ; set offset of what we want to read |
1043 | set_io P0_RSAR0 |
1014 | set_io [ebx + device.io_addr], P0_RSAR0 |
1044 | mov ax, si |
1015 | mov ax, si |
1045 | out dx, al |
1016 | out dx, al |
1046 | - | ||
1047 | set_io P0_RSAR1 |
1017 | set_io [ebx + device.io_addr], P0_RSAR1 |
1048 | shr ax, 8 |
1018 | shr ax, 8 |
1049 | out dx, al |
1019 | out dx, al |
1050 | 1020 | ||
1051 | ; start DMA read |
1021 | ; start DMA read |
1052 | set_io P0_COMMAND |
1022 | set_io [ebx + device.io_addr], P0_COMMAND |
1053 | mov al, CMD_RD0 + CMD_STA |
1023 | mov al, CMD_RD0 + CMD_STA |
1054 | out dx, al |
1024 | out dx, al |
1055 | 1025 | ||
1056 | set_io NE_ASIC |
- | |
1057 | 1026 | set_io [ebx + device.io_addr], NE_ASIC |
|
1058 | test [device.flags], FLAG_16BIT |
1027 | test [ebx + device.flags], FLAG_16BIT |
1059 | jz .8bits |
- | |
1060 | 1028 | jz .8bits |
|
1061 | DEBUGF 1, "(16-bit mode)\n" |
- | |
1062 | 1029 | DEBUGF 1, "(16-bit mode)\n" |
|
1063 | shr cx, 1 ; note that if the number was odd, carry flag will be set |
1030 | shr cx, 1 ; note that if the number was odd, carry flag will be set |
1064 | pushf |
- | |
1065 | 1031 | pushf |
|
1066 | .16bits: |
1032 | .16bits: |
1067 | in ax, dx |
1033 | in ax, dx |
1068 | stosw |
1034 | stosw |
1069 | loopw .16bits |
1035 | loopw .16bits |
1070 | - | ||
1071 | inc cx |
- | |
1072 | popf |
1036 | popf |
1073 | jnc .done |
1037 | jnc wait_dma_done |
- | 1038 | in al, dx |
|
- | 1039 | stosb |
|
1074 | jmp .8bits_ |
1040 | jmp wait_dma_done |
1075 | 1041 | ||
1076 | .8bits: |
1042 | .8bits: |
1077 | DEBUGF 1, "(8-bit mode)\n" |
1043 | DEBUGF 1, "(8-bit mode)\n" |
1078 | - | ||
1079 | .8bits_: |
1044 | .8bits_: |
1080 | in al, dx |
1045 | in al, dx |
1081 | stosb |
1046 | stosb |
1082 | loopw .8bits_ |
1047 | loopw .8bits_ |
1083 | - | ||
1084 | - | ||
1085 | .done: |
- | |
1086 | ; set_io 0 |
- | |
1087 | ; set_io P0_ISR |
- | |
1088 | ; |
- | |
1089 | ; .dmawait: ; Wait for Remote DMA Complete |
- | |
1090 | ; in al, dx |
- | |
1091 | ; test al, ISR_RDC |
- | |
1092 | ; jz .dmawait |
1048 | jmp wait_dma_done |
1093 | ; and al, not ISR_RDC |
- | |
1094 | ; out dx, al ; clear the bit |
- | |
1095 | - | ||
1096 | ret |
- | |
1097 | 1049 | ||
1098 | 1050 | ||
1099 | 1051 | ||
1100 | 1052 | ||
1101 | ;*************************************************************************** |
1053 | ;*************************************************************************** |
1102 | ; |
1054 | ; |
1103 | ; PIO_write |
1055 | ; PIO_write |
1104 | ; |
1056 | ; |
1105 | ; Description |
1057 | ; Description |
1106 | ; writes a frame to the ethernet card via Programmed I/O |
1058 | ; writes a frame to the ethernet card via Programmed I/O |
1107 | ; dst in di |
1059 | ; dst in di |
1108 | ; cnt in cx |
1060 | ; cnt in cx |
1109 | ; src in esi |
1061 | ; src in esi |
1110 | ;*************************************************************************** |
1062 | ;*************************************************************************** |
1111 | PIO_write: |
1063 | PIO_write: |
1112 | 1064 | ||
1113 | DEBUGF 1, "Eth PIO Write from %x to %x, %u bytes ", esi, di, cx |
1065 | DEBUGF 1, "Eth PIO Write from %x to %x, %u bytes ", esi, di, cx |
- | 1066 | ||
1114 | 1067 | ; Stop DMA + start |
|
1115 | set_io 0 |
1068 | set_io [ebx + device.io_addr], 0 |
1116 | ; set_io P0_COMMAND |
1069 | ; set_io [ebx + device.io_addr], P0_COMMAND |
1117 | mov al, CMD_RD2 + CMD_STA |
1070 | mov al, CMD_RD2 + CMD_STA |
1118 | out dx, al |
1071 | out dx, al |
- | 1072 | ||
1119 | 1073 | ; Request confirmation of end of DMA transfer |
|
1120 | set_io P0_ISR |
1074 | set_io [ebx + device.io_addr], P0_ISR |
1121 | mov al, ISR_RDC |
1075 | mov al, ISR_RDC |
1122 | out dx, al |
1076 | out dx, al |
- | 1077 | ||
1123 | 1078 | ; Program number of bytes we want to write |
|
1124 | set_io P0_RBCR0 |
1079 | set_io [ebx + device.io_addr], P0_RBCR0 |
1125 | mov al, cl |
1080 | mov al, cl |
1126 | out dx, al |
- | |
1127 | 1081 | out dx, al |
|
1128 | set_io P0_RBCR1 |
1082 | set_io [ebx + device.io_addr], P0_RBCR1 |
1129 | mov al, ch |
1083 | mov al, ch |
1130 | out dx, al |
1084 | out dx, al |
- | 1085 | ||
1131 | 1086 | ; Program where we want to write |
|
1132 | mov ax, di |
1087 | mov ax, di |
1133 | set_io P0_RSAR0 |
1088 | set_io [ebx + device.io_addr], P0_RSAR0 |
1134 | out dx, al |
1089 | out dx, al |
1135 | shr ax, 8 |
1090 | shr ax, 8 |
1136 | set_io P0_RSAR1 |
1091 | set_io [ebx + device.io_addr], P0_RSAR1 |
- | 1092 | out dx, al |
|
1137 | out dx, al |
1093 | |
1138 | 1094 | ; Set the DMA to write |
|
1139 | set_io P0_COMMAND |
1095 | set_io [ebx + device.io_addr], P0_COMMAND |
1140 | mov al, CMD_RD1 + CMD_STA |
1096 | mov al, CMD_RD1 + CMD_STA |
1141 | out dx, al |
1097 | out dx, al |
1142 | 1098 | ||
1143 | set_io NE_ASIC |
1099 | set_io [ebx + device.io_addr], NE_ASIC |
1144 | test [device.flags], FLAG_16BIT |
1100 | test [ebx + device.flags], FLAG_16BIT |
1145 | jz .8_bit |
- | |
1146 | 1101 | jz .8_bit |
|
1147 | DEBUGF 1, "(16-bit mode)\n" |
- | |
1148 | 1102 | DEBUGF 1, "(16-bit mode)\n" |
|
1149 | shr cx, 1 ; note that if the number was odd, carry flag will be set |
1103 | shr cx, 1 ; note that if the number was odd, carry flag will be set |
1150 | pushf ; save the flags for later |
- | |
1151 | 1104 | pushf ; save the flags for later |
|
1152 | .16bit: |
1105 | .16bit: |
1153 | lodsw |
1106 | lodsw |
1154 | out dx, ax |
1107 | out dx, ax |
1155 | loopw .16bit |
1108 | loopw .16bit |
1156 | - | ||
1157 | popf |
1109 | popf |
1158 | jnc .done |
1110 | jnc wait_dma_done |
- | 1111 | lodsb |
|
1159 | inc cx |
1112 | out dx, al |
1160 | jmp .8_bit_ |
1113 | jmp wait_dma_done |
1161 | 1114 | ||
1162 | .8_bit: |
- | |
1163 | 1115 | .8_bit: |
|
1164 | DEBUGF 1, "(8-bit mode)\n" |
- | |
1165 | 1116 | DEBUGF 1, "(8-bit mode)\n" |
|
1166 | .8_bit_: |
1117 | .8_bit_: |
1167 | lodsb |
1118 | lodsb |
1168 | out dx, al |
1119 | out dx, al |
1169 | loopw .8_bit_ |
1120 | loopw .8_bit_ |
- | 1121 | jmp wait_dma_done |
|
- | 1122 | ||
- | 1123 | ||
- | 1124 | ||
- | 1125 | wait_dma_done: |
|
1170 | - | ||
1171 | .done: |
1126 | |
1172 | ; set_io 0 |
1127 | set_io [ebx + device.io_addr], 0 |
1173 | ; set_io P0_ISR |
1128 | set_io [ebx + device.io_addr], P0_ISR |
1174 | ; .dmawait: ; Wait for Remote DMA Complete |
1129 | .dmawait: |
1175 | ; in al, dx |
1130 | in al, dx |
1176 | ; test al, ISR_RDC |
1131 | test al, ISR_RDC ; Remote DMA Complete |
1177 | ; jz .dmawait |
1132 | jz .dmawait |
1178 | ; and al, not ISR_RDC |
1133 | ; and al, not ISR_RDC |
1179 | ; out dx, al ; clear the bit |
1134 | ; out dx, al ; clear the bit |
1180 | 1135 | ||
1181 | ret |
1136 | ret |
1182 | 1137 | ||
1183 | 1138 | ||
1184 | - | ||
1185 | ; place all initialized data here |
1139 | |
1186 | align 4 |
- | |
1187 | - | ||
1188 | devices dd 0 |
- | |
1189 | version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) |
1140 | ; End of code |
1190 | my_service db 'RTL8029',0 ; max 16 chars include zero |
1141 | |
1191 | - | ||
- | 1142 | ||
1192 | ;device_1 db 'Realtek 8029',0 |
1143 | data fixups |
- | 1144 | end data |
|
1193 | ;device_2 db 'Realtek 8019',0 |
1145 | |
- | 1146 | include '../peimport.inc' |
|
- | 1147 | ||
- | 1148 | my_service db 'RTL8029', 0 ; max 16 chars include zero |
|
1194 | ;device_3 db 'Realtek 8019AS',0 |
1149 | |
- | 1150 | ;sz_8029 db 'Realtek 8029', 0 |
|
1195 | ;device_4 db 'ne2000',0 |
1151 | ;sz_8019 db 'Realtek 8019', 0 |
1196 | ;device_5 db 'DP8390',0 |
- | |
- | 1152 | ;sz_8019as db 'Realtek 8019AS', 0 |
|
1197 | 1153 | ;sz_ne2k db 'ne2000', 0 |
|
- | 1154 | ;sz_dp8390 db 'DP8390', 0 |
|
1198 | include_debug_strings |
1155 | |
1199 | 1156 | include_debug_strings ; All data wich FDO uses will be included here |
|
1200 | section '.data' data readable writable align 16 |
1157 | |
1201 | ; place all uninitialized data here |
1158 | align 4 |
1202 | 1159 | devices dd 0 |
|
1203 | device_list rd MAX_DEVICES |
1160 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling |