1/**
2 * \file
3 * \brief Debug system calls shared by all architectures, user-side
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, 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, Universitaetstrasse 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
24errval_t sys_nop(void)
25{
26    return syscall1(SYSCALL_NOP).error;
27}
28
29errval_t sys_reboot(void)
30{
31    return syscall1(SYSCALL_REBOOT).error;
32}
33
34errval_t sys_debug_context_counter_reset(void)
35{
36    return syscall2(SYSCALL_DEBUG, DEBUG_CONTEXT_COUNTER_RESET).error;
37}
38
39errval_t sys_debug_context_counter_read(uint64_t *ret)
40{
41    struct sysret sr = syscall2(SYSCALL_DEBUG, DEBUG_CONTEXT_COUNTER_READ);
42    *ret = sr.value;
43    return sr.error;
44}
45
46errval_t sys_debug_print_context_counter(void)
47{
48    uint64_t val;
49    errval_t err = sys_debug_context_counter_read(&val);
50    if (err_is_ok(err)) {
51        printf("core %d: csc = %" PRIu64 "\n", disp_get_core_id(), val);
52    }
53    return err;
54}
55
56errval_t sys_debug_timeslice_counter_read(uint64_t *ret)
57{
58    struct sysret sr = syscall2(SYSCALL_DEBUG, DEBUG_TIMESLICE_COUNTER_READ);
59    *ret = sr.value;
60    return sr.error;
61}
62
63errval_t sys_debug_print_timeslice(void)
64{
65    uint64_t val;
66    errval_t err = sys_debug_timeslice_counter_read(&val);
67    if (err_is_ok(err)) {
68        printf("core %d: kernel_now = %" PRIu64 "\n", disp_get_core_id(), val);
69    }
70    return err;
71}
72
73errval_t sys_debug_flush_cache(void)
74{
75    return syscall2(SYSCALL_DEBUG, DEBUG_FLUSH_CACHE).error;
76}
77
78errval_t sys_debug_flush_tlb(void)
79{
80    return syscall2(SYSCALL_DEBUG, DEBUG_FLUSH_TLB).error;
81}
82
83errval_t sys_debug_send_ipi(uint8_t destination, uint8_t shorthand, uint8_t vector)
84{
85    return syscall5(SYSCALL_DEBUG,
86                   DEBUG_SEND_IPI, destination, shorthand, vector).error;
87}
88
89errval_t sys_debug_set_breakpoint(uintptr_t addr, uint8_t mode, uint8_t length)
90{
91    return syscall5(SYSCALL_DEBUG,
92                    DEBUG_SET_BREAKPOINT, addr, mode, length).error;
93}
94
95errval_t sys_debug_cap_trace_ctrl(uintptr_t types, genpaddr_t start, gensize_t size)
96{
97    return syscall5(SYSCALL_DEBUG,
98                    DEBUG_TRACE_PMEM_CTRL, types, start, size).error;
99}
100
101
102errval_t sys_debug_create_irq_src_cap(struct capref cap, uint64_t start,
103        uint64_t end)
104{
105    uint8_t dcn_level = get_cnode_level(cap);
106    capaddr_t dcn_addr = get_cnode_addr(cap);
107
108    struct sysret sr = syscall7(SYSCALL_DEBUG, DEBUG_CREATE_IRQ_SRC_CAP,
109                                dcn_level, dcn_addr, cap.slot, start, end);
110    return sr.error;
111}
112
113