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

  1. version    equ    1
  2.  
  3.     include    defs.asm
  4.  
  5. ;Ported from Tim Krauskopf's micnet.asm, an assembly language
  6. ;driver for the MICOM-Interlan NI5210 by Russell Nelson.  Any bugs
  7. ;are due to Russell Nelson.
  8.  
  9. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  10.  
  11. ;   This program is free software; you can redistribute it and/or modify
  12. ;   it under the terms of the GNU General Public License as published by
  13. ;   the Free Software Foundation, version 1.
  14. ;
  15. ;   This program is distributed in the hope that it will be useful,
  16. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;   GNU General Public License for more details.
  19. ;
  20. ;   You should have received a copy of the GNU General Public License
  21. ;   along with this program; if not, write to the Free Software
  22. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24.     .286                ;the 3c507 requires a 286.
  25.  
  26. code    segment    word public
  27.     assume    cs:code, ds:code
  28.  
  29. ;
  30. ;  Equates for controlling the 3c507 board
  31. ;
  32. IO_CONTROL    equ    06h
  33. IO_INTCLR    equ    0ah
  34. IO_CA        equ    0bh
  35. IO_RAM        equ    0eh
  36. IO_INT        equ    0fh
  37.  
  38. ;IO_CONTROL bits:
  39. _RST    equ    80h            ;not reset
  40. LBK    equ    20h            ;loopback
  41. IEN    equ    04h            ;interrupt enable
  42. VB0    equ    01h            ;vb0.
  43.  
  44.     public    int_no
  45. int_no        db    3,0,0,0        ; interrupt number
  46. io_addr        dw    300h,0        ; I/O address for card
  47. base_addr    dw      0c000h,0    ; base segment for board
  48.  
  49.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  50. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  51. driver_type    db    13        ;from the packet spec
  52. driver_name    db    "3c507",0    ;name of the driver.
  53. driver_function    db    2
  54. parameter_list    label    byte
  55.     db    1    ;major rev of packet driver
  56.     db    9    ;minor rev of packet driver
  57.     db    14    ;length of parameter list
  58.     db    EADDR_LEN    ;length of MAC-layer address
  59.     dw    GIANT    ;MTU, including MAC headers
  60.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  61.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  62.     dw    0    ;(# of successive xmits) - 1
  63. int_num    dw    0    ;Interrupt # to hook for post-EOI
  64.             ;processing, 0 == none,
  65.  
  66. enable_network:
  67. ;  connect to network
  68.     loadport
  69.     setport    IO_CONTROL
  70.     mov    al,_RST or IEN or VB0
  71.     out    dx,al
  72.     ret
  73.  
  74.  
  75. reset_586:
  76. ;  Reset the chip
  77.     loadport
  78.     setport    IO_CONTROL
  79.     mov    al,LBK
  80.     out    dx,al
  81.     jmp    $+2
  82.     jmp    $+2
  83.     mov    al,_RST or LBK or VB0
  84.     out    dx,al
  85.     setport    IO_INTCLR        ;clear the interupt latch.
  86.     out    dx,al
  87.     ret
  88.  
  89.  
  90. doca:
  91. ;we may be called from places in which ds is unknown.
  92.     assume    ds:nothing
  93.     loadport
  94.     setport IO_CA
  95.     out    dx, al
  96.     ret
  97.     assume    ds:code
  98. ;yet, we really should assume ds==code for the rest of this stuff.
  99.  
  100.  
  101. ;
  102. ; Here we include the code that is common between 82586 implementations.
  103. ; Everything above this is resident.
  104.     include    82586.asm
  105. ; Everything below this is discarded upon installation.
  106.  
  107.     public    usage_msg
  108. usage_msg    db    "usage: 3c507 [options] <packet_int_no> <io_addr>",CR,LF,'$'
  109.  
  110.     public    copyright_msg
  111. copyright_msg    db    "Packet driver for the 3C507, version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version,".",'0'+i82586_version,CR,LF,'$'
  112.  
  113. main_memory_only    label    byte
  114.     db    "Memory window must be in the 0xc000 -> 0xd800 range.",CR,LF,'$'
  115.  
  116. signature    db    'PKT DRVR',0
  117. signature_len    equ    $-signature
  118.  
  119. their_int    dd    ?
  120. found_3c507    db    0
  121.  
  122. check_board:
  123.     mov    SCP,0            ; 16 bit bus type in scb.
  124.  
  125. ;we look for another 3c507 packet driver.  If there is one, we don't write
  126. ;the ID pattern, because that resets the board's bus interface.
  127.     mov    al,60h
  128. check_ints:
  129.     push    ax
  130.     mov    ah,35h            ;get their packet interrupt.
  131.     int    21h
  132.  
  133.     lea    di,3[bx]        ;see if there is already a signature
  134.     mov    si,offset signature    ;  there.
  135.     mov    cx,signature_len
  136.     repe    cmpsb
  137.     jne    check_ints_1
  138.  
  139.     mov    their_int.offs,bx
  140.     mov    their_int.segm,es
  141.  
  142.     push    ds
  143.     mov    ax,1ffh            ;get the board's parameters
  144.     pushf
  145.     cli
  146.     call    their_int
  147.     pop    ds
  148.     cmp    dl,driver_type
  149.     jne    check_ints_1
  150.  
  151.     inc    found_3c507        ;yes!  We found another 3c507.
  152. check_ints_1:
  153.     pop    ax
  154.     inc    al
  155.     cmp    al,80h
  156.     jbe    check_ints
  157.  
  158.     cmp    found_3c507,0
  159.     jne    check_ints_2
  160.     call    write_id_pat
  161. check_ints_2:
  162.  
  163.     loadport
  164.     setport    IO_RAM
  165.     in    al,dx
  166.     test    al,20h            ;8088 address or 80286 address?
  167.     je    check_board_3
  168.     mov    dx,offset main_memory_only
  169.     stc
  170.     ret
  171. check_board_3:
  172.     and    al,18h
  173. ;00 = 0c000h, 08 = 0c800h, 10 = 0d000h, 18 = 0d800h.
  174.     mov    ah,al
  175.     xor    al,al
  176.     add    ah,0c0h
  177.     mov    base_addr,ax
  178.  
  179.     setport    IO_INT
  180.     in    al,dx
  181.     and    al,0fh
  182.     mov    int_no,al
  183.  
  184.     setport    IO_CONTROL
  185.     mov    al,_RST or IEN or VB0
  186.     out    dx,al
  187.  
  188.     clc
  189.     ret
  190.  
  191.  
  192. write_id_pat:
  193.     mov    dx,100h
  194.     xor    al,al
  195.     out    dx,al            ;reset hardware pattern generator
  196.     mov    cx,0ffh
  197.     mov    al,0ffh
  198. write_id_pat_1:
  199.     out    dx,al            ;keep writing matching values...
  200.     shl    al,1
  201.     jnc    write_id_pat_2
  202.     xor    al,0e7h
  203. write_id_pat_2:
  204.     loop    write_id_pat_1
  205.     xor    al,al
  206.     out    dx,al            ;now put adapter in RUN state.
  207.     ret
  208.  
  209.  
  210. get_address:
  211. ;get the address of the interface.
  212. ;enter with es:di -> place to get the address, cx = size of address buffer.
  213. ;exit with nc, cx = actual size of address, or cy if buffer not big enough.
  214.     assume    ds:code
  215.     mov    dx,io_addr        ; Get our IO base address.
  216.     cld
  217. get_address_1:
  218.     in    al,dx            ; get a byte of the eprom address
  219.     stosb                ; put it away
  220.     inc    dx            ; next register
  221.     loop    get_address_1        ; go back for rest
  222.     ret
  223.  
  224.  
  225.     public    parse_args
  226. parse_args:
  227.     mov    di,offset io_addr
  228.     call    get_number
  229.     clc
  230.     ret
  231.  
  232.  
  233. int_no_name    db    "Interrupt number ",'$'
  234. io_addr_name    db    "I/O port ",'$'
  235. base_addr_name    db    "Memory address ",'$'
  236.  
  237.  
  238.     public    print_parameters
  239. print_parameters:
  240.     mov    di,offset int_no
  241.     mov    dx,offset int_no_name
  242.     call    print_number
  243.     mov    di,offset io_addr
  244.     mov    dx,offset io_addr_name
  245.     call    print_number
  246.     mov    ax,memory_begin
  247.     mov    cl,4
  248.     shr    ax,cl
  249.     add    base_addr,ax
  250.     push    ax
  251.     mov    di,offset base_addr
  252.     mov    dx,offset base_addr_name
  253.     call    print_number
  254.     pop    ax
  255.     sub    base_addr,ax
  256.     ret
  257.  
  258.     include    memtest.asm
  259.  
  260. code    ends
  261.  
  262.     end
  263.  
  264.