1/**
2 * \file
3 * \brief Debug system calls, user-side
4 */
5
6/*
7 * Copyright (c) 2007-2010, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <barrelfish/barrelfish.h>
16#include <barrelfish/dispatch.h>
17#include <barrelfish/syscall_arch.h>
18#include <barrelfish_kpi/sys_debug.h>
19#include <barrelfish/sys_debug.h>
20#include <stdio.h>
21#include <inttypes.h>
22
23/* XXX - should be merged with timer_hertz_read. */
24errval_t sys_debug_get_tsc_per_ms(uint64_t *ret)
25{
26    struct sysret sr = syscall2(SYSCALL_DEBUG, DEBUG_GET_TSC_PER_MS);
27    *ret = sr.value;
28    return sr.error;
29}
30
31errval_t sys_debug_hardware_timer_read(uintptr_t* v)
32{
33    struct sysret sr
34        = syscall2(SYSCALL_DEBUG, DEBUG_HARDWARE_TIMER_READ);
35    *v = sr.value;
36    return sr.error;
37}
38
39errval_t sys_debug_hardware_timer_hertz_read(uintptr_t* v)
40{
41    struct sysret sr
42        = syscall2(SYSCALL_DEBUG, DEBUG_HARDWARE_TIMER_HERTZ_READ);
43    *v = sr.value;
44    return sr.error;
45}
46
47errval_t sys_debug_hardware_global_timer_read(uint64_t *ret)
48{
49    struct sysret sr;
50
51    uint32_t l, h;
52
53    do {
54        h = syscall2(SYSCALL_DEBUG, DEBUG_HARDWARE_GLOBAL_TIMER_HIGH).value;
55        l = syscall2(SYSCALL_DEBUG, DEBUG_HARDWARE_GLOBAL_TIMER_LOW).value;
56        // read high again, in case it changed
57        sr = syscall2(SYSCALL_DEBUG, DEBUG_HARDWARE_GLOBAL_TIMER_HIGH);
58    } while(h != sr.value && err_is_ok(sr.error));
59
60    if(err_is_ok(sr.error) && ret) {
61        *ret = (((uint64_t) h) << 32) | ((uint32_t) l);
62    }
63
64    return sr.error;
65}
66
67