home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / GRDBDL17.ZIP / PCI.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-10-26  |  5.5 KB  |  220 lines

  1. ;
  2. ; GRDB
  3. ;
  4. ; Copyright(c) LADsoft
  5. ;
  6. ; David Lindauer, camille@bluegrass.net
  7. ;
  8. ; this module donated by:
  9. ;
  10. ;  Trung Nguyen <trungn@texmicro.com>
  11. ;
  12. ; a BIOS developer at texas micro inc.
  13. ;
  14. ;
  15. ; PCI.ASM
  16. ;
  17. ; Function: PCI commands
  18. ;
  19. ;
  20.     ;MASM MODE
  21.     .MODEL SMALL
  22.     .386
  23.  
  24. include  eprints.inc 
  25. include  einput.inc 
  26. include  emtrap.inc 
  27.  
  28. IODELAY MACRO
  29.         out     0EDh, al
  30. ENDM
  31.  
  32.     PUBLIC pci
  33.  
  34.     .data
  35.  
  36.     .CODE
  37. pci    PROC
  38.     lodsb
  39.     cmp    al,'?'        ; verify subcommand
  40.         jz      pfaCmd          ; PFA command
  41.     call    ReadNumber    ; PFA
  42.     jc    pciErr
  43.         cmp     eax, 0FFFFh     ; Q:Valid PFA
  44.         ja      pciErr          ;   N:
  45.         mov     ebx, eax
  46.     call    WadeSpace    ; 
  47.     jz    pciErr
  48.     call    ReadNumber    ; Reg
  49.     jc    pciErr
  50.         cmp     eax, 0FFh       ; Q:Valid Reg
  51.         ja      pciErr          ;   N:
  52.         mov     ah, al
  53.         push    ax
  54.     call    WadeSpace    ; 
  55.         pop     ax
  56.     jnz    pciDoWrite
  57.         call    PciByteRead
  58.         push    ax
  59.     call    crlf
  60.         pop     ax        
  61.         call    PrintByte
  62.         jmp     pciNoErr
  63.  
  64. pciDoWrite:
  65.         push    ax
  66.     call    ReadNumber    ; Value
  67.     jc    pciErr
  68.         cmp     eax, 0FFh       ; Q:Valid val
  69.         ja      pciErr          ;   N:
  70.         mov     cl, al
  71.         pop     ax
  72.         mov     al, cl
  73.         push    ax
  74.     call    WadeSpace    ;
  75.         pop     ax
  76.     jnz    pciErr
  77.         call    pciByteWrite
  78.         jmp     pciNoErr
  79.  
  80. pfaCmd:
  81.     call    WadeSpace    ; get operator
  82.     jz    pciErr
  83.         xor     ebx, ebx
  84.     call    ReadNumber    ; Bus
  85.     jc    pciErr
  86.         cmp     eax, 0FFh       ; Q:Valid Bus
  87.         ja      pciErr          ;   N:
  88.         mov     bl, al          ;   Y: Get bus
  89.         shl     bx, 8
  90.     call    WadeSpace    ; get operator
  91.     jz    pciErr
  92.     call    ReadNumber    ; Dev
  93.     jc    pciErr
  94.         cmp     eax, 01Fh       ; Q:Valid Dev
  95.         ja      pciErr          ;   N:
  96.         mov     bl, al          ;   Y: Get Dev
  97.         shl     bl, 3
  98.     call    WadeSpace    ; get operator
  99.     jz    pciErr
  100.     call    ReadNumber    ; Func
  101.     jc    pciErr
  102.         cmp     eax, 07h        ; Q:Valid Func
  103.         ja      pciErr          ;   N:
  104.         or      bl, al
  105.     call    WadeSpace
  106.     jnz    pciErr
  107.     call    crlf
  108.         mov     ax, bx
  109.         call    PrintWord
  110.  
  111. pciNoErr:
  112.         clc
  113.         jmp     pciDone
  114.  
  115. pciErr:
  116.         stc
  117.  
  118. pciDone:
  119.         ret        
  120. pci    endp
  121.  
  122.  
  123. ;----------------------------------------------------------------------------
  124. ;       PciByteRead -
  125. ;       This proc will read the byte from the register and device
  126. ;
  127. ;       Entry:  BX = PFA 
  128. ;                    Bit<15..8>=Bus
  129. ;                    Bit<7...3>=Dev
  130. ;                    Bit<2..0>=Func
  131. ;               AH = Reg
  132. ;       Exit:
  133. ;               AL = register contents.
  134. ;       Affected registers:
  135. ;               AL is destroyed, all other registers are preserved.
  136. ;
  137. PciByteRead PROC
  138.         push    cx
  139.         push    dx
  140.         push    eax
  141.         mov     ch, ah          ; Save register in CH
  142.         mov     eax,0800000h
  143.         or      ax, bx          ; Get PFA
  144.         shl     eax, 8          ; Make room for register
  145.         mov     al, ch          ; Place register info in location
  146.         and     al,0FCh         ; Strip off alignment data.
  147.         mov     dx,0CF8h        ;
  148.         out     dx,eax
  149.         IODELAY
  150.         call    PointToByte     ; Align the PCI data port to out byte.
  151.         in      al,dx           ; Fetch the data.
  152.         IODELAY
  153.         mov     cl, al          ; Save data first
  154.         pop     eax
  155.         mov     al, cl          ; Place data back
  156.         pop     dx
  157.         pop     cx
  158.         ret
  159. PciByteRead ENDP
  160.  
  161. ;----------------------------------------------------------------------------
  162. ;       PciByteWrite - 
  163. ;       This proc will write a byte to the register and device
  164. ;
  165. ;       Entry:  BX = PFA 
  166. ;                    Bit<15..8>=Bus
  167. ;                    Bit<7...3>=Dev
  168. ;                    Bit<2..0>=Func
  169. ;               AH = Reg
  170. ;               AL = Value
  171. ;       Exit:
  172. ;               None.
  173. ;       Affected registers:
  174. ;               All registers are preserved.
  175. ;
  176. PciByteWrite PROC
  177.         push    cx
  178.         push    dx
  179.         push    eax
  180.         mov     cx, ax          ; Save register and value in CX
  181.         mov     eax,0800000h
  182.         or      ax, bx          ; Get PFA
  183.         shl     eax, 8          ; Make room for register
  184.         mov     al, ch          ; Place register info in location
  185.         and     al,0FCh         ; Strip off alignment data.
  186.         mov     dx,0CF8h        ;
  187.         out     dx,eax
  188.         IODELAY
  189.         call    PointToByte     ; Align the PCI data port to out byte.
  190.         mov     al, cl          ; Get value back
  191.         out     dx, al          ; BlastIT!!!!
  192.         IODELAY
  193.         pop     eax
  194.         pop     dx
  195.         pop     cx
  196.         ret
  197. PciByteWrite ENDP
  198.  
  199. ;----------------------------------------------------------------------------
  200. ;       PointToByte
  201. ;       This proc provides the appropriate PCI IO port address to properly
  202. ;       access data in the PCI CFG space.
  203. ;       Entry:
  204. ;               CH = Register to use.
  205. ;       Exit:
  206. ;               DX = PCI data port IO address.
  207. ;       Affected registers:
  208. ;               DX is modified, all other registers are preserved.
  209. ;
  210. PointToByte PROC
  211.         push    cx
  212.         and     cx,0300h        ; Strip all but byte information.
  213.         xchg    ch, cl          ; Swap the LSB and MSB
  214.         mov     dx,0CFCh        ; Base PCI IO port.
  215.         add     dx,cx           ; Point to our register.
  216.         pop     cx
  217.         ret
  218. PointToByte ENDP
  219.  
  220. end