tools/*: remove bcc and as86 as they are no longer required to compile the system...
[virtualbox.git] / src / recompiler / softmmu_header.h
blob06e2466da3ac88570cfb33da70d83fe1dfcf6f40
1 /*
2 * Software MMU support
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/>.
21 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
22 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
23 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
24 * a choice of LGPL license versions is made available with the language indicating
25 * that LGPLv2 or any later version may be used, or where a choice of which version
26 * of the LGPL is applied is otherwise unspecified.
29 #if DATA_SIZE == 8
30 #define SUFFIX q
31 #define USUFFIX q
32 #define DATA_TYPE uint64_t
33 #elif DATA_SIZE == 4
34 #define SUFFIX l
35 #define USUFFIX l
36 #define DATA_TYPE uint32_t
37 #elif DATA_SIZE == 2
38 #define SUFFIX w
39 #define USUFFIX uw
40 #define DATA_TYPE uint16_t
41 #define DATA_STYPE int16_t
42 #elif DATA_SIZE == 1
43 #define SUFFIX b
44 #define USUFFIX ub
45 #define DATA_TYPE uint8_t
46 #define DATA_STYPE int8_t
47 #else
48 #error unsupported data size
49 #endif
51 #if ACCESS_TYPE < (NB_MMU_MODES)
53 #define CPU_MMU_INDEX ACCESS_TYPE
54 #define MMUSUFFIX _mmu
56 #elif ACCESS_TYPE == (NB_MMU_MODES)
58 #define CPU_MMU_INDEX (cpu_mmu_index(env))
59 #define MMUSUFFIX _mmu
61 #elif ACCESS_TYPE == (NB_MMU_MODES + 1)
63 #define CPU_MMU_INDEX (cpu_mmu_index(env))
64 #define MMUSUFFIX _cmmu
66 #else
67 #error invalid ACCESS_TYPE
68 #endif
70 #if DATA_SIZE == 8
71 #define RES_TYPE uint64_t
72 #else
73 #define RES_TYPE uint32_t
74 #endif
76 #if ACCESS_TYPE == (NB_MMU_MODES + 1)
77 #define ADDR_READ addr_code
78 #else
79 #define ADDR_READ addr_read
80 #endif
82 /* generic load/store macros */
84 static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(target_ulong ptr)
86 int page_index;
87 RES_TYPE res;
88 target_ulong addr;
89 uintptr_t physaddr;
90 int mmu_idx;
92 addr = ptr;
93 page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
94 mmu_idx = CPU_MMU_INDEX;
95 if (unlikely(env->tlb_table[mmu_idx][page_index].ADDR_READ !=
96 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
97 res = glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, mmu_idx);
98 } else {
99 physaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
100 res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)physaddr);
102 return res;
105 #if DATA_SIZE <= 2
106 static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(target_ulong ptr)
108 int res, page_index;
109 target_ulong addr;
110 uintptr_t physaddr;
111 int mmu_idx;
113 addr = ptr;
114 page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
115 mmu_idx = CPU_MMU_INDEX;
116 if (unlikely(env->tlb_table[mmu_idx][page_index].ADDR_READ !=
117 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
118 res = (DATA_STYPE)glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, mmu_idx);
119 } else {
120 physaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
121 res = glue(glue(lds, SUFFIX), _raw)((uint8_t *)physaddr);
123 return res;
125 #endif
127 #if ACCESS_TYPE != (NB_MMU_MODES + 1)
129 /* generic store macro */
131 static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
133 int page_index;
134 target_ulong addr;
135 uintptr_t physaddr;
136 int mmu_idx;
138 addr = ptr;
139 page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
140 mmu_idx = CPU_MMU_INDEX;
141 if (unlikely(env->tlb_table[mmu_idx][page_index].addr_write !=
142 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
143 glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, mmu_idx);
144 } else {
145 physaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
146 glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);
150 #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
152 #if ACCESS_TYPE != (NB_MMU_MODES + 1)
154 #if DATA_SIZE == 8
155 static inline float64 glue(ldfq, MEMSUFFIX)(target_ulong ptr)
157 union {
158 float64 d;
159 uint64_t i;
160 } u;
161 u.i = glue(ldq, MEMSUFFIX)(ptr);
162 return u.d;
165 static inline void glue(stfq, MEMSUFFIX)(target_ulong ptr, float64 v)
167 union {
168 float64 d;
169 uint64_t i;
170 } u;
171 u.d = v;
172 glue(stq, MEMSUFFIX)(ptr, u.i);
174 #endif /* DATA_SIZE == 8 */
176 #if DATA_SIZE == 4
177 static inline float32 glue(ldfl, MEMSUFFIX)(target_ulong ptr)
179 union {
180 float32 f;
181 uint32_t i;
182 } u;
183 u.i = glue(ldl, MEMSUFFIX)(ptr);
184 return u.f;
187 static inline void glue(stfl, MEMSUFFIX)(target_ulong ptr, float32 v)
189 union {
190 float32 f;
191 uint32_t i;
192 } u;
193 u.f = v;
194 glue(stl, MEMSUFFIX)(ptr, u.i);
196 #endif /* DATA_SIZE == 4 */
198 #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
200 #undef RES_TYPE
201 #undef DATA_TYPE
202 #undef DATA_STYPE
203 #undef SUFFIX
204 #undef USUFFIX
205 #undef DATA_SIZE
206 #undef CPU_MMU_INDEX
207 #undef MMUSUFFIX
208 #undef ADDR_READ