Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / clients / net-snk / kernel / timer.c
1 /******************************************************************************
2  * Copyright (c) 2004, 2008 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12
13 #include <stdint.h>
14 #include "kernel.h"
15
16 //*******************************************************************
17 // variable "tb_freq" contains the frequency in Hz
18 // and is read from the device tree (setup by LLFW) in "init.c"
19 uint64_t tb_freq;
20
21 //-------------------------------------------------------------------
22 // Read the current timebase
23 uint64_t get_time(void)
24 {
25     uint64_t act;
26
27     __asm__ __volatile__( 
28         "0:     mftbu   %0 ;\
29                 mftbl   %%r0 ; \
30                 mftbu   %%r4 ; \
31                 cmpw    %0,%%r4 ; \
32                 bne     0b; \
33                 sldi    %0,%0,32; \
34                 or      %0,%0,%%r0"
35         : "=r"(act)
36         : /* no inputs */
37         : "r0", "r4");
38     return act;
39 }