xref: /openbmc/qemu/target/alpha/sys_helper.c (revision 503bb0b9)
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 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/helper-proto.h"
24 #include "sysemu/sysemu.h"
25 #include "qemu/timer.h"
26 
27 
28 uint64_t helper_load_pcc(CPUAlphaState *env)
29 {
30 #ifndef CONFIG_USER_ONLY
31     /* In system mode we have access to a decent high-resolution clock.
32        In order to make OS-level time accounting work with the RPCC,
33        present it with a well-timed clock fixed at 250MHz.  */
34     return (((uint64_t)env->pcc_ofs << 32)
35             | (uint32_t)(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) >> 2));
36 #else
37     /* In user-mode, QEMU_CLOCK_VIRTUAL doesn't exist.  Just pass through the host cpu
38        clock ticks.  Also, don't bother taking PCC_OFS into account.  */
39     return (uint32_t)cpu_get_host_ticks();
40 #endif
41 }
42 
43 /* PALcode support special instructions */
44 #ifndef CONFIG_USER_ONLY
45 void helper_tbia(CPUAlphaState *env)
46 {
47     tlb_flush(CPU(alpha_env_get_cpu(env)));
48 }
49 
50 void helper_tbis(CPUAlphaState *env, uint64_t p)
51 {
52     tlb_flush_page(CPU(alpha_env_get_cpu(env)), p);
53 }
54 
55 void helper_tb_flush(CPUAlphaState *env)
56 {
57     tb_flush(CPU(alpha_env_get_cpu(env)));
58 }
59 
60 void helper_halt(uint64_t restart)
61 {
62     if (restart) {
63         qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
64     } else {
65         qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
66     }
67 }
68 
69 uint64_t helper_get_vmtime(void)
70 {
71     return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
72 }
73 
74 uint64_t helper_get_walltime(void)
75 {
76     return qemu_clock_get_ns(rtc_clock);
77 }
78 
79 void helper_set_alarm(CPUAlphaState *env, uint64_t expire)
80 {
81     AlphaCPU *cpu = alpha_env_get_cpu(env);
82 
83     if (expire) {
84         env->alarm_expire = expire;
85         timer_mod(cpu->alarm_timer, expire);
86     } else {
87         timer_del(cpu->alarm_timer);
88     }
89 }
90 
91 #endif /* CONFIG_USER_ONLY */
92