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)
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 page_index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
98 mmu_idx
= CPU_MMU_INDEX
;
99 if (unlikely(env
->tlb_table
[mmu_idx
][page_index
].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
+ env
->tlb_table
[mmu_idx
][page_index
].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
,
128 #if !defined(SOFTMMU_CODE_ACCESS)
129 trace_guest_mem_before_exec(
130 ENV_GET_CPU(env
), ptr
,
131 trace_mem_build_info(SHIFT
, true, MO_TE
, false));
135 page_index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
136 mmu_idx
= CPU_MMU_INDEX
;
137 if (unlikely(env
->tlb_table
[mmu_idx
][page_index
].ADDR_READ
!=
138 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))))) {
139 oi
= make_memop_idx(SHIFT
, mmu_idx
);
140 res
= (DATA_STYPE
)glue(glue(helper_ret_ld
, SRETSUFFIX
),
141 MMUSUFFIX
)(env
, addr
, oi
, retaddr
);
143 uintptr_t hostaddr
= addr
+ env
->tlb_table
[mmu_idx
][page_index
].addend
;
144 res
= glue(glue(lds
, SUFFIX
), _p
)((uint8_t *)hostaddr
);
150 glue(glue(cpu_lds
, SUFFIX
), MEMSUFFIX
)(CPUArchState
*env
, target_ulong ptr
)
152 return glue(glue(glue(cpu_lds
, SUFFIX
), MEMSUFFIX
), _ra
)(env
, ptr
, 0);
156 #ifndef SOFTMMU_CODE_ACCESS
158 /* generic store macro */
161 glue(glue(glue(cpu_st
, SUFFIX
), MEMSUFFIX
), _ra
)(CPUArchState
*env
,
163 RES_TYPE v
, uintptr_t retaddr
)
170 #if !defined(SOFTMMU_CODE_ACCESS)
171 trace_guest_mem_before_exec(
172 ENV_GET_CPU(env
), ptr
,
173 trace_mem_build_info(SHIFT
, false, MO_TE
, true));
177 page_index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
178 mmu_idx
= CPU_MMU_INDEX
;
179 if (unlikely(env
->tlb_table
[mmu_idx
][page_index
].addr_write
!=
180 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))))) {
181 oi
= make_memop_idx(SHIFT
, mmu_idx
);
182 glue(glue(helper_ret_st
, SUFFIX
), MMUSUFFIX
)(env
, addr
, v
, oi
,
185 uintptr_t hostaddr
= addr
+ env
->tlb_table
[mmu_idx
][page_index
].addend
;
186 glue(glue(st
, SUFFIX
), _p
)((uint8_t *)hostaddr
, v
);
191 glue(glue(cpu_st
, SUFFIX
), MEMSUFFIX
)(CPUArchState
*env
, target_ulong ptr
,
194 glue(glue(glue(cpu_st
, SUFFIX
), MEMSUFFIX
), _ra
)(env
, ptr
, v
, 0);
197 #endif /* !SOFTMMU_CODE_ACCESS */