Subversion Repositories Kolibri OS

Rev

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