translate.c 320 KB
Newer Older
bellard's avatar
bellard committed
1
2
/*
 *  ARM translation
3
 *
bellard's avatar
bellard committed
4
 *  Copyright (c) 2003 Fabrice Bellard
pbrook's avatar
pbrook committed
5
 *  Copyright (c) 2005-2007 CodeSourcery
6
 *  Copyright (c) 2007 OpenedHand, Ltd.
bellard's avatar
bellard committed
7
8
9
10
11
12
13
14
15
16
17
18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
bellard's avatar
bellard committed
20
21
22
23
24
25
26
27
28
29
 */
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>

#include "cpu.h"
#include "exec-all.h"
#include "disas.h"
bellard's avatar
bellard committed
30
#include "tcg-op.h"
31
#include "qemu-log.h"
pbrook's avatar
pbrook committed
32

pbrook's avatar
pbrook committed
33
#include "helpers.h"
pbrook's avatar
pbrook committed
34
#define GEN_HELPER 1
pbrook's avatar
pbrook committed
35
#include "helpers.h"
bellard's avatar
bellard committed
36

pbrook's avatar
pbrook committed
37
38
39
40
41
#define ENABLE_ARCH_5J    0
#define ENABLE_ARCH_6     arm_feature(env, ARM_FEATURE_V6)
#define ENABLE_ARCH_6K   arm_feature(env, ARM_FEATURE_V6K)
#define ENABLE_ARCH_6T2   arm_feature(env, ARM_FEATURE_THUMB2)
#define ENABLE_ARCH_7     arm_feature(env, ARM_FEATURE_V7)
bellard's avatar
bellard committed
42

pbrook's avatar
pbrook committed
43
#define ARCH(x) do { if (!ENABLE_ARCH_##x) goto illegal_op; } while(0)
bellard's avatar
bellard committed
44

bellard's avatar
bellard committed
45
46
/* internal defines */
typedef struct DisasContext {
bellard's avatar
bellard committed
47
    target_ulong pc;
bellard's avatar
bellard committed
48
    int is_jmp;
49
50
51
52
    /* Nonzero if this instruction has been conditionally skipped.  */
    int condjmp;
    /* The label that will be jumped to when the instruction is skipped.  */
    int condlabel;
pbrook's avatar
pbrook committed
53
54
55
    /* Thumb-2 condtional execution bits.  */
    int condexec_mask;
    int condexec_cond;
bellard's avatar
bellard committed
56
    struct TranslationBlock *tb;
bellard's avatar
bellard committed
57
    int singlestep_enabled;
bellard's avatar
bellard committed
58
    int thumb;
bellard's avatar
bellard committed
59
60
61
#if !defined(CONFIG_USER_ONLY)
    int user;
#endif
62
    int vfp_enabled;
63
64
    int vec_len;
    int vec_stride;
bellard's avatar
bellard committed
65
66
} DisasContext;

67
68
static uint32_t gen_opc_condexec_bits[OPC_BUF_SIZE];

bellard's avatar
bellard committed
69
70
71
72
73
74
#if defined(CONFIG_USER_ONLY)
#define IS_USER(s) 1
#else
#define IS_USER(s) (s->user)
#endif

pbrook's avatar
pbrook committed
75
76
77
78
/* These instructions trap after executing, so defer them until after the
   conditional executions state has been updated.  */
#define DISAS_WFI 4
#define DISAS_SWI 5
bellard's avatar
bellard committed
79

pbrook's avatar
pbrook committed
80
static TCGv_ptr cpu_env;
pbrook's avatar
pbrook committed
81
/* We reuse the same 64-bit temporaries for efficiency.  */
pbrook's avatar
pbrook committed
82
static TCGv_i64 cpu_V0, cpu_V1, cpu_M0;
83
static TCGv_i32 cpu_R[16];
Paul Brook's avatar
Paul Brook committed
84
85
86
87
88
89
90
static TCGv_i32 cpu_exclusive_addr;
static TCGv_i32 cpu_exclusive_val;
static TCGv_i32 cpu_exclusive_high;
#ifdef CONFIG_USER_ONLY
static TCGv_i32 cpu_exclusive_test;
static TCGv_i32 cpu_exclusive_info;
#endif
pbrook's avatar
pbrook committed
91

pbrook's avatar
pbrook committed
92
/* FIXME:  These should be removed.  */
pbrook's avatar
pbrook committed
93
94
static TCGv cpu_F0s, cpu_F1s;
static TCGv_i64 cpu_F0d, cpu_F1d;
pbrook's avatar
pbrook committed
95

pbrook's avatar
pbrook committed
96
97
#include "gen-icount.h"

98
99
100
101
static const char *regnames[] =
    { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
      "r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc" };

pbrook's avatar
pbrook committed
102
103
104
/* initialize TCG globals.  */
void arm_translate_init(void)
{
105
106
    int i;

pbrook's avatar
pbrook committed
107
108
    cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");

109
110
111
112
113
    for (i = 0; i < 16; i++) {
        cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0,
                                          offsetof(CPUState, regs[i]),
                                          regnames[i]);
    }
Paul Brook's avatar
Paul Brook committed
114
115
116
117
118
119
120
121
122
123
124
125
    cpu_exclusive_addr = tcg_global_mem_new_i32(TCG_AREG0,
        offsetof(CPUState, exclusive_addr), "exclusive_addr");
    cpu_exclusive_val = tcg_global_mem_new_i32(TCG_AREG0,
        offsetof(CPUState, exclusive_val), "exclusive_val");
    cpu_exclusive_high = tcg_global_mem_new_i32(TCG_AREG0,
        offsetof(CPUState, exclusive_high), "exclusive_high");
#ifdef CONFIG_USER_ONLY
    cpu_exclusive_test = tcg_global_mem_new_i32(TCG_AREG0,
        offsetof(CPUState, exclusive_test), "exclusive_test");
    cpu_exclusive_info = tcg_global_mem_new_i32(TCG_AREG0,
        offsetof(CPUState, exclusive_info), "exclusive_info");
#endif
126

pbrook's avatar
pbrook committed
127
128
#define GEN_HELPER 2
#include "helpers.h"
pbrook's avatar
pbrook committed
129
130
131
132
133
}

static int num_temps;

/* Allocate a temporary variable.  */
pbrook's avatar
pbrook committed
134
static TCGv_i32 new_tmp(void)
pbrook's avatar
pbrook committed
135
{
136
137
    num_temps++;
    return tcg_temp_new_i32();
pbrook's avatar
pbrook committed
138
139
140
141
142
}

/* Release a temporary variable.  */
static void dead_tmp(TCGv tmp)
{
143
    tcg_temp_free(tmp);
pbrook's avatar
pbrook committed
144
145
146
    num_temps--;
}

pbrook's avatar
pbrook committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
static inline TCGv load_cpu_offset(int offset)
{
    TCGv tmp = new_tmp();
    tcg_gen_ld_i32(tmp, cpu_env, offset);
    return tmp;
}

#define load_cpu_field(name) load_cpu_offset(offsetof(CPUState, name))

static inline void store_cpu_offset(TCGv var, int offset)
{
    tcg_gen_st_i32(var, cpu_env, offset);
    dead_tmp(var);
}

#define store_cpu_field(var, name) \
    store_cpu_offset(var, offsetof(CPUState, name))

pbrook's avatar
pbrook committed
165
166
167
168
169
170
171
172
173
174
175
176
/* Set a variable to the value of a CPU register.  */
static void load_reg_var(DisasContext *s, TCGv var, int reg)
{
    if (reg == 15) {
        uint32_t addr;
        /* normaly, since we updated PC, we need only to add one insn */
        if (s->thumb)
            addr = (long)s->pc + 2;
        else
            addr = (long)s->pc + 4;
        tcg_gen_movi_i32(var, addr);
    } else {
177
        tcg_gen_mov_i32(var, cpu_R[reg]);
pbrook's avatar
pbrook committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    }
}

/* Create a new temporary and set it to the value of a CPU register.  */
static inline TCGv load_reg(DisasContext *s, int reg)
{
    TCGv tmp = new_tmp();
    load_reg_var(s, tmp, reg);
    return tmp;
}

/* Set a CPU register.  The source must be a temporary and will be
   marked as dead.  */
static void store_reg(DisasContext *s, int reg, TCGv var)
{
    if (reg == 15) {
        tcg_gen_andi_i32(var, var, ~1);
        s->is_jmp = DISAS_JUMP;
    }
197
    tcg_gen_mov_i32(cpu_R[reg], var);
pbrook's avatar
pbrook committed
198
199
200
201
    dead_tmp(var);
}

/* Value extensions.  */
pbrook's avatar
pbrook committed
202
203
#define gen_uxtb(var) tcg_gen_ext8u_i32(var, var)
#define gen_uxth(var) tcg_gen_ext16u_i32(var, var)
pbrook's avatar
pbrook committed
204
205
206
#define gen_sxtb(var) tcg_gen_ext8s_i32(var, var)
#define gen_sxth(var) tcg_gen_ext16s_i32(var, var)

pbrook's avatar
pbrook committed
207
208
#define gen_sxtb16(var) gen_helper_sxtb16(var, var)
#define gen_uxtb16(var) gen_helper_uxtb16(var, var)
pbrook's avatar
pbrook committed
209

pbrook's avatar
pbrook committed
210

211
212
213
214
215
216
static inline void gen_set_cpsr(TCGv var, uint32_t mask)
{
    TCGv tmp_mask = tcg_const_i32(mask);
    gen_helper_cpsr_write(var, tmp_mask);
    tcg_temp_free_i32(tmp_mask);
}
pbrook's avatar
pbrook committed
217
218
219
220
221
222
223
224
225
226
227
/* Set NZCV flags from the high 4 bits of var.  */
#define gen_set_nzcv(var) gen_set_cpsr(var, CPSR_NZCV)

static void gen_exception(int excp)
{
    TCGv tmp = new_tmp();
    tcg_gen_movi_i32(tmp, excp);
    gen_helper_exception(tmp);
    dead_tmp(tmp);
}

pbrook's avatar
pbrook committed
228
229
230
231
static void gen_smul_dual(TCGv a, TCGv b)
{
    TCGv tmp1 = new_tmp();
    TCGv tmp2 = new_tmp();
232
233
    tcg_gen_ext16s_i32(tmp1, a);
    tcg_gen_ext16s_i32(tmp2, b);
pbrook's avatar
pbrook committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
    tcg_gen_mul_i32(tmp1, tmp1, tmp2);
    dead_tmp(tmp2);
    tcg_gen_sari_i32(a, a, 16);
    tcg_gen_sari_i32(b, b, 16);
    tcg_gen_mul_i32(b, b, a);
    tcg_gen_mov_i32(a, tmp1);
    dead_tmp(tmp1);
}

/* Byteswap each halfword.  */
static void gen_rev16(TCGv var)
{
    TCGv tmp = new_tmp();
    tcg_gen_shri_i32(tmp, var, 8);
    tcg_gen_andi_i32(tmp, tmp, 0x00ff00ff);
    tcg_gen_shli_i32(var, var, 8);
    tcg_gen_andi_i32(var, var, 0xff00ff00);
    tcg_gen_or_i32(var, var, tmp);
    dead_tmp(tmp);
}

/* Byteswap low halfword and sign extend.  */
static void gen_revsh(TCGv var)
{
258
259
260
    tcg_gen_ext16u_i32(var, var);
    tcg_gen_bswap16_i32(var, var);
    tcg_gen_ext16s_i32(var, var);
pbrook's avatar
pbrook committed
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
}

/* Unsigned bitfield extract.  */
static void gen_ubfx(TCGv var, int shift, uint32_t mask)
{
    if (shift)
        tcg_gen_shri_i32(var, var, shift);
    tcg_gen_andi_i32(var, var, mask);
}

/* Signed bitfield extract.  */
static void gen_sbfx(TCGv var, int shift, int width)
{
    uint32_t signbit;

    if (shift)
        tcg_gen_sari_i32(var, var, shift);
    if (shift + width < 32) {
        signbit = 1u << (width - 1);
        tcg_gen_andi_i32(var, var, (1u << width) - 1);
        tcg_gen_xori_i32(var, var, signbit);
        tcg_gen_subi_i32(var, var, signbit);
    }
}

/* Bitfield insertion.  Insert val into base.  Clobbers base and val.  */
static void gen_bfi(TCGv dest, TCGv base, TCGv val, int shift, uint32_t mask)
{
    tcg_gen_andi_i32(val, val, mask);
pbrook's avatar
pbrook committed
290
291
    tcg_gen_shli_i32(val, val, shift);
    tcg_gen_andi_i32(base, base, ~(mask << shift));
pbrook's avatar
pbrook committed
292
293
294
    tcg_gen_or_i32(dest, base, val);
}

295
296
/* Return (b << 32) + a. Mark inputs as dead */
static TCGv_i64 gen_addq_msw(TCGv_i64 a, TCGv b)
pbrook's avatar
pbrook committed
297
{
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
    TCGv_i64 tmp64 = tcg_temp_new_i64();

    tcg_gen_extu_i32_i64(tmp64, b);
    dead_tmp(b);
    tcg_gen_shli_i64(tmp64, tmp64, 32);
    tcg_gen_add_i64(a, tmp64, a);

    tcg_temp_free_i64(tmp64);
    return a;
}

/* Return (b << 32) - a. Mark inputs as dead. */
static TCGv_i64 gen_subq_msw(TCGv_i64 a, TCGv b)
{
    TCGv_i64 tmp64 = tcg_temp_new_i64();

    tcg_gen_extu_i32_i64(tmp64, b);
    dead_tmp(b);
    tcg_gen_shli_i64(tmp64, tmp64, 32);
    tcg_gen_sub_i64(a, tmp64, a);

    tcg_temp_free_i64(tmp64);
    return a;
pbrook's avatar
pbrook committed
321
322
}

pbrook's avatar
pbrook committed
323
324
/* FIXME: Most targets have native widening multiplication.
   It would be good to use that instead of a full wide multiply.  */
pbrook's avatar
pbrook committed
325
/* 32x32->64 multiply.  Marks inputs as dead.  */
pbrook's avatar
pbrook committed
326
static TCGv_i64 gen_mulu_i64_i32(TCGv a, TCGv b)
pbrook's avatar
pbrook committed
327
{
pbrook's avatar
pbrook committed
328
329
    TCGv_i64 tmp1 = tcg_temp_new_i64();
    TCGv_i64 tmp2 = tcg_temp_new_i64();
pbrook's avatar
pbrook committed
330
331
332
333
334
335

    tcg_gen_extu_i32_i64(tmp1, a);
    dead_tmp(a);
    tcg_gen_extu_i32_i64(tmp2, b);
    dead_tmp(b);
    tcg_gen_mul_i64(tmp1, tmp1, tmp2);
336
    tcg_temp_free_i64(tmp2);
pbrook's avatar
pbrook committed
337
338
339
    return tmp1;
}

pbrook's avatar
pbrook committed
340
static TCGv_i64 gen_muls_i64_i32(TCGv a, TCGv b)
pbrook's avatar
pbrook committed
341
{
pbrook's avatar
pbrook committed
342
343
    TCGv_i64 tmp1 = tcg_temp_new_i64();
    TCGv_i64 tmp2 = tcg_temp_new_i64();
pbrook's avatar
pbrook committed
344
345
346
347
348
349

    tcg_gen_ext_i32_i64(tmp1, a);
    dead_tmp(a);
    tcg_gen_ext_i32_i64(tmp2, b);
    dead_tmp(b);
    tcg_gen_mul_i64(tmp1, tmp1, tmp2);
350
    tcg_temp_free_i64(tmp2);
pbrook's avatar
pbrook committed
351
352
353
    return tmp1;
}

pbrook's avatar
pbrook committed
354
355
356
357
358
359
360
/* Swap low and high halfwords.  */
static void gen_swap_half(TCGv var)
{
    TCGv tmp = new_tmp();
    tcg_gen_shri_i32(tmp, var, 16);
    tcg_gen_shli_i32(var, var, 16);
    tcg_gen_or_i32(var, var, tmp);
pbrook's avatar
pbrook committed
361
    dead_tmp(tmp);
pbrook's avatar
pbrook committed
362
363
}

pbrook's avatar
pbrook committed
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/* Dual 16-bit add.  Result placed in t0 and t1 is marked as dead.
    tmp = (t0 ^ t1) & 0x8000;
    t0 &= ~0x8000;
    t1 &= ~0x8000;
    t0 = (t0 + t1) ^ tmp;
 */

static void gen_add16(TCGv t0, TCGv t1)
{
    TCGv tmp = new_tmp();
    tcg_gen_xor_i32(tmp, t0, t1);
    tcg_gen_andi_i32(tmp, tmp, 0x8000);
    tcg_gen_andi_i32(t0, t0, ~0x8000);
    tcg_gen_andi_i32(t1, t1, ~0x8000);
    tcg_gen_add_i32(t0, t0, t1);
    tcg_gen_xor_i32(t0, t0, tmp);
    dead_tmp(tmp);
    dead_tmp(t1);
}

pbrook's avatar
pbrook committed
384
385
#define gen_set_CF(var) tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, CF))

pbrook's avatar
pbrook committed
386
387
388
389
390
/* Set CF to the top bit of var.  */
static void gen_set_CF_bit31(TCGv var)
{
    TCGv tmp = new_tmp();
    tcg_gen_shri_i32(tmp, var, 31);
391
    gen_set_CF(tmp);
pbrook's avatar
pbrook committed
392
393
394
395
396
397
    dead_tmp(tmp);
}

/* Set N and Z flags from var.  */
static inline void gen_logic_CC(TCGv var)
{
pbrook's avatar
pbrook committed
398
399
    tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, NF));
    tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, ZF));
pbrook's avatar
pbrook committed
400
401
402
}

/* T0 += T1 + CF.  */
403
static void gen_adc(TCGv t0, TCGv t1)
pbrook's avatar
pbrook committed
404
{
pbrook's avatar
pbrook committed
405
    TCGv tmp;
406
    tcg_gen_add_i32(t0, t0, t1);
pbrook's avatar
pbrook committed
407
    tmp = load_cpu_field(CF);
408
    tcg_gen_add_i32(t0, t0, tmp);
pbrook's avatar
pbrook committed
409
410
411
    dead_tmp(tmp);
}

412
413
414
415
416
417
418
419
420
421
/* dest = T0 + T1 + CF. */
static void gen_add_carry(TCGv dest, TCGv t0, TCGv t1)
{
    TCGv tmp;
    tcg_gen_add_i32(dest, t0, t1);
    tmp = load_cpu_field(CF);
    tcg_gen_add_i32(dest, dest, tmp);
    dead_tmp(tmp);
}

pbrook's avatar
pbrook committed
422
423
424
/* dest = T0 - T1 + CF - 1.  */
static void gen_sub_carry(TCGv dest, TCGv t0, TCGv t1)
{
pbrook's avatar
pbrook committed
425
    TCGv tmp;
pbrook's avatar
pbrook committed
426
    tcg_gen_sub_i32(dest, t0, t1);
pbrook's avatar
pbrook committed
427
    tmp = load_cpu_field(CF);
pbrook's avatar
pbrook committed
428
429
430
431
432
    tcg_gen_add_i32(dest, dest, tmp);
    tcg_gen_subi_i32(dest, dest, 1);
    dead_tmp(tmp);
}

pbrook's avatar
pbrook committed
433
434
435
/* FIXME:  Implement this natively.  */
#define tcg_gen_abs_i32(t0, t1) gen_helper_abs(t0, t1)

pbrook's avatar
pbrook committed
436
static void shifter_out_im(TCGv var, int shift)
pbrook's avatar
pbrook committed
437
{
pbrook's avatar
pbrook committed
438
439
440
    TCGv tmp = new_tmp();
    if (shift == 0) {
        tcg_gen_andi_i32(tmp, var, 1);
pbrook's avatar
pbrook committed
441
    } else {
pbrook's avatar
pbrook committed
442
        tcg_gen_shri_i32(tmp, var, shift);
443
        if (shift != 31)
pbrook's avatar
pbrook committed
444
445
446
447
448
            tcg_gen_andi_i32(tmp, tmp, 1);
    }
    gen_set_CF(tmp);
    dead_tmp(tmp);
}
pbrook's avatar
pbrook committed
449

pbrook's avatar
pbrook committed
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
/* Shift by immediate.  Includes special handling for shift == 0.  */
static inline void gen_arm_shift_im(TCGv var, int shiftop, int shift, int flags)
{
    switch (shiftop) {
    case 0: /* LSL */
        if (shift != 0) {
            if (flags)
                shifter_out_im(var, 32 - shift);
            tcg_gen_shli_i32(var, var, shift);
        }
        break;
    case 1: /* LSR */
        if (shift == 0) {
            if (flags) {
                tcg_gen_shri_i32(var, var, 31);
                gen_set_CF(var);
            }
            tcg_gen_movi_i32(var, 0);
        } else {
            if (flags)
                shifter_out_im(var, shift - 1);
            tcg_gen_shri_i32(var, var, shift);
        }
        break;
    case 2: /* ASR */
        if (shift == 0)
            shift = 32;
        if (flags)
            shifter_out_im(var, shift - 1);
        if (shift == 32)
          shift = 31;
        tcg_gen_sari_i32(var, var, shift);
        break;
    case 3: /* ROR/RRX */
        if (shift != 0) {
            if (flags)
                shifter_out_im(var, shift - 1);
487
            tcg_gen_rotri_i32(var, var, shift); break;
pbrook's avatar
pbrook committed
488
        } else {
pbrook's avatar
pbrook committed
489
            TCGv tmp = load_cpu_field(CF);
pbrook's avatar
pbrook committed
490
491
492
            if (flags)
                shifter_out_im(var, 0);
            tcg_gen_shri_i32(var, var, 1);
pbrook's avatar
pbrook committed
493
494
495
496
497
498
499
            tcg_gen_shli_i32(tmp, tmp, 31);
            tcg_gen_or_i32(var, var, tmp);
            dead_tmp(tmp);
        }
    }
};

pbrook's avatar
pbrook committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
static inline void gen_arm_shift_reg(TCGv var, int shiftop,
                                     TCGv shift, int flags)
{
    if (flags) {
        switch (shiftop) {
        case 0: gen_helper_shl_cc(var, var, shift); break;
        case 1: gen_helper_shr_cc(var, var, shift); break;
        case 2: gen_helper_sar_cc(var, var, shift); break;
        case 3: gen_helper_ror_cc(var, var, shift); break;
        }
    } else {
        switch (shiftop) {
        case 0: gen_helper_shl(var, var, shift); break;
        case 1: gen_helper_shr(var, var, shift); break;
        case 2: gen_helper_sar(var, var, shift); break;
515
516
        case 3: tcg_gen_andi_i32(shift, shift, 0x1f);
                tcg_gen_rotr_i32(var, var, shift); break;
pbrook's avatar
pbrook committed
517
518
519
520
521
        }
    }
    dead_tmp(shift);
}

pbrook's avatar
pbrook committed
522
523
524
525
526
527
528
529
530
#define PAS_OP(pfx) \
    switch (op2) {  \
    case 0: gen_pas_helper(glue(pfx,add16)); break; \
    case 1: gen_pas_helper(glue(pfx,addsubx)); break; \
    case 2: gen_pas_helper(glue(pfx,subaddx)); break; \
    case 3: gen_pas_helper(glue(pfx,sub16)); break; \
    case 4: gen_pas_helper(glue(pfx,add8)); break; \
    case 7: gen_pas_helper(glue(pfx,sub8)); break; \
    }
pbrook's avatar
pbrook committed
531
static void gen_arm_parallel_addsub(int op1, int op2, TCGv a, TCGv b)
pbrook's avatar
pbrook committed
532
{
pbrook's avatar
pbrook committed
533
    TCGv_ptr tmp;
pbrook's avatar
pbrook committed
534
535
536
537

    switch (op1) {
#define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b, tmp)
    case 1:
pbrook's avatar
pbrook committed
538
        tmp = tcg_temp_new_ptr();
pbrook's avatar
pbrook committed
539
540
        tcg_gen_addi_ptr(tmp, cpu_env, offsetof(CPUState, GE));
        PAS_OP(s)
541
        tcg_temp_free_ptr(tmp);
pbrook's avatar
pbrook committed
542
543
        break;
    case 5:
pbrook's avatar
pbrook committed
544
        tmp = tcg_temp_new_ptr();
pbrook's avatar
pbrook committed
545
546
        tcg_gen_addi_ptr(tmp, cpu_env, offsetof(CPUState, GE));
        PAS_OP(u)
547
        tcg_temp_free_ptr(tmp);
pbrook's avatar
pbrook committed
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
        break;
#undef gen_pas_helper
#define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b)
    case 2:
        PAS_OP(q);
        break;
    case 3:
        PAS_OP(sh);
        break;
    case 6:
        PAS_OP(uq);
        break;
    case 7:
        PAS_OP(uh);
        break;
#undef gen_pas_helper
    }
}
pbrook's avatar
pbrook committed
566
567
#undef PAS_OP

pbrook's avatar
pbrook committed
568
569
/* For unknown reasons Arm and Thumb-2 use arbitrarily different encodings.  */
#define PAS_OP(pfx) \
570
    switch (op1) {  \
pbrook's avatar
pbrook committed
571
572
573
574
575
576
577
    case 0: gen_pas_helper(glue(pfx,add8)); break; \
    case 1: gen_pas_helper(glue(pfx,add16)); break; \
    case 2: gen_pas_helper(glue(pfx,addsubx)); break; \
    case 4: gen_pas_helper(glue(pfx,sub8)); break; \
    case 5: gen_pas_helper(glue(pfx,sub16)); break; \
    case 6: gen_pas_helper(glue(pfx,subaddx)); break; \
    }
