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