⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kern_time.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	$Id: kern_time.c,v 1.1.1.1 2001/10/01 18:47:34 patrik Exp $ *//*	$OpenBSD: kern_time.c,v 1.14 1999/06/06 19:21:34 deraadt Exp $	*//*	$NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $	*//* * Copyright (c) 1982, 1986, 1989, 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * *	@(#)kern_time.c	8.4 (Berkeley) 5/26/95 */#include <sys/param.h>#include <sys/resourcevar.h>#include <sys/kernel.h>#include <sys/systm.h>#include <sys/proc.h>#if 0#include <sys/vnode.h>#endif#include <sys/signalvar.h>#if 0#include <sys/mount.h>#endif#include <sys/syscallargs.h>#if defined(NFSCLIENT) || defined(NFSSERVER)#include <nfs/rpcv2.h>#include <nfs/nfsproto.h>#include <nfs/nfs_var.h>#endif#include <machine/cpu.h>#ifdef NOTUSED_BY_PMONstatic void	settime __P((struct timeval *));/*  * Time of day and interval timer support. * * These routines provide the kernel entry points to get and set * the time-of-day and per-process interval timers.  Subroutines * here provide support for adding and subtracting timeval structures * and decrementing interval timers, optionally reloading the interval * timers when they expire. *//* This function is used by clock_settime and settimeofday */static voidsettime(tv)	struct timeval *tv;{	struct timeval delta;	int s;	/* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */	s = splclock();	timersub(tv, &time, &delta);	time = *tv;	(void) splsoftclock();	timeradd(&boottime, &delta, &boottime);	timeradd(&runtime, &delta, &runtime);#	if defined(NFS) || defined(NFSSERVER)		nqnfs_lease_updatetime(delta.tv_sec);#	endif	splx(s);	resettodr();}#ifndef POSIX1003_1b/* ARGSUSED */intsys_clock_gettime(p, v, retval)	struct proc *p;	void *v;	register_t *retval;{	register struct sys_clock_gettime_args /* {		syscallarg(clockid_t) clock_id;		syscallarg(struct timespec *) tp;	} */ *uap = v;	clockid_t clock_id;	struct timeval atv;	struct timespec ats;	clock_id = SCARG(uap, clock_id);	if (clock_id != CLOCK_REALTIME)		return (EINVAL);	microtime(&atv);	TIMEVAL_TO_TIMESPEC(&atv,&ats);	return copyout(&ats, SCARG(uap, tp), sizeof(ats));}/* ARGSUSED */intsys_clock_settime(p, v, retval)	struct proc *p;	void *v;	register_t *retval;{	register struct sys_clock_settime_args /* {		syscallarg(clockid_t) clock_id;		syscallarg(const struct timespec *) tp;	} */ *uap = v;	clockid_t clock_id;	struct timeval atv;	struct timespec ats;	int error;	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)		return (error);	clock_id = SCARG(uap, clock_id);	if (clock_id != CLOCK_REALTIME)		return (EINVAL);	if ((error = copyin(SCARG(uap, tp), &ats, sizeof(ats))) != 0)		return (error);	TIMESPEC_TO_TIMEVAL(&atv,&ats);	/*	 * If the system is secure, we do not allow the time to be	 * set to an earlier value (it may be slowed using adjtime,	 * but not set back). This feature prevent interlopers from	 * setting arbitrary time stamps on files.	 */	if (securelevel > 1 && timercmp(&atv, &time, <))		return (EPERM);	settime(&atv);	return (0);}intsys_clock_getres(p, v, retval)	struct proc *p;	void *v;	register_t *retval;{	register struct sys_clock_getres_args /* {		syscallarg(clockid_t) clock_id;		syscallarg(struct timespec *) tp;	} */ *uap = v;	clockid_t clock_id;	struct timespec ts;	int error = 0;	clock_id = SCARG(uap, clock_id);	if (clock_id != CLOCK_REALTIME)		return (EINVAL);	if (SCARG(uap, tp)) {		ts.tv_sec = 0;		ts.tv_nsec = 1000000000 / hz;		error = copyout(&ts, SCARG(uap, tp), sizeof (ts));	}	return error;}/* ARGSUSED */intsys_nanosleep(p, v, retval)	struct proc *p;	void *v;	register_t *retval;{	static int nanowait;	register struct sys_nanosleep_args/* {		syscallarg(const struct timespec *) rqtp;		syscallarg(struct timespec *) rmtp;	} */ *uap = v;	struct timespec rqt;	struct timespec rmt;	struct timeval atv, utv;	int error, s, timo;	error = copyin((const void *)SCARG(uap, rqtp), (void *)&rqt,	    sizeof(struct timespec));	if (error)		return (error);	TIMESPEC_TO_TIMEVAL(&atv,&rqt)	if (itimerfix(&atv))		return (EINVAL);	s = splclock();	timeradd(&atv,&time,&atv);	timo = hzto(&atv);	/* 	 * Avoid inadvertantly sleeping forever	 */	if (timo == 0)		timo = 1;	splx(s);	error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo);	if (error == ERESTART)		error = EINTR;	if (error == EWOULDBLOCK)		error = 0;	if (SCARG(uap, rmtp)) {		int error;		s = splclock();		utv = time;		splx(s);		timersub(&atv, &utv, &utv);		if (utv.tv_sec < 0)			timerclear(&utv);		TIMEVAL_TO_TIMESPEC(&utv, &rmt);		error = copyout((void *)&rmt, (void *)SCARG(uap,rmtp),		    sizeof(rmt));				if (error)			return (error);	}	return error;}#endif          /* ! POSIX1003_1b */#endif /* NOTUSED_BY_PMON *//* ARGSUSED */intsys_gettimeofday(p, v, retval)	struct proc *p;	void *v;	register_t *retval;{	register struct sys_gettimeofday_args /* {		syscallarg(struct timeval *) tp;		syscallarg(struct timezone *) tzp;	} */ *uap = v;	struct timeval atv;	int error = 0;	if (SCARG(uap, tp)) {		microtime(&atv);		if ((error = copyout((void *)&atv, (void *)SCARG(uap, tp),		    sizeof (atv))))			return (error);	}	if (SCARG(uap, tzp))		error = copyout((void *)&tz, (void *)SCARG(uap, tzp),		    sizeof (tz));	return (error);}#ifdef NOTUSED_BY_PMON/* ARGSUSED */intsys_settimeofday(p, v, retval)	struct proc *p;	void *v;	register_t *retval;{	struct sys_settimeofday_args /* {		syscallarg(struct timeval *) tv;		syscallarg(struct timezone *) tzp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -