-
Notifications
You must be signed in to change notification settings - Fork 33
/
device.c
135 lines (110 loc) · 3.14 KB
/
device.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <exec/types.h>
#include <exec/execbase.h>
#include <exec/devices.h>
#include <exec/errors.h>
#include <exec/ports.h>
#include <libraries/dos.h>
#include <proto/exec.h>
#include "device.h"
#include "debug.h"
#include "a314.h"
#include "startup.h"
#include "fix_mem_region.h"
#include "memory_allocator.h"
#include "pi_if.h"
#define SysBase (*(struct ExecBase **)4)
const char device_name[] = A314_NAME;
const char id_string[] = A314_NAME " 1.0 (25 Aug 2018)";
static struct Library *init_device(__reg("a6") struct ExecBase *sys_base, __reg("a0") BPTR seg_list, __reg("d0") struct A314Device *dev)
{
dev->saved_seg_list = seg_list;
dev->running = FALSE;
// We are being called from InitResident() in initializers.asm.
// MakeLibrary() was executed before we got here.
dev->lib.lib_Node.ln_Type = NT_DEVICE;
dev->lib.lib_Node.ln_Name = (char *)device_name;
dev->lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
dev->lib.lib_Version = 1;
dev->lib.lib_Revision = 0;
dev->lib.lib_IdString = (APTR)id_string;
dbg_init();
dbg_info("Started");
// AddDevice() is executed after we return.
return &dev->lib;
}
static BPTR expunge(__reg("a6") struct A314Device *dev)
{
// There is currently no support for unloading a314.device.
if (TRUE) //dev->lib_OpenCnt != 0)
{
dev->lib.lib_Flags |= LIBF_DELEXP;
return 0;
}
/*
BPTR seg_list = saved_seg_list;
Remove(&dev->lib_Node);
FreeMem((char *)dev - dev->lib_NegSize, dev->lib_NegSize + dev->lib_PosSize);
return seg_list;
*/
}
static void open(__reg("a6") struct A314Device *dev, __reg("a1") struct A314_IORequest *ior, __reg("d0") ULONG unitnum, __reg("d1") ULONG flags)
{
dbg_trace("Enter: open device");
dev->lib.lib_OpenCnt++;
if (dev->lib.lib_OpenCnt == 1 && !dev->running)
{
if (!task_start(dev))
{
ior->a314_Request.io_Error = IOERR_OPENFAIL;
ior->a314_Request.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
dev->lib.lib_OpenCnt--;
return;
}
dev->running = TRUE;
}
ior->a314_Request.io_Error = 0;
ior->a314_Request.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
}
static BPTR close(__reg("a6") struct A314Device *dev, __reg("a1") struct A314_IORequest *ior)
{
dbg_trace("Enter: close device");
ior->a314_Request.io_Device = NULL;
ior->a314_Request.io_Unit = NULL;
dev->lib.lib_OpenCnt--;
if (dev->lib.lib_OpenCnt == 0 && (dev->lib.lib_Flags & LIBF_DELEXP))
return expunge(dev);
return 0;
}
static void begin_io(__reg("a6") struct A314Device *dev, __reg("a1") struct A314_IORequest *ior)
{
dbg_trace("Enter: begin_io");
PutMsg(&dev->task_mp, (struct Message *)ior);
ior->a314_Request.io_Flags &= ~IOF_QUICK;
}
static ULONG abort_io(__reg("a6") struct A314Device *dev, __reg("a1") struct A314_IORequest *ior)
{
// There is currently no support for aborting an IORequest.
return IOERR_NOCMD;
}
static const ULONG device_vectors[] =
{
(ULONG)open,
(ULONG)close,
(ULONG)expunge,
0,
(ULONG)begin_io,
(ULONG)abort_io,
(ULONG)a314base_translate_address,
(ULONG)a314base_alloc_mem,
(ULONG)a314base_free_mem,
(ULONG)a314base_write_mem,
(ULONG)a314base_read_mem,
-1,
};
const ULONG auto_init_tables[] =
{
sizeof(struct A314Device),
(ULONG)device_vectors,
0,
(ULONG)init_device,
};