qemu-common.h: Remove include of cpu.h

The "qemu-common.h" included "cpu.h" when NEED_CPU_H was defined, which
introduced some nasty circular header dependency issues that affect later
patches in this series.

This patch removes the include, and fixes all other sources to include
"cpu.h" as needed instead.

+ Move loader declarations to "hw/loader.h"
+ Move some stuff from "qemu/timer.h" to "exec/cpu-all.h"

Change-Id: Ida1a4eccd889bae450b35ee32a931273ffe1f8d8
diff --git a/android/main.c b/android/main.c
index f2a55d3..1a10040 100644
--- a/android/main.c
+++ b/android/main.c
@@ -18,6 +18,7 @@
 #include <process.h>
 #endif
 
+#include "config.h"
 #include "android/sockets.h"
 
 #include "android/android.h"
diff --git a/cpus.c b/cpus.c
index ccc36ad..ce13a55 100644
--- a/cpus.c
+++ b/cpus.c
@@ -23,6 +23,8 @@
  */
 #include "config-host.h"
 
+#include "cpu.h"
+#include "exec/exec-all.h"
 #include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
 #include "exec/gdbstub.h"
@@ -653,3 +655,18 @@
     }
 }
 
+/* Return the virtual CPU time, based on the instruction counter.  */
+int64_t cpu_get_icount(void)
+{
+    int64_t icount;
+    CPUOldState *env = cpu_single_env;;
+
+    icount = qemu_icount;
+    if (env) {
+        if (!can_do_io(env)) {
+            fprintf(stderr, "Bad clock read\n");
+        }
+        icount -= (env->icount_decr.u16.low + env->icount_extra);
+    }
+    return qemu_icount_bias + (icount << icount_time_shift);
+}
diff --git a/hw/android/goldfish/audio.c b/hw/android/goldfish/audio.c
index 05ca3a4..8c7cfd2 100644
--- a/hw/android/goldfish/audio.c
+++ b/hw/android/goldfish/audio.c
@@ -9,6 +9,7 @@
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 */
+#include "cpu.h"
 #include "migration/qemu-file.h"
 #include "hw/android/goldfish/device.h"
 #include "audio/audio.h"
diff --git a/hw/android/goldfish/battery.c b/hw/android/goldfish/battery.c
index 896362b..867f5c4 100644
--- a/hw/android/goldfish/battery.c
+++ b/hw/android/goldfish/battery.c
@@ -9,6 +9,7 @@
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 */
+#include "cpu.h"
 #include "migration/qemu-file.h"
 #include "hw/android/goldfish/device.h"
 #include "hw/power_supply.h"
diff --git a/hw/android/goldfish/device.c b/hw/android/goldfish/device.c
index 87ce575..225f63c 100644
--- a/hw/android/goldfish/device.c
+++ b/hw/android/goldfish/device.c
@@ -9,6 +9,7 @@
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 */
+#include "cpu.h"
 #include "migration/qemu-file.h"
 #include "hw/arm/pic.h"
 #include "hw/android/goldfish/device.h"
diff --git a/hw/android/goldfish/events_device.c b/hw/android/goldfish/events_device.c
index 8a8720c..7fd2996 100644
--- a/hw/android/goldfish/events_device.c
+++ b/hw/android/goldfish/events_device.c
@@ -14,6 +14,8 @@
 #include "android/charmap.h"
 #include "android/globals.h"  /* for android_hw */
 #include "android/multitouch-screen.h"
+#include "exec/cpu-common.h"
+#include "exec/hwaddr.h"
 #include "hw/irq.h"
 #include "android/user-events.h"
 #include "ui/console.h"
diff --git a/hw/android/goldfish/fb.c b/hw/android/goldfish/fb.c
index e9ccf4b..b2f72a6 100644
--- a/hw/android/goldfish/fb.c
+++ b/hw/android/goldfish/fb.c
@@ -9,6 +9,7 @@
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 */
+#include "cpu.h"
 #include "migration/qemu-file.h"
 #include "android/android.h"
 #include "android/utils/debug.h"
