clock.c revision 1.1
11.1Spooka/*      $NetBSD: clock.c,v 1.1 2011/01/26 01:18:54 pooka Exp $ */
21.1Spooka
31.1Spooka/*-
41.1Spooka * Copyright (c) 2010 The NetBSD Foundation, Inc.
51.1Spooka * Copyright (c) 1999 The NetBSD Foundation, Inc.
61.1Spooka * All rights reserved.
71.1Spooka *
81.1Spooka * This code was written by Alessandro Forin and Neil Pittman
91.1Spooka * at Microsoft Research and contributed to The NetBSD Foundation
101.1Spooka * by Microsoft Corporation.
111.1Spooka *
121.1Spooka * Redistribution and use in source and binary forms, with or without
131.1Spooka * modification, are permitted provided that the following conditions
141.1Spooka * are met:
151.1Spooka * 1. Redistributions of source code must retain the above copyright
161.1Spooka *    notice, this list of conditions and the following disclaimer.
171.1Spooka * 2. Redistributions in binary form must reproduce the above copyright
181.1Spooka *    notice, this list of conditions and the following disclaimer in the
191.1Spooka *    documentation and/or other materials provided with the distribution.
201.1Spooka *
211.1Spooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
221.1Spooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
231.1Spooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
241.1Spooka * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
251.1Spooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
261.1Spooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
271.1Spooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
281.1Spooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
291.1Spooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
301.1Spooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
311.1Spooka * POSSIBILITY OF SUCH DAMAGE.
321.1Spooka */
331.1Spooka
341.1Spooka#include <sys/types.h>
351.1Spooka#include <machine/emipsreg.h>
361.1Spooka
371.1Spooka#include <stand/common/common.h>
381.1Spooka
391.1Spookalong
401.1Spookagetsecs()
411.1Spooka{
421.1Spooka    struct _Tc *Tc = (struct _Tc *)TIMER_DEFAULT_ADDRESS;
431.1Spooka	uint64_t now;
441.1Spooka    static int inited = 0;
451.1Spooka
461.1Spooka    if (!inited) {
471.1Spooka        inited = 1;
481.1Spooka        Tc->Control = TCCT_ENABLE;
491.1Spooka    }
501.1Spooka
511.1Spooka    /* starts from 0 at powerup, and counts up */
521.1Spooka	now = Tc->FreeRunning;
531.1Spooka#if 0
541.1Spooka    /* requires full 64bit math support */
551.1Spooka    now = now / 10*1000*1000;
561.1Spooka#else
571.1Spooka    /* good nuf */
581.1Spooka    now = now >> 23;
591.1Spooka#endif
601.1Spooka    return (long) now;
611.1Spooka}
62