11.2Schristos/*      $NetBSD: clock.c,v 1.2 2014/02/24 22:31:56 christos 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.2Schristos#include <lib/libsa/net.h>
371.1Spooka
381.1Spooka#include <stand/common/common.h>
391.1Spooka
401.2Schristossatime_t
411.2Schristosgetsecs(void)
421.1Spooka{
431.1Spooka    struct _Tc *Tc = (struct _Tc *)TIMER_DEFAULT_ADDRESS;
441.1Spooka	uint64_t now;
451.1Spooka    static int inited = 0;
461.1Spooka
471.1Spooka    if (!inited) {
481.1Spooka        inited = 1;
491.1Spooka        Tc->Control = TCCT_ENABLE;
501.1Spooka    }
511.1Spooka
521.1Spooka    /* starts from 0 at powerup, and counts up */
531.1Spooka	now = Tc->FreeRunning;
541.1Spooka#if 0
551.1Spooka    /* requires full 64bit math support */
561.1Spooka    now = now / 10*1000*1000;
571.1Spooka#else
581.1Spooka    /* good nuf */
591.1Spooka    now = now >> 23;
601.1Spooka#endif
611.1Spooka    return (long) now;
621.1Spooka}
63