2 * Routines common to user and system emulation of load/store.
4 * Copyright (c) 2003 Fabrice Bellard
6 * SPDX-License-Identifier: GPL-2.0-or-later
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
12 * Load helpers for tcg-ldst.h
15 tcg_target_ulong helper_ldub_mmu(CPUArchState *env, uint64_t addr,
16 MemOpIdx oi, uintptr_t retaddr)
18 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_8);
19 return do_ld1_mmu(env_cpu(env), addr, oi, retaddr, MMU_DATA_LOAD);
22 tcg_target_ulong helper_lduw_mmu(CPUArchState *env, uint64_t addr,
23 MemOpIdx oi, uintptr_t retaddr)
25 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_16);
26 return do_ld2_mmu(env_cpu(env), addr, oi, retaddr, MMU_DATA_LOAD);
29 tcg_target_ulong helper_ldul_mmu(CPUArchState *env, uint64_t addr,
30 MemOpIdx oi, uintptr_t retaddr)
32 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_32);
33 return do_ld4_mmu(env_cpu(env), addr, oi, retaddr, MMU_DATA_LOAD);
36 uint64_t helper_ldq_mmu(CPUArchState *env, uint64_t addr,
37 MemOpIdx oi, uintptr_t retaddr)
39 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_64);
40 return do_ld8_mmu(env_cpu(env), addr, oi, retaddr, MMU_DATA_LOAD);
44 * Provide signed versions of the load routines as well. We can of course
45 * avoid this for 64-bit data, or for 32-bit data on 32-bit host.
48 tcg_target_ulong helper_ldsb_mmu(CPUArchState *env, uint64_t addr,
49 MemOpIdx oi, uintptr_t retaddr)
51 return (int8_t)helper_ldub_mmu(env, addr, oi, retaddr);
54 tcg_target_ulong helper_ldsw_mmu(CPUArchState *env, uint64_t addr,
55 MemOpIdx oi, uintptr_t retaddr)
57 return (int16_t)helper_lduw_mmu(env, addr, oi, retaddr);
60 tcg_target_ulong helper_ldsl_mmu(CPUArchState *env, uint64_t addr,
61 MemOpIdx oi, uintptr_t retaddr)
63 return (int32_t)helper_ldul_mmu(env, addr, oi, retaddr);
66 Int128 helper_ld16_mmu(CPUArchState *env, uint64_t addr,
67 MemOpIdx oi, uintptr_t retaddr)
69 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_128);
70 return do_ld16_mmu(env_cpu(env), addr, oi, retaddr);
73 Int128 helper_ld_i128(CPUArchState *env, uint64_t addr, uint32_t oi)
75 return helper_ld16_mmu(env, addr, oi, GETPC());
79 * Store helpers for tcg-ldst.h
82 void helper_stb_mmu(CPUArchState *env, uint64_t addr, uint32_t val,
83 MemOpIdx oi, uintptr_t ra)
85 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_8);
86 do_st1_mmu(env_cpu(env), addr, val, oi, ra);
89 void helper_stw_mmu(CPUArchState *env, uint64_t addr, uint32_t val,
90 MemOpIdx oi, uintptr_t retaddr)
92 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_16);
93 do_st2_mmu(env_cpu(env), addr, val, oi, retaddr);
96 void helper_stl_mmu(CPUArchState *env, uint64_t addr, uint32_t val,
97 MemOpIdx oi, uintptr_t retaddr)
99 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_32);
100 do_st4_mmu(env_cpu(env), addr, val, oi, retaddr);
103 void helper_stq_mmu(CPUArchState *env, uint64_t addr, uint64_t val,
104 MemOpIdx oi, uintptr_t retaddr)
106 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_64);
107 do_st8_mmu(env_cpu(env), addr, val, oi, retaddr);
110 void helper_st16_mmu(CPUArchState *env, uint64_t addr, Int128 val,
111 MemOpIdx oi, uintptr_t retaddr)
113 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_128);
114 do_st16_mmu(env_cpu(env), addr, val, oi, retaddr);
117 void helper_st_i128(CPUArchState *env, uint64_t addr, Int128 val, MemOpIdx oi)
119 helper_st16_mmu(env, addr, val, oi, GETPC());
123 * Load helpers for cpu_ldst.h
126 static void plugin_load_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi)
128 qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R);
131 uint8_t cpu_ldb_mmu(CPUArchState *env, abi_ptr addr, MemOpIdx oi, uintptr_t ra)
135 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_UB);
136 ret = do_ld1_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD);
137 plugin_load_cb(env, addr, oi);
141 uint16_t cpu_ldw_mmu(CPUArchState *env, abi_ptr addr,
142 MemOpIdx oi, uintptr_t ra)
146 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_16);
147 ret = do_ld2_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD);
148 plugin_load_cb(env, addr, oi);
152 uint32_t cpu_ldl_mmu(CPUArchState *env, abi_ptr addr,
153 MemOpIdx oi, uintptr_t ra)
157 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_32);
158 ret = do_ld4_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD);
159 plugin_load_cb(env, addr, oi);
163 uint64_t cpu_ldq_mmu(CPUArchState *env, abi_ptr addr,
164 MemOpIdx oi, uintptr_t ra)
168 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_64);
169 ret = do_ld8_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD);
170 plugin_load_cb(env, addr, oi);
174 Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr,
175 MemOpIdx oi, uintptr_t ra)
179 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_128);
180 ret = do_ld16_mmu(env_cpu(env), addr, oi, ra);
181 plugin_load_cb(env, addr, oi);
186 * Store helpers for cpu_ldst.h
189 static void plugin_store_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi)
191 qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W);
194 void cpu_stb_mmu(CPUArchState *env, abi_ptr addr, uint8_t val,
195 MemOpIdx oi, uintptr_t retaddr)
197 helper_stb_mmu(env, addr, val, oi, retaddr);
198 plugin_store_cb(env, addr, oi);
201 void cpu_stw_mmu(CPUArchState *env, abi_ptr addr, uint16_t val,
202 MemOpIdx oi, uintptr_t retaddr)
204 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_16);
205 do_st2_mmu(env_cpu(env), addr, val, oi, retaddr);
206 plugin_store_cb(env, addr, oi);
209 void cpu_stl_mmu(CPUArchState *env, abi_ptr addr, uint32_t val,
210 MemOpIdx oi, uintptr_t retaddr)
212 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_32);
213 do_st4_mmu(env_cpu(env), addr, val, oi, retaddr);
214 plugin_store_cb(env, addr, oi);
217 void cpu_stq_mmu(CPUArchState *env, abi_ptr addr, uint64_t val,
218 MemOpIdx oi, uintptr_t retaddr)
220 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_64);
221 do_st8_mmu(env_cpu(env), addr, val, oi, retaddr);
222 plugin_store_cb(env, addr, oi);
225 void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int128 val,
226 MemOpIdx oi, uintptr_t retaddr)
228 tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_128);
229 do_st16_mmu(env_cpu(env), addr, val, oi, retaddr);
230 plugin_store_cb(env, addr, oi);
234 * Wrappers of the above
237 uint32_t cpu_ldub_mmuidx_ra(CPUArchState *env, abi_ptr addr,
238 int mmu_idx, uintptr_t ra)
240 MemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);
241 return cpu_ldb_mmu(env, addr, oi, ra);
244 int cpu_ldsb_mmuidx_ra(CPUArchState *env, abi_ptr addr,
245 int mmu_idx, uintptr_t ra)
247 return (int8_t)cpu_ldub_mmuidx_ra(env, addr, mmu_idx, ra);
250 uint32_t cpu_lduw_be_mmuidx_ra(CPUArchState *env, abi_ptr addr,
251 int mmu_idx, uintptr_t ra)
253 MemOpIdx oi = make_memop_idx(MO_BEUW | MO_UNALN, mmu_idx);
254 return cpu_ldw_mmu(env, addr, oi, ra);
257 int cpu_ldsw_be_mmuidx_ra(CPUArchState *env, abi_ptr addr,
258 int mmu_idx, uintptr_t ra)
260 return (int16_t)cpu_lduw_be_mmuidx_ra(env, addr, mmu_idx, ra);
263 uint32_t cpu_ldl_be_mmuidx_ra(CPUArchState *env, abi_ptr addr,
264 int mmu_idx, uintptr_t ra)
266 MemOpIdx oi = make_memop_idx(MO_BEUL | MO_UNALN, mmu_idx);
267 return cpu_ldl_mmu(env, addr, oi, ra);
270 uint64_t cpu_ldq_be_mmuidx_ra(CPUArchState *env, abi_ptr addr,
271 int mmu_idx, uintptr_t ra)
273 MemOpIdx oi = make_memop_idx(MO_BEUQ | MO_UNALN, mmu_idx);
274 return cpu_ldq_mmu(env, addr, oi, ra);
277 uint32_t cpu_lduw_le_mmuidx_ra(CPUArchState *env, abi_ptr addr,
278 int mmu_idx, uintptr_t ra)
280 MemOpIdx oi = make_memop_idx(MO_LEUW | MO_UNALN, mmu_idx);
281 return cpu_ldw_mmu(env, addr, oi, ra);
284 int cpu_ldsw_le_mmuidx_ra(CPUArchState *env, abi_ptr addr,
285 int mmu_idx, uintptr_t ra)
287 return (int16_t)cpu_lduw_le_mmuidx_ra(env, addr, mmu_idx, ra);
290 uint32_t cpu_ldl_le_mmuidx_ra(CPUArchState *env, abi_ptr addr,
291 int mmu_idx, uintptr_t ra)
293 MemOpIdx oi = make_memop_idx(MO_LEUL | MO_UNALN, mmu_idx);
294 return cpu_ldl_mmu(env, addr, oi, ra);
297 uint64_t cpu_ldq_le_mmuidx_ra(CPUArchState *env, abi_ptr addr,
298 int mmu_idx, uintptr_t ra)
300 MemOpIdx oi = make_memop_idx(MO_LEUQ | MO_UNALN, mmu_idx);
301 return cpu_ldq_mmu(env, addr, oi, ra);
304 void cpu_stb_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val,
305 int mmu_idx, uintptr_t ra)
307 MemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);
308 cpu_stb_mmu(env, addr, val, oi, ra);
311 void cpu_stw_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val,
312 int mmu_idx, uintptr_t ra)
314 MemOpIdx oi = make_memop_idx(MO_BEUW | MO_UNALN, mmu_idx);
315 cpu_stw_mmu(env, addr, val, oi, ra);
318 void cpu_stl_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val,
319 int mmu_idx, uintptr_t ra)
321 MemOpIdx oi = make_memop_idx(MO_BEUL | MO_UNALN, mmu_idx);
322 cpu_stl_mmu(env, addr, val, oi, ra);
325 void cpu_stq_be_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint64_t val,
326 int mmu_idx, uintptr_t ra)
328 MemOpIdx oi = make_memop_idx(MO_BEUQ | MO_UNALN, mmu_idx);
329 cpu_stq_mmu(env, addr, val, oi, ra);
332 void cpu_stw_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val,
333 int mmu_idx, uintptr_t ra)
335 MemOpIdx oi = make_memop_idx(MO_LEUW | MO_UNALN, mmu_idx);
336 cpu_stw_mmu(env, addr, val, oi, ra);
339 void cpu_stl_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint32_t val,
340 int mmu_idx, uintptr_t ra)
342 MemOpIdx oi = make_memop_idx(MO_LEUL | MO_UNALN, mmu_idx);
343 cpu_stl_mmu(env, addr, val, oi, ra);
346 void cpu_stq_le_mmuidx_ra(CPUArchState *env, abi_ptr addr, uint64_t val,
347 int mmu_idx, uintptr_t ra)
349 MemOpIdx oi = make_memop_idx(MO_LEUQ | MO_UNALN, mmu_idx);
350 cpu_stq_mmu(env, addr, val, oi, ra);
353 /*--------------------------*/
355 uint32_t cpu_ldub_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
357 int mmu_index = cpu_mmu_index(env_cpu(env), false);
358 return cpu_ldub_mmuidx_ra(env, addr, mmu_index, ra);
361 int cpu_ldsb_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
363 return (int8_t)cpu_ldub_data_ra(env, addr, ra);
366 uint32_t cpu_lduw_be_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
368 int mmu_index = cpu_mmu_index(env_cpu(env), false);
369 return cpu_lduw_be_mmuidx_ra(env, addr, mmu_index, ra);
372 int cpu_ldsw_be_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
374 return (int16_t)cpu_lduw_be_data_ra(env, addr, ra);
377 uint32_t cpu_ldl_be_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
379 int mmu_index = cpu_mmu_index(env_cpu(env), false);
380 return cpu_ldl_be_mmuidx_ra(env, addr, mmu_index, ra);
383 uint64_t cpu_ldq_be_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
385 int mmu_index = cpu_mmu_index(env_cpu(env), false);
386 return cpu_ldq_be_mmuidx_ra(env, addr, mmu_index, ra);
389 uint32_t cpu_lduw_le_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
391 int mmu_index = cpu_mmu_index(env_cpu(env), false);
392 return cpu_lduw_le_mmuidx_ra(env, addr, mmu_index, ra);
395 int cpu_ldsw_le_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
397 return (int16_t)cpu_lduw_le_data_ra(env, addr, ra);
400 uint32_t cpu_ldl_le_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
402 int mmu_index = cpu_mmu_index(env_cpu(env), false);
403 return cpu_ldl_le_mmuidx_ra(env, addr, mmu_index, ra);
406 uint64_t cpu_ldq_le_data_ra(CPUArchState *env, abi_ptr addr, uintptr_t ra)
408 int mmu_index = cpu_mmu_index(env_cpu(env), false);
409 return cpu_ldq_le_mmuidx_ra(env, addr, mmu_index, ra);
412 void cpu_stb_data_ra(CPUArchState *env, abi_ptr addr,
413 uint32_t val, uintptr_t ra)
415 int mmu_index = cpu_mmu_index(env_cpu(env), false);
416 cpu_stb_mmuidx_ra(env, addr, val, mmu_index, ra);
419 void cpu_stw_be_data_ra(CPUArchState *env, abi_ptr addr,
420 uint32_t val, uintptr_t ra)
422 int mmu_index = cpu_mmu_index(env_cpu(env), false);
423 cpu_stw_be_mmuidx_ra(env, addr, val, mmu_index, ra);
426 void cpu_stl_be_data_ra(CPUArchState *env, abi_ptr addr,
427 uint32_t val, uintptr_t ra)
429 int mmu_index = cpu_mmu_index(env_cpu(env), false);
430 cpu_stl_be_mmuidx_ra(env, addr, val, mmu_index, ra);
433 void cpu_stq_be_data_ra(CPUArchState *env, abi_ptr addr,
434 uint64_t val, uintptr_t ra)
436 int mmu_index = cpu_mmu_index(env_cpu(env), false);
437 cpu_stq_be_mmuidx_ra(env, addr, val, mmu_index, ra);
440 void cpu_stw_le_data_ra(CPUArchState *env, abi_ptr addr,
441 uint32_t val, uintptr_t ra)
443 int mmu_index = cpu_mmu_index(env_cpu(env), false);
444 cpu_stw_le_mmuidx_ra(env, addr, val, mmu_index, ra);
447 void cpu_stl_le_data_ra(CPUArchState *env, abi_ptr addr,
448 uint32_t val, uintptr_t ra)
450 int mmu_index = cpu_mmu_index(env_cpu(env), false);
451 cpu_stl_le_mmuidx_ra(env, addr, val, mmu_index, ra);
454 void cpu_stq_le_data_ra(CPUArchState *env, abi_ptr addr,
455 uint64_t val, uintptr_t ra)
457 int mmu_index = cpu_mmu_index(env_cpu(env), false);
458 cpu_stq_le_mmuidx_ra(env, addr, val, mmu_index, ra);
461 /*--------------------------*/
463 uint32_t cpu_ldub_data(CPUArchState *env, abi_ptr addr)
465 return cpu_ldub_data_ra(env, addr, 0);
468 int cpu_ldsb_data(CPUArchState *env, abi_ptr addr)
470 return (int8_t)cpu_ldub_data(env, addr);
473 uint32_t cpu_lduw_be_data(CPUArchState *env, abi_ptr addr)
475 return cpu_lduw_be_data_ra(env, addr, 0);
478 int cpu_ldsw_be_data(CPUArchState *env, abi_ptr addr)
480 return (int16_t)cpu_lduw_be_data(env, addr);
483 uint32_t cpu_ldl_be_data(CPUArchState *env, abi_ptr addr)
485 return cpu_ldl_be_data_ra(env, addr, 0);
488 uint64_t cpu_ldq_be_data(CPUArchState *env, abi_ptr addr)
490 return cpu_ldq_be_data_ra(env, addr, 0);
493 uint32_t cpu_lduw_le_data(CPUArchState *env, abi_ptr addr)
495 return cpu_lduw_le_data_ra(env, addr, 0);
498 int cpu_ldsw_le_data(CPUArchState *env, abi_ptr addr)
500 return (int16_t)cpu_lduw_le_data(env, addr);
503 uint32_t cpu_ldl_le_data(CPUArchState *env, abi_ptr addr)
505 return cpu_ldl_le_data_ra(env, addr, 0);
508 uint64_t cpu_ldq_le_data(CPUArchState *env, abi_ptr addr)
510 return cpu_ldq_le_data_ra(env, addr, 0);
513 void cpu_stb_data(CPUArchState *env, abi_ptr addr, uint32_t val)
515 cpu_stb_data_ra(env, addr, val, 0);
518 void cpu_stw_be_data(CPUArchState *env, abi_ptr addr, uint32_t val)
520 cpu_stw_be_data_ra(env, addr, val, 0);
523 void cpu_stl_be_data(CPUArchState *env, abi_ptr addr, uint32_t val)
525 cpu_stl_be_data_ra(env, addr, val, 0);
528 void cpu_stq_be_data(CPUArchState *env, abi_ptr addr, uint64_t val)
530 cpu_stq_be_data_ra(env, addr, val, 0);
533 void cpu_stw_le_data(CPUArchState *env, abi_ptr addr, uint32_t val)
535 cpu_stw_le_data_ra(env, addr, val, 0);
538 void cpu_stl_le_data(CPUArchState *env, abi_ptr addr, uint32_t val)
540 cpu_stl_le_data_ra(env, addr, val, 0);
543 void cpu_stq_le_data(CPUArchState *env, abi_ptr addr, uint64_t val)
545 cpu_stq_le_data_ra(env, addr, val, 0);