No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / mach / mach_clock.c
blob18957e049e03830b5eb362bb15fe62ff2a265c02
1 /* $NetBSD: mach_clock.c,v 1.18 2007/12/20 23:02:59 dsl Exp $ */
3 /*-
4 * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: mach_clock.c,v 1.18 2007/12/20 23:02:59 dsl Exp $");
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/systm.h>
39 #include <sys/signal.h>
40 #include <sys/proc.h>
41 #include <sys/time.h>
43 #include <compat/mach/mach_types.h>
44 #include <compat/mach/mach_message.h>
45 #include <compat/mach/mach_port.h>
46 #include <compat/mach/mach_clock.h>
47 #include <compat/mach/mach_services.h>
48 #include <compat/mach/mach_syscallargs.h>
50 int
51 mach_sys_clock_sleep_trap(struct lwp *l, const struct mach_sys_clock_sleep_trap_args *uap, register_t *retval)
53 /* {
54 syscallarg(mach_clock_port_t) clock_name;
55 syscallarg(mach_sleep_type_t) sleep_type;
56 syscallarg(int) sleep_sec;
57 syscallarg(int) sleep_nsec;
58 syscallarg(mach_timespec_t *) wakeup_time;
59 } */
60 struct timespec mts, cts, tts;
61 mach_timespec_t mcts;
62 int dontcare;
63 int error;
64 int ticks;
66 mts.tv_sec = SCARG(uap, sleep_sec);
67 mts.tv_nsec = SCARG(uap, sleep_nsec);
69 if (SCARG(uap, sleep_type) == MACH_TIME_ABSOLUTE) {
70 nanotime(&cts);
71 timespecsub(&mts, &cts, &tts);
72 } else {
73 tts.tv_sec = mts.tv_sec;
74 tts.tv_nsec = mts.tv_nsec;
77 ticks = tts.tv_sec * hz;
78 ticks += (tts.tv_nsec * hz) / 100000000L;
80 tsleep(&dontcare, PZERO|PCATCH, "sleep", ticks);
82 if (SCARG(uap, wakeup_time) != NULL) {
83 nanotime(&cts);
84 mcts.tv_sec = cts.tv_sec;
85 mcts.tv_nsec = cts.tv_nsec;
86 error = copyout(&mcts, SCARG(uap, wakeup_time), sizeof(mcts));
87 if (error != 0)
88 return error;
91 return 0;
94 int
95 mach_sys_timebase_info(struct lwp *l, const struct mach_sys_timebase_info_args *uap, register_t *retval)
97 /* {
98 syscallarg(mach_timebase_info_t) info;
99 } */
100 int error;
101 struct mach_timebase_info info;
103 /* XXX This is probably bus speed, fill it accurately */
104 info.numer = 4000000000UL;
105 info.denom = 75189611UL;
107 if ((error = copyout(&info, (void *)SCARG(uap, info),
108 sizeof(info))) != 0)
109 return error;
111 return 0;
117 mach_clock_get_time(struct mach_trap_args *args)
119 mach_clock_get_time_request_t *req = args->smsg;
120 mach_clock_get_time_reply_t *rep = args->rmsg;
121 size_t *msglen = args->rsize;
122 struct timeval tv;
124 microtime(&tv);
126 *msglen = sizeof(*rep);
127 mach_set_header(rep, req, *msglen);
129 rep->rep_cur_time.tv_sec = tv.tv_sec;
130 rep->rep_cur_time.tv_nsec = tv.tv_usec * 1000;
132 mach_set_trailer(rep, *msglen);
134 return 0;