summaryrefslogtreecommitdiff
path: root/lib/libarch/alpha
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1996-07-30 06:46:51 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1996-07-30 06:46:51 +0000
commitaa2c65f59ea3ca790476d33ceeb1eecf85a34344 (patch)
treee1128a627c0a9cd5dd25fdb849839853206b0fc8 /lib/libarch/alpha
parent7becd553fa210c27c280a83563ae3862cb985d83 (diff)
Sync with NetBSD + Add OpenBSD tags
Diffstat (limited to 'lib/libarch/alpha')
-rw-r--r--lib/libarch/alpha/alpha_mmclock_gettime.c56
-rw-r--r--lib/libarch/alpha/alpha_mmclock_init.c69
-rw-r--r--lib/libarch/alpha/gettimeofday.c83
-rw-r--r--lib/libarch/alpha/libalpha.h31
4 files changed, 239 insertions, 0 deletions
diff --git a/lib/libarch/alpha/alpha_mmclock_gettime.c b/lib/libarch/alpha/alpha_mmclock_gettime.c
new file mode 100644
index 00000000000..14afea0fb3e
--- /dev/null
+++ b/lib/libarch/alpha/alpha_mmclock_gettime.c
@@ -0,0 +1,56 @@
+/* $OpenBSD: alpha_mmclock_gettime.c,v 1.3 1996/07/30 06:46:48 niklas Exp $ */
+/* $NetBSD: alpha_mmclock_gettime.c,v 1.1 1995/12/20 12:54:24 cgd Exp $ */
+
+/*
+ * Copyright (c) 1995 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <machine/sysarch.h>
+
+#include "libalpha.h"
+
+void
+alpha_mmclock_gettime(tdp)
+ struct alpha_timedata *tdp;
+{
+ u_long npcc, pccdiff;
+
+ do {
+ tdp->td_tv.tv_usec = alpha_mmclockdata->td_tv.tv_usec;
+ tdp->td_tv.tv_sec = alpha_mmclockdata->td_tv.tv_sec;
+ tdp->td_cc = alpha_mmclockdata->td_cc;
+ } while (tdp->td_tv.tv_usec != alpha_mmclockdata->td_tv.tv_usec ||
+ tdp->td_tv.tv_sec != alpha_mmclockdata->td_tv.tv_sec);
+
+ npcc = rpcc() & 0x00000000ffffffffUL;
+ if (npcc < tdp->td_cc)
+ npcc += 0x0000000100000000UL;
+ tdp->td_cc = npcc - tdp->td_cc;
+}
diff --git a/lib/libarch/alpha/alpha_mmclock_init.c b/lib/libarch/alpha/alpha_mmclock_init.c
new file mode 100644
index 00000000000..3b807f7e23c
--- /dev/null
+++ b/lib/libarch/alpha/alpha_mmclock_init.c
@@ -0,0 +1,69 @@
+/* $OpenBSD: alpha_mmclock_init.c,v 1.3 1996/07/30 06:46:49 niklas Exp $ */
+/* $NetBSD: alpha_mmclock_init.c,v 1.1 1995/12/20 12:55:21 cgd Exp $ */
+
+/*
+ * Copyright (c) 1995 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/mman.h>
+#include <machine/sysarch.h>
+
+#include "libalpha.h"
+
+volatile struct alpha_timedata *alpha_mmclockdata;
+u_long alpha_cycles_per_second;
+
+int __alpha_mmclock_init_failed;
+
+volatile struct alpha_timedata *
+alpha_mmclock_init()
+{
+ int fd;
+
+ if (alpha_mmclockdata != NULL)
+ return (alpha_mmclockdata);
+
+ fd = open("/dev/mmclock", O_RDONLY, 0);
+ if (fd == -1)
+ goto fail;
+
+ alpha_mmclockdata = (struct alpha_timedata *)
+ mmap(NULL, getpagesize(), PROT_READ, MAP_FILE, fd, 0);
+ close(fd);
+ if (alpha_mmclockdata == NULL)
+ goto fail;
+
+ alpha_cycles_per_second = alpha_mmclockdata->td_cpc;
+
+ __alpha_mmclock_init_failed = 0;
+ return (alpha_mmclockdata);
+
+fail:
+ __alpha_mmclock_init_failed = 1;
+ return (NULL);
+}
diff --git a/lib/libarch/alpha/gettimeofday.c b/lib/libarch/alpha/gettimeofday.c
new file mode 100644
index 00000000000..f5e5f375046
--- /dev/null
+++ b/lib/libarch/alpha/gettimeofday.c
@@ -0,0 +1,83 @@
+/* $OpenBSD: gettimeofday.c,v 1.3 1996/07/30 06:46:50 niklas Exp $ */
+/* $NetBSD: gettimeofday.c,v 1.1 1995/12/20 12:56:06 cgd Exp $ */
+
+/*
+ * Copyright (c) 1995 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <machine/sysarch.h>
+
+#include "libalpha.h"
+
+int
+gettimeofday(tvp, tzp)
+ struct timeval *tvp;
+ struct timezone *tzp;
+{
+ u_long opcc, npcc, pccdiff;
+ static struct timeval lasttime;
+
+ if (tzp == NULL && alpha_mmclockdata == NULL &&
+ !__alpha_mmclock_init_failed)
+ alpha_mmclockdata = alpha_mmclock_init();
+ if (tzp != NULL || alpha_mmclockdata == NULL)
+ return (syscall(SYS_gettimeofday, tvp, tzp));
+
+ if (tvp == NULL)
+ return 0;
+
+ do {
+ tvp->tv_usec = alpha_mmclockdata->td_tv.tv_usec;
+ tvp->tv_sec = alpha_mmclockdata->td_tv.tv_sec;
+ opcc = alpha_mmclockdata->td_cc;
+ } while (tvp->tv_usec != alpha_mmclockdata->td_tv.tv_usec ||
+ tvp->tv_sec != alpha_mmclockdata->td_tv.tv_sec);
+
+ npcc = rpcc() & 0x00000000ffffffffUL;
+ if (npcc < opcc)
+ npcc += 0x0000000100000000UL;
+ pccdiff = npcc - opcc;
+
+ tvp->tv_usec += (pccdiff * 1000000) / alpha_cycles_per_second;
+ if (tvp->tv_usec > 1000000) {
+ tvp->tv_sec++;
+ tvp->tv_usec -= 1000000;
+ }
+
+ if ((tvp->tv_sec == lasttime.tv_sec &&
+ tvp->tv_usec <= lasttime.tv_usec) &&
+ (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
+ tvp->tv_sec++;
+ tvp->tv_usec -= 1000000;
+ }
+
+ lasttime = *tvp;
+ return 0;
+}
diff --git a/lib/libarch/alpha/libalpha.h b/lib/libarch/alpha/libalpha.h
new file mode 100644
index 00000000000..68122f14b8f
--- /dev/null
+++ b/lib/libarch/alpha/libalpha.h
@@ -0,0 +1,31 @@
+/* $OpenBSD: libalpha.h,v 1.3 1996/07/30 06:46:50 niklas Exp $ */
+/* $NetBSD: libalpha.h,v 1.1 1995/12/20 12:56:44 cgd Exp $ */
+
+/*
+ * Copyright (c) 1995 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+extern int __alpha_mmclock_init_failed;