~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to target-arm/cpu.h

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
   s<2n+1> maps to the most significant half of d<n>
78
78
 */
79
79
 
 
80
/* CPU state for each instance of a generic timer (in cp15 c14) */
 
81
typedef struct ARMGenericTimer {
 
82
    uint64_t cval; /* Timer CompareValue register */
 
83
    uint32_t ctl; /* Timer Control register */
 
84
} ARMGenericTimer;
 
85
 
 
86
#define GTIMER_PHYS 0
 
87
#define GTIMER_VIRT 1
 
88
#define NUM_GTIMERS 2
 
89
 
 
90
/* Scale factor for generic timers, ie number of ns per tick.
 
91
 * This gives a 62.5MHz timer.
 
92
 */
 
93
#define GTIMER_SCALE 16
 
94
 
80
95
typedef struct CPUARMState {
81
96
    /* Regs for current mode.  */
82
97
    uint32_t regs[16];
148
163
        uint32_t c13_tls1; /* User RW Thread register.  */
149
164
        uint32_t c13_tls2; /* User RO Thread register.  */
150
165
        uint32_t c13_tls3; /* Privileged Thread register.  */
 
166
        uint32_t c14_cntfrq; /* Counter Frequency register */
 
167
        uint32_t c14_cntkctl; /* Timer Control register */
 
168
        ARMGenericTimer c14_timer[NUM_GTIMERS];
151
169
        uint32_t c15_cpar; /* XScale Coprocessor Access Register */
152
170
        uint32_t c15_ticonfig; /* TI925T configuration byte.  */
153
171
        uint32_t c15_i_max; /* Maximum D-cache dirty line index.  */
254
272
                              int mmu_idx);
255
273
#define cpu_handle_mmu_fault cpu_arm_handle_mmu_fault
256
274
 
257
 
static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls)
258
 
{
259
 
  env->cp15.c13_tls2 = newtls;
260
 
}
261
 
 
262
275
#define CPSR_M (0x1f)
263
276
#define CPSR_T (1 << 5)
264
277
#define CPSR_F (1 << 6)
398
411
    ARM_FEATURE_MPIDR, /* has cp15 MPIDR */
399
412
    ARM_FEATURE_PXN, /* has Privileged Execute Never bit */
400
413
    ARM_FEATURE_LPAE, /* has Large Physical Address Extension */
 
414
    ARM_FEATURE_V8,
401
415
    ARM_FEATURE_TRUSTZONE, /* TrustZone Security Extensions. */
402
416
};
403
417
 
431
445
    (((cp) << 16) | ((is64) << 15) | ((crn) << 11) |    \
432
446
     ((crm) << 7) | ((opc1) << 3) | (opc2))
433
447
 
 
448
/* Note that these must line up with the KVM/ARM register
 
449
 * ID field definitions (kvm.c will check this, but we
 
450
 * can't just use the KVM defines here as the kvm headers
 
451
 * are unavailable to non-KVM-specific files)
 
452
 */
 
453
#define CP_REG_SIZE_SHIFT 52
 
454
#define CP_REG_SIZE_MASK       0x00f0000000000000ULL
 
455
#define CP_REG_SIZE_U32        0x0020000000000000ULL
 
456
#define CP_REG_SIZE_U64        0x0030000000000000ULL
 
457
#define CP_REG_ARM             0x4000000000000000ULL
 
458
 
 
459
/* Convert a full 64 bit KVM register ID to the truncated 32 bit
 
460
 * version used as a key for the coprocessor register hashtable
 
461
 */
 
462
static inline uint32_t kvm_to_cpreg_id(uint64_t kvmid)
 
463
{
 
464
    uint32_t cpregid = kvmid;
 
465
    if ((kvmid & CP_REG_SIZE_MASK) == CP_REG_SIZE_U64) {
 
466
        cpregid |= (1 << 15);
 
467
    }
 
468
    return cpregid;
 
469
}
 
470
 
 
471
/* Convert a truncated 32 bit hashtable key into the full
 
472
 * 64 bit KVM register ID.
 
473
 */
 
474
static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid)
 
475
{
 
476
    uint64_t kvmid = cpregid & ~(1 << 15);
 
477
    if (cpregid & (1 << 15)) {
 
478
        kvmid |= CP_REG_SIZE_U64 | CP_REG_ARM;
 
479
    } else {
 
480
        kvmid |= CP_REG_SIZE_U32 | CP_REG_ARM;
 
481
    }
 
482
    return kvmid;
 
483
}
 
484
 
434
485
/* ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a
435
486
 * special-behaviour cp reg and bits [15..8] indicate what behaviour
436
487
 * it has. Otherwise it is a simple cp reg, where CONST indicates that
441
492
 * a register definition to override a previous definition for the
442
493
 * same (cp, is64, crn, crm, opc1, opc2) tuple: either the new or the
443
494
 * old must have the OVERRIDE bit set.
 
495
 * NO_MIGRATE indicates that this register should be ignored for migration;
 
496
 * (eg because any state is accessed via some other coprocessor register).
 
497
 * IO indicates that this register does I/O and therefore its accesses
 
498
 * need to be surrounded by gen_io_start()/gen_io_end(). In particular,
 
499
 * registers which implement clocks or timers require this.
444
500
 */
