Revision | 5b3cc34c346e216c81f0750f586a016c33f2e08f (tree) |
---|---|
Zeit | 2021-08-25 20:02:14 |
Autor | Philippe Mathieu-Daudé <f4bug@amsa...> |
Commiter | Philippe Mathieu-Daudé |
target/mips: Call cpu_is_bigendian & inline GET_OFFSET in ld/st helpers
The target endianess information is stored in the BigEndian
bit of the Config0 register in CP0.
As a first step, inline the GET_OFFSET() macro, calling
cpu_is_bigendian() to get the 'direction' of the offset.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20210818215517.2560994-2-f4bug@amsat.org>
@@ -52,31 +52,36 @@ HELPER_LD_ATOMIC(lld, ldq, 0x7, (target_ulong)) | ||
52 | 52 | |
53 | 53 | #endif /* !CONFIG_USER_ONLY */ |
54 | 54 | |
55 | +static inline bool cpu_is_bigendian(CPUMIPSState *env) | |
56 | +{ | |
57 | + return extract32(env->CP0_Config0, CP0C0_BE, 1); | |
58 | +} | |
59 | + | |
55 | 60 | #ifdef TARGET_WORDS_BIGENDIAN |
56 | 61 | #define GET_LMASK(v) ((v) & 3) |
57 | -#define GET_OFFSET(addr, offset) (addr + (offset)) | |
58 | 62 | #else |
59 | 63 | #define GET_LMASK(v) (((v) & 3) ^ 3) |
60 | -#define GET_OFFSET(addr, offset) (addr - (offset)) | |
61 | 64 | #endif |
62 | 65 | |
63 | 66 | void helper_swl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2, |
64 | 67 | int mem_idx) |
65 | 68 | { |
69 | + int dir = cpu_is_bigendian(env) ? 1 : -1; | |
70 | + | |
66 | 71 | cpu_stb_mmuidx_ra(env, arg2, (uint8_t)(arg1 >> 24), mem_idx, GETPC()); |
67 | 72 | |
68 | 73 | if (GET_LMASK(arg2) <= 2) { |
69 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 1), (uint8_t)(arg1 >> 16), | |
74 | + cpu_stb_mmuidx_ra(env, arg2 + 1 * dir, (uint8_t)(arg1 >> 16), | |
70 | 75 | mem_idx, GETPC()); |
71 | 76 | } |
72 | 77 | |
73 | 78 | if (GET_LMASK(arg2) <= 1) { |
74 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 2), (uint8_t)(arg1 >> 8), | |
79 | + cpu_stb_mmuidx_ra(env, arg2 + 2 * dir, (uint8_t)(arg1 >> 8), | |
75 | 80 | mem_idx, GETPC()); |
76 | 81 | } |
77 | 82 | |
78 | 83 | if (GET_LMASK(arg2) == 0) { |
79 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 3), (uint8_t)arg1, | |
84 | + cpu_stb_mmuidx_ra(env, arg2 + 3 * dir, (uint8_t)arg1, | |
80 | 85 | mem_idx, GETPC()); |
81 | 86 | } |
82 | 87 | } |
@@ -84,20 +89,22 @@ void helper_swl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2, | ||
84 | 89 | void helper_swr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2, |
85 | 90 | int mem_idx) |
86 | 91 | { |
92 | + int dir = cpu_is_bigendian(env) ? 1 : -1; | |
93 | + | |
87 | 94 | cpu_stb_mmuidx_ra(env, arg2, (uint8_t)arg1, mem_idx, GETPC()); |
88 | 95 | |
89 | 96 | if (GET_LMASK(arg2) >= 1) { |
90 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -1), (uint8_t)(arg1 >> 8), | |
97 | + cpu_stb_mmuidx_ra(env, arg2 - 1 * dir, (uint8_t)(arg1 >> 8), | |
91 | 98 | mem_idx, GETPC()); |
92 | 99 | } |
93 | 100 | |
94 | 101 | if (GET_LMASK(arg2) >= 2) { |
95 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -2), (uint8_t)(arg1 >> 16), | |
102 | + cpu_stb_mmuidx_ra(env, arg2 - 2 * dir, (uint8_t)(arg1 >> 16), | |
96 | 103 | mem_idx, GETPC()); |
97 | 104 | } |
98 | 105 | |
99 | 106 | if (GET_LMASK(arg2) == 3) { |
100 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -3), (uint8_t)(arg1 >> 24), | |
107 | + cpu_stb_mmuidx_ra(env, arg2 - 3 * dir, (uint8_t)(arg1 >> 24), | |
101 | 108 | mem_idx, GETPC()); |
102 | 109 | } |
103 | 110 | } |
@@ -116,40 +123,42 @@ void helper_swr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2, | ||
116 | 123 | void helper_sdl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2, |
117 | 124 | int mem_idx) |
118 | 125 | { |
126 | + int dir = cpu_is_bigendian(env) ? 1 : -1; | |
127 | + | |
119 | 128 | cpu_stb_mmuidx_ra(env, arg2, (uint8_t)(arg1 >> 56), mem_idx, GETPC()); |
120 | 129 | |
121 | 130 | if (GET_LMASK64(arg2) <= 6) { |
122 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 1), (uint8_t)(arg1 >> 48), | |
131 | + cpu_stb_mmuidx_ra(env, arg2 + 1 * dir, (uint8_t)(arg1 >> 48), | |
123 | 132 | mem_idx, GETPC()); |
124 | 133 | } |
125 | 134 | |
126 | 135 | if (GET_LMASK64(arg2) <= 5) { |
127 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 2), (uint8_t)(arg1 >> 40), | |
136 | + cpu_stb_mmuidx_ra(env, arg2 + 2 * dir, (uint8_t)(arg1 >> 40), | |
128 | 137 | mem_idx, GETPC()); |
129 | 138 | } |
130 | 139 | |
131 | 140 | if (GET_LMASK64(arg2) <= 4) { |
132 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 3), (uint8_t)(arg1 >> 32), | |
141 | + cpu_stb_mmuidx_ra(env, arg2 + 3 * dir, (uint8_t)(arg1 >> 32), | |
133 | 142 | mem_idx, GETPC()); |
134 | 143 | } |
135 | 144 | |
136 | 145 | if (GET_LMASK64(arg2) <= 3) { |
137 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 4), (uint8_t)(arg1 >> 24), | |
146 | + cpu_stb_mmuidx_ra(env, arg2 + 4 * dir, (uint8_t)(arg1 >> 24), | |
138 | 147 | mem_idx, GETPC()); |
139 | 148 | } |
140 | 149 | |
141 | 150 | if (GET_LMASK64(arg2) <= 2) { |
142 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 5), (uint8_t)(arg1 >> 16), | |
151 | + cpu_stb_mmuidx_ra(env, arg2 + 5 * dir, (uint8_t)(arg1 >> 16), | |
143 | 152 | mem_idx, GETPC()); |
144 | 153 | } |
145 | 154 | |
146 | 155 | if (GET_LMASK64(arg2) <= 1) { |
147 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 6), (uint8_t)(arg1 >> 8), | |
156 | + cpu_stb_mmuidx_ra(env, arg2 + 6 * dir, (uint8_t)(arg1 >> 8), | |
148 | 157 | mem_idx, GETPC()); |
149 | 158 | } |
150 | 159 | |
151 | 160 | if (GET_LMASK64(arg2) <= 0) { |
152 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, 7), (uint8_t)arg1, | |
161 | + cpu_stb_mmuidx_ra(env, arg2 + 7 * dir, (uint8_t)arg1, | |
153 | 162 | mem_idx, GETPC()); |
154 | 163 | } |
155 | 164 | } |
@@ -157,40 +166,42 @@ void helper_sdl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2, | ||
157 | 166 | void helper_sdr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2, |
158 | 167 | int mem_idx) |
159 | 168 | { |
169 | + int dir = cpu_is_bigendian(env) ? 1 : -1; | |
170 | + | |
160 | 171 | cpu_stb_mmuidx_ra(env, arg2, (uint8_t)arg1, mem_idx, GETPC()); |
161 | 172 | |
162 | 173 | if (GET_LMASK64(arg2) >= 1) { |
163 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -1), (uint8_t)(arg1 >> 8), | |
174 | + cpu_stb_mmuidx_ra(env, arg2 - 1 * dir, (uint8_t)(arg1 >> 8), | |
164 | 175 | mem_idx, GETPC()); |
165 | 176 | } |
166 | 177 | |
167 | 178 | if (GET_LMASK64(arg2) >= 2) { |
168 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -2), (uint8_t)(arg1 >> 16), | |
179 | + cpu_stb_mmuidx_ra(env, arg2 - 2 * dir, (uint8_t)(arg1 >> 16), | |
169 | 180 | mem_idx, GETPC()); |
170 | 181 | } |
171 | 182 | |
172 | 183 | if (GET_LMASK64(arg2) >= 3) { |
173 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -3), (uint8_t)(arg1 >> 24), | |
184 | + cpu_stb_mmuidx_ra(env, arg2 - 3 * dir, (uint8_t)(arg1 >> 24), | |
174 | 185 | mem_idx, GETPC()); |
175 | 186 | } |
176 | 187 | |
177 | 188 | if (GET_LMASK64(arg2) >= 4) { |
178 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -4), (uint8_t)(arg1 >> 32), | |
189 | + cpu_stb_mmuidx_ra(env, arg2 - 4 * dir, (uint8_t)(arg1 >> 32), | |
179 | 190 | mem_idx, GETPC()); |
180 | 191 | } |
181 | 192 | |
182 | 193 | if (GET_LMASK64(arg2) >= 5) { |
183 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -5), (uint8_t)(arg1 >> 40), | |
194 | + cpu_stb_mmuidx_ra(env, arg2 - 5 * dir, (uint8_t)(arg1 >> 40), | |
184 | 195 | mem_idx, GETPC()); |
185 | 196 | } |
186 | 197 | |
187 | 198 | if (GET_LMASK64(arg2) >= 6) { |
188 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -6), (uint8_t)(arg1 >> 48), | |
199 | + cpu_stb_mmuidx_ra(env, arg2 - 6 * dir, (uint8_t)(arg1 >> 48), | |
189 | 200 | mem_idx, GETPC()); |
190 | 201 | } |
191 | 202 | |
192 | 203 | if (GET_LMASK64(arg2) == 7) { |
193 | - cpu_stb_mmuidx_ra(env, GET_OFFSET(arg2, -7), (uint8_t)(arg1 >> 56), | |
204 | + cpu_stb_mmuidx_ra(env, arg2 - 7 * dir, (uint8_t)(arg1 >> 56), | |
194 | 205 | mem_idx, GETPC()); |
195 | 206 | } |
196 | 207 | } |