Statistics
| Branch: | Revision:

root / softmmu_header.h @ 85e8dab1

History | View | Annotate | Download (6.5 kB)

1 b92e5a22 bellard
/*
2 b92e5a22 bellard
 *  Software MMU support
3 5fafdf24 ths
 *
4 efbf29b6 Blue Swirl
 * Generate inline load/store functions for one MMU mode and data
5 efbf29b6 Blue Swirl
 * size.
6 efbf29b6 Blue Swirl
 *
7 efbf29b6 Blue Swirl
 * Generate a store function as well as signed and unsigned loads. For
8 efbf29b6 Blue Swirl
 * 32 and 64 bit cases, also generate floating point functions with
9 efbf29b6 Blue Swirl
 * the same size.
10 efbf29b6 Blue Swirl
 *
11 efbf29b6 Blue Swirl
 * Not used directly but included from softmmu_exec.h and exec-all.h.
12 efbf29b6 Blue Swirl
 *
13 b92e5a22 bellard
 *  Copyright (c) 2003 Fabrice Bellard
14 b92e5a22 bellard
 *
15 b92e5a22 bellard
 * This library is free software; you can redistribute it and/or
16 b92e5a22 bellard
 * modify it under the terms of the GNU Lesser General Public
17 b92e5a22 bellard
 * License as published by the Free Software Foundation; either
18 b92e5a22 bellard
 * version 2 of the License, or (at your option) any later version.
19 b92e5a22 bellard
 *
20 b92e5a22 bellard
 * This library is distributed in the hope that it will be useful,
21 b92e5a22 bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 b92e5a22 bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23 b92e5a22 bellard
 * Lesser General Public License for more details.
24 b92e5a22 bellard
 *
25 b92e5a22 bellard
 * You should have received a copy of the GNU Lesser General Public
26 8167ee88 Blue Swirl
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 b92e5a22 bellard
 */