diff --git a/hw/android/goldfish/mmc.c b/hw/android/goldfish/mmc.c
index 4d861bb..e37bb59 100644
--- a/hw/android/goldfish/mmc.c
+++ b/hw/android/goldfish/mmc.c
@@ -9,6 +9,7 @@
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 */
+#include "cpu.h"
 #include "migration/qemu-file.h"
 #include "hw/android/goldfish/device.h"
 #include "hw/mmc.h"
diff --git a/hw/core/dma.c b/hw/core/dma.c
index d8828f4..5e9bc8d 100644
--- a/hw/core/dma.c
+++ b/hw/core/dma.c
@@ -21,6 +21,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "cpu.h"
+#include "exec/cpu-common.h"
 #include "hw/hw.h"
 #include "hw/isa/isa.h"
 
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 8e74125..77f4774 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
  */
 
+#include "exec/cpu-common.h"
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
 #include "monitor/monitor.h"
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index 913b074..bdda698 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -13,7 +13,7 @@
 
 #include "sysemu/sysemu.h"
 #include "hw/i386/smbios.h"
-
+#include "hw/loader.h"
 /*
  * Structures shared with the BIOS
  */
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 2bbe45b..da637a6 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "cpu.h"
 #include "hw/hw.h"
 #include "sysemu/sysemu.h"
 #include "hw/isa/isa.h"
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index b812a69..42ac3f7 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "cpu.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "monitor/monitor.h"
diff --git a/include/disas/disas.h b/include/disas/disas.h
index c13ca9a..aac2531 100644
--- a/include/disas/disas.h
+++ b/include/disas/disas.h
@@ -4,6 +4,8 @@
 #include "qemu-common.h"
 
 #ifdef NEED_CPU_H
