home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
dev
/
c
/
rkrm
/
sampledevice
/
ramdev.device.asm
< prev
next >
Wrap
Assembly Source File
|
1992-09-03
|
46KB
|
1,416 lines
*************************************************************************
*
* Copyright (C) 1986,1988,1989 Commodore Amiga Inc. All rights reserved.
* Permission granted for non-commercial use.
*
*************************************************************************
*
* ramdev.asm -- Skeleton device code.
*
* A sample 4 unit ramdisk that can be bound to an expansion slot device,
* or used without. Works with the Fast File System.
* This code is required reading for device driver writers. It contains
* information not found elsewhere. This code is somewhat old; you probably
* don't want to copy it directly.
*
* This example includes a task, though a task is not actually needed for
* a simple ram disk. Unlike a single set of hardware registers that
* may need to be shared by multiple tasks, ram can be freely shared.
* This example does not show arbitration of hardware resources.
*
* Tested with CAPE and Metacomco
*
* Based on mydev.asm
* 10/07/86 Modified by Lee Erickson to be a simple disk device
* using RAM to simulate a disk.
* 02/02/88 Modified by C. Scheppner, renamed ramdev
* 09/28/88 Repaired by Bryce Nesbitt for new release
* 11/02/88 More clarifications
* 02/01/89 Even more clarifications & warnings
* 02/22/89 START/STOP fix from Marco Papa
*
* Bugs: If RTF_AUTOINIT fails, library base still left in memory.
*
*************************************************************************
SECTION firstsection
NOLIST
include "exec/types.i"
include "exec/devices.i"
include "exec/initializers.i"
include "exec/memory.i"
include "exec/resident.i"
include "exec/io.i"
include "exec/ables.i"
include "exec/errors.i"
include "exec/tasks.i"
include "hardware/intbits.i"
include "asmsupp.i" ;standard asmsupp.i, same as used for library
include "ramdev.i"
IFNE AUTOMOUNT
include "libraries/expansion.i"
include "libraries/configvars.i"
include "libraries/configregs.i"
ENDC
LIST
ABSEXECBASE equ 4 ;Absolute location of the pointer to exec.library base
;------ These don't have to be external, but it helps some
;------ debuggers to have them globally visible
XDEF Init
XDEF Open
XDEF Close
XDEF Expunge
XDEF Null
XDEF myName
XDEF BeginIO
XDEF AbortIO
;Pull these _LVOs in from amiga.lib
XLIB AddIntServer
XLIB RemIntServer
XLIB Debug
XLIB InitStruct
XLIB OpenLibrary
XLIB CloseLibrary
XLIB Alert
XLIB FreeMem
XLIB Remove
XLIB AddPort
XLIB AllocMem
XLIB AddTask
XLIB PutMsg
XLIB RemTask
XLIB ReplyMsg
XLIB Signal
XLIB GetMsg
XLIB Wait
XLIB WaitPort
XLIB AllocSignal
XLIB SetTaskPri
XLIB GetCurrentBinding ;Use to get list of boards for this driver
XLIB MakeDosNode
XLIB AddDosNode
XLIB CopyMemQuick ;Highly optimized copy function from exec.library
INT_ABLES ;Macro from exec/ables.i
;-----------------------------------------------------------------------
; The first executable location. This should return an error
; in case someone tried to run you as a program (instead of
; loading you as a device).
FirstAddress:
moveq #-1,d0
rts
;-----------------------------------------------------------------------
; A romtag structure. After your driver is brought in from disk, the
; disk image will be scanned for this structure to discover magic constants
; about you (such as where to start running you from...).
;-----------------------------------------------------------------------
; Most people will not need a priority and should leave it at zero.
; the RT_PRI field is used for configuring the roms. Use "mods" from
; wack to look at the other romtags in the system
MYPRI EQU 0
initDDescrip:
;STRUCTURE RT,0
DC.W RTC_MATCHWORD ; UWORD RT_MATCHWORD (Magic cookie)
DC.L initDDescrip ; APTR RT_MATCHTAG (Back pointer)
DC.L EndCode ; APTR RT_ENDSKIP (To end of this hunk)
DC.B RTF_AUTOINIT ; UBYTE RT_FLAGS (magic-see "Init:")
DC.B VERSION ; UBYTE RT_VERSION
DC.B NT_DEVICE ; UBYTE RT_TYPE (must be correct)
DC.B MYPRI ; BYTE RT_PRI
DC.L myName ; APTR RT_NAME (exec name)
DC.L idString ; APTR RT_IDSTRING (text string)
DC.L Init ; APTR RT_INIT
; LABEL RT_SIZE
;This name for debugging use
IFNE INFO_LEVEL ;If any debugging enabled at all
subSysName:
dc.b "ramdev",0
ENDC
; this is the name that the device will have
myName: MYDEVNAME
IFNE AUTOMOUNT
ExLibName dc.b 'expansion.library',0 ; Expansion Library Name
ENDC
; a major version number.
VERSION: EQU 37
; A particular revision. This should uniquely identify the bits in the
; device. I use a script that advances the revision number each time
; I recompile. That way there is never a question of which device
; that really is.
REVISION: EQU 1
; this is an identifier tag to help in supporting the device
; format is 'name version.revision (d.m.yy)',<cr>,<lf>,<null>
idString: dc.b 'ramdev 37.1 (28.8.91)',13,10,0
; force word alignment
ds.w 0
; The romtag specified that we were "RTF_AUTOINIT". This means
; that the RT_INIT structure member points to one of these
; tables below. If the AUTOINIT bit was not set then RT_INIT
; would point to a routine to run.
Init:
DC.L MyDev_Sizeof ; data space size
DC.L funcTable ; pointer to function initializers
DC.L dataTable ; pointer to data initializers
DC.L initRoutine ; routine to run
funcTable:
;------ standard system routines
dc.l Open
dc.l Close
dc.l Expunge
dc.l Null ;Reserved for future use!
;------ my device definitions
dc.l BeginIO
dc.l AbortIO
;------ custom extended functions
dc.l FunctionA
dc.l FunctionB
;------ function table end marker
dc.l -1
;The data table initializes static data structures. The format is
;specified in exec/InitStruct routine's manual pages. The
;INITBYTE/INITWORD/INITLONG macros are in the file "exec/initializers.i".
;The first argument is the offset from the device base for this
;byte/word/long. The second argument is the value to put in that cell.
;The table is null terminated
;
dataTable:
INITBYTE LN_TYPE,NT_DEVICE ;Must be LN_TYPE!
INITLONG LN_NAME,myName
INITBYTE LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
INITWORD LIB_VERSION,VERSION
INITWORD LIB_REVISION,REVISION
INITLONG LIB_IDSTRING,idString
DC.W 0 ;terminate list
;-------- initRoutine -------------------------------------------------------
;
; FOR RTF_AUTOINIT:
; This routine gets called after the device has been allocated.
; The device pointer is in D0. The AmigaDOS segment list is in a0.
; If it returns the device pointer, then the device will be linked
; into the device list. If it returns NULL, then the device
; will be unloaded.
;
; IMPORTANT:
; If you don't use the "RTF_AUTOINIT" feature, there is an additional
; caveat. If you allocate memory in your Open function, remember that
; allocating memory can cause an Expunge... including an expunge of your
; device. This must not be fatal. The easy solution is don't add your
; device to the list until after it is ready for action.
;
; This call is single-threaded by exec; please read the description for
; "Open" below.
;
; Register Usage
; ==============
; a3 -- Points to temporary RAM
; a4 -- Expansion library base
; a5 -- device pointer
; a6 -- Exec base
;----------------------------------------------------------------------
initRoutine:
;------ get the device pointer into a convenient A register
PUTMSG 5,<'%s/Init: called'>
movem.l d1-d7/a0-a5,-(sp) ; Preserve ALL modified registers
move.l d0,a5
;------ save a pointer to exec
move.l a6,md_SysLib(a5) ;faster access than move.l 4,a6
;------ save pointer to our loaded code (the SegList)
move.l a0,md_SegList(a5)
IFNE AUTOMOUNT
***************************************