pbrook's avatar
pbrook committed
578
static void gen_thumb2_parallel_addsub(int op1, int op2, TCGv a, TCGv b)
pbrook's avatar
pbrook committed
579
{
pbrook's avatar
pbrook committed
580
    TCGv_ptr tmp;
pbrook's avatar
pbrook committed
581

582
    switch (op2) {
pbrook's avatar
pbrook committed
583
584
#define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b, tmp)
    case 0:
pbrook's avatar
pbrook committed
585
        tmp = tcg_temp_new_ptr();
pbrook's avatar
pbrook committed
586
587
        tcg_gen_addi_ptr(tmp, cpu_env, offsetof(CPUState, GE));
        PAS_OP(s)
588
        tcg_temp_free_ptr(tmp);
pbrook's avatar
pbrook committed
589
590
        break;
    case 4:
pbrook's avatar
pbrook committed
591
        tmp = tcg_temp_new_ptr();
pbrook's avatar
pbrook committed
592
593
        tcg_gen_addi_ptr(tmp, cpu_env, offsetof(CPUState, GE));
        PAS_OP(u)
594
        tcg_temp_free_ptr(tmp);
pbrook's avatar
pbrook committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
        break;
#undef gen_pas_helper
#define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b)
    case 1:
        PAS_OP(q);
        break;
    case 2:
        PAS_OP(sh);
        break;
    case 5:
        PAS_OP(uq);
        break;
    case 6:
        PAS_OP(uh);
        break;
#undef gen_pas_helper
    }
}
pbrook's avatar
pbrook committed
613
614
#undef PAS_OP

pbrook's avatar
pbrook committed
615
616
617
618
619
620
621
622
static void gen_test_cc(int cc, int label)
{
    TCGv tmp;
    TCGv tmp2;
    int inv;

    switch (cc) {
    case 0: /* eq: Z */
pbrook's avatar
pbrook committed
623
        tmp = load_cpu_field(ZF);
pbrook's avatar
pbrook committed
624
        tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
pbrook's avatar
pbrook committed
625
626
        break;
    case 1: /* ne: !Z */
pbrook's avatar
pbrook committed
627
        tmp = load_cpu_field(ZF);
pbrook's avatar
pbrook committed
628
        tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
pbrook's avatar
pbrook committed
629
630
631
        break;
    case 2: /* cs: C */
        tmp = load_cpu_field(CF);
pbrook's avatar
pbrook committed
632
        tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
pbrook's avatar
pbrook committed
633
634
635
        break;
    case 3: /* cc: !C */
        tmp = load_cpu_field(CF);
pbrook's avatar
pbrook committed
636
        tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
pbrook's avatar
pbrook committed
637
638
        break;
    case 4: /* mi: N */
pbrook's avatar
pbrook committed
639
        tmp = load_cpu_field(NF);
pbrook's avatar
pbrook committed
640
        tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
pbrook's avatar
pbrook committed
641
642
        break;
    case 5: /* pl: !N */
pbrook's avatar
pbrook committed
643
        tmp = load_cpu_field(NF);
pbrook's avatar
pbrook committed
644
        tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
pbrook's avatar
pbrook committed
645
646
647
        break;
    case 6: /* vs: V */
        tmp = load_cpu_field(VF);
pbrook's avatar
pbrook committed
648
        tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
pbrook's avatar
pbrook committed
649
650
651
        break;
    case 7: /* vc: !V */
        tmp = load_cpu_field(VF);
pbrook's avatar
pbrook committed
652
        tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
pbrook's avatar
pbrook committed
653
654
655
656
        break;
    case 8: /* hi: C && !Z */
        inv = gen_new_label();
        tmp = load_cpu_field(CF);
pbrook's avatar
pbrook committed
657
        tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, inv);
pbrook's avatar
pbrook committed
658
        dead_tmp(tmp);
pbrook's avatar
pbrook committed
659
        tmp = load_cpu_field(ZF);
pbrook's avatar
pbrook committed
660
        tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, label);
pbrook's avatar
pbrook committed
661
662
663
664
        gen_set_label(inv);
        break;
    case 9: /* ls: !C || Z */
        tmp = load_cpu_field(CF);
pbrook's avatar
pbrook committed
665
        tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
pbrook's avatar
pbrook committed
666
        dead_tmp(tmp);
pbrook's avatar
pbrook committed
667
        tmp = load_cpu_field(ZF);
pbrook's avatar
pbrook committed
668
        tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
pbrook's avatar
pbrook committed
669
670
671
        break;
    case 10: /* ge: N == V -> N ^ V == 0 */
        tmp = load_cpu_field(VF);
pbrook's avatar
pbrook committed
672
        tmp2 = load_cpu_field(NF);
pbrook's avatar
pbrook committed
673
674
        tcg_gen_xor_i32(tmp, tmp, tmp2);
        dead_tmp(tmp2);
pbrook's avatar
pbrook committed
675
        tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
pbrook's avatar
pbrook committed
676
677
678
        break;
    case 11: /* lt: N != V -> N ^ V != 0 */
        tmp = load_cpu_field(VF);
pbrook's avatar
pbrook committed
679
        tmp2 = load_cpu_field(NF);
pbrook's avatar
pbrook committed
680
681
        tcg_gen_xor_i32(tmp, tmp, tmp2);
        dead_tmp(tmp2);
pbrook's avatar
pbrook committed
682
        tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
pbrook's avatar
pbrook committed
683
684
685
        break;
    case 12: /* gt: !Z && N == V */
        inv = gen_new_label();
pbrook's avatar
pbrook committed
686
        tmp = load_cpu_field(ZF);
pbrook's avatar
pbrook committed
687
        tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, inv);
pbrook's avatar
pbrook committed
688
689
        dead_tmp(tmp);
        tmp = load_cpu_field(VF);
pbrook's avatar
pbrook committed
690
        tmp2 = load_cpu_field(NF);
pbrook's avatar
pbrook committed
691
692
        tcg_gen_xor_i32(tmp, tmp, tmp2);
        dead_tmp(tmp2);
pbrook's avatar
pbrook committed
693
        tcg_gen_brcondi_i32(TCG_COND_GE, tmp, 0, label);
pbrook's avatar
pbrook committed
694
695
696
        gen_set_label(inv);
        break;
    case 13: /* le: Z || N != V */
pbrook's avatar
pbrook committed
697
        tmp = load_cpu_field(ZF);
pbrook's avatar
pbrook committed
698
        tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
pbrook's avatar
pbrook committed
699
700
        dead_tmp(tmp);
        tmp = load_cpu_field(VF);
pbrook's avatar
pbrook committed
701
        tmp2 = load_cpu_field(NF);
pbrook's avatar
pbrook committed
702
703
        tcg_gen_xor_i32(tmp, tmp, tmp2);
        dead_tmp(tmp2);
pbrook's avatar
pbrook committed
704
        tcg_gen_brcondi_i32(TCG_COND_LT, tmp, 0, label);
pbrook's avatar
pbrook committed
705
706
707
708
709
710
711
        break;
    default:
        fprintf(stderr, "Bad condition code 0x%x\n", cc);
        abort();
    }
    dead_tmp(tmp);
}
bellard's avatar
bellard committed
712

713
static const uint8_t table_logic_cc[16] = {
bellard's avatar
bellard committed
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
    1, /* and */
    1, /* xor */
    0, /* sub */
    0, /* rsb */
    0, /* add */
    0, /* adc */
    0, /* sbc */
    0, /* rsc */
    1, /* andl */
    1, /* xorl */
    0, /* cmp */
    0, /* cmn */
    1, /* orr */
    1, /* mov */
    1, /* bic */
    1, /* mvn */
};
731

pbrook's avatar
pbrook committed
732
733
/* Set PC and Thumb state from an immediate address.  */
static inline void gen_bx_im(DisasContext *s, uint32_t addr)
bellard's avatar
bellard committed
734
{
pbrook's avatar
pbrook committed
735
    TCGv tmp;
bellard's avatar
bellard committed
736

pbrook's avatar
pbrook committed
737
    s->is_jmp = DISAS_UPDATE;
pbrook's avatar
pbrook committed
738
    if (s->thumb != (addr & 1)) {
739
        tmp = new_tmp();
pbrook's avatar
pbrook committed
740
741
        tcg_gen_movi_i32(tmp, addr & 1);
        tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, thumb));
742
        dead_tmp(tmp);
pbrook's avatar
pbrook committed
743
    }
744
    tcg_gen_movi_i32(cpu_R[15], addr & ~1);
pbrook's avatar
pbrook committed
745
746
747
748
749
750
}

