home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / NETWORK / DRIVERSS.ZIP / NE2000.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-01-26  |  6.8 KB  |  310 lines

  1. version    equ    4
  2. ;History:4,1 0
  3.  
  4. ;  Russell Nelson, Clarkson University.
  5. ;  Copyright, 1988-1991, Russell Nelson
  6. ;  The following people have contributed to this code: David Horne, Eric
  7. ;  Henderson, and Bob Clements.
  8.  
  9. ;   This program is free software; you can redistribute it and/or modify
  10. ;   it under the terms of the GNU General Public License as published by
  11. ;   the Free Software Foundation, version 1.
  12. ;
  13. ;   This program is distributed in the hope that it will be useful,
  14. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;   GNU General Public License for more details.
  17. ;
  18. ;   You should have received a copy of the GNU General Public License
  19. ;   along with this program; if not, write to the Free Software
  20. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.     include    defs.asm
  23.  
  24. code    segment    word public
  25.     assume    cs:code, ds:code
  26.  
  27. ;*****************************************************************************
  28. ;
  29. ;    NE2000 controller board offsets
  30. ;    IO port definition (BASE in io_addr)
  31. ;*****************************************************************************
  32. NE_DATAPORT    EQU    10h        ; NE2000 Port Window.
  33. NE_RESET    EQU    1fh        ; Issue a read for reset
  34. EN_OFF        equ    0h
  35.  
  36.     include    8390.inc
  37.  
  38. ; Shared memory management parameters
  39.  
  40. SM_TSTART_PG    equ    040h    ; First page of TX buffer
  41. SM_RSTART_PG    equ    046h    ; Starting page of RX ring
  42. SM_RSTOP_PG    equ    080h    ; Last page +1 of RX ring
  43.  
  44. pause_    macro
  45. ;    jmp    $+2
  46. endm
  47.  
  48. longpause macro
  49.     push    cx
  50.     mov    cx,0
  51.     loop    $
  52.     pop    cx
  53. endm
  54.  
  55. ram_enable    macro
  56.     endm
  57.  
  58. reset_8390    macro
  59.     loadport
  60.     setport    NE_RESET
  61.     in    al,dx
  62.     longpause
  63.     out    dx,al        ; should set command 21, 80
  64.     longpause
  65.  
  66.     endm
  67.  
  68. terminate_board    macro
  69.     endm
  70.  
  71.     public    int_no, io_addr
  72. int_no        db    2,0,0,0        ;must be four bytes long for get_number.
  73. io_addr        dw    0300h,0        ; I/O address for card (jumpers)
  74.  
  75.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  76. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  77. driver_type    dw    54        ;from the packet spec
  78. driver_name    db    'NE2000',0    ;name of the driver.
  79. driver_function    db    2
  80. parameter_list    label    byte
  81.     db    1    ;major rev of packet driver
  82.     db    9    ;minor rev of packet driver
  83.     db    14    ;length of parameter list
  84.     db    EADDR_LEN    ;length of MAC-layer address
  85.     dw    GIANT    ;MTU, including MAC headers
  86.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  87.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  88.     dw    0    ;(# of successive xmits) - 1
  89. int_num    dw    0    ;Interrupt # to hook for post-EOI
  90.             ;processing, 0 == none,
  91.  
  92. is_186        db    0
  93.  
  94. ;
  95. ;    Block input routine
  96. ;    CX = byte count, es:di = buffer location, ax = buffer address
  97.  
  98.     public    block_input
  99. block_input:
  100.     push    ax        ; save buffer address
  101.     loadport
  102.     setport EN_CCMD
  103.     pause_
  104.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  105.     out    dx,al
  106.     setport    EN0_RCNTLO    ; remote byte count 0
  107.     pause_
  108.     mov    al,cl
  109.     out    dx,al
  110.     setport    EN0_RCNTHI
  111.     pause_
  112.     mov    al,ch
  113.     out    dx,al
  114.     pop    ax        ; get our page back
  115.     setport    EN0_RSARLO
  116.     pause_
  117.     out    dx,al        ; set as hi address
  118.     setport    EN0_RSARHI
  119.     pause_
  120.     mov    al,ah
  121.     out    dx,al
  122.     setport EN_CCMD
  123.     pause_
  124.     mov    al,ENC_RREAD+ENC_START    ; read and start
  125.     out    dx,al
  126.     setport    NE_DATAPORT
  127.     pause_
  128.     cmp    is_186,0
  129.     jnz    read_186
  130. read_loop:
  131.     in    al,dx        ; get a byte
  132.     stosb            ; save it
  133.     loop    read_loop
  134.     ret
  135. read_186:
  136.     inc    cx        ; make even
  137.     shr    cx,1        ; word count
  138.     db    0f3h, 06dh    ;masm 4.0 doesn't grok "rep insw"
  139.     ret
  140. ;
  141. ;    Block output routine
  142. ;    CX = byte count, ds:si = buffer location, ax = buffer address
  143.  
  144. block_output:
  145.     assume    ds:nothing
  146.     push    ax        ; save buffer address
  147.     inc    cx        ; make even
  148.     and    cx,0fffeh
  149.     loadport
  150.     setport EN_CCMD
  151.     pause_
  152.     mov    al,ENC_NODMA+ENC_START
  153.     out    dx,al        ; stop & clear the chip
  154.     setport    EN0_RCNTLO    ; remote byte count 0
  155.     pause_
  156.     mov    al,cl
  157.     out    dx,al
  158.     setport    EN0_RCNTHI
  159.     pause_
  160.     mov    al,ch
  161.     out    dx,al
  162.     pop    ax        ; get our page back
  163.     setport    EN0_RSARLO
  164.     pause_
  165.     out    dx,al        ; set as lo address
  166.     setport    EN0_RSARHI
  167.     pause_
  168.     mov    al,ah
  169.     out    dx,al
  170.     setport EN_CCMD
  171.     pause_
  172.     mov    al,ENC_RWRITE+ENC_START    ; write and start
  173.     out    dx,al
  174.     setport    NE_DATAPORT
  175.     pause_
  176.     cmp    byte ptr is_186,0
  177.     jnz    write_186
  178. write_loop:
  179.     lodsb            ; get a byte
  180.     out    dx,al        ; save it
  181.     loop    write_loop
  182.     jmp    short block_output_1
  183. write_186:
  184.     shr    cx,1        ; word count
  185.     db    0f3h, 06fh    ;masm 4.0 doesn't grok "rep outsw"
  186. block_output_1:
  187.     mov    cx,0
  188.     setport    EN0_ISR
  189. tx_check_rdc:
  190.     in    al,dx
  191.     test    al,ENISR_RDC    ; dma done ???
  192.     jnz    tx_start
  193.     loop    tx_check_rdc
  194.     stc
  195.     ret
  196. tx_start:
  197.     clc
  198.     ret
  199.  
  200.  
  201.     include    8390.asm
  202.  
  203.     public    usage_msg
  204. usage_msg    db    "usage: NE2000 [-n] [-d] [-w] <packet_int_no> <int_level> <io_addr>",CR,LF,'$'
  205.  
  206.     public    copyright_msg
  207. copyright_msg    db    "Packet driver for NE2000, version "
  208.         db    '0'+majver,".",'0'+version,".",'0'+dp8390_version,CR,LF,'$'
  209.  
  210. cfg_err_msg    db    "NE2000 Configuration failed. Check parameters.",CR,LF,'$'
  211. int_no_name    db    "Interrupt number ",'$'
  212. io_addr_name    db    "I/O port ",'$'
  213.  
  214.     extrn    set_recv_isr: near
  215.  
  216. ;enter with si -> argument string, di -> word to store.
  217. ;if there is no number, don't change the number.
  218.     extrn    get_number: near
  219.  
  220. ;enter with dx -> name of word, di -> dword to print.
  221.     extrn    print_number: near
  222.  
  223.     public    parse_args
  224. parse_args:
  225. ;exit with nc if all went well, cy otherwise.
  226.     mov    di,offset int_no
  227.     call    get_number
  228.     mov    di,offset io_addr
  229.     call    get_number
  230.     clc
  231.     ret
  232.  
  233.     extrn    etopen_diagn: byte
  234.  
  235. init_card:
  236. ;get the board data. This is (16) bytes starting at remote
  237. ;dma address 0. Put it in a buffer called board_data.
  238.     assume    ds:code
  239.  
  240.     or    endcfg,ENDCFG_WTS
  241.  
  242.     loadport
  243.     mov    al,endcfg
  244.     setport    EN0_DCFG
  245.     pause_
  246.     out    dx,al
  247.  
  248.     mov    cx,10h        ; get 16 bytes,
  249.     push    ds
  250.     pop    es        ; set es to ds
  251.     mov    di,offset board_data
  252.  
  253.     setport EN_CCMD
  254.     pause_
  255.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  256.     out    dx,al
  257.     setport    EN0_RCNTLO    ; remote byte count 0
  258.     pause_
  259.     mov    al,20h        ; count is actually doubled.
  260.     out    dx,al
  261.     setport    EN0_RCNTHI
  262.     pause_
  263.     xor    al,al        ; high byte of count is zero.
  264.     out    dx,al
  265.  
  266.     mov    ax,0        ; from address 0
  267.  
  268.     setport    EN0_RSARLO
  269.     pause_
  270.     out    dx,al        ; set as hi address
  271.     setport    EN0_RSARHI
  272.     pause_
  273.     mov    al,ah
  274.     out    dx,al
  275.     setport EN_CCMD
  276.     pause_
  277.     mov    al,ENC_RREAD+ENC_START    ; read and start
  278.     out    dx,al
  279.     setport    NE_DATAPORT
  280.     pause_
  281. sp_read_loop:
  282.     in    al,dx        ; get a byte
  283.     stosb            ; save it
  284.     loop    sp_read_loop
  285.  
  286.     push    ds              ; Copy from card's address to current address
  287.     pop     es
  288.  
  289.     mov si, offset board_data    ; address is at start
  290.     mov di, offset curr_hw_addr
  291.     mov cx, EADDR_LEN       ; Copy one address length
  292.     rep     movsb           ; ..
  293.  
  294.     ret
  295.  
  296.     public    print_parameters
  297. print_parameters:
  298. ;echo our command-line parameters
  299.     mov    di,offset int_no
  300.     mov    dx,offset int_no_name
  301.     call    print_number
  302.     mov    di,offset io_addr
  303.     mov    dx,offset io_addr_name
  304.     call    print_number
  305.     ret
  306.  
  307. code    ends
  308.  
  309.     end
  310.