28 b92e5a22 bellard
#if DATA_SIZE == 8
29 b92e5a22 bellard
#define SUFFIX q
30 61382a50 bellard
#define USUFFIX q
31 b92e5a22 bellard
#define DATA_TYPE uint64_t
32 b92e5a22 bellard
#elif DATA_SIZE == 4
33 b92e5a22 bellard
#define SUFFIX l
34 61382a50 bellard
#define USUFFIX l
35 b92e5a22 bellard
#define DATA_TYPE uint32_t
36 b92e5a22 bellard
#elif DATA_SIZE == 2
37 b92e5a22 bellard
#define SUFFIX w
38 61382a50 bellard
#define USUFFIX uw
39 b92e5a22 bellard
#define DATA_TYPE uint16_t
40 b92e5a22 bellard
#define DATA_STYPE int16_t
41 b92e5a22 bellard
#elif DATA_SIZE == 1
42 b92e5a22 bellard
#define SUFFIX b
43 61382a50 bellard
#define USUFFIX ub
44 b92e5a22 bellard
#define DATA_TYPE uint8_t
45 b92e5a22 bellard
#define DATA_STYPE int8_t
46 b92e5a22 bellard
#else
47 b92e5a22 bellard
#error unsupported data size
48 b92e5a22 bellard
#endif
49 b92e5a22 bellard
50 6ebbf390 j_mayer
#if ACCESS_TYPE < (NB_MMU_MODES)
51 61382a50 bellard
52 6ebbf390 j_mayer
#define CPU_MMU_INDEX ACCESS_TYPE
53 61382a50 bellard
#define MMUSUFFIX _mmu
54 61382a50 bellard
55 6ebbf390 j_mayer
#elif ACCESS_TYPE == (NB_MMU_MODES)
56 61382a50 bellard
57 6ebbf390 j_mayer
#define CPU_MMU_INDEX (cpu_mmu_index(env))
58 61382a50 bellard
#define MMUSUFFIX _mmu
59 61382a50 bellard
60 6ebbf390 j_mayer
#elif ACCESS_TYPE == (NB_MMU_MODES + 1)
61 61382a50 bellard
62 6ebbf390 j_mayer
#define CPU_MMU_INDEX (cpu_mmu_index(env))
63 61382a50 bellard
#define MMUSUFFIX _cmmu
64 61382a50 bellard
65 b92e5a22 bellard
#else
66 61382a50 bellard
#error invalid ACCESS_TYPE
67 b92e5a22 bellard
#endif
68 b92e5a22 bellard
69 b92e5a22 bellard
#if DATA_SIZE == 8
70 b92e5a22 bellard
#define RES_TYPE uint64_t
71 b92e5a22 bellard
#else
72 c086b783 Igor V. Kovalenko
#define RES_TYPE uint32_t
73 b92e5a22 bellard
#endif
74 b92e5a22 bellard
75 6ebbf390 j_mayer
#if ACCESS_TYPE == (NB_MMU_MODES + 1)
76 84b7b8e7 bellard
#define ADDR_READ addr_code
77 84b7b8e7 bellard
#else
78 84b7b8e7 bellard
#define ADDR_READ addr_read
79 84b7b8e7 bellard
#endif
80 b92e5a22 bellard
81 e141ab52 Blue Swirl
#ifndef CONFIG_TCG_PASS_AREG0
82 e141ab52 Blue Swirl
#define ENV_PARAM
83 e141ab52 Blue Swirl
#define ENV_VAR
84 e141ab52 Blue Swirl
#define CPU_PREFIX
85 e141ab52 Blue Swirl
#define HELPER_PREFIX __
86 e141ab52 Blue Swirl
#else
87 e141ab52 Blue Swirl
#define ENV_PARAM CPUArchState *env,
88 e141ab52 Blue Swirl
#define ENV_VAR env,
89 e141ab52 Blue Swirl
#define CPU_PREFIX cpu_
90 e141ab52 Blue Swirl
#define HELPER_PREFIX helper_
91 e141ab52 Blue Swirl
#endif
92 e141ab52 Blue Swirl
93 e16c53fa bellard
/* generic load/store macros */
94 e16c53fa bellard
95 e141ab52 Blue Swirl
static inline RES_TYPE
96 e141ab52 Blue Swirl
glue(glue(glue(CPU_PREFIX, ld), USUFFIX), MEMSUFFIX)(ENV_PARAM
97 e141ab52 Blue Swirl
                                                     target_ulong ptr)
98 b92e5a22 bellard
{
99 4d7a0880 blueswir1
    int page_index;
100 b92e5a22 bellard
    RES_TYPE res;
101 c27004ec bellard
    target_ulong addr;
102 c27004ec bellard
    unsigned long physaddr;
103 6ebbf390 j_mayer
    int mmu_idx;
104 61382a50 bellard
105 c27004ec bellard
    addr = ptr;
106 4d7a0880 blueswir1
    page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
107 6ebbf390 j_mayer
    mmu_idx = CPU_MMU_INDEX;
108 551bd27f ths
    if (unlikely(env->tlb_table[mmu_idx][page_index].ADDR_READ !=
109 551bd27f ths
                 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
110 e141ab52 Blue Swirl
        res = glue(glue(glue(HELPER_PREFIX, ld), SUFFIX), MMUSUFFIX)(ENV_VAR
111 e141ab52 Blue Swirl
                                                                     addr,
112 e141ab52 Blue Swirl
                                                                     mmu_idx);
113 b92e5a22 bellard
    } else {
114 4d7a0880 blueswir1
        physaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
115 61382a50 bellard
        res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)physaddr);
116 b92e5a22 bellard
    }
117 b92e5a22 bellard
    return res;