/* Set PC and Thumb state from var.  var is marked as dead.  */
static inline void gen_bx(DisasContext *s, TCGv var)
{
    s->is_jmp = DISAS_UPDATE;
751
752
753
    tcg_gen_andi_i32(cpu_R[15], var, ~1);
    tcg_gen_andi_i32(var, var, 1);
    store_cpu_field(var, thumb);
pbrook's avatar
pbrook committed
754
755
}

756
757
758
759
760
761
762
763
764
765
766
767
768
/* Variant of store_reg which uses branch&exchange logic when storing
   to r15 in ARM architecture v7 and above. The source must be a temporary
   and will be marked as dead. */
static inline void store_reg_bx(CPUState *env, DisasContext *s,
                                int reg, TCGv var)
{
    if (reg == 15 && ENABLE_ARCH_7) {
        gen_bx(s, var);
    } else {
        store_reg(s, reg, var);
    }
}

pbrook's avatar
pbrook committed
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
static inline TCGv gen_ld8s(TCGv addr, int index)
{
    TCGv tmp = new_tmp();
    tcg_gen_qemu_ld8s(tmp, addr, index);
    return tmp;
}
static inline TCGv gen_ld8u(TCGv addr, int index)
{
    TCGv tmp = new_tmp();
    tcg_gen_qemu_ld8u(tmp, addr, index);
    return tmp;
}
static inline TCGv gen_ld16s(TCGv addr, int index)
{
    TCGv tmp = new_tmp();
    tcg_gen_qemu_ld16s(tmp, addr, index);
    return tmp;
}
static inline TCGv gen_ld16u(TCGv addr, int index)
{
    TCGv tmp = new_tmp();
    tcg_gen_qemu_ld16u(tmp, addr, index);
    return tmp;
}
static inline TCGv gen_ld32(TCGv addr, int index)
{
    TCGv tmp = new_tmp();
    tcg_gen_qemu_ld32u(tmp, addr, index);
    return tmp;
}
799
800
801
802
803
804
static inline TCGv_i64 gen_ld64(TCGv addr, int index)
{
    TCGv_i64 tmp = tcg_temp_new_i64();
    tcg_gen_qemu_ld64(tmp, addr, index);
    return tmp;
}
pbrook's avatar
pbrook committed
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
static inline void gen_st8(TCGv val, TCGv addr, int index)
{
    tcg_gen_qemu_st8(val, addr, index);
    dead_tmp(val);
}
static inline void gen_st16(TCGv val, TCGv addr, int index)
{
    tcg_gen_qemu_st16(val, addr, index);
    dead_tmp(val);
}
static inline void gen_st32(TCGv val, TCGv addr, int index)
{
    tcg_gen_qemu_st32(val, addr, index);
    dead_tmp(val);
}
820
821
822
823
824
static inline void gen_st64(TCGv_i64 val, TCGv addr, int index)
{
    tcg_gen_qemu_st64(val, addr, index);
    tcg_temp_free_i64(val);
}
bellard's avatar
bellard committed
825

pbrook's avatar
pbrook committed
826
827
static inline void gen_set_pc_im(uint32_t val)
{
828
    tcg_gen_movi_i32(cpu_R[15], val);
pbrook's avatar
pbrook committed
829
830
}

bellard's avatar
bellard committed
831
832
833
/* Force a TB lookup after an instruction that changes the CPU state.  */
static inline void gen_lookup_tb(DisasContext *s)
{
834
    tcg_gen_movi_i32(cpu_R[15], s->pc & ~1);
bellard's avatar
bellard committed
835
836
837
    s->is_jmp = DISAS_UPDATE;
}

pbrook's avatar
pbrook committed
838
839
static inline void gen_add_data_offset(DisasContext *s, unsigned int insn,
                                       TCGv var)
bellard's avatar
bellard committed
840
{
bellard's avatar
bellard committed
841
    int val, rm, shift, shiftop;
pbrook's avatar
pbrook committed
842
    TCGv offset;
bellard's avatar
bellard committed
843
844
845
846
847
848

    if (!(insn & (1 << 25))) {
        /* immediate */
        val = insn & 0xfff;
        if (!(insn & (1 << 23)))
            val = -val;
bellard's avatar
bellard committed
849
        if (val != 0)
pbrook's avatar
pbrook committed
850
            tcg_gen_addi_i32(var, var, val);
bellard's avatar
bellard committed
851
852
853
854
    } else {
        /* shift/register */
        rm = (insn) & 0xf;
        shift = (insn >> 7) & 0x1f;
bellard's avatar
bellard committed
855
        shiftop = (insn >> 5) & 3;
pbrook's avatar
pbrook committed
856
        offset = load_reg(s, rm);
pbrook's avatar
pbrook committed
857
        gen_arm_shift_im(offset, shiftop, shift, 0);
bellard's avatar
bellard committed
858
        if (!(insn & (1 << 23)))
pbrook's avatar
pbrook committed
859
            tcg_gen_sub_i32(var, var, offset);
bellard's avatar
bellard committed
860
        else
pbrook's avatar
pbrook committed
861
            tcg_gen_add_i32(var, var, offset);
pbrook's avatar
pbrook committed
862
        dead_tmp(offset);
bellard's avatar
bellard committed
863
864
865
    }
}

pbrook's avatar
pbrook committed
866
static inline void gen_add_datah_offset(DisasContext *s, unsigned int insn,
pbrook's avatar
pbrook committed
867
                                        int extra, TCGv var)
bellard's avatar
bellard committed
868
869
{
    int val, rm;
pbrook's avatar
pbrook committed
870
    TCGv offset;
871

bellard's avatar
bellard committed
872
873
874
875
876
    if (insn & (1 << 22)) {
        /* immediate */
        val = (insn & 0xf) | ((insn >> 4) & 0xf0);
        if (!(insn & (1 << 23)))
            val = -val;
877
        val += extra;
bellard's avatar
bellard committed
878
        if (val != 0)
pbrook's avatar
pbrook committed
879
            tcg_gen_addi_i32(var, var, val);
bellard's avatar
bellard committed
880
881
    } else {
        /* register */
pbrook's avatar
pbrook committed
882
        if (extra)
pbrook's avatar
pbrook committed
883
            tcg_gen_addi_i32(var, var, extra);
bellard's avatar
bellard committed
884
        rm = (insn) & 0xf;
pbrook's avatar
pbrook committed
885
        offset = load_reg(s, rm);
bellard's avatar
bellard committed
886
        if (!(insn & (1 << 23)))
pbrook's avatar
pbrook committed
887
            tcg_gen_sub_i32(var, var, offset);
bellard's avatar
bellard committed
888
        else
pbrook's avatar
pbrook committed
889
            tcg_gen_add_i32(var, var, offset);
pbrook's avatar
pbrook committed
890
        dead_tmp(offset);
bellard's avatar
bellard committed
891
892
893
    }
}

pbrook's avatar
pbrook committed
894
895
896
897
898
899
900
#define VFP_OP2(name)                                                 \
static inline void gen_vfp_##name(int dp)                             \
{                                                                     \
    if (dp)                                                           \
        gen_helper_vfp_##name##d(cpu_F0d, cpu_F0d, cpu_F1d, cpu_env); \
    else                                                              \
        gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, cpu_F1s, cpu_env); \
bellard's avatar
bellard committed
901
902
}

pbrook's avatar
pbrook committed
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
VFP_OP2(add)
VFP_OP2(sub)
VFP_OP2(mul)
VFP_OP2(div)

#undef VFP_OP2

static inline void gen_vfp_abs(int dp)
{
    if (dp)
        gen_helper_vfp_absd(cpu_F0d, cpu_F0d);
    else
        gen_helper_vfp_abss(cpu_F0s, cpu_F0s);
}

static inline void gen_vfp_neg(int dp)
{
    if (dp)
        gen_helper_vfp_negd(cpu_F0d, cpu_F0d);
    else
        gen_helper_vfp_negs(cpu_F0s, cpu_F0s);
}

static inline void gen_vfp_sqrt(int dp)
{
    if (dp)
        gen_helper_vfp_sqrtd(cpu_F0d, cpu_F0d, cpu_env);
    else
        gen_helper_vfp_sqrts(cpu_F0s, cpu_F0s, cpu_env);
}

static inline void gen_vfp_cmp(int dp)
{
    if (dp)
        gen_helper_vfp_cmpd(cpu_F0d, cpu_F1d, cpu_env);
    else
        gen_helper_vfp_cmps(cpu_F0s, cpu_F1s, cpu_env);
}

static inline void gen_vfp_cmpe(int dp)
{
    if (dp)
        gen_helper_vfp_cmped(cpu_F0d, cpu_F1d, cpu_env);
    else
        gen_helper_vfp_cmpes(cpu_F0s, cpu_F1s, cpu_env);
}

