ECE291 Computer Engineering II Plavcan, Summer 1997

Lecture Z

Today's Topics


What is DMA?


DMA Hardware (8237 DMAC)

  • Processor has HOLD/HOLD Acknowledge lines to interact with 8237
  • DRQ4 services slave controller
  • Priorities are set ast fixed
  • ISA address/data/control lines are also connected (not shown)

  • 8237 Modes

    DMA Cycle


    Coding DMA Transfers

      Programming the DMA controller is not a simple process, but it can be reduced to the following steps:

      1. Find the Page and Page Offset of the memory block you wish to transfer
      2. Turn off the DMA channel (so it win't accept requests while you reprogram it)
      3. Clear the byte pointer flip/flop
      4. Write the transfer mode to the mode register
      5. Write the page offset to the address register
      6. Write the length (-1 byte/word) to the count register
        (0=1 byte, 65535=64Kbytes)
      7. Write the page # to the page register
      8. Re-enable the DMA channel
      9. Set up target device
      ; Code to convert segment:offset to page:page_offset
      ;
      ; SI contains offset,
      ; DX contains segment
      :
      
         mov ax,dx
         mov cl,4
         shl ax,cl                ; shift segment left 4 
         shr dx,cl                ; shift segment right 12
         add si,ax                ; add shifted segment to offset
         adc dh,0                 
      ; Now SI contains the offset within the page, 
      ; the low 4-bits of DH contain the page #
      
      ; Disable the DMA channel so we can set it
         mov ax,channel
         and ax,3                  ; channel mod 4
         or ax,MODE                ; set mode bits
         out MASKREG,al            ; write DMA mode
      
      ; Clear byte ptr F/F
         out BYTEREG,al                 ; any value to reset
      
      ; write mode to mode register
         mov al, mode
         out MODEREG,al
      
      ; write page offset to address reg.
         mov ax,si                 ; get offset in ax
         out ADDRREG,al            ; write LSB of DMA offset
         mov al,ah                 
         out ADDRREG,al            ; write MSB of DMA offset
      
      ; write length (-1) to count reg.
         mov ax,length             ; ax=length-1
         dec ax                    ;
         out COUNTREG,al           ; write LSB of size
         mov al,ah                 
         out COUNTREG,al           ; write MSB of size
      
      ; write page# to page register
         mov al,dh
         out PAGEREG,al            ; write page
      
      ; re-enable the channel
         mov ax,channel
         and al,3                  ; channel mod 4
         out MASKREG,al            ; enable sound card DMA
      
      ; now set up the target device...


    Sound Blaster DSP

    See "ISA System Architecture" (Tom Shandley / Don Anderson, Mindshare Press) for more information on DMA.


    Return to ECE291 Lecture Index

    Copyright 1996 Matt Plavcan