usim

Check-in [200674745d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:uch11: Make sure each backend now is a seperate compilation unit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ams/sdl
Files: files | file ages | folders
SHA3-256: 200674745d86752a8bb70c280899d00324d413b5ecf126e7fbcd66190d877387
User & Date: ams 2024-06-25 11:30:51
Context
2024-06-25
12:45
uch11: Split out uch11 backend guts into seperate header, leave uch11.h for MIT CADR specifics. check-in: b32ca4506b user: ams tags: ams/sdl
11:30
uch11: Make sure each backend now is a seperate compilation unit. check-in: 200674745d user: ams tags: ams/sdl
11:20
uch11: Split backend code to seperate files. check-in: 9e48bb8745 user: ams tags: ams/sdl
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# LDFLAGS +=
# USIM_TV_BACKEND =

ucfg.o: ucfg.h ucfg.defs lmch.defs knight.defs

$(USIM_TV_BACKEND) iob.o cadet.o knight.o usim.o: lmch.defs knight.defs

# Add uch11-local.o uch11-chaosd.o when they can compile.
USIM_UCH11 = uch11.o uch11-udp.o \
	chutil.o challoc.o chdopen.o chopen.o MINI.o FILE.o glob.o

USIM_OBJS = usim.o ucode.o uexec.o umem.o iob.o mouse.o kbd.o knight.o cadet.o tv.o $(USIM_TV_BACKEND) $(USIM_UCH11) disk.o ini.o ucfg.o trace.o udiss.o usym.o misc.o m32.o idle.o \
	$(CHAOS)/libhosts/libhosts.a
usim: $(USIM_OBJS)
	$(CC) $(CFLAGS) -o $@ $(USIM_OBJS) -lpthread $(LDFLAGS)








<
|







50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
# LDFLAGS +=
# USIM_TV_BACKEND =

ucfg.o: ucfg.h ucfg.defs lmch.defs knight.defs

$(USIM_TV_BACKEND) iob.o cadet.o knight.o usim.o: lmch.defs knight.defs


USIM_UCH11 = uch11.o uch11-local.o uch11-chaosd.o uch11-udp.o \
	chutil.o challoc.o chdopen.o chopen.o MINI.o FILE.o glob.o

USIM_OBJS = usim.o ucode.o uexec.o umem.o iob.o mouse.o kbd.o knight.o cadet.o tv.o $(USIM_TV_BACKEND) $(USIM_UCH11) disk.o ini.o ucfg.o trace.o udiss.o usym.o misc.o m32.o idle.o \
	$(CHAOS)/libhosts/libhosts.a
usim: $(USIM_OBJS)
	$(CC) $(CFLAGS) -o $@ $(USIM_OBJS) -lpthread $(LDFLAGS)

Changes to uch11-chaosd.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
/* Connect to a chaos daemon via a Unix socket.
 */

// #include <sys/poll.h>
// #include <sys/socket.h>
// #include <sys/stat.h>
// #include <sys/time.h>
// #include <sys/types.h>
// #include <sys/uio.h>
// #include <sys/un.h>
// 
// #include <netinet/in.h>
// 
// #include <sys/types.h>
// #include <sys/socket.h>
// #include <netdb.h>
// #include <arpa/inet.h>
// 
// #include <err.h>
// #include <pthread.h>
// #include <stddef.h>
// #include <stdint.h>
// #include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <time.h>
// #include <unistd.h>
// 
// #include "uch11.h"
// #include "chaosd.h"
// #include "hosttab.h"
// #include "misc.h"
// #include "ucfg.h"
// #include "ucode.h"
// #include "usim.h"
// #include "utrace.h"

#define UNIX_SOCKET_PATH	"/var/tmp/"
#define UNIX_SOCKET_CLIENT_NAME	"chaosd_"
#define UNIX_SOCKET_SERVER_NAME	"chaosd_server"
#define UNIX_SOCKET_PERM	S_IRWXU

static int
chaos_send_to_chaosd(char *buffer, int size)
{
	int wcount, dest_addr;

	/*
	 * Local loopback.
	 */



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|






|







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
/* Connect to a chaos daemon via a Unix socket.
 */

 #include <sys/poll.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/un.h>
 
 #include <netinet/in.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <arpa/inet.h>
 
 #include <err.h>
 #include <pthread.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
 
 #include "uch11.h"
 #include "chaosd.h"
 #include "hosttab.h"
 #include "misc.h"
 #include "ucfg.h"
 #include "ucode.h"
 #include "usim.h"
 #include "utrace.h"

#define UNIX_SOCKET_PATH	"/var/tmp/"
#define UNIX_SOCKET_CLIENT_NAME	"chaosd_"
#define UNIX_SOCKET_SERVER_NAME	"chaosd_server"
#define UNIX_SOCKET_PERM	S_IRWXU

int
chaos_send_to_chaosd(char *buffer, int size)
{
	int wcount, dest_addr;

	/*
	 * Local loopback.
	 */
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
			perror("chaos write");
			return -1;
		}
	}
	return 0;
}

