home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / driver6s / tail.asm < prev    next >
Assembly Source File  |  1990-04-13  |  10KB  |  352 lines

  1. ;   PC/FTP Packet Driver source, conforming to version 1.05 of the spec
  2. ;   Russell Nelson, Clarkson University.  July 20, 1988
  3. ;   Updated to version 1.08 Feb. 17, 1989.
  4. ;   Copyright 1988,1989 Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment byte public
  22.     assume    cs:code, ds:code
  23.  
  24.     extrn    phd_dioa: byte
  25.     extrn    phd_environ: word
  26.  
  27. ;usage_msg is of the form "usage: driver <packet_int_no> <args>"
  28.     extrn    usage_msg: byte
  29.  
  30. ;copyright_msg is of the form:
  31. ;"Packet driver for the foobar",CR,LF
  32. ;"Portions Copyright 19xx, J. Random Hacker".
  33.     extrn    copyright_msg: byte
  34.  
  35. copyleft_msg    label    byte
  36.  db "Packet driver skeleton copyright 1988-90, Russell Nelson.",CR,LF
  37.  db "This program is free software; see the file COPYING for details.",CR,LF
  38.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  39. crlf_msg    db    CR,LF,'$'
  40.  
  41. ;parse_args should parse the arguments.
  42. ;called with ds:si -> immediately after the packet_int_no.
  43.     extrn    parse_args: near
  44.  
  45.     extrn    our_isr: near, their_isr: dword
  46.     extrn    packet_int_no: byte
  47.     extrn    is_at: byte, sys_features: byte
  48.     extrn    int_no: byte
  49.     extrn    driver_class: byte
  50.  
  51. location_msg    db    "Packet driver loaded at segment ",'$'
  52.  
  53. packet_int_no_name    db    "Packet interrupt number ",'$'
  54. eaddr_msg    db    "My Ethernet address is ",'$'
  55. aaddr_msg    db    "My ARCnet address is ",'$'
  56.  
  57. signature    db    'PKT DRVR',0
  58. signature_len    equ    $-signature
  59.  
  60. already_msg    db    CR,LF,"There is already a packet driver at ",'$'
  61. packet_int_msg    db    CR,LF
  62.         db    "Error: <packet_int_no> should be in the range 0x60 to 0x80"
  63.         db    '$'
  64. int_msg        db    CR,LF
  65.         db    "Error: <int_no> should be no larger than "
  66. int_msg_num    label    word
  67.         db    "xx"
  68.         db    '$'
  69.  
  70. our_address    db    EADDR_LEN dup(?)
  71.     public    etopen_diagn
  72. etopen_diagn    db    0        ; errorlevel from etopen if set
  73.  
  74. ;etopen should initialize the device.  If it needs to give an error, it
  75. ;can issue the error message and quit to dos.
  76.     extrn    etopen: near
  77.  
  78. ;get the address of the interface.
  79. ;enter with es:di -> place to get the address, cx = size of address buffer.
  80. ;exit with nc, cx = actual size of address, or cy if buffer not big enough.
  81.     extrn    get_address: near
  82.  
  83. already_error:
  84.     mov    dx,offset already_msg
  85.     mov    di,offset packet_int_no
  86.     call    print_number
  87.     mov    ax,4c05h        ; give errorlevel 5
  88.     int    21h
  89.  
  90. usage_error:
  91.     mov    dx,offset usage_msg
  92.     public    error
  93. error:
  94.     mov    ah,9
  95.     int    21h
  96.     mov    ax,4c0ah        ; give errorlevel 10
  97.     int    21h
  98.  
  99.     public    start_1
  100. start_1:
  101.     mov    dx,offset copyright_msg
  102.     mov    ah,9
  103.     int    21h
  104.  
  105.     mov    dx,offset copyleft_msg
  106.     mov    ah,9
  107.     int    21h
  108.  
  109.     mov    si,offset phd_dioa+1
  110.     call    skip_blanks        ;end of line?
  111.     cmp    al,CR
  112.     je    usage_error
  113.  
  114. ;print the location we were loaded at.
  115.     mov    dx,offset location_msg
  116.     mov    ah,9
  117.     int    21h
  118.  
  119.     mov    ax,cs            ;print cs as a word.
  120.     call    wordout
  121.  
  122.     mov    dx,offset crlf_msg
  123.     mov    ah,9
  124.     int    21h
  125.  
  126.     mov    di,offset packet_int_no    ;parse the packet interrupt number
  127.     mov    bx,offset packet_int_no_name
  128.     call    get_number        ;  for them.
  129.  
  130.     call    parse_args
  131.     jc    usage_error
  132.  
  133.     call    skip_blanks        ;end of line?
  134.     cmp    al,CR
  135.     jne    usage_error
  136.  
  137.     mov    dx,offset packet_int_msg;make sure that the packet interrupt
  138.     cmp    packet_int_no,60h    ;  number is in range.
  139.     jb    error
  140.     cmp    packet_int_no,80h
  141.     ja    error
  142.  
  143.     mov    ah,35h            ;get their packet interrupt.
  144.     mov    al,packet_int_no
  145.     int    21h
  146.  
  147.     lea    di,3[bx]        ;see if there is already a signature
  148.     mov    si,offset signature    ;  there.
  149.     mov    cx,signature_len
  150.     repe    cmpsb
  151.     jne    not_one_yet
  152.     jmp    already_error        ;yes, so we can't go there.
  153. not_one_yet:
  154.  
  155. ;
  156. ; Get the feature byte (if reliable) so we can know if it is a microchannel
  157. ; computer and how many interrupts there are
  158.         mov     ah,0c0h
  159.         int     15h                     ; es:bx <- sys features block
  160.         mov     al,7                    ;maximum interrupt on a PC
  161.         mov     int_msg_num,'7'+' '*256
  162.         jc      look_in_ROM
  163.         mov     dx,es:[bx]              ; # of feature bytes
  164.         cmp     dx,4
  165.         jae    got_features
  166. look_in_ROM:
  167.     mov    dx,0f000h        ;ROM segment
  168.     mov    es,dx
  169.     cmp    byte ptr es:[0fffeh],0fch    ;is this an AT?
  170.     jne    not_at            ;no.
  171.         or      sys_features,040h       ; ATs have 2nd 8259
  172.     jmp    isa_at            ; assume no microchannel
  173. got_features:
  174.         mov     ah,es:[bx+2]            ; model byte
  175.         cmp     ah,0fch
  176.         je      at_ps2
  177.         ja      not_at                  ; FD, FE and FF are not ATs
  178.         cmp     ah,0f8h
  179.         je      at_ps2
  180.         ja      not_at                  ; F9, FA and FB are not ATs
  181.         cmp     ah,09ah
  182.         jb      not_at                  ; old non-AT Compacs go here
  183. at_ps2:                                 ; 9B - F8 and FC are assumed to
  184.         mov     ah,es:[bx+5]            ;   have reliable feature byte
  185.         mov     sys_features,ah
  186.         test    sys_features,040h       ; 2nd 8259 ?
  187.         jz      not_at
  188. isa_at:
  189.         inc     is_at
  190.         mov     al,15                   ;maximum interrupt on an AT
  191.         mov     int_msg_num,'1'+'5'*256
  192.         cmp     int_no,2                ;map IRQ 2 to IRQ 9.
  193.         jne     not_at
  194.         mov     int_no,9
  195. not_at:
  196.  
  197.     mov    dx,offset int_msg    ;make sure that the packet interrupt
  198.     cmp    int_no,al        ;  number is in range.
  199.     jbe    int_ok
  200.     jmp    error
  201. int_ok:
  202.  
  203.     call    etopen            ;init the driver.  If any errors,
  204.                     ;this routine returns cy.
  205.     jnc    yes_resident
  206.     jmp    no_resident
  207. yes_resident:
  208.  
  209.     push    dx            ;remember where they want to end.
  210.  
  211.     mov    ah,35h            ;remember their packet interrupt.
  212.     mov    al,packet_int_no
  213.     int    21h
  214.     mov    their_isr.offs,bx
  215.     mov    their_isr.segm,es
  216.  
  217.     mov    ah,25h            ;install our packet interrupt
  218.     mov    dx,offset our_isr
  219.     int    21h
  220.  
  221.     cmp    driver_class,1        ;Ethernet?
  222.     jne    print_addr_2        ;no, don't print what we don't have.
  223.  
  224.     push    ds
  225.     pop    es
  226.     mov    di,offset our_address
  227.     mov    cx,EADDR_LEN
  228.     call    get_address
  229.  
  230.     mov    dx,offset eaddr_msg
  231.     mov    ah,9
  232.     int    21h
  233.  
  234.     mov    si,offset our_address
  235.     call    print_ether_addr
  236.  
  237.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  238.     mov    ah,9
  239.     int    21h
  240.  
  241. print_addr_2:
  242.  
  243.     cmp    driver_class,8        ;ARCnet?
  244.     jne    print_addr_3        ;no, don't print what we don't have.
  245.  
  246.     push    ds
  247.     pop    es
  248.     mov    di,offset our_address
  249.     mov    cx,ARCADDR_LEN
  250.     call    get_address
  251.  
  252.     mov    dx,offset aaddr_msg
  253.     mov    ah,9
  254.     int    21h
  255.  
  256.     mov    al,our_address
  257.     mov    cl,' '            ;Don't eliminate leading zeroes.
  258.     call    byteout
  259.  
  260.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  261.     mov    ah,9
  262.     int    21h
  263.  
  264. print_addr_3:
  265.  
  266.     mov    ah,49h            ;free our environment, because
  267.     mov    es,phd_environ        ;  we won't need it.
  268.     int    21h
  269.  
  270.     mov    bx,1            ;get the stdout handle.
  271.     mov    ah,3eh            ;close it in case they redirected it.
  272.     int    21h
  273.  
  274.     pop    dx            ;get their ending address.
  275.     add    dx,0fh            ;round up to next highest paragraph.
  276.     mov    cl,4
  277.     shr    dx,cl
  278.     mov    ah,31h            ;terminate, stay resident.
  279.     mov    al,etopen_diagn        ; errorlevel (0 - 9, just diagnostics)
  280.     int    21h
  281.  
  282. no_resident:
  283.     mov    ax,4c00h + 32        ; give errorlevel 32
  284.     cmp    al,etopen_diagn
  285.     ja    no_et_diagn        ; etopen gave specific reason?
  286.     mov    al,etopen_diagn        ; yes, use that for error level
  287. no_et_diagn:
  288.     int    21h
  289.  
  290. ;             Suggested errorlevels:
  291. ;
  292. ; _____________________  0 = normal
  293. ;              1 = unsuitable memory address given; corrected
  294. ; In most cases every-     2 = unsuitable IRQ level given; corrected
  295. ; thing should work as     3 = unsuitable DMA channel given; corrected
  296. ; expected for lev 1-5     4 = unsuitable IO addr given; corrected (only 1 card)
  297. ; _____________________     5 = packet driver for this int # already loaded
  298. ; External errors, when    20 = general cable failure (but pkt driver is loaded)
  299. ; corrected normal    21 = network cable is open             -"-
  300. ; operation starts    22 = network cable is shorted          -"-
  301. ; _____________________ 23 = 
  302. ; Packet driver not    30 = usage message
  303. ; loaded. A new load    31 = arguments out of range
  304. ; attempt must be done    32 = unspecified device initialization error
  305. ;            33 = 
  306. ;            34 = suggested memory already occupied
  307. ;            35 = suggested IRQ already occupied
  308. ;            36 = suggested DMA channel already occupied
  309. ;            37 = could not find the network card at this IO address
  310.  
  311.  
  312.     public    print_number
  313. print_number:
  314. ;enter with dx -> dollar terminated name of number, di ->dword.
  315. ;exit with the number printed and the cursor advanced to the next line.
  316.     mov    ah,9            ;print the name of the number.
  317.     int    21h
  318.     mov    al,'0'
  319.     call    chrout
  320.     mov    al,'x'
  321.     call    chrout
  322.     mov    ax,[di]            ;print the number in hex.
  323.     mov    dx,[di+2]
  324.     call    dwordout
  325.     mov    al,' '
  326.     call    chrout
  327.     mov    al,'('
  328.     call    chrout
  329.     mov    ax,[di]            ;print the number in decimal.
  330.     mov    dx,[di+2]
  331.     call    decout
  332.     mov    al,')'
  333.     call    chrout
  334.     mov    al,CR
  335.     call    chrout
  336.     mov    al,LF
  337.     call    chrout
  338.     ret
  339.  
  340.  
  341.     include    getnum.asm
  342.     include    getdig.asm
  343.     include    skipblk.asm
  344.     include    decout.asm
  345.     include    digout.asm
  346.     include    chrout.asm
  347.     include    printea.asm
  348.  
  349. code    ends
  350.  
  351.     end
  352.