static inline void gen_vfp_F1_ld0(int dp)
{
    if (dp)
balrog's avatar
balrog committed
953
        tcg_gen_movi_i64(cpu_F1d, 0);
pbrook's avatar
pbrook committed
954
    else
balrog's avatar
balrog committed
955
        tcg_gen_movi_i32(cpu_F1s, 0);
pbrook's avatar
pbrook committed
956
957
958
959
960
961
962
963
964
965
966
967
968
}

static inline void gen_vfp_uito(int dp)
{
    if (dp)
        gen_helper_vfp_uitod(cpu_F0d, cpu_F0s, cpu_env);
    else
        gen_helper_vfp_uitos(cpu_F0s, cpu_F0s, cpu_env);
}

static inline void gen_vfp_sito(int dp)
{
    if (dp)
969
        gen_helper_vfp_sitod(cpu_F0d, cpu_F0s, cpu_env);
pbrook's avatar
pbrook committed
970
    else
971
        gen_helper_vfp_sitos(cpu_F0s, cpu_F0s, cpu_env);
pbrook's avatar
pbrook committed
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
}

static inline void gen_vfp_toui(int dp)
{
    if (dp)
        gen_helper_vfp_touid(cpu_F0s, cpu_F0d, cpu_env);
    else
        gen_helper_vfp_touis(cpu_F0s, cpu_F0s, cpu_env);
}

static inline void gen_vfp_touiz(int dp)
{
    if (dp)
        gen_helper_vfp_touizd(cpu_F0s, cpu_F0d, cpu_env);
    else
        gen_helper_vfp_touizs(cpu_F0s, cpu_F0s, cpu_env);
}

static inline void gen_vfp_tosi(int dp)
{
    if (dp)
        gen_helper_vfp_tosid(cpu_F0s, cpu_F0d, cpu_env);
    else
        gen_helper_vfp_tosis(cpu_F0s, cpu_F0s, cpu_env);
}

static inline void gen_vfp_tosiz(int dp)
pbrook's avatar
pbrook committed
999
1000
{
    if (dp)
pbrook's avatar
pbrook committed
1001
        gen_helper_vfp_tosizd(cpu_F0s, cpu_F0d, cpu_env);
pbrook's avatar
pbrook committed
1002
    else
pbrook's avatar
pbrook committed
1003
1004
1005
1006
1007
1008
        gen_helper_vfp_tosizs(cpu_F0s, cpu_F0s, cpu_env);
}

#define VFP_GEN_FIX(name) \
static inline void gen_vfp_##name(int dp, int shift) \
{ \
1009
    TCGv tmp_shift = tcg_const_i32(shift); \
pbrook's avatar
pbrook committed
1010
    if (dp) \
1011
        gen_helper_vfp_##name##d(cpu_F0d, cpu_F0d, tmp_shift, cpu_env);\
pbrook's avatar
pbrook committed
1012
    else \
1013
1014
        gen_helper_vfp_##name##s(cpu_F0s, cpu_F0s, tmp_shift, cpu_env);\
    tcg_temp_free_i32(tmp_shift); \
pbrook's avatar
pbrook committed
1015
}
pbrook's avatar
pbrook committed
1016
1017
1018
1019
1020
1021
1022
1023
1024
VFP_GEN_FIX(tosh)
VFP_GEN_FIX(tosl)
VFP_GEN_FIX(touh)
VFP_GEN_FIX(toul)
VFP_GEN_FIX(shto)
VFP_GEN_FIX(slto)
VFP_GEN_FIX(uhto)
VFP_GEN_FIX(ulto)
#undef VFP_GEN_FIX
pbrook's avatar
pbrook committed
1025

1026
static inline void gen_vfp_ld(DisasContext *s, int dp, TCGv addr)
bellard's avatar
bellard committed
1027
1028
{
    if (dp)
1029
        tcg_gen_qemu_ld64(cpu_F0d, addr, IS_USER(s));
bellard's avatar
bellard committed
1030
    else
1031
        tcg_gen_qemu_ld32u(cpu_F0s, addr, IS_USER(s));
bellard's avatar
bellard committed
1032
1033
}

1034
static inline void gen_vfp_st(DisasContext *s, int dp, TCGv addr)
bellard's avatar
bellard committed
1035
1036
{
    if (dp)
1037
        tcg_gen_qemu_st64(cpu_F0d, addr, IS_USER(s));
bellard's avatar
bellard committed
1038
    else
1039
        tcg_gen_qemu_st32(cpu_F0s, addr, IS_USER(s));
bellard's avatar
bellard committed
1040
1041
}

bellard's avatar
bellard committed
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
static inline long
vfp_reg_offset (int dp, int reg)
{
    if (dp)
        return offsetof(CPUARMState, vfp.regs[reg]);
    else if (reg & 1) {
        return offsetof(CPUARMState, vfp.regs[reg >> 1])
          + offsetof(CPU_DoubleU, l.upper);
    } else {
        return offsetof(CPUARMState, vfp.regs[reg >> 1])
          + offsetof(CPU_DoubleU, l.lower);
    }
}
pbrook's avatar
pbrook committed
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065

/* Return the offset of a 32-bit piece of a NEON register.
   zero is the least significant end of the register.  */
static inline long
neon_reg_offset (int reg, int n)
{
    int sreg;
    sreg = reg * 2 + n;
    return vfp_reg_offset(0, sreg);
}

pbrook's avatar
pbrook committed
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
static TCGv neon_load_reg(int reg, int pass)
{
    TCGv tmp = new_tmp();
    tcg_gen_ld_i32(tmp, cpu_env, neon_reg_offset(reg, pass));
    return tmp;
}

static void neon_store_reg(int reg, int pass, TCGv var)
{
    tcg_gen_st_i32(var, cpu_env, neon_reg_offset(reg, pass));
    dead_tmp(var);
}

pbrook's avatar
pbrook committed
1079
static inline void neon_load_reg64(TCGv_i64 var, int reg)
pbrook's avatar
pbrook committed
1080
1081
1082
1083
{
    tcg_gen_ld_i64(var, cpu_env, vfp_reg_offset(1, reg));
}

pbrook's avatar
pbrook committed
1084
static inline void neon_store_reg64(TCGv_i64 var, int reg)
pbrook's avatar
pbrook committed
1085
1086
1087
1088
{
    tcg_gen_st_i64(var, cpu_env, vfp_reg_offset(1, reg));
}

pbrook's avatar
pbrook committed
1089
1090
1091
1092
1093
#define tcg_gen_ld_f32 tcg_gen_ld_i32
#define tcg_gen_ld_f64 tcg_gen_ld_i64
#define tcg_gen_st_f32 tcg_gen_st_i32
#define tcg_gen_st_f64 tcg_gen_st_i64

bellard's avatar
bellard committed
1094
1095
1096
static inline void gen_mov_F0_vreg(int dp, int reg)
{
    if (dp)
pbrook's avatar
pbrook committed
1097
        tcg_gen_ld_f64(cpu_F0d, cpu_env, vfp_reg_offset(dp, reg));
bellard's avatar
bellard committed
1098
    else
pbrook's avatar
pbrook committed
1099
        tcg_gen_ld_f32(cpu_F0s, cpu_env, vfp_reg_offset(dp, reg));
bellard's avatar
bellard committed
1100
1101
1102
1103
1104
}

static inline void gen_mov_F1_vreg(int dp, int reg)
{
    if (dp)
pbrook's avatar
pbrook committed
1105
        tcg_gen_ld_f64(cpu_F1d, cpu_env, vfp_reg_offset(dp, reg));
bellard's avatar
bellard committed
1106
    else
pbrook's avatar
pbrook committed
1107
        tcg_gen_ld_f32(cpu_F1s, cpu_env, vfp_reg_offset(dp, reg));
bellard's avatar
bellard committed
1108
1109
1110
1111
1112
}

static inline void gen_mov_vreg_F0(int dp, int reg)
{
    if (dp)
pbrook's avatar
pbrook committed
1113
        tcg_gen_st_f64(cpu_F0d, cpu_env, vfp_reg_offset(dp, reg));
bellard's avatar
bellard committed
1114
    else
pbrook's avatar
pbrook committed
1115
        tcg_gen_st_f32(cpu_F0s, cpu_env, vfp_reg_offset(dp, reg));
bellard's avatar
bellard committed
1116
1117
}

1118
1119
#define ARM_CP_RW_BIT	(1 << 20)

pbrook's avatar
pbrook committed
1120
static inline void iwmmxt_load_reg(TCGv_i64 var, int reg)
pbrook's avatar
pbrook committed
1121
1122
1123
1124
{
    tcg_gen_ld_i64(var, cpu_env, offsetof(CPUState, iwmmxt.regs[reg]));
}