static int
chaos_poll_chaosd(void)
{
	ssize_t ret;
	struct pollfd pfd[1];
	int nfds, timeout;
	unsigned char lenbytes[4];
	ssize_t len;







|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
			perror("chaos write");
			return -1;
		}
	}
	return 0;
}

int
chaos_poll_chaosd(void)
{
	ssize_t ret;
	struct pollfd pfd[1];
	int nfds, timeout;
	unsigned char lenbytes[4];
	ssize_t len;

Changes to uch11-local.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
/* Local Chaos -- this should go into chlib.c
 */

// #include <sys/poll.h>
// #include <sys/socket.h>
// #include <sys/stat.h>
// #include <sys/time.h>
// #include <sys/types.h>
// #include <sys/uio.h>
// #include <sys/un.h>
// 
// #include <netinet/in.h>
// 
// #include <sys/types.h>
// #include <sys/socket.h>
// #include <netdb.h>
// #include <arpa/inet.h>
// 
// #include <err.h>
// #include <pthread.h>
// #include <stddef.h>
// #include <stdint.h>
// #include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <time.h>
// #include <unistd.h>
// 
// #include "uch11.h"
// #include "chaosd.h"
// #include "hosttab.h"
// #include "misc.h"
// #include "ucfg.h"
// #include "ucode.h"
// #include "usim.h"
// #include "utrace.h"

static void
chaos_queue(struct packet *packet)
{
	struct packet_queue *node;

	node = malloc(sizeof(struct packet_queue));
	node->packet = packet;
	pthread_mutex_lock(&recvqueue);



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|







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
/* Local Chaos -- this should go into chlib.c
 */

 #include <sys/poll.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/un.h>
 
 #include <netinet/in.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <arpa/inet.h>
 
 #include <err.h>
 #include <pthread.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
 
 #include "uch11.h"
 #include "chaosd.h"
 #include "hosttab.h"
 #include "misc.h"
 #include "ucfg.h"
 #include "ucode.h"
 #include "usim.h"
 #include "utrace.h"

void
chaos_queue(struct packet *packet)
{
	struct packet_queue *node;

	node = malloc(sizeof(struct packet_queue));
	node->packet = packet;
	pthread_mutex_lock(&recvqueue);
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
		pthread_cond_wait(&conn->queuecond, &conn->queuesem);
		pthread_mutex_unlock(&conn->queuesem);
		if (conn->cn_state == CSCLOSED)
			return NOPKT;
	}
}

static int
chaos_queue_time_pkt(unsigned short saddr, unsigned short sidx)
{
	time_t t;
	struct timeval time;
	struct packet *answer;

	INFO(TRACE_CHAOS, "chaos: RFC (TIME): answering...\n");







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
		pthread_cond_wait(&conn->queuecond, &conn->queuesem);
		pthread_mutex_unlock(&conn->queuesem);
		if (conn->cn_state == CSCLOSED)
			return NOPKT;
	}
}

