QEMU update with VENOM (CVE-2015-3456) patch
[packages/centos6/qemu.git] / 0008-target-s390x-split-integer-helpers.patch
1 From e9f67c1f326a995ff0000a08a223435386867d8f Mon Sep 17 00:00:00 2001
2 From: Blue Swirl <blauwirbel@gmail.com>
3 Date: Sun, 2 Sep 2012 07:33:33 +0000
4 Subject: [PATCH] target-s390x: split integer helpers
5
6 Move integer helpers to int_helper.c.
7
8 Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
9 Signed-off-by: Alexander Graf <agraf@suse.de>
10 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
11 ---
12  target-s390x/Makefile.objs |   3 +-
13  target-s390x/int_helper.c  | 201 +++++++++++++++++++++++++++++++++++++++++++++
14  target-s390x/op_helper.c   | 170 --------------------------------------
15  3 files changed, 203 insertions(+), 171 deletions(-)
16  create mode 100644 target-s390x/int_helper.c
17
18 diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
19 index f9437d6..e8f66e9 100644
20 --- a/target-s390x/Makefile.objs
21 +++ b/target-s390x/Makefile.objs
22 @@ -1,8 +1,9 @@
23  obj-y += translate.o op_helper.o helper.o cpu.o interrupt.o
24 -obj-y += fpu_helper.o cc_helper.o
25 +obj-y += int_helper.o fpu_helper.o cc_helper.o
26  obj-$(CONFIG_SOFTMMU) += machine.o
27  obj-$(CONFIG_KVM) += kvm.o
28  
29  $(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
30 +$(obj)/int_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
31  $(obj)/fpu_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
32  $(obj)/cc_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
33 diff --git a/target-s390x/int_helper.c b/target-s390x/int_helper.c
34 new file mode 100644
35 index 0000000..e2eeb07
36 --- /dev/null
37 +++ b/target-s390x/int_helper.c
38 @@ -0,0 +1,201 @@
39 +/*
40 + *  S/390 integer helper routines
41 + *
42 + *  Copyright (c) 2009 Ulrich Hecht
43 + *  Copyright (c) 2009 Alexander Graf
44 + *
45 + * This library is free software; you can redistribute it and/or
46 + * modify it under the terms of the GNU Lesser General Public
47 + * License as published by the Free Software Foundation; either
48 + * version 2 of the License, or (at your option) any later version.
49 + *
50 + * This library is distributed in the hope that it will be useful,
51 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
52 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
53 + * Lesser General Public License for more details.
54 + *
55 + * You should have received a copy of the GNU Lesser General Public
56 + * License along with this library; if not, see <http://www.gnu.org/licenses/>.
57 + */
58 +
59 +#include "cpu.h"
60 +#include "dyngen-exec.h"
61 +#include "host-utils.h"
62 +#include "helper.h"
63 +
64 +/* #define DEBUG_HELPER */
65 +#ifdef DEBUG_HELPER
66 +#define HELPER_LOG(x...) qemu_log(x)
67 +#else
68 +#define HELPER_LOG(x...)
69 +#endif
70 +
71 +/* 64/64 -> 128 unsigned multiplication */
72 +void HELPER(mlg)(uint32_t r1, uint64_t v2)
73 +{
74 +#if HOST_LONG_BITS == 64 && defined(__GNUC__)
75 +    /* assuming 64-bit hosts have __uint128_t */
76 +    __uint128_t res = (__uint128_t)env->regs[r1 + 1];
77 +
78 +    res *= (__uint128_t)v2;
79 +    env->regs[r1] = (uint64_t)(res >> 64);
80 +    env->regs[r1 + 1] = (uint64_t)res;
81 +#else
82 +    mulu64(&env->regs[r1 + 1], &env->regs[r1], env->regs[r1 + 1], v2);
83 +#endif
84 +}
85 +
86 +/* 128 -> 64/64 unsigned division */
87 +void HELPER(dlg)(uint32_t r1, uint64_t v2)
88 +{
89 +    uint64_t divisor = v2;
90 +
91 +    if (!env->regs[r1]) {
92 +        /* 64 -> 64/64 case */
93 +        env->regs[r1] = env->regs[r1 + 1] % divisor;
94 +        env->regs[r1 + 1] = env->regs[r1 + 1] / divisor;
95 +        return;
96 +    } else {
97 +#if HOST_LONG_BITS == 64 && defined(__GNUC__)
98 +        /* assuming 64-bit hosts have __uint128_t */
99 +        __uint128_t dividend = (((__uint128_t)env->regs[r1]) << 64) |
100 +            (env->regs[r1 + 1]);
101 +        __uint128_t quotient = dividend / divisor;
102 +        __uint128_t remainder = dividend % divisor;
103 +
104 +        env->regs[r1 + 1] = quotient;
105 +        env->regs[r1] = remainder;
106 +#else
107 +        /* 32-bit hosts would need special wrapper functionality - just abort if
108 +           we encounter such a case; it's very unlikely anyways. */
109 +        cpu_abort(env, "128 -> 64/64 division not implemented\n");
110 +#endif
111 +    }
112 +}
113 +
114 +/* absolute value 32-bit */
115 +uint32_t HELPER(abs_i32)(int32_t val)
116 +{
117 +    if (val < 0) {
118 +        return -val;
119 +    } else {
120 +        return val;
121 +    }
122 +}
123 +
124 +/* negative absolute value 32-bit */
125 +int32_t HELPER(nabs_i32)(int32_t val)
126 +{
127 +    if (val < 0) {
128 +        return val;
129 +    } else {
130 +        return -val;
131 +    }
132 +}
133 +
134 +/* absolute value 64-bit */
135 +uint64_t HELPER(abs_i64)(int64_t val)
136 +{
137 +    HELPER_LOG("%s: val 0x%" PRIx64 "\n", __func__, val);
138 +
139 +    if (val < 0) {
140 +        return -val;
141 +    } else {
142 +        return val;
143 +    }
144 +}
145 +
146 +/* negative absolute value 64-bit */
147 +int64_t HELPER(nabs_i64)(int64_t val)
148 +{
149 +    if (val < 0) {
150 +        return val;
151 +    } else {
152 +        return -val;
153 +    }
154 +}
155 +
156 +/* add with carry 32-bit unsigned */
157 +uint32_t HELPER(addc_u32)(uint32_t cc, uint32_t v1, uint32_t v2)
158 +{
159 +    uint32_t res;
160 +
161 +    res = v1 + v2;
162 +    if (cc & 2) {
163 +        res++;
164 +    }
165 +
166 +    return res;
167 +}
168 +
169 +/* subtract unsigned v2 from v1 with borrow */
170 +uint32_t HELPER(slb)(uint32_t cc, uint32_t r1, uint32_t v2)
171 +{
172 +    uint32_t v1 = env->regs[r1];
173 +    uint32_t res = v1 + (~v2) + (cc >> 1);
174 +
175 +    env->regs[r1] = (env->regs[r1] & 0xffffffff00000000ULL) | res;
176 +    if (cc & 2) {
177 +        /* borrow */
178 +        return v1 ? 1 : 0;
179 +    } else {
180 +        return v1 ? 3 : 2;
181 +    }
182 +}
183 +
184 +/* subtract unsigned v2 from v1 with borrow */
185 +uint32_t HELPER(slbg)(uint32_t cc, uint32_t r1, uint64_t v1, uint64_t v2)
186 +{
187 +    uint64_t res = v1 + (~v2) + (cc >> 1);
188 +
189 +    env->regs[r1] = res;
190 +    if (cc & 2) {
191 +        /* borrow */
192 +        return v1 ? 1 : 0;
193 +    } else {
194 +        return v1 ? 3 : 2;
195 +    }
196 +}
197 +
198 +/* find leftmost one */
199 +uint32_t HELPER(flogr)(uint32_t r1, uint64_t v2)
200 +{
201 +    uint64_t res = 0;
202 +    uint64_t ov2 = v2;
203 +
204 +    while (!(v2 & 0x8000000000000000ULL) && v2) {
205 +        v2 <<= 1;
206 +        res++;
207 +    }
208 +
209 +    if (!v2) {
210 +        env->regs[r1] = 64;
211 +        env->regs[r1 + 1] = 0;
212 +        return 0;
213 +    } else {
214 +        env->regs[r1] = res;
215 +        env->regs[r1 + 1] = ov2 & ~(0x8000000000000000ULL >> res);
216 +        return 2;
217 +    }
218 +}
219 +
220 +uint64_t HELPER(cvd)(int32_t bin)
221 +{
222 +    /* positive 0 */
223 +    uint64_t dec = 0x0c;
224 +    int shift = 4;
225 +
226 +    if (bin < 0) {
227 +        bin = -bin;
228 +        dec = 0x0d;
229 +    }
230 +
231 +    for (shift = 4; (shift < 64) && bin; shift += 4) {
232 +        int current_number = bin % 10;
233 +
234 +        dec |= (current_number) << shift;
235 +        bin /= 10;
236 +    }
237 +
238 +    return dec;
239 +}
240 diff --git a/target-s390x/op_helper.c b/target-s390x/op_helper.c
241 index eced890..3b8b997 100644
242 --- a/target-s390x/op_helper.c
243 +++ b/target-s390x/op_helper.c
244 @@ -352,49 +352,6 @@ void HELPER(stcm)(uint32_t r1, uint32_t mask, uint64_t addr)
245      HELPER_LOG("\n");
246  }
247  
248 -/* 64/64 -> 128 unsigned multiplication */
249 -void HELPER(mlg)(uint32_t r1, uint64_t v2)
250 -{
251 -#if HOST_LONG_BITS == 64 && defined(__GNUC__)
252 -    /* assuming 64-bit hosts have __uint128_t */
253 -    __uint128_t res = (__uint128_t)env->regs[r1 + 1];
254 -
255 -    res *= (__uint128_t)v2;
256 -    env->regs[r1] = (uint64_t)(res >> 64);
257 -    env->regs[r1 + 1] = (uint64_t)res;
258 -#else
259 -    mulu64(&env->regs[r1 + 1], &env->regs[r1], env->regs[r1 + 1], v2);
260 -#endif
261 -}
262 -
263 -/* 128 -> 64/64 unsigned division */
264 -void HELPER(dlg)(uint32_t r1, uint64_t v2)
265 -{
266 -    uint64_t divisor = v2;
267 -
268 -    if (!env->regs[r1]) {
269 -        /* 64 -> 64/64 case */
270 -        env->regs[r1] = env->regs[r1 + 1] % divisor;
271 -        env->regs[r1 + 1] = env->regs[r1 + 1] / divisor;
272 -        return;
273 -    } else {
274 -#if HOST_LONG_BITS == 64 && defined(__GNUC__)
275 -        /* assuming 64-bit hosts have __uint128_t */
276 -        __uint128_t dividend = (((__uint128_t)env->regs[r1]) << 64) |
277 -            (env->regs[r1 + 1]);
278 -        __uint128_t quotient = dividend / divisor;
279 -        __uint128_t remainder = dividend % divisor;
280 -
281 -        env->regs[r1 + 1] = quotient;
282 -        env->regs[r1] = remainder;
283 -#else
284 -        /* 32-bit hosts would need special wrapper functionality - just abort if
285 -           we encounter such a case; it's very unlikely anyways. */
286 -        cpu_abort(env, "128 -> 64/64 division not implemented\n");
287 -#endif
288 -    }
289 -}
290 -
291  static inline uint64_t get_address(int x2, int b2, int d2)
292  {
293      uint64_t r = d2;
294 @@ -677,61 +634,6 @@ uint32_t HELPER(ex)(uint32_t cc, uint64_t v1, uint64_t addr, uint64_t ret)
295      return cc;
296  }
297  
298 -/* absolute value 32-bit */
299 -uint32_t HELPER(abs_i32)(int32_t val)
300 -{
301 -    if (val < 0) {
302 -        return -val;
303 -    } else {
304 -        return val;
305 -    }
306 -}
307 -
308 -/* negative absolute value 32-bit */
309 -int32_t HELPER(nabs_i32)(int32_t val)
310 -{
311 -    if (val < 0) {
312 -        return val;
313 -    } else {
314 -        return -val;
315 -    }
316 -}
317 -
318 -/* absolute value 64-bit */
319 -uint64_t HELPER(abs_i64)(int64_t val)
320 -{
321 -    HELPER_LOG("%s: val 0x%" PRIx64 "\n", __func__, val);
322 -
323 -    if (val < 0) {
324 -        return -val;
325 -    } else {
326 -        return val;
327 -    }
328 -}
329 -
330 -/* negative absolute value 64-bit */
331 -int64_t HELPER(nabs_i64)(int64_t val)
332 -{
333 -    if (val < 0) {
334 -        return val;
335 -    } else {
336 -        return -val;
337 -    }
338 -}
339 -
340 -/* add with carry 32-bit unsigned */
341 -uint32_t HELPER(addc_u32)(uint32_t cc, uint32_t v1, uint32_t v2)
342 -{
343 -    uint32_t res;
344 -
345 -    res = v1 + v2;
346 -    if (cc & 2) {
347 -        res++;
348 -    }
349 -
350 -    return res;
351 -}
352 -
353  /* store character under mask high operates on the upper half of r1 */
354  void HELPER(stcmh)(uint32_t r1, uint64_t address, uint32_t mask)
355  {
356 @@ -936,57 +838,6 @@ uint32_t HELPER(clcle)(uint32_t r1, uint64_t a2, uint32_t r3)
357      return cc;
358  }
359  
360 -/* subtract unsigned v2 from v1 with borrow */
361 -uint32_t HELPER(slb)(uint32_t cc, uint32_t r1, uint32_t v2)
362 -{
363 -    uint32_t v1 = env->regs[r1];
364 -    uint32_t res = v1 + (~v2) + (cc >> 1);
365 -
366 -    env->regs[r1] = (env->regs[r1] & 0xffffffff00000000ULL) | res;
367 -    if (cc & 2) {
368 -        /* borrow */
369 -        return v1 ? 1 : 0;
370 -    } else {
371 -        return v1 ? 3 : 2;
372 -    }
373 -}
374 -
375 -/* subtract unsigned v2 from v1 with borrow */
376 -uint32_t HELPER(slbg)(uint32_t cc, uint32_t r1, uint64_t v1, uint64_t v2)
377 -{
378 -    uint64_t res = v1 + (~v2) + (cc >> 1);
379 -
380 -    env->regs[r1] = res;
381 -    if (cc & 2) {
382 -        /* borrow */
383 -        return v1 ? 1 : 0;
384 -    } else {
385 -        return v1 ? 3 : 2;
386 -    }
387 -}
388 -
389 -/* find leftmost one */
390 -uint32_t HELPER(flogr)(uint32_t r1, uint64_t v2)
391 -{
392 -    uint64_t res = 0;
393 -    uint64_t ov2 = v2;
394 -
395 -    while (!(v2 & 0x8000000000000000ULL) && v2) {
396 -        v2 <<= 1;
397 -        res++;
398 -    }
399 -
400 -    if (!v2) {
401 -        env->regs[r1] = 64;
402 -        env->regs[r1 + 1] = 0;
403 -        return 0;
404 -    } else {
405 -        env->regs[r1] = res;
406 -        env->regs[r1 + 1] = ov2 & ~(0x8000000000000000ULL >> res);
407 -        return 2;
408 -    }
409 -}
410 -
411  /* checksum */
412  void HELPER(cksm)(uint32_t r1, uint32_t r2)
413  {
414 @@ -1026,27 +877,6 @@ void HELPER(cksm)(uint32_t r1, uint32_t r2)
415          ((uint32_t)cksm + (cksm >> 32));
416  }
417  
418 -uint64_t HELPER(cvd)(int32_t bin)
419 -{
420 -    /* positive 0 */
421 -    uint64_t dec = 0x0c;
422 -    int shift = 4;
423 -
424 -    if (bin < 0) {
425 -        bin = -bin;
426 -        dec = 0x0d;
427 -    }
428 -
429 -    for (shift = 4; (shift < 64) && bin; shift += 4) {
430 -        int current_number = bin % 10;
431 -
432 -        dec |= (current_number) << shift;
433 -        bin /= 10;
434 -    }
435 -
436 -    return dec;
437 -}
438 -
439  void HELPER(unpk)(uint32_t len, uint64_t dest, uint64_t src)
440  {
441      int len_dest = len >> 4;
442 -- 
443 1.7.12.1
444