Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 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 "cpu.h" |
| 21 | #include "helper.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 22 | #include "sysemu/sysemu.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 23 | #include "qemu/timer.h" |
Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 24 | |
| 25 | |
| 26 | uint64_t helper_load_pcc(CPUAlphaState *env) |
| 27 | { |
| 28 | #ifndef CONFIG_USER_ONLY |
| 29 | /* In system mode we have access to a decent high-resolution clock. |
| 30 | In order to make OS-level time accounting work with the RPCC, |
| 31 | present it with a well-timed clock fixed at 250MHz. */ |
| 32 | return (((uint64_t)env->pcc_ofs << 32) |
| 33 | | (uint32_t)(qemu_get_clock_ns(vm_clock) >> 2)); |
| 34 | #else |
| 35 | /* In user-mode, vm_clock doesn't exist. Just pass through the host cpu |
| 36 | clock ticks. Also, don't bother taking PCC_OFS into account. */ |
| 37 | return (uint32_t)cpu_get_real_ticks(); |
| 38 | #endif |
| 39 | } |
| 40 | |
| 41 | /* PALcode support special instructions */ |
| 42 | #ifndef CONFIG_USER_ONLY |
| 43 | void helper_hw_ret(CPUAlphaState *env, uint64_t a) |
| 44 | { |
| 45 | env->pc = a & ~3; |
| 46 | env->intr_flag = 0; |
| 47 | env->lock_addr = -1; |
| 48 | if ((a & 1) == 0) { |
| 49 | env->pal_mode = 0; |
| 50 | swap_shadow_regs(env); |
| 51 | } |
| 52 | } |
| 53 | |
Richard Henderson | ba96394 | 2013-07-26 11:22:21 -1000 | [diff] [blame] | 54 | void helper_call_pal(CPUAlphaState *env, uint64_t pc, uint64_t entry_ofs) |
| 55 | { |
| 56 | int pal_mode = env->pal_mode; |
| 57 | env->exc_addr = pc | pal_mode; |
| 58 | env->pc = env->palbr + entry_ofs; |
| 59 | if (!pal_mode) { |
| 60 | env->pal_mode = 1; |
| 61 | swap_shadow_regs(env); |
| 62 | } |
| 63 | } |
| 64 | |
Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 65 | void helper_tbia(CPUAlphaState *env) |
| 66 | { |
| 67 | tlb_flush(env, 1); |
| 68 | } |
| 69 | |
| 70 | void helper_tbis(CPUAlphaState *env, uint64_t p) |
| 71 | { |
| 72 | tlb_flush_page(env, p); |
| 73 | } |
| 74 | |
Richard Henderson | a9ead83 | 2013-07-26 12:00:32 -1000 | [diff] [blame^] | 75 | void helper_tb_flush(CPUAlphaState *env) |
| 76 | { |
| 77 | tb_flush(env); |
| 78 | } |
| 79 | |
Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 80 | void helper_halt(uint64_t restart) |
| 81 | { |
| 82 | if (restart) { |
| 83 | qemu_system_reset_request(); |
| 84 | } else { |
| 85 | qemu_system_shutdown_request(); |
| 86 | } |
| 87 | } |
| 88 | |
Richard Henderson | 19e0cbb | 2013-07-16 06:45:57 -0700 | [diff] [blame] | 89 | uint64_t helper_get_vmtime(void) |
| 90 | { |
| 91 | return qemu_get_clock_ns(vm_clock); |
| 92 | } |
| 93 | |
| 94 | uint64_t helper_get_walltime(void) |
Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 95 | { |
| 96 | return qemu_get_clock_ns(rtc_clock); |
| 97 | } |
| 98 | |
| 99 | void helper_set_alarm(CPUAlphaState *env, uint64_t expire) |
| 100 | { |
Andreas Färber | c924585 | 2012-10-31 02:41:11 +0100 | [diff] [blame] | 101 | AlphaCPU *cpu = alpha_env_get_cpu(env); |
| 102 | |
Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 103 | if (expire) { |
| 104 | env->alarm_expire = expire; |
Andreas Färber | c924585 | 2012-10-31 02:41:11 +0100 | [diff] [blame] | 105 | qemu_mod_timer(cpu->alarm_timer, expire); |
Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 106 | } else { |
Andreas Färber | c924585 | 2012-10-31 02:41:11 +0100 | [diff] [blame] | 107 | qemu_del_timer(cpu->alarm_timer); |
Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 108 | } |
| 109 | } |
Richard Henderson | ba96394 | 2013-07-26 11:22:21 -1000 | [diff] [blame] | 110 | |
Richard Henderson | 69163fb | 2012-03-24 09:51:12 -0700 | [diff] [blame] | 111 | #endif /* CONFIG_USER_ONLY */ |