+#include "cpu.h"
+
 /* Disassemble this for me please... (debugging). */
 void disas(FILE *out, void *code, unsigned long size);
 void target_disas(FILE *out, CPUArchState *env, target_ulong code,
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 0e58222..3ad9657 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -1,13 +1,11 @@
 #ifndef CPU_COMMON_H
 #define CPU_COMMON_H 1
 
-/* CPU interfaces that are target indpendent.  */
+#include "qemu-common.h"
 
-#if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
-#define WORDS_ALIGNED
-#endif
+/* CPU interfaces that are target independent.  */
 
-#ifdef TARGET_PHYS_ADDR_BITS
+#ifndef CONFIG_USER_ONLY
 #include "exec/hwaddr.h"
 #endif
 
@@ -18,10 +16,36 @@
 #include "qemu/bswap.h"
 #include "qemu/queue.h"
 
+/**
+ * CPUListState:
+ * @cpu_fprintf: Print function.
+ * @file: File to print to using @cpu_fprint.
+ *
+ * State commonly used for iterating over CPU models.
+ */
+typedef struct CPUListState {
+    fprintf_function cpu_fprintf;
+    FILE *file;
+} CPUListState;
+
 #if !defined(CONFIG_USER_ONLY)
 
+enum device_endian {
+    DEVICE_NATIVE_ENDIAN,
+    DEVICE_BIG_ENDIAN,
+    DEVICE_LITTLE_ENDIAN,
+};
+
 /* address in the RAM (different from a physical address) */
-typedef unsigned long ram_addr_t;
+#if defined(CONFIG_XEN_BACKEND)
+typedef uint64_t ram_addr_t;
+#  define RAM_ADDR_MAX UINT64_MAX
+#  define RAM_ADDR_FMT "%" PRIx64
+#else
+typedef uintptr_t ram_addr_t;
+#  define RAM_ADDR_MAX UINTPTR_MAX
+#  define RAM_ADDR_FMT "%" PRIxPTR
+#endif
 
 /* memory API */
 
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 7bc632b..b4e20d3 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -433,4 +433,18 @@
 /* vl.c */
 extern int singlestep;
 
+/* Deterministic execution requires that IO only be performed on the last
+   instruction of a TB so that interrupts take effect immediately.  */
+static inline int can_do_io(CPUArchState *env)
+{
+    if (!use_icount)
+        return 1;
+
+    /* If not executing code then assume we are ok.  */
+    if (!env->current_tb)
+        return 1;
+
+    return env->can_do_io != 0;
+}
+
 #endif
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index 356294a..dd96c6c 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -11,6 +11,8 @@
 #define GDB_WATCHPOINT_ACCESS    4
 
 #ifdef NEED_CPU_H
+#include "cpu.h"
+
 typedef void (*gdb_syscall_complete_cb)(CPUOldState *env,
                                         target_ulong ret, target_ulong err);
 
diff --git a/include/exec/hwaddr.h b/include/exec/hwaddr.h
index 9ccf56d..7c4a771 100644
--- a/include/exec/hwaddr.h
+++ b/include/exec/hwaddr.h
@@ -3,6 +3,12 @@
 #ifndef TARGPHYS_H
 #define TARGPHYS_H
 
+#include <stdint.h>
+
+#ifndef TARGET_PHYS_ADDR_BITS
+#define TARGET_PHYS_ADDR_BITS 32
+#endif
+
 #ifdef TARGET_PHYS_ADDR_BITS
 /* hwaddr is the type of a physical address (its size can
    be different from 'target_ulong').  */
diff --git a/include/hw/android/goldfish/device.h b/include/hw/android/goldfish/device.h
index 2f529b5..4ffcd9d 100644
--- a/include/hw/android/goldfish/device.h
+++ b/include/hw/android/goldfish/device.h
@@ -12,6 +12,8 @@
 #ifndef GOLDFISH_DEVICE_H
 #define GOLDFISH_DEVICE_H
 
+#include "exec/cpu-common.h"
+
 struct goldfish_device {
     struct goldfish_device *next;
     struct goldfish_device *prev;
diff --git a/include/hw/android/goldfish/trace.h b/include/hw/android/goldfish/trace.h
index 3e92f3e..01c7338 100644
--- a/include/hw/android/goldfish/trace.h
+++ b/include/hw/android/goldfish/trace.h
@@ -13,6 +13,7 @@
 #define _TRACE_DEV_H_
 
 #include "hw/android/goldfish/device.h"
+#include "cpu.h"
 
 #define CLIENT_PAGE_SIZE        4096
 
diff --git a/include/hw/android/goldfish/vmem.h b/include/hw/android/goldfish/vmem.h
index 0cade84..be7974d 100644
--- a/include/hw/android/goldfish/vmem.h
+++ b/include/hw/android/goldfish/vmem.h
@@ -12,6 +12,8 @@
 #ifndef GOLDFISH_VMEM_H
 #define GOLDFISH_VMEM_H
 
+#include "cpu.h"
+
 // Call these functions instead of cpu_memory_rw_debug and
 // cpu_get_phys_page_debug to ensure virtual address translation always works
 // properly, and efficently, under KVM.
diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h
index 11754c7..10f8414 100644
--- a/include/hw/arm/arm.h
+++ b/include/hw/arm/arm.h
@@ -11,6 +11,9 @@
 #ifndef ARM_MISC_H
 #define ARM_MISC_H 1
 
+#include "cpu.h"
+#include "hw/loader.h"
+
 /* The CPU is also modeled as an interrupt controller.  */
 #define ARM_PIC_CPU_IRQ 0
 #define ARM_PIC_CPU_FIQ 1
diff --git a/include/hw/arm/pic.h b/include/hw/arm/pic.h
index 365b988..ab7ef65 100644
--- a/include/hw/arm/pic.h
+++ b/include/hw/arm/pic.h
@@ -14,6 +14,7 @@
 #ifndef ARM_INTERRUPT_H
 #define ARM_INTERRUPT_H 1
 
+#include "cpu.h"
 #include "hw/irq.h"
 
 /* The CPU is also modeled as an interrupt controller.  */
diff --git a/include/hw/arm/pxa.h b/include/hw/arm/pxa.h
index 9f9479b..e0b7612 100644
--- a/include/hw/arm/pxa.h
+++ b/include/hw/arm/pxa.h
@@ -9,6 +9,8 @@
 #ifndef PXA_H
 # define PXA_H			"hw/arm/pxa.h"
 
+#include "cpu.h"
+
 /* Interrupt numbers */
 # define PXA2XX_PIC_SSP3	0
 # define PXA2XX_PIC_USBH2	2
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 8242af6..2077a7c 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -3,6 +3,8 @@
 #ifndef HW_BOARDS_H
 #define HW_BOARDS_H
 
+#include "exec/cpu-common.h"
+
 typedef void QEMUMachineInitFunc(ram_addr_t ram_size,
                                  const char *boot_device,
                                  const char *kernel_filename,
diff --git a/include/hw/hw.h b/include/hw/hw.h
index 45ef74e..ed1667f 100644
--- a/include/hw/hw.h
+++ b/include/hw/hw.h
@@ -5,7 +5,7 @@
 #include "qemu-common.h"
 #include "hw/irq.h"
 
-#if defined(TARGET_PHYS_ADDRESS_SPACE_BITS) && !defined(NEED_CPU_H)
+#ifdef NEED_CPU_H
 #include "cpu.h"
 #endif
 
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index f8d9420..4d0e4c6 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -1,7 +1,9 @@
 #ifndef HW_PC_H
 #define HW_PC_H
 
+#include "cpu.h"
 #include "qemu-common.h"
+#include "exec/hwaddr.h"
 
 /* PC-style peripherals (also used by other machines).  */
 
diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h
index 4f5bc83..f3f04d0 100644
--- a/include/hw/isa/isa.h
+++ b/include/hw/isa/isa.h
@@ -3,6 +3,7 @@
 
 /* ISA bus */
 
+#include "exec/hwaddr.h"
 #include "exec/ioport.h"
 #include "hw/qdev.h"
 
diff --git a/include/hw/loader.h b/include/hw/loader.h
new file mode 100644
index 0000000..6d31ee0
--- /dev/null
+++ b/include/hw/loader.h
@@ -0,0 +1,70 @@
+#ifndef LOADER_H
+#define LOADER_H
+
+#include "cpu.h"
+#include "qapi/qmp/qdict.h"
+#include "hw/nvram/fw_cfg.h"
+
+/* loader.c */
+int get_image_size(const char *filename);
+int load_image(const char *filename, uint8_t *addr); /* deprecated */
+int load_image_targphys(const char *filename, hwaddr,
+                        uint64_t max_sz);
+int load_elf(const char *filename, int64_t address_offset,
+             uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
+int load_aout(const char *filename, hwaddr addr, int max_sz);
+int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
+                int *is_linux);
+
+/**
+ * load_ramdisk:
+ * @filename: Path to the ramdisk image
+ * @addr: Memory address to load the ramdisk to
+ * @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks)
+ *
+ * Load a ramdisk image with U-Boot header to the specified memory
+ * address.
+ *
+ * Returns the size of the loaded image on success, -1 otherwise.
+ */
+int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz);
+
+ssize_t read_targphys(const char *name,
+                      int fd, hwaddr dst_addr, size_t nbytes);
+void pstrcpy_targphys(const char *name,
+                      hwaddr dest, int buf_size,
+                      const char *source);
+
+#ifndef CONFIG_ANDROID  // TODO(digit)
+extern bool rom_file_in_ram;
+
+int rom_add_file(const char *file, const char *fw_dir,
+                 hwaddr addr, int32_t bootindex);
+void *rom_add_blob(const char *name, const void *blob, size_t len,
+                   hwaddr addr, const char *fw_file_name,
+                   FWCfgReadCallback fw_callback, void *callback_opaque);
+int rom_add_elf_program(const char *name, void *data, size_t datasize,
+                        size_t romsize, hwaddr addr);
+int rom_load_all(void);
+void rom_load_done(void);
+void rom_set_fw(FWCfgState *f);
+int rom_copy(uint8_t *dest, hwaddr addr, size_t size);
+void *rom_ptr(hwaddr addr);
+void do_info_roms(Monitor *mon, const QDict *qdict);
+
+#define rom_add_file_fixed(_f, _a, _i)          \
+    rom_add_file(_f, NULL, _a, _i)
+#define rom_add_blob_fixed(_f, _b, _l, _a)      \
+    rom_add_blob(_f, _b, _l, _a, NULL, NULL, NULL)
+
+#define PC_ROM_MIN_VGA     0xc0000
+#define PC_ROM_MIN_OPTION  0xc8000
+#define PC_ROM_MAX         0xe0000
+#define PC_ROM_ALIGN       0x800
+#define PC_ROM_SIZE        (PC_ROM_MAX - PC_ROM_MIN_VGA)
+
+int rom_add_vga(const char *file);
+int rom_add_option(const char *file, int32_t bootindex);
+#endif  // !CONFIG_ANDROID
+
+#endif
diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index 105806e..0327a33 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -3,6 +3,7 @@
 
 /* Devices attached directly to the main system bus.  */
 
+#include "exec/hwaddr.h"
 #include "hw/qdev.h"
 
 #define QDEV_MAX_MMIO 5
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 48c3324..52ce89b 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -12,9 +12,14 @@
 #ifndef QEMU_COMMON_H
 #define QEMU_COMMON_H
 
+#include <setjmp.h>
+
 #include "qemu/compiler.h"
 #include "config-host.h"
 #include "qemu/typedefs.h"
+#include "qemu/osdep.h"
+#include "qemu/bswap.h"
+
 
 #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
 #define WORDS_ALIGNED
@@ -100,19 +105,6 @@
 #define PRIo64 "I64o"
 #endif
 
-/* FIXME: Remove NEED_CPU_H.  */
-#ifndef NEED_CPU_H
-
-#include <setjmp.h>
-#include "qemu/osdep.h"
-#include "qemu/bswap.h"
-
-#else
-
-#include "cpu.h"
-
-#endif /* !defined(NEED_CPU_H) */
-
 /* bottom halves */
 typedef void QEMUBHFunc(void *opaque);
 
@@ -523,4 +515,6 @@
  */
 int parse_debug_env(const char *name, int max, int initial);
 
+extern int use_icount;
+
 #endif
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index bdec364..1de8498 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -313,19 +313,6 @@
 #endif
 
 #ifdef NEED_CPU_H
-/* Deterministic execution requires that IO only be performed on the last
-   instruction of a TB so that interrupts take effect immediately.  */
-static inline int can_do_io(CPUOldState *env)
-{
-    if (!use_icount)
-        return 1;
-
-    /* If not executing code then assume we are ok.  */
-    if (!env->current_tb)
-        return 1;
-
-    return env->can_do_io != 0;
-}
 #endif
 
 #ifdef CONFIG_PROFILER
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 5b97bb5..7f86d89 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -15,6 +15,7 @@
 #define QEMU_KVM_H
 
 #include "config.h"
+#include "cpu.h"
 #include "qemu/queue.h"
 
 #ifdef CONFIG_KVM
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 19f6d5a..bf4b7dd 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -9,6 +9,8 @@
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qerror.h"
 
+#include "exec/hwaddr.h"
+
 #ifdef _WIN32
 #include <windows.h>
 #endif
@@ -228,6 +230,7 @@
 
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
+#if 0 //DIGIT
 #ifdef NEED_CPU_H
 /* loader.c */
 int get_image_size(const char *filename);
@@ -245,6 +248,7 @@
 void pstrcpy_targphys(hwaddr dest, int buf_size,
                       const char *source);
 #endif
+#endif //DIGIT
 
 void do_usb_add(Monitor *mon, const char *devname);
 void do_usb_del(Monitor *mon, const char *devname);
diff --git a/kvm-all.c b/kvm-all.c
index 428f25d..3ee3296 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -20,6 +20,7 @@
 
 #include <linux/kvm.h>
 
+#include "cpu.h"
 #include "qemu-common.h"
 #include "sysemu/sysemu.h"
 #include "hw/hw.h"
diff --git a/qemu-timer.c b/qemu-timer.c
index 61ff581..7ac4336 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -1370,19 +1370,3 @@
     return 1000;
 #endif
 }
-
-/* Return the virtual CPU time, based on the instruction counter.  */
-int64_t cpu_get_icount(void)
-{
-    int64_t icount;
-    CPUOldState *env = cpu_single_env;;
-
-    icount = qemu_icount;
-    if (env) {
-        if (!can_do_io(env)) {
-            fprintf(stderr, "Bad clock read\n");
-        }
-        icount -= (env->icount_decr.u16.low + env->icount_extra);
-    }
-    return qemu_icount_bias + (icount << icount_time_shift);
-}
diff --git a/target-arm/machine.c b/target-arm/machine.c
index 1726fd5..61239c3 100644
--- a/target-arm/machine.c
+++ b/target-arm/machine.c
@@ -1,3 +1,4 @@
+#include "cpu.h"
 #include "hw/hw.h"
 #include "hw/boards.h"