int
chaos_queue_time_pkt(unsigned short saddr, unsigned short sidx)
{
	time_t t;
	struct timeval time;
	struct packet *answer;

	INFO(TRACE_CHAOS, "chaos: RFC (TIME): answering...\n");
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
	answer->pk_pkn = 0;
	answer->pk_ackn = 0;
	*(long *) &answer->pk_cdata[0] = t;
	chaos_queue(answer);
	return 0;
}

static int
chaos_queue_uptime_pkt(unsigned short saddr, unsigned short sidx)
{
	struct packet *answer;

	INFO(TRACE_CHAOS, "chaos: RFC (UPTIME): answering...\n");
	answer = pkalloc(sizeof(long), 0);
	answer->pk_op = ANSOP;
	SET_PH_LEN(answer->pk_phead, sizeof(long));
	SET_CH_ADDR(answer->pk_daddr, saddr);
	SET_CH_INDEX(answer->pk_didx, sidx);
	SET_CH_ADDR(answer->pk_saddr, chaos_addr(ucfg.chaos_servername, 0));
	SET_CH_INDEX(answer->pk_sidx, 0);
	answer->pk_pkn = 0;
	answer->pk_ackn = 0;
	*(long *) &answer->pk_cdata[0] = 0;
	chaos_queue(answer);
	return 0;
}

static int
chaos_queue_status_pkt(unsigned short saddr, unsigned short sidx)
{
	struct packet *answer;
	struct status *status;

	INFO(TRACE_CHAOS, "chaos: RFC (STATUS): answering...\n");
	answer = pkalloc(CHSTATNAME + 2 * 2, 0);	/* Only room for name and subnet+nwords */







|



















|







212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
	answer->pk_pkn = 0;
	answer->pk_ackn = 0;
	*(long *) &answer->pk_cdata[0] = t;
	chaos_queue(answer);
	return 0;
}

int
chaos_queue_uptime_pkt(unsigned short saddr, unsigned short sidx)
{
	struct packet *answer;

	INFO(TRACE_CHAOS, "chaos: RFC (UPTIME): answering...\n");
	answer = pkalloc(sizeof(long), 0);
	answer->pk_op = ANSOP;
	SET_PH_LEN(answer->pk_phead, sizeof(long));
	SET_CH_ADDR(answer->pk_daddr, saddr);
	SET_CH_INDEX(answer->pk_didx, sidx);
	SET_CH_ADDR(answer->pk_saddr, chaos_addr(ucfg.chaos_servername, 0));
	SET_CH_INDEX(answer->pk_sidx, 0);
	answer->pk_pkn = 0;
	answer->pk_ackn = 0;
	*(long *) &answer->pk_cdata[0] = 0;
	chaos_queue(answer);
	return 0;
}

int
chaos_queue_status_pkt(unsigned short saddr, unsigned short sidx)
{
	struct packet *answer;
	struct status *status;

	INFO(TRACE_CHAOS, "chaos: RFC (STATUS): answering...\n");
	answer = pkalloc(CHSTATNAME + 2 * 2, 0);	/* Only room for name and subnet+nwords */
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
	status->sb_data->sb_ident = (chaos_addr(ucfg.chaos_servername, 0) >> 8) | 0400;
	/* and say no data is following */
	status->sb_data->sb_nshorts = 0 * sizeof(int) / sizeof(short);
	chaos_queue(answer);
	return 0;
}

static int
chaos_queue_file_pkt(struct packet *packet)
{
	void processdata(struct connection *conn);
	struct packet *answer;
	struct connection *conn;

	packet->pk_cdata[PH_LEN(packet->pk_phead)] = '\0';







|







260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
	status->sb_data->sb_ident = (chaos_addr(ucfg.chaos_servername, 0) >> 8) | 0400;
	/* and say no data is following */
	status->sb_data->sb_nshorts = 0 * sizeof(int) / sizeof(short);
	chaos_queue(answer);
	return 0;
}

