home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / ethiie.asm < prev    next >
Assembly Source File  |  1995-06-25  |  10KB  |  395 lines

  1. version    equ    0
  2. ;History:254,1
  3.  
  4. ;  The following people have contributed to this code: David Horne, Eric
  5. ;  Henderson, and Bob Clements.
  6. ;
  7. ;  This packet driver for Nokia Data Ethernet IIe adapter is based
  8. ;  on the NE2000 driver.  Adaptation was made by Markku Toijala and
  9. ;  Markku Viima, Nokia Data Systems Oy, Helsinki, Finland.
  10.  
  11. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  12.  
  13. ;   This program is free software; you can redistribute it and/or modify
  14. ;   it under the terms of the GNU General Public License as published by
  15. ;   the Free Software Foundation, version 1.
  16. ;
  17. ;   This program is distributed in the hope that it will be useful,
  18. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. ;   GNU General Public License for more details.
  21. ;
  22. ;   You should have received a copy of the GNU General Public License
  23. ;   along with this program; if not, write to the Free Software
  24. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. ;
  26.  
  27.     include    defs.asm
  28.  
  29. code    segment    word public
  30.     assume    cs:code, ds:code
  31.  
  32. ;*****************************************************************************
  33. ;
  34. ;    Nokia Data Ethernet IIe controller board offsets
  35. ;    IO port definition (BASE in io_addr)
  36. ;*****************************************************************************
  37.  
  38. ND_DATAPORT    EQU    400h        ; ETHIIE Port Window.
  39. ND_INTF_REG    EQU    402h        ; ETHIIE Status Setup Register
  40. EN_OFF        equ    0h
  41.  
  42. ND_SOFT_RESET    equ    20h        ; bitmask for RESET bit
  43. ND_INTF_BNC    equ    00h        ; BNC (or TP) interface used
  44. ND_INTF_DIX    equ    40h        ; DIX interface used
  45. ND_INTF_ROM    equ    80h        ; ROM disable.
  46.  
  47.  
  48.     include    8390.inc
  49.  
  50. ;*****************************************************************************
  51. ;
  52. ;    Nokia Data EtherNet IIe controller RAM (16 kbytes) is 
  53. ;    organized into Transmit and Receive areas as:
  54. ;*****************************************************************************
  55.  
  56. SM_TSTART_PG    equ    00h    ; First page of TX buffer
  57. SM_RSTART_PG    equ    06h    ; Starting page of RX ring
  58. SM_RSTOP_PG    equ    40h    ; Last page +1 of RX ring
  59.  
  60. pause_    macro
  61. ;    jmp    $+2
  62. ;
  63. ; The reason for the pause_ macro is to establish a minimum time between
  64. ; accesses to the card hardware. The assumption is that the fetch and execution
  65. ; of the jmp $+2 instruction will provide this time. In a fast cache machine
  66. ; this may be a false assumption. In a fast cache machine, there may be 
  67. ; NO REAL TIME DIFFERENCE between the two I/O instruction streams below:
  68. ;
  69. ;    in    al,dx        in    al,dx
  70. ;    jmp    $+2
  71. ;    in    al,dx        in    al,dx
  72. ;
  73. ; To establish a minimum delay, an I/O instruction must be used. A good rule of
  74. ; thumb is that ISA I/O instructions take ~1.0 microseconds and MCA I/O
  75. ; instructions take ~0.5 microseconds. Reading the NMI Status Register (0x61)
  76. ; is a good way to pause on all machines.
  77. ;
  78. ; The National 8390 Chip (NIC) requires 4 bus clocks between successive
  79. ; chip selects (National DP8390 Data Sheet Addendum, June 1990 -- it took them
  80. ; long enough to figure this out and tell everyone) or the NIC behaves badly.
  81. ; Therefor one I/O instruction should be inserted between each successive
  82. ; NIC I/O instruction that could occur 'back - to - back' on a fast cache
  83. ; machine.
  84. ;   - gft - 910529
  85. ;
  86.     push    ax
  87.     in    al, 61h
  88.     pop    ax
  89. ;
  90. endm
  91.  
  92. reset_8390    macro
  93.     loadport
  94.     setport    ND_INTF_REG
  95.     in    al,dx            ; read current value
  96.     or    al,ND_SOFT_RESET     ; set RESET bit in reg.
  97.     out    dx,al            ; And write register
  98.     longpause
  99.     xor    al,ND_SOFT_RESET     ; Reset RESET bit in reg.
  100.     out    dx,al            ; Write back
  101.     longpause
  102.  
  103. ;-----
  104. ; Set IRQ Selection according to Interrupt Number.
  105. ;-----
  106.         loadport
  107.         setport ND_INTF_REG
  108.         mov    al,int_no
  109.         mov    ah,01h                ; Suppose IRQ5.
  110.         cmp    al,05                ; But is really?
  111.         je    int_ok                ; Yes, skip over.
  112.         mov    ah,02                ; Suppose IRQ2/9.
  113.         cmp    al,09                ; But is really?
  114.         je    int_ok                ; Yes, skip over.
  115.         mov    ah,04                ; Suppose IRQ12.
  116.         cmp    al,12                ; But is really?
  117.         je    int_ok                ; Yes, skip over. 
  118.         mov    ah,08h                ; Suppose IRQ15.
  119. int_ok:
  120. ;-----
  121. ; Add Transceiver Bit and write interface register.
  122. ;-----
  123.     cmp    byte ptr thin_not_thick,00 ; Now set the interface
  124.     jz    set_dix               ; Jump if thick
  125.     mov    al,ND_INTF_BNC           ; Select BNC interface.
  126.     jmp    short addxcv           ;
  127. set_dix:
  128.     mov    al,ND_INTF_DIX           ; Select DIX interface.
  129. addxcv:    
  130.     add    al,ah               ; combine with interrupt
  131.     out    dx,al               ; and write to the card
  132.     endm
  133.  
  134. terminate_board    macro
  135.     endm
  136.  
  137.     public    int_no, io_addr,thin_not_thick
  138. int_no        db    2,0,0,0        ;must be four bytes long for get_number.
  139. io_addr        dw    0300h,0        ; I/O address for card (jumpers)
  140. thin_not_thick    dw    1,0        ; Non-zero means thin net
  141.  
  142.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  143. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  144. driver_type    dw    86        ;from the packet spec
  145. driver_name    db    'ETHIIE',0    ;name of the driver.
  146. driver_function    db    2
  147. parameter_list    label    byte
  148.     db    1    ;major rev of packet driver
  149.     db    9    ;minor rev of packet driver
  150.     db    14    ;length of parameter list
  151.     db    EADDR_LEN    ;length of MAC-layer address
  152.     dw    GIANT    ;MTU, including MAC headers
  153.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  154.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  155.     dw    0    ;(# of successive xmits) - 1
  156. int_num    dw    0    ;Interrupt # to hook for post-EOI
  157.             ;processing, 0 == none,
  158.  
  159.     extrn    is_186: byte        ;=0 if 808[68], =1 if 80[123]86.
  160.  
  161. ;
  162. ;    Block input routine
  163. ;    CX = byte count, es:di = buffer location, ax = buffer address
  164.  
  165.     public    block_input
  166. block_input:
  167.     push    ax        ; save buffer address
  168.     loadport
  169.     setport EN_CCMD
  170.     pause_
  171.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  172.     out    dx,al
  173.     setport    EN0_RCNTLO    ; remote byte count 0
  174.     pause_
  175.     mov    al,cl
  176.     out    dx,al
  177.     setport    EN0_RCNTHI
  178.     pause_
  179.     mov    al,ch
  180.     out    dx,al
  181.     pop    ax        ; get our page back
  182.     setport    EN0_RSARLO
  183.     pause_
  184.     out    dx,al        ; set as hi address
  185.     setport    EN0_RSARHI
  186.     pause_
  187.     mov    al,ah
  188.     out    dx,al
  189.     setport EN_CCMD
  190.     pause_
  191.     mov    al,ENC_RREAD+ENC_START    ; read and start
  192.     out    dx,al
  193.     setport    ND_DATAPORT
  194.     pause_
  195.     cmp    is_186,0
  196.     jnz    read_186
  197. read_loop:
  198.     in    al,dx        ; get a byte
  199.     stosb            ; save it
  200.     loop    read_loop
  201.     ret
  202. read_186:
  203.     shr    cx,1        ; word count
  204.     .286
  205.     rep    insw
  206.     .8086
  207.     jnc    read_186_1
  208.     in    ax,dx        ; get the remaining byte.
  209.     stosb
  210. read_186_1:
  211.     ret
  212. ;
  213. ;    Block output routine
  214. ;    CX = byte count, ds:si = buffer location, ax = buffer address
  215.  
  216. block_output:
  217.     assume    ds:nothing
  218.     push    ax        ; save buffer address
  219.     loadport
  220.     setport EN_CCMD
  221.     pause_
  222.     mov    al,ENC_NODMA+ENC_START
  223.     out    dx,al        ; stop & clear the chip
  224.     setport    EN0_RCNTLO    ; remote byte count 0
  225.     pause_
  226.     mov    al,cl
  227.     out    dx,al
  228.     setport    EN0_RCNTHI
  229.     pause_
  230.     mov    al,ch
  231.     out    dx,al
  232.     pop    ax        ; get our page back
  233.     setport    EN0_RSARLO
  234.     pause_
  235.     out    dx,al        ; set as lo address
  236.     setport    EN0_RSARHI
  237.     pause_
  238.     mov    al,ah
  239.     out    dx,al
  240.     setport EN_CCMD
  241.     pause_
  242.     mov    al,ENC_RWRITE+ENC_START    ; write and start
  243.     out    dx,al
  244.     setport    ND_DATAPORT
  245.     pause_
  246.     cmp    is_186,0
  247.     jnz    write_186
  248. write_loop:
  249.     lodsb            ; get a byte
  250.     out    dx,al        ; save it
  251.     loop    write_loop
  252.     jmp    short block_output_1
  253. write_186:
  254.     inc    cx        ; round up
  255.     shr    cx,1        ; word count
  256.     .286
  257.     rep    outsw
  258.     .8086
  259. block_output_1:
  260.     mov    cx,0
  261.     setport    EN0_ISR
  262. tx_check_rdc:
  263.     in    al,dx
  264.     test    al,ENISR_RDC    ; dma done ???
  265.     jnz    tx_start
  266.     loop    tx_check_rdc
  267.     stc
  268.     ret
  269. tx_start:
  270.     clc
  271.     ret
  272.  
  273.     include    8390.asm
  274.     .LIST
  275.  
  276.     public    usage_msg
  277. usage_msg    db    "usage: ETHIIE [options] <packet_int_no> <hardware_irq> <io_addr> <thin_net>",CR,LF,'$'
  278.  
  279.     public    copyright_msg
  280. copyright_msg    db    "Packet driver for ICL EtherTeam16, version "
  281.         db    '0'+(majver / 10),'0'+(majver mod 10),".",'0'+version,".",'0'+dp8390_version,CR,LF,'$'
  282.  
  283. int_no_name    db    "Interrupt number ",'$'
  284. io_addr_name    db    "I/O port ",'$'
  285.  
  286. thin_msg    db    "Using the built-in transceiver (thinwire)",CR,LF,'$'
  287. thick_msg    db    "Using the external transceiver (thickwire)",CR,LF,'$'
  288.  
  289.     extrn    set_recv_isr: near
  290.  
  291. ;enter with si -> argument string, di -> word to store.
  292. ;if there is no number, don't change the number.
  293.     extrn    get_number: near
  294.  
  295. ;enter with dx -> name of word, di -> dword to print.
  296.     extrn    print_number: near
  297.  
  298.     public    parse_args
  299. parse_args:
  300. ;exit with nc if all went well, cy otherwise.
  301.     mov    di,offset int_no
  302.     call    get_number
  303.     mov    di,offset io_addr
  304.     call    get_number
  305.     mov    di,offset thin_not_thick    ; May override thick/thin cable flag
  306.     call    get_number
  307.     clc
  308.     ret
  309.  
  310.     extrn    etopen_diagn: byte
  311.  
  312. init_card:
  313. ;get the board data. This is (16) bytes starting at remote
  314. ;dma address 8000h. Put it in a buffer called board_data.
  315.     assume    ds:code
  316.  
  317.     or    endcfg,ENDCFG_WTS
  318.  
  319.     loadport
  320.     mov    al,endcfg
  321.     setport    EN0_DCFG
  322.     pause_
  323.     out    dx,al
  324.  
  325.     mov    cx,10h        ; get 16 bytes,
  326.     movseg    es,ds
  327.     mov    di,offset board_data
  328.  
  329.     setport EN_CCMD
  330.     pause_
  331.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  332.     out    dx,al
  333.     setport    EN0_RCNTLO    ; remote byte count 0
  334.     pause_
  335.     mov    al,20h        ; count is actually doubled.
  336.     out    dx,al
  337.     setport    EN0_RCNTHI
  338.     pause_
  339.     xor    al,al        ; high byte of count is zero.
  340.     out    dx,al
  341.  
  342.     mov    ax,8000h    ; from address 0
  343.  
  344.     setport    EN0_RSARLO
  345.     pause_
  346.     out    dx,al        ; set as hi address
  347.     setport    EN0_RSARHI
  348.     pause_
  349.     mov    al,ah
  350.     out    dx,al
  351.     setport EN_CCMD
  352.     pause_
  353.     mov    al,ENC_RREAD+ENC_START    ; read and start
  354.     out    dx,al
  355.     loadport
  356.     setport    ND_DATAPORT
  357.     pause_
  358. sp_read_loop:
  359.     in    ax,dx        ; get a byte
  360.     stosb            ; save it
  361.     loop    sp_read_loop
  362.  
  363.     push    ds              ; Copy from card's address to current address
  364.     pop     es
  365.  
  366.     mov si, offset board_data    ; address is at start
  367.     mov di, offset rom_address
  368.     mov cx, EADDR_LEN       ; Copy one address length
  369.     rep     movsb           ; ..
  370.  
  371.     clc
  372.     ret
  373.  
  374.     public    print_parameters
  375. print_parameters:
  376. ;echo our command-line parameters
  377.     mov    di,offset int_no
  378.     mov    dx,offset int_no_name
  379.     call    print_number
  380.     mov    di,offset io_addr
  381.     mov    dx,offset io_addr_name
  382.     call    print_number
  383.     mov    dx,offset thin_msg
  384.     cmp    thin_not_thick,0    ; May override thick/thin cable flag
  385.     jne    print_parameters_1
  386.     mov    dx,offset thick_msg
  387. print_parameters_1:
  388.     mov    ah,9
  389.     int    21h
  390.     ret
  391.  
  392. code    ends
  393.  
  394.     end
  395.