118 b92e5a22 bellard
}
119 b92e5a22 bellard
120 b92e5a22 bellard
#if DATA_SIZE <= 2
121 e141ab52 Blue Swirl
static inline int
122 e141ab52 Blue Swirl
glue(glue(glue(CPU_PREFIX, lds), SUFFIX), MEMSUFFIX)(ENV_PARAM
123 e141ab52 Blue Swirl
                                                     target_ulong ptr)
124 b92e5a22 bellard
{
125 4d7a0880 blueswir1
    int res, page_index;
126 c27004ec bellard
    target_ulong addr;
127 c27004ec bellard
    unsigned long physaddr;
128 6ebbf390 j_mayer
    int mmu_idx;
129 61382a50 bellard
130 c27004ec bellard
    addr = ptr;
131 4d7a0880 blueswir1
    page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
132 6ebbf390 j_mayer
    mmu_idx = CPU_MMU_INDEX;
133 551bd27f ths
    if (unlikely(env->tlb_table[mmu_idx][page_index].ADDR_READ !=
134 551bd27f ths
                 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
135 e141ab52 Blue Swirl
        res = (DATA_STYPE)glue(glue(glue(HELPER_PREFIX, ld), SUFFIX),
136 e141ab52 Blue Swirl
                               MMUSUFFIX)(ENV_VAR addr, mmu_idx);
137 b92e5a22 bellard
    } else {
138 4d7a0880 blueswir1
        physaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
139 b92e5a22 bellard
        res = glue(glue(lds, SUFFIX), _raw)((uint8_t *)physaddr);
140 b92e5a22 bellard
    }
141 b92e5a22 bellard
    return res;
142 b92e5a22 bellard
}
143 b92e5a22 bellard
#endif
144 b92e5a22 bellard
145 6ebbf390 j_mayer
#if ACCESS_TYPE != (NB_MMU_MODES + 1)
146 84b7b8e7 bellard
147 e16c53fa bellard
/* generic store macro */
148 e16c53fa bellard
149 e141ab52 Blue Swirl
static inline void
150 e141ab52 Blue Swirl
glue(glue(glue(CPU_PREFIX, st), SUFFIX), MEMSUFFIX)(ENV_PARAM target_ulong ptr,
151 e141ab52 Blue Swirl
                                                    RES_TYPE v)
152 b92e5a22 bellard
{
153 4d7a0880 blueswir1
    int page_index;
154 c27004ec bellard
    target_ulong addr;
155 c27004ec bellard
    unsigned long physaddr;
156 6ebbf390 j_mayer
    int mmu_idx;
157 61382a50 bellard
158 c27004ec bellard
    addr = ptr;
159 4d7a0880 blueswir1
    page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
160 6ebbf390 j_mayer
    mmu_idx = CPU_MMU_INDEX;
161 551bd27f ths
    if (unlikely(env->tlb_table[mmu_idx][page_index].addr_write !=
162 551bd27f ths
                 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
163 e141ab52 Blue Swirl
        glue(glue(glue(HELPER_PREFIX, st), SUFFIX), MMUSUFFIX)(ENV_VAR addr, v,
164 e141ab52 Blue Swirl
                                                               mmu_idx);
165 b92e5a22 bellard
    } else {
166 4d7a0880 blueswir1
        physaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
167 b92e5a22 bellard
        glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);
168 b92e5a22 bellard
    }
169 b92e5a22 bellard
}
170 b92e5a22 bellard
171 6ebbf390 j_mayer
#endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
172 84b7b8e7 bellard
173 6ebbf390 j_mayer
#if ACCESS_TYPE != (NB_MMU_MODES + 1)
174 e16c53fa bellard
175 2d603d22 bellard
#if DATA_SIZE == 8
176 e141ab52 Blue Swirl
static inline float64 glue(glue(CPU_PREFIX, ldfq), MEMSUFFIX)(ENV_PARAM
177 e141ab52 Blue Swirl
                                                              target_ulong ptr)
178 2d603d22 bellard
{
179 2d603d22 bellard
    union {
180 3f87bf69 bellard
        float64 d;
181 2d603d22 bellard
        uint64_t i;
182 2d603d22 bellard
    } u;
183 e141ab52 Blue Swirl
    u.i = glue(glue(CPU_PREFIX, ldq), MEMSUFFIX)(ENV_VAR ptr);
184 2d603d22 bellard
    return u.d;
185 2d603d22 bellard
}
186 2d603d22 bellard
187 e141ab52 Blue Swirl
static inline void glue(glue(CPU_PREFIX, stfq), MEMSUFFIX)(ENV_PARAM
188 e141ab52 Blue Swirl
                                                           target_ulong ptr,
189 e141ab52 Blue Swirl
                                                           float64 v)
190 2d603d22 bellard
{
191 2d603d22 bellard
    union {
192 3f87bf69 bellard
        float64 d;
193 2d603d22 bellard
        uint64_t i;
194 2d603d22 bellard
    } u;
195 2d603d22 bellard
    u.d = v;
196 e141ab52 Blue Swirl
    glue(glue(CPU_PREFIX, stq), MEMSUFFIX)(ENV_VAR ptr, u.i);
197 2d603d22 bellard
}
198 2d603d22 bellard
#endif /* DATA_SIZE == 8 */
199 2d603d22 bellard
200 2d603d22 bellard
#if DATA_SIZE == 4
201 e141ab52 Blue Swirl
static inline float32 glue(glue(CPU_PREFIX, ldfl), MEMSUFFIX)(ENV_PARAM
202 e141ab52 Blue Swirl
                                                              target_ulong ptr)
203 2d603d22 bellard
{
204 2d603d22 bellard
    union {
205 3f87bf69 bellard
        float32 f;
206 2d603d22 bellard
        uint32_t i;
207 2d603d22 bellard
    } u;
208 e141ab52 Blue Swirl
    u.i = glue(glue(CPU_PREFIX, ldl), MEMSUFFIX)(ENV_VAR ptr);
209 2d603d22 bellard
    return u.f;
210 2d603d22 bellard
}
211 2d603d22 bellard
212 e141ab52 Blue Swirl
static inline void glue(glue(CPU_PREFIX, stfl), MEMSUFFIX)(ENV_PARAM
213 e141ab52 Blue Swirl
                                                           target_ulong ptr,
214 e141ab52 Blue Swirl
                                                           float32 v)
215 2d603d22 bellard
{
216 2d603d22 bellard
    union {
217 3f87bf69 bellard
        float32 f;
218 2d603d22 bellard
        uint32_t i;
219 2d603d22 bellard
    } u;
220 2d603d22 bellard
    u.f = v;
221 e141ab52 Blue Swirl
    glue(glue(CPU_PREFIX, stl), MEMSUFFIX)(ENV_VAR ptr, u.i);
222 2d603d22 bellard
}
223 2d603d22 bellard
#endif /* DATA_SIZE == 4 */
224 2d603d22 bellard
225 6ebbf390 j_mayer
#endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
226 84b7b8e7 bellard
227 b92e5a22 bellard
#undef RES_TYPE
228 b92e5a22 bellard
#undef DATA_TYPE
229 b92e5a22 bellard
#undef DATA_STYPE
230 b92e5a22 bellard
#undef SUFFIX
231 61382a50 bellard
#undef USUFFIX
232 b92e5a22 bellard
#undef DATA_SIZE
233 6ebbf390 j_mayer
#undef CPU_MMU_INDEX
234 61382a50 bellard
#undef MMUSUFFIX
235 84b7b8e7 bellard
#undef ADDR_READ
236 e141ab52 Blue Swirl
#undef ENV_PARAM
237 e141ab52 Blue Swirl
#undef ENV_VAR
238 e141ab52 Blue Swirl
#undef CPU_PREFIX
239 e141ab52 Blue Swirl
#undef HELPER_PREFIX