int
chaos_queue_file_pkt(struct packet *packet)
{
	void processdata(struct connection *conn);
	struct packet *answer;
	struct connection *conn;

	packet->pk_cdata[PH_LEN(packet->pk_phead)] = '\0';
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
	*(unsigned short *) &answer->pk_cdata[2] = conn->cn_rwsize;
	chaos_connection_queue(conn, answer);
	conn->cn_state = CSLISTEN;
	processdata(conn);
	return 0;
}

static int
chaos_queue_mini_pkt(struct packet *packet)
{
	void processmini(struct connection *conn);
	struct packet *answer;
	struct connection *conn;

	packet->pk_cdata[PH_LEN(packet->pk_phead)] = '\0';







|







283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
	*(unsigned short *) &answer->pk_cdata[2] = conn->cn_rwsize;
	chaos_connection_queue(conn, answer);
	conn->cn_state = CSLISTEN;
	processdata(conn);
	return 0;
}

int
chaos_queue_mini_pkt(struct packet *packet)
{
	void processmini(struct connection *conn);
	struct packet *answer;
	struct connection *conn;

	packet->pk_cdata[PH_LEN(packet->pk_phead)] = '\0';
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
	chaos_connection_queue(conn, answer);
	conn->cn_state = CSLISTEN;
	conn->cn_rlast = 1;
	processmini(conn);
	return 0;
}

static int
chaos_send_to_local(char *buffer, int size)
{				/* ---!!! rcvpkt ? */
	struct packet *packet;
	struct connection *conn;

	packet = (struct packet *) buffer;
	/*







|







307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
	chaos_connection_queue(conn, answer);
	conn->cn_state = CSLISTEN;
	conn->cn_rlast = 1;
	processmini(conn);
	return 0;
}

int
chaos_send_to_local(char *buffer, int size)
{				/* ---!!! rcvpkt ? */
	struct packet *packet;
	struct connection *conn;

	packet = (struct packet *) buffer;
	/*
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
		pkt = pkalloc((size_t) size, 0);
		memcpy(pkt, packet, size);
		chaos_connection_queue(conn, pkt);
	}
	return 0;
}

static int
chaos_poll_local(void)
{
	struct packet *packet;
	struct packet_queue *node;
	int size;

	/*







|







449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
		pkt = pkalloc((size_t) size, 0);
		memcpy(pkt, packet, size);
		chaos_connection_queue(conn, pkt);
	}
	return 0;
}

int
chaos_poll_local(void)
{
	struct packet *packet;
	struct packet_queue *node;
	int size;

	/*

Changes to uch11-udp.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
/* Chaos over UDP */

// #include <sys/poll.h>
// #include <sys/socket.h>
// #include <sys/stat.h>
// #include <sys/time.h>
// #include <sys/types.h>
// #include <sys/uio.h>
// #include <sys/un.h>
// 
// #include <netinet/in.h>
// 
// #include <sys/types.h>
// #include <sys/socket.h>
// #include <netdb.h>
// #include <arpa/inet.h>
// 
// #include <err.h>
// #include <pthread.h>
// #include <stddef.h>
// #include <stdint.h>
// #include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <time.h>
// #include <unistd.h>
// 
// #include "uch11.h"
// #include "chaosd.h"
// #include "hosttab.h"
// #include "misc.h"
// #include "ucfg.h"
// #include "ucode.h"
// #include "usim.h"
// #include "utrace.h"

int hybrid_udp_and_local = 0;



static int
chudpopen(void)
{
	int sock, lport, res, udp_dport, braddr;
	struct sockaddr_in sin;
	struct addrinfo *he, hi;
	struct in_addr udp_dest;



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|


>

>
|







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
/* Chaos over UDP */

#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/un.h>

#include <netinet/in.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>

#include <err.h>
#include <pthread.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#include "uch11.h"
#include "chaosd.h"
#include "hosttab.h"
#include "misc.h"
#include "ucfg.h"
#include "ucode.h"
#include "usim.h"
#include "utrace.h"

int hybrid_udp_and_local = 0;
u_short udp_bridge_chaddr;


int
chudpopen(void)
{
	int sock, lport, res, udp_dport, braddr;
	struct sockaddr_in sin;
	struct addrinfo *he, hi;
	struct in_addr udp_dest;

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
	unsigned short ch_hw_srcaddr:16;
	unsigned short ch_hw_checksum:16;
};

/* Max: CHUDP header, Chaos header, Chaos data, trailer */
#define CHUDP_MAXLEN (sizeof(struct chudp_header)+sizeof(struct pkt_header)+CH_PK_MAX_DATALEN+sizeof(struct chaos_hw_trailer))

static u_char trans_chudpbuf[CHUDP_MAXLEN];

/* So sorry about this. */
void
ntohs_buf(u_short *ibuf, u_short *obuf, int len)
{
	int i;
	for (i = 0; i < len; i += 2)
		*obuf++ = ntohs(*ibuf++);
}

static int
chaos_send_to_udp(char *buffer, int size)
{
	int wcount, dest_addr;

	/*
	 * Local loopback.
	 */







|










|







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
	unsigned short ch_hw_srcaddr:16;
	unsigned short ch_hw_checksum:16;
};

/* Max: CHUDP header, Chaos header, Chaos data, trailer */
#define CHUDP_MAXLEN (sizeof(struct chudp_header)+sizeof(struct pkt_header)+CH_PK_MAX_DATALEN+sizeof(struct chaos_hw_trailer))

u_char trans_chudpbuf[CHUDP_MAXLEN];

/* So sorry about this. */
void
ntohs_buf(u_short *ibuf, u_short *obuf, int len)
{
	int i;
	for (i = 0; i < len; i += 2)
		*obuf++ = ntohs(*ibuf++);
}

int
chaos_send_to_udp(char *buffer, int size)
{
	int wcount, dest_addr;

	/*
	 * Local loopback.
	 */
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
			ERR(TRACE_CHAOS, "chaos: could not send the full pkt: %d sent, expected %d", nb, size + sizeof(struct chudp_header));
			return -1;
		}
	}
	return 0;
}

