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