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