static int
chaos_poll_udp(void)
{
	/* basically copy chaos_poll_chaosd but skip CHUDP header and swap */
	ssize_t ret;
	struct pollfd pfd[1];
	int nfds, timeout;
	unsigned char lenbytes[4];







|







246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
			ERR(TRACE_CHAOS, "chaos: could not send the full pkt: %d sent, expected %d", nb, size + sizeof(struct chudp_header));
			return -1;
		}
	}
	return 0;
}

int
chaos_poll_udp(void)
{
	/* basically copy chaos_poll_chaosd but skip CHUDP header and swap */
	ssize_t ret;
	struct pollfd pfd[1];
	int nfds, timeout;
	unsigned char lenbytes[4];

Changes to uch11.c.

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
#include "hosttab.h"
#include "misc.h"
#include "ucfg.h"
#include "ucode.h"
#include "usim.h"
#include "utrace.h"

enum
{
	CHAOS_CSR_TIMER_INTERRUPT_ENABLE = (01 << 00),	/* CHBUSY */
	CHAOS_CSR_LOOP_BACK = (01 << 01),	/* CHLPBK */
	CHAOS_CSR_RECEIVE_ALL = (01 << 02),	/* CHSPY */
	CHAOS_CSR_RECEIVER_CLEAR = (01 << 03),
	CHAOS_CSR_RECEIVE_ENABLE = (01 << 04),	/* CHREN */
	CHAOS_CSR_TRANSMIT_ENABLE = (01 << 05),	/* CHRIEN */
	CHAOS_CSR_INTERRUPT_ENABLES = (02 << 04),
	CHAOS_CSR_TRANSMIT_ABORT = (01 << 06),	/* CHABRT */
	CHAOS_CSR_TRANSMIT_DONE = (01 << 07),	/* CHTDN */
	CHAOS_CSR_TRANSMITTER_CLEAR = (01 << 010),	/* CHTCLR */
	CHAOS_CSR_LOST_COUNT = (04 << 011),	/* CHLC */
	CHAOS_CSR_RESET = (01 << 015),	/* CHRST */
	CHAOS_CSR_CRC_ERROR = (01 << 016),	/* CHCRC */
	CHAOS_CSR_RECEIVE_DONE = (01 << 017),	/* CHRDN */
} CHAOS_HARDWARE_VALUES;

int uch11_backend = UCH11_BACKEND_LOCAL;
int uch11_myaddr = 0177040;	/* LOCAL-CADR */
int uch11_serveraddr = 0177001;	/* LOCAL-BRIDGE */



static int uch11_csr;
static int uch11_bit_count;
static int uch11_lost_count;

static unsigned short uch11_xmit_buffer[4096];
static int uch11_xmit_buffer_size;
static int uch11_xmit_buffer_ptr;

static unsigned short uch11_rcv_buffer[4096];
static unsigned short uch11_rcv_buffer_toss[4096];
static int uch11_rcv_buffer_ptr;
static int uch11_rcv_buffer_size;
static bool uch11_rcv_buffer_empty;

static int reconnect_delay;
static bool reconnect_chaos;

static int (*uch11_send)(char *, int);

static void uch11_force_reconect(void);
extern void uch11_reconnect(void);

extern void settreeroot(const char *, const char *prefix);






// udp
static u_short udp_bridge_chaddr;
static int chudpopen(void);
static int chaos_send_to_udp(char *buffer, int size);
static int chaos_poll_udp(void);

// deamon
static int chaosd_fd;

static pthread_mutex_t recvqueue;
static pthread_mutex_t recvqueue;
struct queue_head queuehead = TAILQ_HEAD_INITIALIZER(queuehead);

static int chaos_send_to_chaosd(char *buffer, int size);
static int chaos_poll_chaosd(void);

// local

static int chaos_send_to_local(char *buffer, int size);
static int chaos_poll_local(void);

/*
 * RFC1071: Compute Internet Checksum for COUNT bytes beginning at
 * location ADDR.
 */
static unsigned short
uch11_checksum(const unsigned char *addr, int count)
{
	long sum;

	sum = 0;
	while (count > 1) {
		sum += *(addr) << 8 | *(addr + 1);







<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




>
>
|
|
|

|
|
|

|
|
|
|
|

|
|

|

|




>
>
>
>
>

|
|
|
|


|

<
<
<
<
|
|



|
|





|







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
#include "hosttab.h"
#include "misc.h"
#include "ucfg.h"
#include "ucode.h"
#include "usim.h"
#include "utrace.h"



















int uch11_backend = UCH11_BACKEND_LOCAL;
int uch11_myaddr = 0177040;	/* LOCAL-CADR */
int uch11_serveraddr = 0177001;	/* LOCAL-BRIDGE */



int uch11_csr;
int uch11_bit_count;
int uch11_lost_count;

unsigned short uch11_xmit_buffer[4096];
int uch11_xmit_buffer_size;
int uch11_xmit_buffer_ptr;

 unsigned short uch11_rcv_buffer[4096];
 unsigned short uch11_rcv_buffer_toss[4096];
int uch11_rcv_buffer_ptr;
int uch11_rcv_buffer_size;
bool uch11_rcv_buffer_empty;

int reconnect_delay;
bool reconnect_chaos;

int (*uch11_send)(char *, int);

void uch11_force_reconect(void);
extern void uch11_reconnect(void);

extern void settreeroot(const char *, const char *prefix);

 pthread_mutex_t recvqueue;
 pthread_mutex_t recvqueue;
struct queue_head queuehead = TAILQ_HEAD_INITIALIZER(queuehead);


// udp

int chudpopen(void);
int chaos_send_to_udp(char *buffer, int size);
int chaos_poll_udp(void);

// deamon
int chaosd_fd;





int chaos_send_to_chaosd(char *buffer, int size);
int chaos_poll_chaosd(void);

// local

int chaos_send_to_local(char *buffer, int size);
int chaos_poll_local(void);

/*
 * RFC1071: Compute Internet Checksum for COUNT bytes beginning at
 * location ADDR.
 */
unsigned short
uch11_checksum(const unsigned char *addr, int count)
{
	long sum;

	sum = 0;
	while (count > 1) {
		sum += *(addr) << 8 | *(addr + 1);
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
		sum = (sum & 0xffff) + (sum >> 16);
	return (~sum) & 0xffff;
}

/*
 * Called when we are we have something in uch11_rcv_buffer.
 */
static void
uch11_rx_pkt(void)
{
	uch11_rcv_buffer_ptr = 0;
	uch11_bit_count = (uch11_rcv_buffer_size * 2 * 8) - 1;
	INFO(TRACE_CHAOS, "chaos: receiving %d words\n", uch11_rcv_buffer_size);
	if (uch11_rcv_buffer_size > 0) {
		DEBUG(TRACE_CHAOS, "chaos: set csr receive done, generate interrupt\n");
		uch11_csr |= CHAOS_CSR_RECEIVE_DONE;
		if (uch11_csr & CHAOS_CSR_RECEIVE_ENABLE)
			assert_unibus_interrupt(0270);
	} else {
		DEBUG(TRACE_CHAOS, "chaos: recieve buffer empty\n");
	}
}

static void
uch11_xmit_done_intr(void)
{
	uch11_csr |= CHAOS_CSR_TRANSMIT_DONE;
	if (uch11_csr & CHAOS_CSR_TRANSMIT_ENABLE)
		assert_unibus_interrupt(0270);
}








|















|







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
		sum = (sum & 0xffff) + (sum >> 16);
	return (~sum) & 0xffff;
}

/*
 * Called when we are we have something in uch11_rcv_buffer.
 */
void
uch11_rx_pkt(void)
{
	uch11_rcv_buffer_ptr = 0;
	uch11_bit_count = (uch11_rcv_buffer_size * 2 * 8) - 1;
	INFO(TRACE_CHAOS, "chaos: receiving %d words\n", uch11_rcv_buffer_size);
	if (uch11_rcv_buffer_size > 0) {
		DEBUG(TRACE_CHAOS, "chaos: set csr receive done, generate interrupt\n");
		uch11_csr |= CHAOS_CSR_RECEIVE_DONE;
		if (uch11_csr & CHAOS_CSR_RECEIVE_ENABLE)
			assert_unibus_interrupt(0270);
	} else {
		DEBUG(TRACE_CHAOS, "chaos: recieve buffer empty\n");
	}
}

void
uch11_xmit_done_intr(void)
{
	uch11_csr |= CHAOS_CSR_TRANSMIT_DONE;
	if (uch11_csr & CHAOS_CSR_TRANSMIT_ENABLE)
		assert_unibus_interrupt(0270);
}

299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
		chaos_poll_local();
	else if (uch11_backend == UCH11_BACKEND_DAEMON)
		chaos_poll_chaosd();
	else if (uch11_backend == UCH11_BACKEND_UDP)
		chaos_poll_udp();
}

static void
uch11_force_reconect(void)
{
	if (uch11_backend == UCH11_BACKEND_DAEMON) {
		WARNING(TRACE_CHAOS, "chaos: forcing reconnect to chaosd\n");
		close(chaosd_fd);
		chaosd_fd = -1;
		reconnect_chaos = true;







|







285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
		chaos_poll_local();
	else if (uch11_backend == UCH11_BACKEND_DAEMON)
		chaos_poll_chaosd();
	else if (uch11_backend == UCH11_BACKEND_UDP)
		chaos_poll_udp();
}

void
uch11_force_reconect(void)
{
	if (uch11_backend == UCH11_BACKEND_DAEMON) {
		WARNING(TRACE_CHAOS, "chaos: forcing reconnect to chaosd\n");
		close(chaosd_fd);
		chaosd_fd = -1;
		reconnect_chaos = true;
392
393
394
395
396
397
398
399
400
401
	}
	if (root_directory == NULL)
		err(1, "could not resolve %s", whichconf);
	NOTICE(TRACE_USIM, "chaos: mapping %s to %s\n", whichdir, root_directory);
	return 0;
}

#include "uch11-chaosd.c"
#include "uch11-local.c"
#include "uch11-udp.c"







|
|
|
378
379
380
381
382
383
384
385
386
387
	}
	if (root_directory == NULL)
		err(1, "could not resolve %s", whichconf);
	NOTICE(TRACE_USIM, "chaos: mapping %s to %s\n", whichdir, root_directory);
	return 0;
}

//#include "uch11-chaosd.c"
//#include "uch11-local.c"
//#include "uch11-udp.c"

Changes to uch11.h.

36
37
38
39
40
41
42














































extern int uch11_get_csr(void);
extern void uch11_set_csr(int);
extern int uch11_get_bit_count(void);
extern int uch11_get_rcv_buffer(void);
extern void uch11_put_xmit_buffer(int);
extern void uch11_xmit_pkt(void);




















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

extern int uch11_get_csr(void);
extern void uch11_set_csr(int);
extern int uch11_get_bit_count(void);
extern int uch11_get_rcv_buffer(void);
extern void uch11_put_xmit_buffer(int);
extern void uch11_xmit_pkt(void);


extern struct queue_head queuehead;
extern pthread_mutex_t recvqueue;
extern pthread_mutex_t recvqueue;

enum
{
	CHAOS_CSR_TIMER_INTERRUPT_ENABLE = (01 << 00),	/* CHBUSY */
	CHAOS_CSR_LOOP_BACK = (01 << 01),	/* CHLPBK */
	CHAOS_CSR_RECEIVE_ALL = (01 << 02),	/* CHSPY */
	CHAOS_CSR_RECEIVER_CLEAR = (01 << 03),
	CHAOS_CSR_RECEIVE_ENABLE = (01 << 04),	/* CHREN */
	CHAOS_CSR_TRANSMIT_ENABLE = (01 << 05),	/* CHRIEN */
	CHAOS_CSR_INTERRUPT_ENABLES = (02 << 04),
	CHAOS_CSR_TRANSMIT_ABORT = (01 << 06),	/* CHABRT */
	CHAOS_CSR_TRANSMIT_DONE = (01 << 07),	/* CHTDN */
	CHAOS_CSR_TRANSMITTER_CLEAR = (01 << 010),	/* CHTCLR */
	CHAOS_CSR_LOST_COUNT = (04 << 011),	/* CHLC */
	CHAOS_CSR_RESET = (01 << 015),	/* CHRST */
	CHAOS_CSR_CRC_ERROR = (01 << 016),	/* CHCRC */
	CHAOS_CSR_RECEIVE_DONE = (01 << 017),	/* CHRDN */
} CHAOS_HARDWARE_VALUES;

#include <stdbool.h>
extern int chaosd_fd;
extern int uch11_backend;
extern int uch11_myaddr;
extern int uch11_serveraddr;

extern bool reconnect_chaos;

extern int uch11_csr;
extern int uch11_bit_count;
extern int uch11_lost_count;

extern unsigned short uch11_xmit_buffer[4096];
extern int uch11_xmit_buffer_size;
extern int uch11_xmit_buffer_ptr;

extern  unsigned short uch11_rcv_buffer[4096];
extern  unsigned short uch11_rcv_buffer_toss[4096];
extern int uch11_rcv_buffer_ptr;
extern int uch11_rcv_buffer_size;
extern bool uch11_rcv_buffer_empty;