445
501
#define ARM_CP_SPECIAL 1
446
502
#define ARM_CP_CONST 2
447
503
#define ARM_CP_64BIT 4
448
504
#define ARM_CP_SUPPRESS_TB_END 8
449
505
#define ARM_CP_OVERRIDE 16
 
506
#define ARM_CP_NO_MIGRATE 32
 
507
#define ARM_CP_IO 64
450
508
#define ARM_CP_NOP (ARM_CP_SPECIAL | (1 << 8))
451
509
#define ARM_CP_WFI (ARM_CP_SPECIAL | (2 << 8))
452
510
#define ARM_LAST_SPECIAL ARM_CP_WFI
453
511
/* Used only as a terminator for ARMCPRegInfo lists */
454
512
#define ARM_CP_SENTINEL 0xffff
455
513
/* Mask of only the flag bits in a type field */
456
 
#define ARM_CP_FLAG_MASK 0x1f
 
514
#define ARM_CP_FLAG_MASK 0x7f
457
515
 
458
516
/* Return true if cptype is a valid type field. This is used to try to
459
517
 * catch errors where the sentinel has been accidentally left off the end
463
521
{
464
522
    return ((cptype & ~ARM_CP_FLAG_MASK) == 0)
465
523
        || ((cptype & ARM_CP_SPECIAL) &&
466
 
            (cptype <= ARM_LAST_SPECIAL));
 
524
            ((cptype & ~ARM_CP_FLAG_MASK) <= ARM_LAST_SPECIAL));
467
525
}
468
526
 
469
527
/* Access rights:
569
627
     * by fieldoffset.
570
628
     */
571
629
    CPWriteFn *writefn;
 
630
    /* Function for doing a "raw" read; used when we need to copy
 
631
     * coprocessor state to the kernel for KVM or out for
 
632
     * migration. This only needs to be provided if there is also a
 
633
     * readfn and it makes an access permission check.
 
634
     */
 
635
    CPReadFn *raw_readfn;
 
636
    /* Function for doing a "raw" write; used when we need to copy KVM
 
637
     * kernel coprocessor state into userspace, or for inbound
 
638
     * migration. This only needs to be provided if there is also a
 
639
     * writefn and it makes an access permission check or masks out
 
640
     * "unwritable" bits or has write-one-to-clear or similar behaviour.
 
641
     */
 
642
    CPWriteFn *raw_writefn;
572
643
    /* Function for resetting the register. If NULL, then reset will be done
573
644
     * by writing resetvalue to the field specified in fieldoffset. If
574
645
     * fieldoffset is 0 then no reset will be done.
612
683
    return (ri->access >> ((arm_current_pl(env) * 2) + isread)) & 1;
613
684
}
614
685
 
 
686
/**
 
687
 * write_list_to_cpustate
 
688
 * @cpu: ARMCPU
 
689
 *
 
690
 * For each register listed in the ARMCPU cpreg_indexes list, write
 
691
 * its value from the cpreg_values list into the ARMCPUState structure.
 
692
 * This updates TCG's working data structures from KVM data or
 
693
 * from incoming migration state.
 
694
 *
 
695
 * Returns: true if all register values were updated correctly,
 
696
 * false if some register was unknown or could not be written.
 
697
 * Note that we do not stop early on failure -- we will attempt
 
698
 * writing all registers in the list.
 
699
 */
 
700
bool write_list_to_cpustate(ARMCPU *cpu);
 
701
 
 
702
/**
 
703
 * write_cpustate_to_list:
 
704
 * @cpu: ARMCPU
 
705
 *
 
706
 * For each register listed in the ARMCPU cpreg_indexes list, write
 
707
 * its value from the ARMCPUState structure into the cpreg_values list.
 
708
 * This is used to copy info from TCG's working data structures into
 
709
 * KVM or for outbound migration.
 
710
 *
 
711
 * Returns: true if all register values were read correctly,
 
712
 * false if some register was unknown or could not be read.
 
713
 * Note that we do not stop early on failure -- we will attempt
 
714
 * reading all registers in the list.
 
715
 */
 
716
bool write_cpustate_to_list(ARMCPU *cpu);
 
717
 
615
718
/* Does the core conform to the the "MicroController" profile. e.g. Cortex-M3.
616
719
   Note the M in older cores (eg. ARM7TDMI) stands for Multiply. These are
617
720
   conventional cores (ie. Application or Realtime profile).  */
656
759
    return (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR ? 1 : 0;
657
760
}
658
761
 
659
 
#if defined(CONFIG_USER_ONLY)
660
 
static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp)
661
 
{
662
 
    if (newsp)
663
 
        env->regs[13] = newsp;
664
 
    env->regs[0] = 0;
665
 
}
666
 
#endif
667
 
 
668
762
#include "exec/cpu-all.h"
669
763
 
670
764
/* Bit usage in the TB flags field: */
732
826
 
733
827
#include "exec/exec-all.h"
734
828
 
735
 
static inline void cpu_pc_from_tb(CPUARMState *env, TranslationBlock *tb)
736
 
{
737
 
    env->regs[15] = tb->pc;
738
 
}
739
 
 
740
829
/* Load an instruction and return it in the standard little-endian order */
741
830
static inline uint32_t arm_ldl_code(CPUARMState *env, uint32_t addr,
742
831
                                    bool do_swap)