pbrook's avatar
pbrook committed
1125
static inline void iwmmxt_store_reg(TCGv_i64 var, int reg)
pbrook's avatar
pbrook committed
1126
1127
1128
1129
{
    tcg_gen_st_i64(var, cpu_env, offsetof(CPUState, iwmmxt.regs[reg]));
}

1130
static inline TCGv iwmmxt_load_creg(int reg)
pbrook's avatar
pbrook committed
1131
{
1132
1133
1134
    TCGv var = new_tmp();
    tcg_gen_ld_i32(var, cpu_env, offsetof(CPUState, iwmmxt.cregs[reg]));
    return var;
pbrook's avatar
pbrook committed
1135
1136
}

1137
static inline void iwmmxt_store_creg(int reg, TCGv var)
pbrook's avatar
pbrook committed
1138
{
1139
    tcg_gen_st_i32(var, cpu_env, offsetof(CPUState, iwmmxt.cregs[reg]));
1140
    dead_tmp(var);
pbrook's avatar
pbrook committed
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
}

static inline void gen_op_iwmmxt_movq_wRn_M0(int rn)
{
    iwmmxt_store_reg(cpu_M0, rn);
}

static inline void gen_op_iwmmxt_movq_M0_wRn(int rn)
{
    iwmmxt_load_reg(cpu_M0, rn);
}

static inline void gen_op_iwmmxt_orq_M0_wRn(int rn)
{
    iwmmxt_load_reg(cpu_V1, rn);
    tcg_gen_or_i64(cpu_M0, cpu_M0, cpu_V1);
}

static inline void gen_op_iwmmxt_andq_M0_wRn(int rn)
{
    iwmmxt_load_reg(cpu_V1, rn);
    tcg_gen_and_i64(cpu_M0, cpu_M0, cpu_V1);
}

static inline void gen_op_iwmmxt_xorq_M0_wRn(int rn)
{
    iwmmxt_load_reg(cpu_V1, rn);
    tcg_gen_xor_i64(cpu_M0, cpu_M0, cpu_V1);
}

#define IWMMXT_OP(name) \
static inline void gen_op_iwmmxt_##name##_M0_wRn(int rn) \
{ \
    iwmmxt_load_reg(cpu_V1, rn); \
    gen_helper_iwmmxt_##name(cpu_M0, cpu_M0, cpu_V1); \
}

#define IWMMXT_OP_ENV(name) \
static inline void gen_op_iwmmxt_##name##_M0_wRn(int rn) \
{ \
    iwmmxt_load_reg(cpu_V1, rn); \
    gen_helper_iwmmxt_##name(cpu_M0, cpu_env, cpu_M0, cpu_V1); \
}

