home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 4 Drivers / 04-Drivers.zip / cyrix.zip / cyrix.asm next >
Assembly Source File  |  1992-07-13  |  7KB  |  296 lines

  1.         page    50,132
  2.         .286
  3.  
  4.         .xlist
  5.         INCL_BASE  equ  1
  6.         include OS2.INC
  7.         .list
  8.  
  9.         extrn   DosWrite:far
  10.  
  11.         public  header
  12.         public  devhlp
  13.         public  msg1
  14.         public  msg2
  15.         public  msg3
  16.         public  cBytesWritten
  17.         public  tInterrupt
  18.         public  fError
  19.         public  fEnabled
  20.         public  strategy
  21.         public  init
  22.         public  enable
  23.         public  strategy9
  24.         public  dataPtr
  25.  
  26. DGROUP  group   _DATA
  27.  
  28. _DATA   segment word    public  'DATA'
  29. header  label   dword
  30.         dd      -1
  31.         dw      1000000010000000b       ; char device, OS/2 1.x level
  32.         dw      strategy
  33.         dw      0
  34.         db      'Cyrix   '
  35.         db      8 dup (0)
  36.  
  37.         align   4
  38. devhlp  label   dword
  39.         dw      ?
  40.         dw      ?
  41.  
  42. fEnabled        label   byte
  43.         db      -1                      ; -1 => cache not enabled
  44.                                         ; 0 => cache enabled
  45.         ;
  46.         ; put all data to remain resident before msg1
  47.         ;
  48. msg1    label   byte
  49.         db      13,10,10
  50.         db      'Cyrix Device Driver version 1.0.'
  51.         db      13,10
  52. msg1_l  equ     ($ - offset msg1)
  53.  
  54. msg2    label   byte
  55.         db      13,10,10
  56.         db      'Install failed.'
  57.         db      13,10
  58. msg2_l  equ     ($ - offset msg2)
  59.  
  60. msg3    label   byte
  61.         db      13,10,10
  62.         db      'Install successful.'
  63.         db      13,10
  64. msg3_l  equ     ($ - offset msg3)
  65.  
  66. fError  label   byte
  67.         db      -1                      ; -1 => install failed
  68.                                         ; 0 => install successful
  69. cBytesWritten   label   word
  70.         dw      ?
  71.  
  72. _DATA   ends
  73.  
  74. _TEXT   segment word    public  'CODE'
  75.         assume  cs:_TEXT, ds:DGROUP, es:NOTHING
  76.  
  77. strategy        proc    far
  78. ;;;;        int 3
  79.         cmp     byte ptr es:[bx+2],0    ; init?
  80.         mov     ax,8103h                ; assume not
  81.         jne     strategy9
  82.  
  83.         call    init
  84.         jc      @F
  85.  
  86.         mov     byte ptr fError,0       ; signal no error during install
  87.  
  88. @@:
  89.         ;
  90.         ; assume error occurred during install
  91.         ;
  92.         lea     ax,DGROUP:msg2
  93.         mov     cx,msg2_l
  94.         cmp     byte ptr fError,0
  95.         jne     @F
  96.  
  97.         lea     ax,DGROUP:msg3
  98.         mov     cx,msg3_l
  99.  
  100. @@:
  101.         push    1
  102.         push    ds
  103.         push    ax              ; offset of message
  104.  
  105.         push    cx              ; length of message
  106.  
  107.         push    ds              
  108.         push    offset DGROUP:cBytesWritten
  109.  
  110.         call    DosWrite
  111.  
  112.         mov     ax,0810ch               ; error, done, general failure
  113.         cmp     byte ptr fError,-1
  114.         je      strategy9
  115.  
  116.         mov     ax,0100h                ; no error, done
  117.  
  118. strategy9:
  119.         mov     word ptr es:[bx+3],ax
  120.         ret
  121. strategy        endp
  122.  
  123. enable  proc    near
  124.         .386p
  125.  
  126.         push    eax
  127.         push    ebx
  128.  
  129.         cli
  130.         jmp     $+2
  131.  
  132.         ; disable cache filling & flush cache
  133.         mov     eax,cr0
  134.         mov     ebx,eax         ; save copy cr0
  135.  
  136.         and     eax,(10011111111111111111111111111111b)
  137.         mov     cr0,eax
  138.  
  139.         ; flush cache
  140.         db      00001111b, 00001000b    ; invalidate cache (invd)
  141.  
  142.         ; turn on NC0, NC1, & BARB
  143.         ; NC0
  144.         ; bit 0 = 1 inhibits caching  1st 64K bytes at each 1Mb boundary
  145.         ;
  146.         ; NC1
  147.         ; bit 1 = 1 inhibits caching of memory addresses 09ffffh to 0ffffffh
  148.         ; 
  149.         ; BARB
  150.         ; bit 5 = 1 forces cache to flush when HOLD state entered
  151.         ; (HOLD state entered when BUS master active (or DRAM refresh?)
  152.         ;
  153.         mov     al,0c0h
  154.         out     22h,al
  155.         mov     al,23h
  156.         out     23h,al
  157.  
  158.         ; set start address equal to 0 & block size to disabled for NCR1
  159.         mov     al,0c5h
  160.         out     22h,al
  161.         mov     al,0
  162.         out     23h,al
  163.         mov     al,0c6h
  164.         out     22h,al
  165.         mov     al,0
  166.         out     23h,al
  167.  
  168.         ; set start address to 0 & block size to disabled for NCR2
  169.         mov     al,0c8h
  170.         out     22h,al
  171.         mov     al,0
  172.         out     23h,al
  173.         mov     al,0c9h
  174.         out     22h,al
  175.         mov     al,0
  176.         out     23h,al
  177.  
  178.         ; set start address to 0 & block size to disabled for NCR3
  179.         mov     al,0cbh
  180.         out     22h,al
  181.         mov     al,0h
  182.         out     23h,al
  183.         mov     al,0cch
  184.         out     22h,al
  185.         mov     al,0h
  186.         out     23h,al
  187.  
  188.         ; set start address to 0 & block size to disabled for NCR4
  189.         mov     al,0ceh
  190.         out     22h,al
  191.         mov     al,0h
  192.         out     23h,al
  193.         mov     al,0cfh
  194.         out     22h,al
  195.         mov     al,0
  196.         out     23h,al
  197.  
  198.         ; enable cache filling
  199.         mov     eax,ebx         ; restore cr0
  200.         or      eax,01100000000000000000000000000000b
  201.         mov     cr0,eax
  202.  
  203.         pop     ebx
  204.         pop     eax
  205.  
  206.         sti
  207.  
  208.         .286
  209.         ret
  210. enable  endp
  211.  
  212.         align   4
  213. dataPtr label   word
  214.         dw      _DATA
  215.  
  216.         align   4
  217. tInterrupt      proc    far
  218.         ; must save used registers
  219.         push    cx
  220.         push    ds
  221.  
  222.         ;
  223.         ; point DS to local data
  224.         ;
  225.         mov     ds,cs:dataPtr
  226.  
  227.         ;
  228.         ; see if we been here before
  229.         ;
  230.         xor     cx,cx
  231.         xchg    cl,fEnabled
  232.         jcxz    tInterrupt9
  233.  
  234.         call    enable
  235.  
  236.         align   4
  237. tInterrupt9:
  238.         pop     ds
  239.         pop     cx
  240.         ret
  241. tInterrupt      endp
  242.  
  243.         ;
  244.         ; put all code to remain resident before init
  245.         ;
  246. init    proc    near
  247.         ;
  248.         ; announce presence
  249.         ;
  250.         push    1
  251.         push    ds
  252.         push    offset DGROUP:msg1
  253.         push    msg1_l
  254.  
  255.         push    ds
  256.         push    offset DGROUP:cBytesWritten
  257.         call    DosWrite
  258.  
  259.         ;
  260.         ; save address of devhlp entry point
  261.         ;
  262.         mov     ax,es:[bx+14]
  263.         mov     word ptr devhlp+0,ax
  264.         mov     ax,es:[bx+16]
  265.         mov     word ptr devhlp+2,ax
  266.  
  267.         ;
  268.         ; add timer handler to list of timer handlers
  269.         ;
  270.         lea     ax,_TEXT:tInterrupt
  271.         mov     dl,29                   ; add timer function
  272.         call    devhlp
  273.         jnc     @F
  274.  
  275.         ;
  276.         ; call failed => don't install driver
  277.         ;
  278.         mov     word ptr es:[bx+14],0
  279.         mov     word ptr es:[bx+16],0
  280.         jmp     short init9
  281.  
  282. @@:
  283.         ;
  284.         ; tell kernel what to keep resident
  285.         ;
  286.         mov     word ptr es:[bx+14],offset CS:init
  287.         mov     word ptr es:[bx+16],offset DGROUP:msg1
  288.  
  289. init9:
  290.         ret
  291. init    endp
  292.  
  293. _TEXT   ends
  294.  
  295.         end
  296.