target-arm/cpu.h: common pstate save/restore

This adds a universal program state save and restore function. This is
intended to simplify the migration serialisation functionality and avoid
special casing depending on the mode of the CPU at serialisation time.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
v2:
  - reword commentary for restore_state_from_spsr
  - rm commented out code
  - add set_condition_codes for flags
  - add xpsr_read functionality

v3:
  - rebase
  - checkpatch.pl issues
target-arm: Support save/load for 64 bit CPUs

This enables the saving and restoring of machine state by including the
current program state (*psr) and xregs. The save_state_to_spsr hides the
details of if the processor is in 32 or 64 bit mode at the time.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---

v2 (ajb)
  - use common state save functions
  - re-base to latest origin/master
  - clean up commented out code
target-arm: replace cpsr/xpsr/pstate_read calls

Use the unified save_state_to_spsr. I've also updated the interrupt
helpers to restore via the restore_state_from_spsr() functions. In the
aarch32 case this also needs to call switch_mode() to do the appropriate
fiddling.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

--

v2
  - include xpsr_read conversions
  - checkpatch fixes
arm/nwfps: replace cpsr_write with set_condition_codes

This is a pre-cursor to removing the cpsr_write function completely from
the code base. set_condition_codes() only affects the integer condition
flags.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---

v2
 - fix nwfpe set_condition_codes
linux-user/main.c: __kernel_cmpxchg set env->CF directly

As we only need to manipulate the single flag do it directly though env.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---

v2:
  - remove unused cpsr
  - the direct flag setting seems a little hacky?
target-arm: remove last users of cpsr_write

And use the new machinery to to save and restore program state. The old
cpsr_write function did some special handling for mode switches which
has been moved into the helper function.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
v2:
  - rebase
  - add mask helper function
  - checkpatch fixes
target-arm: remove final users of pstate_write

This converts all users of pstate_write to use the common state
save/restore functionality.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
target-arm/kvm.c: better error reporting

When we have a problem syncing CP registers between kvm<->qemu it's a
lot more useful to have the names of the registers in the log than just
a random abort() and core dump.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
v2
  - less verbose log message
  - fix checkpatch warnings
target-arm/kvm: make reg sync code common between kvm32/64

Before we launch a guest we query KVM for the list of "co-processor"
registers it knows about which is used later for save/restore of machine
state. The logic is identical for both 32-bit and 64-bit so I've moved
it all into the common code and simplified the exit paths (as failure =>
exit).

This list may well have more registers than are known by the TCG
emulation which is not necessarily a problem but it does stop us from
migrating between KVM and TCG hosted guests. I've added some additional
checking to report those registers under -d unimp.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>