File:  [MW Coherent from dump] / coherent / d / PS2_KERNEL / coh.386 / clist.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:39 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/* $Header: /var/lib/cvsd/repos/coherent/coherent/d/PS2_KERNEL/coh.386/clist.c,v 1.1.1.1 2019/05/29 04:56:39 root Exp $ */
/* (lgl-
 *	The information contained herein is a trade secret of Mark Williams
 *	Company, and  is confidential information.  It is provided  under a
 *	license agreement,  and may be  copied or disclosed  only under the
 *	terms of  that agreement.  Any  reproduction or disclosure  of this
 *	material without the express written authorization of Mark Williams
 *	Company or persuant to the license agreement is unlawful.
 *
 *	COHERENT Version 2.3.37
 *	Copyright (c) 1982, 1983, 1984.
 *	An unpublished work by Mark Williams Company, Chicago.
 *	All rights reserved.
 -lgl) */
/*
 * Coherent.
 * Character list management.
 *
 * $Log: clist.c,v $
 * Revision 1.1.1.1  2019/05/29 04:56:39  root
 * coherent
 *
 * Revision 1.2  92/08/04  12:30:26  bin
 * changed for kernel 59
 * 
 * Revision 1.2  92/01/06  11:58:44  hal
 * Compile with cc.mwc.
 * 
 * Revision 1.1	88/03/24  16:13:33	src
 * Initial revision
 * 
 */
#include <sys/coherent.h>
#include <sys/clist.h>
#include <sys/sched.h>

#define	cvirt(p)	((CLIST *)(p))
#ifdef TRACER
int nclfree = 0;
#endif

/*
 * Initialise character list queues.
 *
 * Clist are not mapped.
 */
cltinit()
{
	register cmap_t cm;
	register cmap_t lm;
	register paddr_t p;
	register int s;

	s = sphi();
	lm = 0;
	for (p = clistp+NCLIST*sizeof(CLIST); (p-=sizeof(CLIST)) >= clistp; ) {
		cm = p;
		cvirt(cm)->cl_fp = lm;
		lm = cm;
	}
	cltfree = lm;
#ifdef TRACER
	nclfree = NCLIST;
#endif
	spl(s);
}

/*
 * Get a character from the given queue.
 */
getq(cqp)
register CQUEUE *cqp;
{
	register cmap_t op;
	register cmap_t np;
	register int ox;
	register int c;
	register int s;

	if (cqp->cq_cc == 0)
		return (-1);
	s = sphi();
	op = cqp->cq_op;
	ox = cqp->cq_ox;
	c = cvirt(op)->cl_ch[ox]&0377;
	if (--cqp->cq_cc==0 || ++cqp->cq_ox==NCPCL) {
		cqp->cq_ox = 0;
		np = cvirt(op)->cl_fp;
		cvirt(op)->cl_fp = cltfree;
		cqp->cq_op = np;
		cltfree = op;
		if (np == 0) {
			cqp->cq_ip = 0;
			cqp->cq_ix = 0;
		}
		if (cltwant) {
			cltwant = 0;
			wakeup((char *)&cltwant);
		}
#ifdef TRACER
		T_HAL(0x0040, {nclfree++; printf("F%d ", nclfree);});
#endif
	}
	spl(s);
	return (c);
}

/*
 * Put a character on the given queue.
 */
putq(cqp, c)
register CQUEUE *cqp;
{
	register cmap_t ip;
	register int ix;
	register int s;
	register cmap_t np;

	s = sphi();
	ip = cqp->cq_ip;
	if ((ix=cqp->cq_ix) == 0) {
		if ((ip=cltfree) == 0) {
			spl(s);
			return (-1);
		}
		cltfree = cvirt(ip)->cl_fp;
		cvirt(ip)->cl_fp = 0;
		if ((np=cqp->cq_ip) == 0)
			cqp->cq_op = ip;
		else {
			cvirt(np)->cl_fp = ip;
		}
		cqp->cq_ip = ip;
		T_HAL(0x0040, { nclfree--; printf("f%d ", nclfree);});
	}
	cvirt(ip)->cl_ch[ix] = c;
	if (++cqp->cq_ix == NCPCL)
		cqp->cq_ix = 0;
	cqp->cq_cc++;
	spl(s);
	return c;
}

/*
 * Clear a character queue.
 */
clrq(cqp)
register CQUEUE *cqp;
{
	register int s;

	s = sphi();
	while (getq(cqp) >= 0)
		;
	spl(s);
}

/*
 * Wait for more character queues to become available.
 */
waitq()
{
	while (cltfree == 0) {
		T_HAL(0x0080, putchar('+'));
		cltwant = 1;
		v_sleep((char *)&cltwant, CVCLIST, IVCLIST, SVCLIST, "waitq");
		/* Wait for more character queues to become available.  */
	}
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.