4 * Generate inline load/store functions for one MMU mode and data
7 * Generate a store function as well as signed and unsigned loads.
9 * Not used directly but included from cpu_ldst.h.
11 * Copyright (c) 2003 Fabrice Bellard
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 #if !defined(SOFTMMU_CODE_ACCESS)
28 #include "trace-root.h"
31 #include "trace/mem.h"
36 #define DATA_TYPE uint64_t
41 #define DATA_TYPE uint32_t
46 #define DATA_TYPE uint16_t
47 #define DATA_STYPE int16_t
52 #define DATA_TYPE uint8_t
53 #define DATA_STYPE int8_t
56 #error unsupported data size
60 #define RES_TYPE uint64_t
62 #define RES_TYPE uint32_t
65 #ifdef SOFTMMU_CODE_ACCESS
66 #define ADDR_READ addr_code
67 #define MMUSUFFIX _cmmu
68 #define URETSUFFIX SUFFIX
69 #define SRETSUFFIX SUFFIX
71 #define ADDR_READ addr_read
72 #define MMUSUFFIX _mmu
73 #define URETSUFFIX USUFFIX
74 #define SRETSUFFIX glue(s, SUFFIX)
77 /* generic load/store macros */
79 static inline RES_TYPE
80 glue(glue(glue(cpu_ld
, USUFFIX
), MEMSUFFIX
), _ra
)(CPUArchState
*env
,
90 #if !defined(SOFTMMU_CODE_ACCESS)
91 trace_guest_mem_before_exec(
92 ENV_GET_CPU(env
), ptr
,
93 trace_mem_build_info(SHIFT
, false, MO_TE
, false));
97 mmu_idx
= CPU_MMU_INDEX
;
98 entry
= tlb_entry(env
, mmu_idx
, addr
);
99 if (unlikely(entry
->ADDR_READ
!=
100 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))))) {
101 oi
= make_memop_idx(SHIFT
, mmu_idx
);
102 res
= glue(glue(helper_ret_ld
, URETSUFFIX
), MMUSUFFIX
)(env
, addr
,
105 uintptr_t hostaddr
= addr
+ entry
->addend
;
106 res
= glue(glue(ld
, USUFFIX
), _p
)((uint8_t *)hostaddr
);
111 static inline RES_TYPE
112 glue(glue(cpu_ld
, USUFFIX
), MEMSUFFIX
)(CPUArchState
*env
, target_ulong ptr
)
114 return glue(glue(glue(cpu_ld
, USUFFIX
), MEMSUFFIX
), _ra
)(env
, ptr
, 0);
119 glue(glue(glue(cpu_lds
, SUFFIX
), MEMSUFFIX
), _ra
)(CPUArchState
*env
,
129 #if !defined(SOFTMMU_CODE_ACCESS)
130 trace_guest_mem_before_exec(
131 ENV_GET_CPU(env
), ptr
,
132 trace_mem_build_info(SHIFT
, true, MO_TE
, false));
136 mmu_idx
= CPU_MMU_INDEX
;
137 entry
= tlb_entry(env
, mmu_idx
, addr
);
138 if (unlikely(entry
->ADDR_READ
!=
139 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))))) {
140 oi
= make_memop_idx(SHIFT
, mmu_idx
);
141 res
= (DATA_STYPE
)glue(glue(helper_ret_ld
, SRETSUFFIX
),
142 MMUSUFFIX
)(env
, addr
, oi
, retaddr
);
144 uintptr_t hostaddr
= addr
+ entry
->addend
;
145 res
= glue(glue(lds
, SUFFIX
), _p
)((uint8_t *)hostaddr
);
151 glue(glue(cpu_lds
, SUFFIX
), MEMSUFFIX
)(CPUArchState
*env
, target_ulong ptr
)
153 return glue(glue(glue(cpu_lds
, SUFFIX
), MEMSUFFIX
), _ra
)(env
, ptr
, 0);
157 #ifndef SOFTMMU_CODE_ACCESS
159 /* generic store macro */
162 glue(glue(glue(cpu_st
, SUFFIX
), MEMSUFFIX
), _ra
)(CPUArchState
*env
,
164 RES_TYPE v
, uintptr_t retaddr
)
171 #if !defined(SOFTMMU_CODE_ACCESS)
172 trace_guest_mem_before_exec(
173 ENV_GET_CPU(env
), ptr
,
174 trace_mem_build_info(SHIFT
, false, MO_TE
, true));
178 mmu_idx
= CPU_MMU_INDEX
;
179 entry
= tlb_entry(env
, mmu_idx
, addr
);
180 if (unlikely(tlb_addr_write(entry
) !=
181 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))))) {
182 oi
= make_memop_idx(SHIFT
, mmu_idx
);
183 glue(glue(helper_ret_st
, SUFFIX
), MMUSUFFIX
)(env
, addr
, v
, oi
,
186 uintptr_t hostaddr
= addr
+ entry
->addend
;
187 glue(glue(st
, SUFFIX
), _p
)((uint8_t *)hostaddr
, v
);
192 glue(glue(cpu_st
, SUFFIX
), MEMSUFFIX
)(CPUArchState
*env
, target_ulong ptr
,
195 glue(glue(glue(cpu_st
, SUFFIX
), MEMSUFFIX
), _ra
)(env
, ptr
, v
, 0);
198 #endif /* !SOFTMMU_CODE_ACCESS */