#define IWMMXT_OP_ENV_SIZE(name) \
IWMMXT_OP_ENV(name##b) \
IWMMXT_OP_ENV(name##w) \
IWMMXT_OP_ENV(name##l)

#define IWMMXT_OP_ENV1(name) \
static inline void gen_op_iwmmxt_##name##_M0(void) \
{ \
    gen_helper_iwmmxt_##name(cpu_M0, cpu_env, cpu_M0); \
}

IWMMXT_OP(maddsq)
IWMMXT_OP(madduq)
IWMMXT_OP(sadb)
IWMMXT_OP(sadw)
IWMMXT_OP(mulslw)
IWMMXT_OP(mulshw)
IWMMXT_OP(mululw)
IWMMXT_OP(muluhw)
IWMMXT_OP(macsw)
IWMMXT_OP(macuw)

IWMMXT_OP_ENV_SIZE(unpackl)
IWMMXT_OP_ENV_SIZE(unpackh)

IWMMXT_OP_ENV1(unpacklub)
IWMMXT_OP_ENV1(unpackluw)
IWMMXT_OP_ENV1(unpacklul)
IWMMXT_OP_ENV1(unpackhub)
IWMMXT_OP_ENV1(unpackhuw)
IWMMXT_OP_ENV1(unpackhul)
IWMMXT_OP_ENV1(unpacklsb)
IWMMXT_OP_ENV1(unpacklsw)
IWMMXT_OP_ENV1(unpacklsl)
IWMMXT_OP_ENV1(unpackhsb)
IWMMXT_OP_ENV1(unpackhsw)
IWMMXT_OP_ENV1(unpackhsl)

IWMMXT_OP_ENV_SIZE(cmpeq)
IWMMXT_OP_ENV_SIZE(cmpgtu)
IWMMXT_OP_ENV_SIZE(cmpgts)

IWMMXT_OP_ENV_SIZE(mins)
IWMMXT_OP_ENV_SIZE(minu)
IWMMXT_OP_ENV_SIZE(maxs)
IWMMXT_OP_ENV_SIZE(maxu)

IWMMXT_OP_ENV_SIZE(subn)
IWMMXT_OP_ENV_SIZE(addn)
IWMMXT_OP_ENV_SIZE(subu)
IWMMXT_OP_ENV_SIZE(addu)
IWMMXT_OP_ENV_SIZE(subs)
IWMMXT_OP_ENV_SIZE(adds)

IWMMXT_OP_ENV(avgb0)
IWMMXT_OP_ENV(avgb1)
IWMMXT_OP_ENV(avgw0)
IWMMXT_OP_ENV(avgw1)

IWMMXT_OP(msadb)

IWMMXT_OP_ENV(packuw)
IWMMXT_OP_ENV(packul)
IWMMXT_OP_ENV(packuq)
IWMMXT_OP_ENV(packsw)
IWMMXT_OP_ENV(packsl)
IWMMXT_OP_ENV(packsq)

static void gen_op_iwmmxt_set_mup(void)
{
    TCGv tmp;
    tmp = load_cpu_field(iwmmxt.cregs[ARM_IWMMXT_wCon]);
    tcg_gen_ori_i32(tmp, tmp, 2);
    store_cpu_field(tmp, iwmmxt.cregs[ARM_IWMMXT_wCon]);
}

static void gen_op_iwmmxt_set_cup(void)
{
    TCGv tmp;
    tmp = load_cpu_field(iwmmxt.cregs[ARM_IWMMXT_wCon]);
    tcg_gen_ori_i32(tmp, tmp, 1);
    store_cpu_field(tmp, iwmmxt.cregs[ARM_IWMMXT_wCon]);
}

static void gen_op_iwmmxt_setpsr_nz(void)
{
    TCGv tmp = new_tmp();
    gen_helper_iwmmxt_setpsr_nz(tmp, cpu_M0);
    store_cpu_field(tmp, iwmmxt.cregs[ARM_IWMMXT_wCASF]);
}

static inline void gen_op_iwmmxt_addl_M0_wRn(int rn)
{
    iwmmxt_load_reg(cpu_V1, rn);
pbrook's avatar
pbrook committed
1279
    tcg_gen_ext32u_i64(cpu_V1, cpu_V1);
pbrook's avatar
pbrook committed
1280
1281
1282
    tcg_gen_add_i64(cpu_M0, cpu_M0, cpu_V1);
}

1283
static inline int gen_iwmmxt_address(DisasContext *s, uint32_t insn, TCGv dest)
1284
1285
1286
{
    int rd;
    uint32_t offset;
1287
    TCGv tmp;
1288
1289

    rd = (insn >> 16) & 0xf;
1290
    tmp = load_reg(s, rd);
1291
1292
1293
1294
1295

    offset = (insn & 0xff) << ((insn >> 7) & 2);
    if (insn & (1 << 24)) {
        /* Pre indexed */
        if (insn & (1 << 23))
1296
            tcg_gen_addi_i32(tmp, tmp, offset);
1297
        else
1298
1299
            tcg_gen_addi_i32(tmp, tmp, -offset);
        tcg_gen_mov_i32(dest, tmp);
1300
        if (insn & (1 << 21))
1301
1302
1303
            store_reg(s, rd, tmp);
        else
            dead_tmp(tmp);
1304
1305
    } else if (insn & (1 << 21)) {
        /* Post indexed */
1306
        tcg_gen_mov_i32(dest, tmp);
1307
        if (insn & (1 << 23))
1308
            tcg_gen_addi_i32(tmp, tmp, offset);
1309
        else
1310
1311
            tcg_gen_addi_i32(tmp, tmp, -offset);
        store_reg(s, rd, tmp);
1312
1313
1314
1315
1316
    } else if (!(insn & (1 << 23)))
        return 1;
    return 0;
}

1317
static inline int gen_iwmmxt_shift(uint32_t insn, uint32_t mask, TCGv dest)
1318
1319
{
    int rd = (insn >> 0) & 0xf;
1320
    TCGv tmp;
1321

1322
1323
    if (insn & (1 << 8)) {
        if (rd < ARM_IWMMXT_wCGR0 || rd > ARM_IWMMXT_wCGR3) {
1324
            return 1;
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
        } else {
            tmp = iwmmxt_load_creg(rd);
        }
    } else {
        tmp = new_tmp();
        iwmmxt_load_reg(cpu_V0, rd);
        tcg_gen_trunc_i64_i32(tmp, cpu_V0);
    }
    tcg_gen_andi_i32(tmp, tmp, mask);
    tcg_gen_mov_i32(dest, tmp);
    dead_tmp(tmp);
1336
1337
1338
1339
1340
1341
1342
1343
1344
    return 0;
}

/* Disassemble an iwMMXt instruction.  Returns nonzero if an error occured
   (ie. an undefined instruction).  */
static int disas_iwmmxt_insn(CPUState *env, DisasContext *s, uint32_t insn)
{
    int rd, wrd;
    int rdhi, rdlo, rd0, rd1, i;
1345
1346
    TCGv addr;
    TCGv tmp, tmp2, tmp3;
1347
1348
1349
1350
1351
1352
1353

    if ((insn & 0x0e000e00) == 0x0c000000) {
        if ((insn & 0x0fe00ff0) == 0x0c400000) {
            wrd = insn & 0xf;
            rdlo = (insn >> 12) & 0xf;
            rdhi = (insn >> 16) & 0xf;
            if (insn & ARM_CP_RW_BIT) {			/* TMRRC */
1354
1355
1356
1357
                iwmmxt_load_reg(cpu_V0, wrd);
                tcg_gen_trunc_i64_i32(cpu_R[rdlo], cpu_V0);
                tcg_gen_shri_i64(cpu_V0, cpu_V0, 32);
                tcg_gen_trunc_i64_i32(cpu_R[rdhi], cpu_V0);
1358
            } else {					/* TMCRR */
1359
1360
                tcg_gen_concat_i32_i64(cpu_V0, cpu_R[rdlo], cpu_R[rdhi]);
                iwmmxt_store_reg(cpu_V0, wrd);
1361
1362
1363
1364
1365
1366
                gen_op_iwmmxt_set_mup();
            }
            return 0;
        }

        wrd = (insn >> 12) & 0xf;
1367
1368
1369
        addr = new_tmp();
        if (gen_iwmmxt_address(s, insn, addr)) {
            dead_tmp(addr);
1370
            return 1;
1371
        }
1372
1373
        if (insn & ARM_CP_RW_BIT) {
            if ((insn >> 28) == 0xf) {			/* WLDRW wCx */
1374
1375
1376
                tmp = new_tmp();
                tcg_gen_qemu_ld32u(tmp, addr, IS_USER(s));
                iwmmxt_store_creg(wrd, tmp);
1377
            } else {
pbrook's avatar
pbrook committed
1378
1379
1380
                i = 1;
                if (insn & (1 << 8)) {
                    if (insn & (1 << 22)) {		/* WLDRD */
1381
                        tcg_gen_qemu_ld64(cpu_M0, addr, IS_USER(s));
pbrook's avatar
pbrook committed
1382
1383
                        i = 0;
                    } else {				/* WLDRW wRd */
1384
                        tmp = gen_ld32(addr, IS_USER(s));
pbrook's avatar
pbrook committed
1385
1386
1387
                    }
                } else {
                    if (insn & (1 << 22)) {		/* WLDRH */
1388
                        tmp = gen_ld16u(addr, IS_USER(s));
pbrook's avatar
pbrook committed
1389
                    } else {				/* WLDRB */
1390
                        tmp = gen_ld8u(addr, IS_USER(s));
pbrook's avatar
pbrook committed
1391
1392
1393
1394
1395
1396
                    }
                }
                if (i) {
                    tcg_gen_extu_i32_i64(cpu_M0, tmp);
                    dead_tmp(tmp);
                }
1397
1398
1399
1400
                gen_op_iwmmxt_movq_wRn_M0(wrd);
            }
        } else {
            if ((insn >> 28) == 0xf) {			/* WSTRW wCx */
1401
1402
                tmp = iwmmxt_load_creg(wrd);
                gen_st32(tmp, addr, IS_USER(s));
1403
1404
            } else {
                gen_op_iwmmxt_movq_M0_wRn(wrd);
pbrook's avatar
pbrook committed
1405
1406
1407
1408
                tmp = new_tmp();
                if (insn & (1 << 8)) {
                    if (insn & (1 << 22)) {		/* WSTRD */
                        dead_tmp(tmp);
1409
                        tcg_gen_qemu_st64(cpu_M0, addr, IS_USER(s));
pbrook's avatar
pbrook committed
1410
1411
                    } else {				/* WSTRW wRd */
                        tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1412
                        gen_st32(tmp, addr, IS_USER(s));
pbrook's avatar
pbrook committed
1413
1414
1415
1416
                    }
                } else {
                    if (insn & (1 << 22)) {		/* WSTRH */
                        tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1417
                        gen_st16(tmp, addr, IS_USER(s));
pbrook's avatar
pbrook committed
1418
1419
                    } else {				/* WSTRB */
                        tcg_gen_trunc_i64_i32(tmp, cpu_M0);
1420
                        gen_st8(tmp, addr, IS_USER(s));
pbrook's avatar
pbrook committed
1421
1422
                    }
                }
1423
1424
            }
        }
1425
        dead_tmp(addr);
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
        return 0;
    }

    if ((insn & 0x0f000000) != 0x0e000000)
        return 1;

    switch (((insn >> 12) & 0xf00) | ((insn >> 4) & 0xff)) {
    case 0x000:						/* WOR */
        wrd = (insn >> 12) & 0xf;
        rd0 = (insn >> 0) & 0xf;
        rd1 = (insn >> 16) & 0xf;
        gen_op_iwmmxt_movq_M0_wRn(rd0);
        gen_op_iwmmxt_orq_M0_wRn(rd1);
        gen_op_iwmmxt_setpsr_nz();
        gen_op_iwmmxt_movq_wRn_M0(wrd);
        gen_op_iwmmxt_set_mup();
        gen_op_iwmmxt_set_cup();
        break;
    case 0x011:						/* TMCR */
        if (insn & 0xf)
            return 1;
        rd = (insn >> 12) & 0xf;
        wrd = (insn >> 16) & 0xf;
        switch (wrd) {
        case ARM_IWMMXT_wCID:
        case ARM_IWMMXT_wCASF:
            break;
        case ARM_IWMMXT_wCon:
            gen_op_iwmmxt_set_cup();
            /* Fall through.  */
        case ARM_IWMMXT_wCSSF:
1457
1458
            tmp = iwmmxt_load_creg(wrd);
            tmp2 = load_reg(s, rd);
1459
            tcg_gen_andc_i32(tmp, tmp, tmp2);
1460
1461
            dead_tmp(tmp2);
            iwmmxt_store_creg(wrd, tmp);
1462
1463
1464
1465
1466
1467
            break;
        case ARM_IWMMXT_wCGR0:
        case ARM_IWMMXT_wCGR1:
        case ARM_IWMMXT_wCGR2:
        case ARM_IWMMXT_wCGR3:
            gen_op_iwmmxt_set_cup();
1468
1469
            tmp = load_reg(s, rd);
            iwmmxt_store_creg(wrd, tmp);
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
            break;
        default:
            return 1;
        }
        break;
    case 0x100:						/* WXOR */
        wrd = (insn >> 12) & 0xf;
        rd0 = (insn >> 0) & 0xf;
        rd1 = (insn >> 16) & 0xf;
        gen_op_iwmmxt_movq_M0_wRn(rd0);
        gen_op_iwmmxt_xorq_M0_wRn(rd1);
        gen_op_iwmmxt_setpsr_nz();
        gen_op_iwmmxt_movq_wRn_M0(wrd);
        gen_op_iwmmxt_set_mup();
        gen_op_iwmmxt_set_cup();
        break;
    case 0x111:						/* TMRC */
        if (insn & 0xf)
            return 1;
        rd = (insn >> 12) & 0xf;
        wrd = (insn >> 16) & 0xf;
1491
1492
        tmp = iwmmxt_load_creg(wrd);
        store_reg(s, rd, tmp);
1493
1494
1495
1496
1497
1498
        break;
    case 0x300:						/* WANDN */
        wrd = (insn >> 12) & 0xf;
        rd0 = (insn >> 0) & 0xf;
        rd1 = (insn >> 16) & 0xf;
        gen_op_iwmmxt_movq_M0_wRn(rd0);
pbrook's avatar
pbrook committed
1499
        tcg_gen_neg_i64(cpu_M0, cpu_M0);
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590