]>
git.proxmox.com Git - mirror_qemu.git/blob - target-alpha/op_helper.c
6711d998b96b0c4e10b6e50b8d3cd6c86c90c5c0
2 * Alpha emulation cpu micro-operations helpers for qemu.
4 * Copyright (c) 2007 Jocelyn Mayer
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.
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.
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/>.
21 #include "dyngen-exec.h"
22 #include "host-utils.h"
23 #include "softfloat.h"
26 #include "qemu-timer.h"
28 /*****************************************************************************/
29 /* Exceptions processing helpers */
31 uint64_t helper_load_pcc (void)
33 #ifndef CONFIG_USER_ONLY
34 /* In system mode we have access to a decent high-resolution clock.
35 In order to make OS-level time accounting work with the RPCC,
36 present it with a well-timed clock fixed at 250MHz. */
37 return (((uint64_t)env
->pcc_ofs
<< 32)
38 | (uint32_t)(qemu_get_clock_ns(vm_clock
) >> 2));
40 /* In user-mode, vm_clock doesn't exist. Just pass through the host cpu
41 clock ticks. Also, don't bother taking PCC_OFS into account. */
42 return (uint32_t)cpu_get_real_ticks();
46 uint64_t helper_load_fpcr (void)
48 return cpu_alpha_load_fpcr (env
);
51 void helper_store_fpcr (uint64_t val
)
53 cpu_alpha_store_fpcr (env
, val
);
56 uint64_t helper_addqv (uint64_t op1
, uint64_t op2
)
60 if (unlikely((tmp
^ op2
^ (-1ULL)) & (tmp
^ op1
) & (1ULL << 63))) {
61 arith_excp(env
, GETPC(), EXC_M_IOV
, 0);
66 uint64_t helper_addlv (uint64_t op1
, uint64_t op2
)
69 op1
= (uint32_t)(op1
+ op2
);
70 if (unlikely((tmp
^ op2
^ (-1UL)) & (tmp
^ op1
) & (1UL << 31))) {
71 arith_excp(env
, GETPC(), EXC_M_IOV
, 0);
76 uint64_t helper_subqv (uint64_t op1
, uint64_t op2
)
80 if (unlikely((op1
^ op2
) & (res
^ op1
) & (1ULL << 63))) {
81 arith_excp(env
, GETPC(), EXC_M_IOV
, 0);
86 uint64_t helper_sublv (uint64_t op1
, uint64_t op2
)
90 if (unlikely((op1
^ op2
) & (res
^ op1
) & (1UL << 31))) {
91 arith_excp(env
, GETPC(), EXC_M_IOV
, 0);
96 uint64_t helper_mullv (uint64_t op1
, uint64_t op2
)
98 int64_t res
= (int64_t)op1
* (int64_t)op2
;
100 if (unlikely((int32_t)res
!= res
)) {
101 arith_excp(env
, GETPC(), EXC_M_IOV
, 0);
103 return (int64_t)((int32_t)res
);
106 uint64_t helper_mulqv (uint64_t op1
, uint64_t op2
)
110 muls64(&tl
, &th
, op1
, op2
);
111 /* If th != 0 && th != -1, then we had an overflow */
112 if (unlikely((th
+ 1) > 1)) {
113 arith_excp(env
, GETPC(), EXC_M_IOV
, 0);
118 /* PALcode support special instructions */
119 #if !defined (CONFIG_USER_ONLY)
120 void helper_hw_ret (uint64_t a
)
127 swap_shadow_regs(env
);
131 void helper_tbia(void)
136 void helper_tbis(uint64_t p
)
138 tlb_flush_page(env
, p
);
141 void helper_halt(uint64_t restart
)
144 qemu_system_reset_request();
146 qemu_system_shutdown_request();
150 uint64_t helper_get_time(void)
152 return qemu_get_clock_ns(rtc_clock
);
155 void helper_set_alarm(uint64_t expire
)
158 env
->alarm_expire
= expire
;
159 qemu_mod_timer(env
->alarm_timer
, expire
);
161 qemu_del_timer(env
->alarm_timer
);
166 /*****************************************************************************/
167 /* Softmmu support */
168 #if !defined (CONFIG_USER_ONLY)
169 uint64_t helper_ldl_phys(uint64_t p
)
171 return (int32_t)ldl_phys(p
);
174 uint64_t helper_ldq_phys(uint64_t p
)
179 uint64_t helper_ldl_l_phys(uint64_t p
)
182 return env
->lock_value
= (int32_t)ldl_phys(p
);
185 uint64_t helper_ldq_l_phys(uint64_t p
)
188 return env
->lock_value
= ldl_phys(p
);
191 void helper_stl_phys(uint64_t p
, uint64_t v
)
196 void helper_stq_phys(uint64_t p
, uint64_t v
)
201 uint64_t helper_stl_c_phys(uint64_t p
, uint64_t v
)
205 if (p
== env
->lock_addr
) {
206 int32_t old
= ldl_phys(p
);
207 if (old
== (int32_t)env
->lock_value
) {
217 uint64_t helper_stq_c_phys(uint64_t p
, uint64_t v
)
221 if (p
== env
->lock_addr
) {
222 uint64_t old
= ldq_phys(p
);
223 if (old
== env
->lock_value
) {
233 static void QEMU_NORETURN
do_unaligned_access(target_ulong addr
, int is_write
,
234 int is_user
, void *retaddr
)
239 do_restore_state(env
, retaddr
);
244 env
->trap_arg0
= addr
;
245 env
->trap_arg1
= insn
>> 26; /* opcode */
246 env
->trap_arg2
= (insn
>> 21) & 31; /* dest regno */
247 env
->exception_index
= EXCP_UNALIGN
;
252 void QEMU_NORETURN
cpu_unassigned_access(CPUAlphaState
*env1
,
253 target_phys_addr_t addr
, int is_write
,
254 int is_exec
, int unused
, int size
)
257 env
->trap_arg0
= addr
;
258 env
->trap_arg1
= is_write
;
259 dynamic_excp(env1
, GETPC(), EXCP_MCHK
, 0);
262 #include "softmmu_exec.h"
264 #define MMUSUFFIX _mmu
268 #include "softmmu_template.h"
271 #include "softmmu_template.h"
274 #include "softmmu_template.h"
277 #include "softmmu_template.h"
279 /* try to fill the TLB and return an exception if error. If retaddr is
280 NULL, it means that the function was called in C code (i.e. not
281 from generated code or from helper.c) */
282 /* XXX: fix it to restore all registers */
283 void tlb_fill(CPUAlphaState
*env1
, target_ulong addr
, int is_write
, int mmu_idx
,
286 CPUAlphaState
*saved_env
;
291 ret
= cpu_alpha_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
292 if (unlikely(ret
!= 0)) {
293 do_restore_state(env
, retaddr
);
294 /* Exception index and error code are already set */