xref: /openbmc/qemu/target/alpha/sys_helper.c (revision 243975c0)
1 /*
2  *  Helpers for system instructions.
3  *
4  *  Copyright (c) 2007 Jocelyn Mayer
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "qemu/osdep.h"
21 #include "cpu.h"
22 #include "exec/exec-all.h"
23 #include "exec/tb-flush.h"
24 #include "exec/helper-proto.h"
25 #include "sysemu/runstate.h"
26 #include "sysemu/sysemu.h"
27 #include "qemu/timer.h"
28 
29 
30 uint64_t helper_load_pcc(CPUAlphaState *env)
31 {
32 #ifndef CONFIG_USER_ONLY
33     /* In system mode we have access to a decent high-resolution clock.
34        In order to make OS-level time accounting work with the RPCC,
35        present it with a well-timed clock fixed at 250MHz.  */
36     return (((uint64_t)env->pcc_ofs << 32)
37             | (uint32_t)(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) >> 2));
38 #else
39     /* In user-mode, QEMU_CLOCK_VIRTUAL doesn't exist.  Just pass through the host cpu
40        clock ticks.  Also, don't bother taking PCC_OFS into account.  */
41     return (uint32_t)cpu_get_host_ticks();
42 #endif
43 }
44 
45 /* PALcode support special instructions */
46 #ifndef CONFIG_USER_ONLY
47 void helper_tbia(CPUAlphaState *env)
48 {
49     tlb_flush(env_cpu(env));
50 }
51 
52 void helper_tbis(CPUAlphaState *env, uint64_t p)
53 {
54     tlb_flush_page(env_cpu(env), p);
55 }
56 
57 void helper_tb_flush(CPUAlphaState *env)
58 {
59     tb_flush(env_cpu(env));
60 }
61 
62 void helper_halt(uint64_t restart)
63 {
64     if (restart) {
65         qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
66     } else {
67         qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
68     }
69 }
70 
71 uint64_t helper_get_vmtime(void)
72 {
73     return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
74 }
75 
76 uint64_t helper_get_walltime(void)
77 {
78     return qemu_clock_get_ns(rtc_clock);
79 }
80 
81 void helper_set_alarm(CPUAlphaState *env, uint64_t expire)
82 {
83     AlphaCPU *cpu = env_archcpu(env);
84 
85     if (expire) {
86         env->alarm_expire = expire;
87         timer_mod(cpu->alarm_timer, expire);
88     } else {
89         timer_del(cpu->alarm_timer);
90     }
91 }
92 
93 #endif /* CONFIG_USER_ONLY */
94