home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / sampledevice / ramdev.device.asm < prev    next >
Assembly Source File  |  1992-09-03  |  46KB  |  1,416 lines

  1.  
  2. *************************************************************************
  3. *
  4. *   Copyright (C) 1986,1988,1989 Commodore Amiga Inc.  All rights reserved.
  5. *   Permission granted for non-commercial use.
  6. *
  7. *************************************************************************
  8. *
  9. * ramdev.asm -- Skeleton device code.
  10. *
  11. * A sample 4 unit ramdisk that can be bound to an expansion slot device,
  12. * or used without.  Works with the Fast File System.
  13. * This code is required reading for device driver writers.  It contains
  14. * information not found elsewhere.  This code is somewhat old; you probably
  15. * don't want to copy it directly.
  16. *
  17. * This example includes a task, though a task is not actually needed for
  18. * a simple ram disk.  Unlike a single set of hardware registers that
  19. * may need to be shared by multiple tasks, ram can be freely shared.
  20. * This example does not show arbitration of hardware resources.
  21. *
  22. * Tested with CAPE and Metacomco
  23. *
  24. *       Based on mydev.asm
  25. *       10/07/86 Modified by Lee Erickson to be a simple disk device
  26. *            using RAM to simulate a disk.
  27. *       02/02/88 Modified by C. Scheppner, renamed ramdev
  28. *       09/28/88 Repaired by Bryce Nesbitt for new release
  29. *       11/02/88 More clarifications
  30. *       02/01/89 Even more clarifications & warnings
  31. *       02/22/89 START/STOP fix from Marco Papa
  32. *
  33. * Bugs: If RTF_AUTOINIT fails, library base still left in memory.
  34. *
  35. *************************************************************************
  36.  
  37.    SECTION firstsection
  38.  
  39.    NOLIST
  40.    include "exec/types.i"
  41.    include "exec/devices.i"
  42.    include "exec/initializers.i"
  43.    include "exec/memory.i"
  44.    include "exec/resident.i"
  45.    include "exec/io.i"
  46.    include "exec/ables.i"
  47.    include "exec/errors.i"
  48.    include "exec/tasks.i"
  49.    include "hardware/intbits.i"
  50.  
  51.    include "asmsupp.i"  ;standard asmsupp.i, same as used for library
  52.    include "ramdev.i"
  53.  
  54.    IFNE AUTOMOUNT
  55.    include "libraries/expansion.i"
  56.    include "libraries/configvars.i"
  57.    include "libraries/configregs.i"
  58.    ENDC
  59.    LIST
  60.  
  61.  
  62. ABSEXECBASE equ 4   ;Absolute location of the pointer to exec.library base
  63.  
  64.  
  65.    ;------ These don't have to be external, but it helps some
  66.    ;------ debuggers to have them globally visible
  67.    XDEF   Init
  68.    XDEF   Open
  69.    XDEF   Close
  70.    XDEF   Expunge
  71.    XDEF   Null
  72.    XDEF   myName
  73.    XDEF   BeginIO
  74.    XDEF   AbortIO
  75.  
  76.    ;Pull these _LVOs in from amiga.lib
  77.    XLIB   AddIntServer
  78.    XLIB   RemIntServer
  79.    XLIB   Debug
  80.    XLIB   InitStruct
  81.    XLIB   OpenLibrary
  82.    XLIB   CloseLibrary
  83.    XLIB   Alert
  84.    XLIB   FreeMem
  85.    XLIB   Remove
  86.    XLIB   AddPort
  87.    XLIB   AllocMem
  88.    XLIB   AddTask
  89.    XLIB   PutMsg
  90.    XLIB   RemTask
  91.    XLIB   ReplyMsg
  92.    XLIB   Signal
  93.    XLIB   GetMsg
  94.    XLIB   Wait
  95.    XLIB   WaitPort
  96.    XLIB   AllocSignal
  97.    XLIB   SetTaskPri
  98.    XLIB   GetCurrentBinding    ;Use to get list of boards for this driver
  99.    XLIB   MakeDosNode
  100.    XLIB   AddDosNode
  101.    XLIB   CopyMemQuick    ;Highly optimized copy function from exec.library
  102.  
  103.    INT_ABLES        ;Macro from exec/ables.i
  104.  
  105.  
  106. ;-----------------------------------------------------------------------
  107. ; The first executable location.  This should return an error
  108. ; in case someone tried to run you as a program (instead of
  109. ; loading you as a device).
  110.  
  111. FirstAddress:
  112.         moveq    #-1,d0
  113.         rts
  114.  
  115. ;-----------------------------------------------------------------------
  116. ; A romtag structure.  After your driver is brought in from disk, the
  117. ; disk image will be scanned for this structure to discover magic constants
  118. ; about you (such as where to start running you from...).
  119. ;-----------------------------------------------------------------------
  120.  
  121.    ; Most people will not need a priority and should leave it at zero.
  122.    ; the RT_PRI field is used for configuring the roms.  Use "mods" from
  123.    ; wack to look at the other romtags in the system
  124. MYPRI    EQU   0
  125.  
  126. initDDescrip:
  127.                 ;STRUCTURE RT,0
  128.      DC.W    RTC_MATCHWORD    ; UWORD RT_MATCHWORD (Magic cookie)
  129.      DC.L    initDDescrip    ; APTR    RT_MATCHTAG  (Back pointer)
  130.      DC.L    EndCode        ; APTR    RT_ENDSKIP   (To end of this hunk)
  131.      DC.B    RTF_AUTOINIT    ; UBYTE RT_FLAGS     (magic-see "Init:")
  132.      DC.B    VERSION        ; UBYTE RT_VERSION
  133.      DC.B    NT_DEVICE        ; UBYTE RT_TYPE      (must be correct)
  134.      DC.B    MYPRI        ; BYTE    RT_PRI
  135.      DC.L    myName        ; APTR    RT_NAME      (exec name)
  136.      DC.L    idString        ; APTR    RT_IDSTRING  (text string)
  137.      DC.L    Init        ; APTR    RT_INIT
  138.            ; LABEL RT_SIZE
  139.  
  140.  
  141.    ;This name for debugging use
  142.    IFNE INFO_LEVEL  ;If any debugging enabled at all
  143. subSysName:
  144.     dc.b    "ramdev",0
  145.    ENDC
  146.  
  147.    ; this is the name that the device will have
  148. myName:      MYDEVNAME
  149.  
  150.  IFNE  AUTOMOUNT
  151. ExLibName    dc.b 'expansion.library',0   ; Expansion Library Name
  152.  ENDC
  153.  
  154.    ; a major version number.
  155. VERSION:    EQU   37
  156.  
  157.    ; A particular revision.  This should uniquely identify the bits in the
  158.    ; device.  I use a script that advances the revision number each time
  159.    ; I recompile.  That way there is never a question of which device
  160.    ; that really is.
  161. REVISION:   EQU   1
  162.  
  163.    ; this is an identifier tag to help in supporting the device
  164.    ; format is 'name version.revision (d.m.yy)',<cr>,<lf>,<null>
  165. idString:   dc.b   'ramdev 37.1 (28.8.91)',13,10,0
  166.  
  167.    ; force word alignment
  168.    ds.w   0
  169.  
  170.  
  171.    ; The romtag specified that we were "RTF_AUTOINIT".  This means
  172.    ; that the RT_INIT structure member points to one of these
  173.    ; tables below.  If the AUTOINIT bit was not set then RT_INIT
  174.    ; would point to a routine to run.
  175.  
  176. Init:
  177.    DC.L   MyDev_Sizeof        ; data space size
  178.    DC.L   funcTable        ; pointer to function initializers
  179.    DC.L   dataTable        ; pointer to data initializers
  180.    DC.L   initRoutine        ; routine to run
  181.  
  182.  
  183. funcTable:
  184.    ;------ standard system routines
  185.    dc.l   Open
  186.    dc.l   Close
  187.    dc.l   Expunge
  188.    dc.l   Null        ;Reserved for future use!
  189.  
  190.    ;------ my device definitions
  191.    dc.l   BeginIO
  192.    dc.l   AbortIO
  193.  
  194.    ;------ custom extended functions
  195.    dc.l   FunctionA
  196.    dc.l   FunctionB
  197.  
  198.    ;------ function table end marker
  199.    dc.l   -1
  200.  
  201.  
  202.    ;The data table initializes static data structures. The format is
  203.    ;specified in exec/InitStruct routine's manual pages.  The
  204.    ;INITBYTE/INITWORD/INITLONG macros are in the file "exec/initializers.i".
  205.    ;The first argument is the offset from the device base for this
  206.    ;byte/word/long. The second argument is the value to put in that cell.
  207.    ;The table is null terminated
  208.    ;
  209. dataTable:
  210.    INITBYTE   LN_TYPE,NT_DEVICE       ;Must be LN_TYPE!
  211.    INITLONG   LN_NAME,myName
  212.    INITBYTE   LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  213.    INITWORD   LIB_VERSION,VERSION
  214.    INITWORD   LIB_REVISION,REVISION
  215.    INITLONG   LIB_IDSTRING,idString
  216.    DC.W   0   ;terminate list
  217.  
  218.  
  219. ;-------- initRoutine -------------------------------------------------------
  220. ;
  221. ; FOR RTF_AUTOINIT:
  222. ;   This routine gets called after the device has been allocated.
  223. ;   The device pointer is in D0.  The AmigaDOS segment list is in a0.
  224. ;   If it returns the device pointer, then the device will be linked
  225. ;   into the device list.  If it returns NULL, then the device
  226. ;   will be unloaded.
  227. ;
  228. ; IMPORTANT:
  229. ;   If you don't use the "RTF_AUTOINIT" feature, there is an additional
  230. ;   caveat.  If you allocate memory in your Open function, remember that
  231. ;   allocating memory can cause an Expunge... including an expunge of your
  232. ;   device.  This must not be fatal.  The easy solution is don't add your
  233. ;   device to the list until after it is ready for action.
  234. ;
  235. ; This call is single-threaded by exec; please read the description for
  236. ; "Open" below.
  237. ;
  238. ; Register Usage
  239. ; ==============
  240. ; a3 -- Points to temporary RAM
  241. ; a4 -- Expansion library base
  242. ; a5 -- device pointer
  243. ; a6 -- Exec base
  244. ;----------------------------------------------------------------------
  245. initRoutine:
  246.    ;------ get the device pointer into a convenient A register
  247.    PUTMSG   5,<'%s/Init: called'>
  248.    movem.l  d1-d7/a0-a5,-(sp)   ; Preserve ALL modified registers
  249.    move.l   d0,a5
  250.  
  251.    ;------ save a pointer to exec
  252.    move.l   a6,md_SysLib(a5)    ;faster access than move.l 4,a6
  253.  
  254.    ;------ save pointer to our loaded code (the SegList)
  255.    move.l   a0,md_SegList(a5)
  256.  
  257.  IFNE  AUTOMOUNT
  258. ***************************************