-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver.c
219 lines (173 loc) · 4.49 KB
/
driver.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "marignotti.h"
#include <gno/kerntool.h>
#include <errno.h>
#include "net.h"
#include "s16debug.h"
#pragma noroot
#pragma optimize 79
int block(int sem)
{
int xerrno = 0;
Kswait(sem, &xerrno);
return xerrno;
}
void copy_addr(xsockaddr_in *src, xsockaddr_in *dest, int *addrlen)
{
int len;
// bytswap the port.
asm {
ldy #2
lda [src],y
xba
sta [src],y
}
len = 8;
if (*addrlen < 8)
len = *addrlen;
else
*addrlen = 8;
// data is truncated if there isn't enough space.
asm {
ldx <len
beq done
ldy #0
sep #0x20
loop:
lda [src],y
sta [dest],y
iny
dex
bne loop
rep #0x20
done:
}
}
int queue_command(Entry *e, Word command, LongWord cookie, LongWord timeout)
{
int xerrno;
SEI();
e->command = command;
e->cookie = cookie;
e->timeout = timeout;
CLI();
xerrno = 0;
Kswait(e->semaphore, &xerrno);
return xerrno;
}
#pragma databank 1
int driver(
int socknum, int req,
void *p1, void *p2,
void *p3, void *p4, void *p5)
{
int rv;
Entry *e;
Word oldBusy;
s16_debug_printf("driver: %04x : %04x", socknum, req);
oldBusy = *BusyFlag;
if (req == PRU_ATTACH)
{
return mattach(socknum, p1, p2, p3, p4, p5);
}
e = find_entry(socknum);
if (!e)
{
if (req == PRU_RCVD || req == PRU_SEND)
*(LongWord *)p2 = 0;
return EBADF;
}
switch (req)
{
case PRU_ABORT:
break;
case PRU_ACCEPT:
return maccept(e, p1, p2, p3, p4, p5);
break;
case PRU_ATTACH:
// KERNsocket(int domain, int type, int protocol, int *ERRNO);
// handled above.
break;
case PRU_BIND:
// KERNbind(int fd, struct sockaddr *my_addr, int addrlen, int *ERRNO)
return mbind(e, p1, p2, p3, p4, p5);
break;
case PRU_CONNECT:
// KERNconnect(int fd, struct sockaddr *serv_addr,
// int addrlen, int *ERRNO)
return mconnect(e, p1, p2, p3, p4, p5);
break;
case PRU_CONNECT2:
break;
case PRU_CONTROL:
return mioctl(e, p1, p2, p3, p4, p5);
break;
case PRU_DETACH:
// called from GS/OS
// int SOCKclose(int sock) part 2
DecBusy();
rv = mdetach(e, p1, p2, p3, p4, p5);
IncBusy();
return rv;
break;
case PRU_DISCONNECT:
// called from GS/OS
// int SOCKclose(int sock) part 1
//return do_disconnect(socknum, m, m_len, addr, addrlen, rights);
return 0;
break;
case PRU_LISTEN:
return mlisten(e, p1, p2, p3, p4, p5);
break;
case PRU_PEERADDR:
return mgetpeername(e, p1, p2, p3, p4, p5);
break;
case PRU_RCVD:
// this may be called from GSOS (in which case IncBusy()
// is in effect
// or from KERNrecvfrom (in which case it isn't).
//
// may block, so be nice.
// SOCKrdwr(struct rwPBlock *pb, word cmd, int sock)
if (oldBusy) DecBusy();
rv = mread(e, p1, p2, p3, p4, p5);
if (oldBusy) IncBusy();
return rv;
break;
case PRU_RCVOOB:
return mreadoob(e, p1, p2, p3, p4, p5);
break;
case PRU_SEND:
// SOCKrdwr(struct rwPBlock *pb, word cmd, int sock)
// same as above.
if (oldBusy) DecBusy();
rv = mwrite(e, p1, p2, p3, p4, p5);
if (oldBusy) IncBusy();
return rv;
break;
case PRU_SENDOOB:
// OOB is always inline. so there.
// this is never called via ReadGS.
return mwrite(e, p1, p2, p3, p4, p5);
break;
case PRU_SENSE:
break;
case PRU_SHUTDOWN:
return mshutdown(e, p1, p2, p3, p4, p5);
break;
case PRU_SOCKADDR:
return mgetsockname(e, p1, p2, p3, p4, p5);
break;
case PRU_CO_GETOPT:
return mgetsockopt(e, p1, p2, p3, p4, p5);
break;
case PRU_CO_SETOPT:
return msetsockopt(e, p1, p2, p3, p4, p5);
break;
case PRU_SELECT:
// int SOCKselect(int pid, int fl, int sock)
return mselect(e, p1, p2, p3, p4, p5);
break;
}
return EINVAL;
}
#pragma databank 0