2 * Helpers for HPPA instructions.
4 * Copyright (c) 2016 Richard Henderson <rth@twiddle.net>
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.
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/>.
20 #include "qemu/osdep.h"
23 #include "exec/exec-all.h"
24 #include "exec/helper-proto.h"
25 #include "exec/cpu_ldst.h"
26 #include "qemu/timer.h"
29 G_NORETURN
void HELPER(excp
)(CPUHPPAState
*env
, int excp
)
31 CPUState
*cs
= env_cpu(env
);
33 cs
->exception_index
= excp
;
37 G_NORETURN
void hppa_dynamic_excp(CPUHPPAState
*env
, int excp
, uintptr_t ra
)
39 CPUState
*cs
= env_cpu(env
);
41 cs
->exception_index
= excp
;
42 cpu_loop_exit_restore(cs
, ra
);
45 void HELPER(tsv
)(CPUHPPAState
*env
, target_ureg cond
)
47 if (unlikely((target_sreg
)cond
< 0)) {
48 hppa_dynamic_excp(env
, EXCP_OVERFLOW
, GETPC());
52 void HELPER(tcond
)(CPUHPPAState
*env
, target_ureg cond
)
55 hppa_dynamic_excp(env
, EXCP_COND
, GETPC());
59 static void atomic_store_3(CPUHPPAState
*env
, target_ulong addr
,
60 uint32_t val
, uintptr_t ra
)
62 int mmu_idx
= cpu_mmu_index(env
, 0);
63 uint32_t old
, new, cmp
, mask
, *haddr
;
66 vaddr
= probe_access(env
, addr
, 3, MMU_DATA_STORE
, mmu_idx
, ra
);
68 cpu_loop_exit_atomic(env_cpu(env
), ra
);
70 haddr
= (uint32_t *)((uintptr_t)vaddr
& -4);
71 mask
= addr
& 1 ? 0x00ffffffu
: 0xffffff00u
;
75 new = be32_to_cpu((cpu_to_be32(old
) & ~mask
) | (val
& mask
));
76 cmp
= qatomic_cmpxchg(haddr
, old
, new);
84 static void do_stby_b(CPUHPPAState
*env
, target_ulong addr
, target_ureg val
,
85 bool parallel
, uintptr_t ra
)
89 cpu_stb_data_ra(env
, addr
, val
, ra
);
92 cpu_stw_data_ra(env
, addr
, val
, ra
);
95 /* The 3 byte store must appear atomic. */
97 atomic_store_3(env
, addr
, val
, ra
);
99 cpu_stb_data_ra(env
, addr
, val
>> 16, ra
);
100 cpu_stw_data_ra(env
, addr
+ 1, val
, ra
);
104 cpu_stl_data_ra(env
, addr
, val
, ra
);
109 void HELPER(stby_b
)(CPUHPPAState
*env
, target_ulong addr
, target_ureg val
)
111 do_stby_b(env
, addr
, val
, false, GETPC());
114 void HELPER(stby_b_parallel
)(CPUHPPAState
*env
, target_ulong addr
,
117 do_stby_b(env
, addr
, val
, true, GETPC());
120 static void do_stby_e(CPUHPPAState
*env
, target_ulong addr
, target_ureg val
,
121 bool parallel
, uintptr_t ra
)
125 /* The 3 byte store must appear atomic. */
127 atomic_store_3(env
, addr
- 3, val
, ra
);
129 cpu_stw_data_ra(env
, addr
- 3, val
>> 16, ra
);
130 cpu_stb_data_ra(env
, addr
- 1, val
>> 8, ra
);
134 cpu_stw_data_ra(env
, addr
- 2, val
>> 16, ra
);
137 cpu_stb_data_ra(env
, addr
- 1, val
>> 24, ra
);
140 /* Nothing is stored, but protection is checked and the
141 cacheline is marked dirty. */
142 probe_write(env
, addr
, 0, cpu_mmu_index(env
, 0), ra
);
147 void HELPER(stby_e
)(CPUHPPAState
*env
, target_ulong addr
, target_ureg val
)
149 do_stby_e(env
, addr
, val
, false, GETPC());
152 void HELPER(stby_e_parallel
)(CPUHPPAState
*env
, target_ulong addr
,
155 do_stby_e(env
, addr
, val
, true, GETPC());
158 void HELPER(ldc_check
)(target_ulong addr
)
160 if (unlikely(addr
& 0xf)) {
161 qemu_log_mask(LOG_GUEST_ERROR
,
162 "Undefined ldc to unaligned address mod 16: "
163 TARGET_FMT_lx
"\n", addr
);
167 target_ureg
HELPER(probe
)(CPUHPPAState
*env
, target_ulong addr
,
168 uint32_t level
, uint32_t want
)
170 #ifdef CONFIG_USER_ONLY
171 return (page_check_range(addr
, 1, want
) == 0) ? 1 : 0;
176 trace_hppa_tlb_probe(addr
, level
, want
);
177 /* Fail if the requested privilege level is higher than current. */
178 if (level
< (env
->iaoq_f
& 3)) {
182 excp
= hppa_get_physical_address(env
, addr
, level
, 0, &phys
, &prot
);
184 if (env
->psw
& PSW_Q
) {
185 /* ??? Needs tweaking for hppa64. */
186 env
->cr
[CR_IOR
] = addr
;
187 env
->cr
[CR_ISR
] = addr
>> 32;
189 if (excp
== EXCP_DTLB_MISS
) {
190 excp
= EXCP_NA_DTLB_MISS
;
192 hppa_dynamic_excp(env
, excp
, GETPC());
194 return (want
& prot
) != 0;
198 target_ureg
HELPER(read_interval_timer
)(void)
200 #ifdef CONFIG_USER_ONLY
201 /* In user-mode, QEMU_CLOCK_VIRTUAL doesn't exist.
202 Just pass through the host cpu clock ticks. */
203 return cpu_get_host_ticks();
205 /* In system mode we have access to a decent high-resolution clock.
206 In order to make OS-level time accounting work with the cr16,
207 present it with a well-timed clock fixed at 250MHz. */
208 return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) >> 2;