xref: /csrg-svn/sys/kern/subr_xxx.c (revision 9758)
1*9758Ssam /*	subr_xxx.c	4.21	82/12/17	*/
234Sbill 
3*9758Ssam #include "../machine/pte.h"
4*9758Ssam 
534Sbill #include "../h/param.h"
634Sbill #include "../h/systm.h"
734Sbill #include "../h/conf.h"
834Sbill #include "../h/inode.h"
934Sbill #include "../h/dir.h"
1034Sbill #include "../h/user.h"
1134Sbill #include "../h/buf.h"
1234Sbill #include "../h/proc.h"
136573Smckusic #include "../h/fs.h"
147427Sroot #include "../h/vm.h"
157427Sroot #include "../h/cmap.h"
167722Swnj #include "../h/uio.h"
1734Sbill 
1834Sbill /*
198555Sroot  * Routine placed in illegal entries in the bdevsw and cdevsw tables.
2034Sbill  */
2134Sbill nodev()
2234Sbill {
2334Sbill 
248555Sroot 	return (ENODEV);
2534Sbill }
2634Sbill 
2734Sbill /*
2834Sbill  * Null routine; placed in insignificant entries
2934Sbill  * in the bdevsw and cdevsw tables.
3034Sbill  */
3134Sbill nulldev()
3234Sbill {
3334Sbill 
348555Sroot 	return (0);
3534Sbill }
3634Sbill 
3734Sbill imin(a, b)
3834Sbill {
3934Sbill 
4034Sbill 	return (a < b ? a : b);
4134Sbill }
4234Sbill 
4334Sbill imax(a, b)
4434Sbill {
4534Sbill 
4634Sbill 	return (a > b ? a : b);
4734Sbill }
4834Sbill 
496573Smckusic unsigned
506573Smckusic min(a, b)
518626Sroot 	u_int a, b;
526573Smckusic {
536573Smckusic 
546573Smckusic 	return (a < b ? a : b);
556573Smckusic }
566573Smckusic 
576573Smckusic unsigned
586573Smckusic max(a, b)
598626Sroot 	u_int a, b;
606573Smckusic {
616573Smckusic 
626573Smckusic 	return (a > b ? a : b);
636573Smckusic }
648626Sroot 
657427Sroot extern	cabase, calimit;
667427Sroot extern	struct pte camap[];
677427Sroot 
687427Sroot caddr_t	cacur = (caddr_t)&cabase;
697427Sroot caddr_t	camax = (caddr_t)&cabase;
707427Sroot int	cax = 0;
717427Sroot /*
727427Sroot  * This is a kernel-mode storage allocator.
737427Sroot  * It is very primitive, currently, in that
747427Sroot  * there is no way to give space back.
757427Sroot  * It serves, for the time being, the needs of
767427Sroot  * auto-configuration code and the like which
777427Sroot  * need to allocate some stuff at boot time.
787427Sroot  */
797427Sroot caddr_t
807427Sroot calloc(size)
817427Sroot 	int size;
827427Sroot {
837427Sroot 	register caddr_t res;
847427Sroot 	register int i;
857427Sroot 
867427Sroot 	if (cacur+size >= (caddr_t)&calimit)
877427Sroot 		panic("calloc");
887427Sroot 	while (cacur+size > camax) {
897427Sroot 		(void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS);
907427Sroot 		vmaccess(&camap[cax], camax, CLSIZE);
917427Sroot 		for (i = 0; i < CLSIZE; i++)
927427Sroot 			clearseg(camap[cax++].pg_pfnum);
937427Sroot 		camax += NBPG * CLSIZE;
947427Sroot 	}
957427Sroot 	res = cacur;
967427Sroot 	cacur += size;
977427Sroot 	return (res);
987427Sroot }
997531Sroot 
1007427Sroot #ifndef vax
1017427Sroot ffs(mask)
1027427Sroot 	register long mask;
1037427Sroot {
1047427Sroot 	register int i;
1057427Sroot 
1067427Sroot 	for(i=1; i<NSIG; i++) {
1077427Sroot 		if (mask & 1)
1087427Sroot 			return (i);
1097427Sroot 		mask >>= 1;
1107427Sroot 	}
1117427Sroot 	return (0);
1127427Sroot }
1137531Sroot 
1147531Sroot bcmp(s1, s2, len)
1157531Sroot 	register char *s1, *s2;
1167531Sroot 	register int len;
1177531Sroot {
1187531Sroot 
1198667S 	while (len--)
1207531Sroot 		if (*s1++ != *s2++)
1217531Sroot 			return (1);
1227531Sroot 	return (0);
1237531Sroot }
1247531Sroot 
1257531Sroot strlen(s1)
1267531Sroot 	register char *s1;
1277531Sroot {
1287531Sroot 	register int len;
1297531Sroot 
1307531Sroot 	for (len = 0; *s1++ != '\0'; len++)
1317531Sroot 		/* void */;
1327531Sroot 	return (len);
1337531Sroot }
1347500Sroot #endif
1357722Swnj 
1367722Swnj /*
1377722Swnj  * Pass back c to the user.
1387722Swnj  */
1397722Swnj passuc(c, uio)
1407722Swnj 	register c;
1417722Swnj 	struct uio *uio;
1427722Swnj {
1437722Swnj 	register struct iovec *iov = uio->uio_iov;
1447722Swnj 
1457722Swnj 	switch (uio->uio_segflg) {
1467722Swnj 
1477722Swnj 	case 0:
1487722Swnj 		if (subyte(iov->iov_base, c) < 0)
1497722Swnj 			goto fault;
1507722Swnj 		break;
1517722Swnj 
1527722Swnj 	case 1:
1537722Swnj 		*iov->iov_base = c;
1547722Swnj 		break;
1557722Swnj 
1567722Swnj 	case 2:
1577722Swnj 		if (suibyte(iov->iov_base, c) < 0)
1587722Swnj 			goto fault;
1597722Swnj 		break;
1607722Swnj 	}
1617722Swnj 	iov->iov_base++;
1627722Swnj 	iov->iov_len--;
1637722Swnj 	uio->uio_resid--;
1647722Swnj 	uio->uio_offset++;
1657722Swnj 	if (iov->iov_len <= 0) {
1667722Swnj 		uio->uio_iov++;
1677722Swnj 		uio->uio_iovcnt--;
1687722Swnj 	}
1697722Swnj 	return (0);
1707722Swnj fault:
1717722Swnj 	return (EFAULT);
1727722Swnj }
173