4 * Copyright (c) 2003 Fabrice Bellard
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/>.
22 #define DATA_TYPE uint64_t
26 #define DATA_TYPE uint32_t
30 #define DATA_TYPE uint16_t
31 #define DATA_STYPE int16_t
35 #define DATA_TYPE uint8_t
36 #define DATA_STYPE int8_t
38 #error unsupported data size
41 #if ACCESS_TYPE < (NB_MMU_MODES)
43 #define CPU_MMU_INDEX ACCESS_TYPE
44 #define MMUSUFFIX _mmu
46 #elif ACCESS_TYPE == (NB_MMU_MODES)
48 #define CPU_MMU_INDEX (cpu_mmu_index(env))
49 #define MMUSUFFIX _mmu
51 #elif ACCESS_TYPE == (NB_MMU_MODES + 1)
53 #define CPU_MMU_INDEX (cpu_mmu_index(env))
54 #define MMUSUFFIX _cmmu
57 #error invalid ACCESS_TYPE
61 #define RES_TYPE uint64_t
63 #define RES_TYPE uint32_t
66 #if ACCESS_TYPE == (NB_MMU_MODES + 1)
67 #define ADDR_READ addr_code
69 #define ADDR_READ addr_read
72 /* generic load/store macros */
74 static inline RES_TYPE
glue(glue(ld
, USUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
79 unsigned long physaddr
;
83 page_index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
84 mmu_idx
= CPU_MMU_INDEX
;
85 if (unlikely(env
->tlb_table
[mmu_idx
][page_index
].ADDR_READ
!=
86 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))))) {
87 res
= glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(addr
, mmu_idx
);
89 physaddr
= addr
+ env
->tlb_table
[mmu_idx
][page_index
].addend
;
90 res
= glue(glue(ld
, USUFFIX
), _raw
)((uint8_t *)physaddr
);
96 static inline int glue(glue(lds
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
100 unsigned long physaddr
;
104 page_index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
105 mmu_idx
= CPU_MMU_INDEX
;
106 if (unlikely(env
->tlb_table
[mmu_idx
][page_index
].ADDR_READ
!=
107 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))))) {
108 res
= (DATA_STYPE
)glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(addr
, mmu_idx
);
110 physaddr
= addr
+ env
->tlb_table
[mmu_idx
][page_index
].addend
;
111 res
= glue(glue(lds
, SUFFIX
), _raw
)((uint8_t *)physaddr
);
117 #if ACCESS_TYPE != (NB_MMU_MODES + 1)
119 /* generic store macro */
121 static inline void glue(glue(st
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
, RES_TYPE v
)
125 unsigned long physaddr
;
129 page_index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
130 mmu_idx
= CPU_MMU_INDEX
;
131 if (unlikely(env
->tlb_table
[mmu_idx
][page_index
].addr_write
!=
132 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))))) {
133 glue(glue(__st
, SUFFIX
), MMUSUFFIX
)(addr
, v
, mmu_idx
);
135 physaddr
= addr
+ env
->tlb_table
[mmu_idx
][page_index
].addend
;
136 glue(glue(st
, SUFFIX
), _raw
)((uint8_t *)physaddr
, v
);
140 #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
142 #if ACCESS_TYPE != (NB_MMU_MODES + 1)
145 static inline float64
glue(ldfq
, MEMSUFFIX
)(target_ulong ptr
)
151 u
.i
= glue(ldq
, MEMSUFFIX
)(ptr
);
155 static inline void glue(stfq
, MEMSUFFIX
)(target_ulong ptr
, float64 v
)
162 glue(stq
, MEMSUFFIX
)(ptr
, u
.i
);
164 #endif /* DATA_SIZE == 8 */
167 static inline float32
glue(ldfl
, MEMSUFFIX
)(target_ulong ptr
)
173 u
.i
= glue(ldl
, MEMSUFFIX
)(ptr
);
177 static inline void glue(stfl
, MEMSUFFIX
)(target_ulong ptr
, float32 v
)
184 glue(stl
, MEMSUFFIX
)(ptr
, u
.i
);
186 #endif /* DATA_SIZE == 4 */
188 #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */