home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / test / dummydev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-10  |  6.9 KB  |  288 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: dummydev.c,v 1.5 1996/12/10 14:00:11 aros Exp $
  4.     $Log: dummydev.c,v $
  5.     Revision 1.5  1996/12/10 14:00:11  aros
  6.     Moved #include into first column to allow makedepend to see it.
  7.  
  8.     Revision 1.4  1996/10/24 15:51:34  aros
  9.     Use the official AROS macros over the __AROS versions.
  10.  
  11.     Revision 1.3  1996/09/13 17:57:10  digulla
  12.     Use IPTR
  13.  
  14.     Revision 1.2  1996/08/01 17:41:38  digulla
  15.     Added standard header for all files
  16.  
  17.     Desc:
  18.     Lang:
  19. */
  20. #include <exec/errors.h>
  21. #include <exec/types.h>
  22. #include <exec/resident.h>
  23. #include <clib/exec_protos.h>
  24. #include <aros/libcall.h>
  25. #ifdef __GNUC__
  26. #   include "dummydev_gcc.h"
  27. #endif
  28. #include "initstruct.h"
  29.  
  30. struct inittable;
  31. extern const char name[];
  32. extern const char version[];
  33. extern const APTR inittabl[4];
  34. extern void *const functable[];
  35. extern const struct inittable datatable;
  36. extern struct dummybase *dummy_init();
  37. extern void dummy_open();
  38. extern BPTR dummy_close();
  39. extern BPTR dummy_expunge();
  40. extern int dummy_null();
  41. extern void dummy_beginio();
  42. extern LONG dummy_abortio();
  43. extern const char end;
  44.  
  45. int entry(void)
  46. {
  47.     /* If the device was executed by accident return error code. */
  48.     return -1;
  49. }
  50.  
  51. const struct Resident resident=
  52. {
  53.     RTC_MATCHWORD,
  54.     (struct Resident *)&resident,
  55.     (APTR)&end,
  56.     RTF_AUTOINIT,
  57.     1,
  58.     NT_LIBRARY,
  59.     0,
  60.     (char *)name,
  61.     (char *)&version[6],
  62.     (ULONG *)inittabl
  63. };
  64.  
  65. const char name[]="dummy.device";
  66.  
  67. const char version[]="$VER: dummy 1.0 (28.3.96)\n\015";
  68.  
  69. const APTR inittabl[4]=
  70. {
  71.     (APTR)sizeof(struct dummybase),
  72.     (APTR)functable,
  73.     (APTR)&datatable,
  74.     &dummy_init
  75. };
  76.  
  77. void *const functable[]=
  78. {
  79.     &dummy_open,
  80.     &dummy_close,
  81.     &dummy_expunge,
  82.     &dummy_null,
  83.     &dummy_beginio,
  84.     &dummy_abortio,
  85.     (void *)-1
  86. };
  87.  
  88. struct inittable
  89. {
  90.     S_CPYO(1,1,B);
  91.     S_CPYO(2,1,L);
  92.     S_CPYO(3,1,B);
  93.     S_CPYO(4,1,W);
  94.     S_CPYO(5,1,W);
  95.     S_CPYO(6,1,L);
  96.     S_END (end);
  97. };
  98.  
  99. #define O(n) offsetof(struct dummybase,n)
  100.  
  101. const struct inittable datatable=
  102. {
  103.     { { I_CPYO(1,B,O(device.dd_Library.lib_Node.ln_Type)), { NT_LIBRARY } } },
  104.     { { I_CPYO(1,L,O(device.dd_Library.lib_Node.ln_Name)), { (IPTR)name } } },
  105.     { { I_CPYO(1,B,O(device.dd_Library.lib_Flags       )), { LIBF_SUMUSED|LIBF_CHANGED } } },
  106.     { { I_CPYO(1,W,O(device.dd_Library.lib_Version     )), { 1 } } },
  107.     { { I_CPYO(1,W,O(device.dd_Library.lib_Revision    )), { 0 } } },
  108.     { { I_CPYO(1,L,O(device.dd_Library.lib_IdString    )), { (IPTR)&version[6] } } },
  109.     I_END ()
  110. };
  111.  
  112. #undef O
  113.  
  114. AROS_LH2(struct dummybase *, init,
  115.  AROS_LA(struct dummybase *, dummybase, D0),
  116.  AROS_LA(BPTR,               segList,   A0),
  117.        struct ExecBase *, SysBase, 0, dummy)
  118. {
  119.     AROS_LIBFUNC_INIT
  120.     /* This function is single-threaded by exec by calling Forbid. */
  121.  
  122.     /* Store arguments */
  123.     dummybase->sysbase=SysBase;
  124.     dummybase->seglist=segList;
  125.  
  126.     /* You would return NULL here if the init failed. */
  127.     return dummybase;
  128.     AROS_LIBFUNC_EXIT
  129. }
  130.  
  131. /* Use This from now on */
  132. #ifdef SysBase
  133. #undef SysBase
  134. #endif
  135. #define SysBase dummybase->sysbase
  136.  
  137. AROS_LH3(void, open,
  138.  AROS_LA(struct dummyrequest *, iob, A1),
  139.  AROS_LA(ULONG,                 unitnum, D0),
  140.  AROS_LA(ULONG,                 flags, D0),
  141.        struct dummybase *, dummybase, 1, dummy)
  142. {
  143.     AROS_LIBFUNC_INIT
  144.     /*
  145.     This function is single-threaded by exec by calling Forbid.
  146.     If you break the Forbid() another task may enter this function
  147.     at the same time. Take care.
  148.     */
  149.  
  150.     /* Keep compiler happy */
  151.     unitnum=0;
  152.     flags=0;
  153.  
  154.     /*
  155.     Normally you'd init the unit and set the unit field here -
  156.     but this is only a dummy without child tasks.
  157.     */
  158.  
  159.     /* I have one more opener. */
  160.     dummybase->device.dd_Library.lib_OpenCnt++;
  161.     dummybase->device.dd_Library.lib_Flags&=~LIBF_DELEXP;
  162.  
  163.     /* Set returncode */
  164.     iob->iorequest.io_Error=0;
  165.  
  166.     /* Mark Message as recently used. */
  167.     iob->iorequest.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  168.     AROS_LIBFUNC_EXIT
  169. }
  170.  
  171. AROS_LH1(BPTR, close,
  172.  AROS_LA(struct dummyrequest *, iob, A1),
  173.        struct dummybase *, dummybase, 2, dummy)
  174. {
  175.     AROS_LIBFUNC_INIT
  176.     /*
  177.     This function is single-threaded by exec by calling Forbid.
  178.     If you break the Forbid() another task may enter this function
  179.     at the same time. Take care.
  180.     */
  181.  
  182.     /* Let any following attemps to use the device crash hard. */
  183.     iob->iorequest.io_Device=(struct Device *)-1;
  184.  
  185.     /* I have one fewer opener. */
  186.     if(!--dummybase->device.dd_Library.lib_OpenCnt)
  187.     {
  188.     /* Delayed expunge pending? */
  189.     if(dummybase->device.dd_Library.lib_Flags&LIBF_DELEXP)
  190.         /* Then expunge the device */
  191.         return expunge();
  192.     }
  193.     return 0;
  194.     AROS_LIBFUNC_EXIT
  195. }
  196.  
  197. AROS_LH0(BPTR, expunge, struct dummybase *, dummybase, 3, dummy)
  198. {
  199.     AROS_LIBFUNC_INIT
  200.  
  201.     BPTR ret;
  202.     /*
  203.     This function is single-threaded by exec by calling Forbid.
  204.     Never break the Forbid() or strange things might happen.
  205.     */
  206.  
  207.     /* Test for openers. */
  208.     if(dummybase->device.dd_Library.lib_OpenCnt)
  209.     {
  210.     /* Set the delayed expunge flag and return. */
  211.     dummybase->device.dd_Library.lib_Flags|=LIBF_DELEXP;
  212.     return 0;
  213.     }
  214.  
  215.     /* Get rid of the device. Remove it from the list. */
  216.     Remove(&dummybase->device.dd_Library.lib_Node);
  217.  
  218.     /* Get returncode here - FreeMem() will destroy the field. */
  219.     ret=dummybase->seglist;
  220.  
  221.     /* Free the memory. */
  222.     FreeMem((char *)dummybase-dummybase->device.dd_Library.lib_NegSize,
  223.         dummybase->device.dd_Library.lib_NegSize+dummybase->device.dd_Library.lib_PosSize);
  224.  
  225.     return ret;
  226.     AROS_LIBFUNC_EXIT
  227. }
  228. AROS_LH0I(int, null, struct dummybase *, dummybase, 4, dummy)
  229. {
  230.     AROS_LIBFUNC_INIT
  231.     return 0;
  232.     AROS_LIBFUNC_EXIT
  233. }
  234.  
  235. AROS_LH1(void, beginio,
  236.  AROS_LA(struct dummyrequest *, iob, A1),
  237.        struct dummybase *, dummybase, 5, dummy)
  238. {
  239.     AROS_LIBFUNC_INIT
  240.  
  241.     /* WaitIO will look into this */
  242.     iob->iorequest.io_Message.mn_Node.ln_Type=NT_MESSAGE;
  243.  
  244.     /*
  245.     Dispatch command (the quick bit tells me that it is allowed to
  246.     wait on the user's context. I'll ignore it here and do everything quick.)
  247.     */
  248.     switch(iob->iorequest.io_Command)
  249.     {
  250.     case 0x1:
  251.         iob->iorequest.io_Error=0;
  252.         iob->id=++(dummybase->count);
  253.         break;
  254.     default:
  255.         iob->iorequest.io_Error=IOERR_NOCMD;
  256.         break;
  257.     /*
  258.         Commands dispatched to a cild task and processed asynchronbously
  259.         clear the quick bit before the end of beginio.
  260.     */
  261.     }
  262.  
  263.     /*
  264.     The request is finished now - so send it back.
  265.     Note that something that was done quick and had the quick bit set
  266.     doesn't need a ReplyMsg().
  267.     */
  268.     if(!(iob->iorequest.io_Flags&IOF_QUICK))
  269.     ReplyMsg(&iob->iorequest.io_Message);
  270.     AROS_LIBFUNC_EXIT
  271. }
  272.  
  273. AROS_LH1I(LONG, abortio,
  274.  AROS_LA(struct dummyrequest *, iob, A1),
  275.        struct dummybase *, dummybase, 6, dummy)
  276. {
  277.     AROS_LIBFUNC_INIT
  278.     /* Get compiler happy */
  279.     iob=0;
  280.  
  281.     /* Since everything is finished quick nothing needs an abort. */
  282.     return IOERR_NOCMD;
  283.     AROS_LIBFUNC_EXIT
  284. }
  285.  
  286. const char end=0;
  287.  
  288.