2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
6 #include <exec/errors.h>
7 #include <exec/types.h>
8 #include <exec/resident.h>
9 #include <clib/exec_protos.h>
10 #include <aros/libcall.h>
12 # include "dummydev_gcc.h"
14 #include "initstruct.h"
17 extern const char name
[];
18 extern const char version
[];
19 extern const APTR inittabl
[4];
20 extern void *const functable
[];
21 extern const struct inittable datatable
;
22 extern struct dummybase
*dummy_init();
23 extern void dummy_open();
24 extern BPTR
dummy_close();
25 extern BPTR
dummy_expunge();
26 extern int dummy_null();
27 extern void dummy_beginio();
28 extern LONG
dummy_abortio();
29 extern const char end
;
33 /* If the device was executed by accident return error code. */
37 const struct Resident resident
=
40 (struct Resident
*)&resident
,
51 const char name
[]="dummy.device";
53 const char version
[]="$VER: dummy 1.0 (28.3.96)\n\015";
55 const APTR inittabl
[4]=
57 (APTR
)sizeof(struct dummybase
),
63 void *const functable
[]=
85 #define O(n) offsetof(struct dummybase,n)
87 const struct inittable datatable
=
89 { { I_CPYO(1,B
,O(device
.dd_Library
.lib_Node
.ln_Type
)), { NT_LIBRARY
} } },
90 { { I_CPYO(1,L
,O(device
.dd_Library
.lib_Node
.ln_Name
)), { (IPTR
)name
} } },
91 { { I_CPYO(1,B
,O(device
.dd_Library
.lib_Flags
)), { LIBF_SUMUSED
|LIBF_CHANGED
} } },
92 { { I_CPYO(1,W
,O(device
.dd_Library
.lib_Version
)), { 1 } } },
93 { { I_CPYO(1,W
,O(device
.dd_Library
.lib_Revision
)), { 0 } } },
94 { { I_CPYO(1,L
,O(device
.dd_Library
.lib_IdString
)), { (IPTR
)&version
[6] } } },
100 AROS_LH2(struct dummybase
*, init
,
101 AROS_LA(struct dummybase
*, dummybase
, D0
),
102 AROS_LA(BPTR
, segList
, A0
),
103 struct ExecBase
*, SysBase
, 0, dummy
)
106 /* This function is single-threaded by exec by calling Forbid. */
108 /* Store arguments */
109 dummybase
->sysbase
=SysBase
;
110 dummybase
->seglist
=segList
;
112 /* You would return NULL here if the init failed. */
117 /* Use This from now on */
121 #define SysBase dummybase->sysbase
124 AROS_LA(struct dummyrequest
*, iob
, A1
),
125 AROS_LA(ULONG
, unitnum
, D0
),
126 AROS_LA(ULONG
, flags
, D0
),
127 struct dummybase
*, dummybase
, 1, dummy
)
131 This function is single-threaded by exec by calling Forbid.
132 If you break the Forbid() another task may enter this function
133 at the same time. Take care.
136 /* Keep compiler happy */
141 Normally you'd init the unit and set the unit field here -
142 but this is only a dummy without child tasks.
145 /* I have one more opener. */
146 dummybase
->device
.dd_Library
.lib_OpenCnt
++;
147 dummybase
->device
.dd_Library
.lib_Flags
&=~LIBF_DELEXP
;
150 iob
->iorequest
.io_Error
=0;
152 /* Mark Message as recently used. */
153 iob
->iorequest
.io_Message
.mn_Node
.ln_Type
=NT_REPLYMSG
;
157 AROS_LH1(BPTR
, close
,
158 AROS_LA(struct dummyrequest
*, iob
, A1
),
159 struct dummybase
*, dummybase
, 2, dummy
)
163 This function is single-threaded by exec by calling Forbid.
164 If you break the Forbid() another task may enter this function
165 at the same time. Take care.
168 /* Let any following attemps to use the device crash hard. */
169 iob
->iorequest
.io_Device
=(struct Device
*)-1;
171 /* I have one fewer opener. */
172 if(!--dummybase
->device
.dd_Library
.lib_OpenCnt
)
174 /* Delayed expunge pending? */
175 if(dummybase
->device
.dd_Library
.lib_Flags
&LIBF_DELEXP
)
176 /* Then expunge the device */
183 AROS_LH0(BPTR
, expunge
, struct dummybase
*, dummybase
, 3, dummy
)
189 This function is single-threaded by exec by calling Forbid.
190 Never break the Forbid() or strange things might happen.
193 /* Test for openers. */
194 if(dummybase
->device
.dd_Library
.lib_OpenCnt
)
196 /* Set the delayed expunge flag and return. */
197 dummybase
->device
.dd_Library
.lib_Flags
|=LIBF_DELEXP
;
201 /* Get rid of the device. Remove it from the list. */
202 Remove(&dummybase
->device
.dd_Library
.lib_Node
);
204 /* Get returncode here - FreeMem() will destroy the field. */
205 ret
=dummybase
->seglist
;
207 /* Free the memory. */
208 FreeMem((char *)dummybase
-dummybase
->device
.dd_Library
.lib_NegSize
,
209 dummybase
->device
.dd_Library
.lib_NegSize
+dummybase
->device
.dd_Library
.lib_PosSize
);
214 AROS_LH0I(int, null
, struct dummybase
*, dummybase
, 4, dummy
)
221 AROS_LH1(void, beginio
,
222 AROS_LA(struct dummyrequest
*, iob
, A1
),
223 struct dummybase
*, dummybase
, 5, dummy
)
227 /* WaitIO will look into this */
228 iob
->iorequest
.io_Message
.mn_Node
.ln_Type
=NT_MESSAGE
;
231 Dispatch command (the quick bit tells me that it is allowed to
232 wait on the user's context. I'll ignore it here and do everything quick.)
234 switch(iob
->iorequest
.io_Command
)
237 iob
->iorequest
.io_Error
=0;
238 iob
->id
=++(dummybase
->count
);
241 iob
->iorequest
.io_Error
=IOERR_NOCMD
;
244 Commands dispatched to a cild task and processed asynchronbously
245 clear the quick bit before the end of beginio.
250 The request is finished now - so send it back.
251 Note that something that was done quick and had the quick bit set
252 doesn't need a ReplyMsg().
254 if(!(iob
->iorequest
.io_Flags
&IOF_QUICK
))
255 ReplyMsg(&iob
->iorequest
.io_Message
);
259 AROS_LH1I(LONG
, abortio
,
260 AROS_LA(struct dummyrequest
*, iob
, A1
),
261 struct dummybase
*, dummybase
, 6, dummy
)
264 /* Get compiler happy */
267 /* Since everything is finished quick nothing needs an abort. */