Statistics
| Branch: | Revision:

root / cpu-defs.h @ b09ea7d5

History | View | Annotate | Download (8.6 kB)

1 ab93bbe2 bellard
/*
2 ab93bbe2 bellard
 * common defines for all CPUs
3 5fafdf24 ths
 *
4 ab93bbe2 bellard
 * Copyright (c) 2003 Fabrice Bellard
5 ab93bbe2 bellard
 *
6 ab93bbe2 bellard
 * This library is free software; you can redistribute it and/or
7 ab93bbe2 bellard
 * modify it under the terms of the GNU Lesser General Public
8 ab93bbe2 bellard
 * License as published by the Free Software Foundation; either
9 ab93bbe2 bellard
 * version 2 of the License, or (at your option) any later version.
10 ab93bbe2 bellard
 *
11 ab93bbe2 bellard
 * This library is distributed in the hope that it will be useful,
12 ab93bbe2 bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ab93bbe2 bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ab93bbe2 bellard
 * Lesser General Public License for more details.
15 ab93bbe2 bellard
 *
16 ab93bbe2 bellard
 * You should have received a copy of the GNU Lesser General Public
17 ab93bbe2 bellard
 * License along with this library; if not, write to the Free Software
18 fad6cb1a aurel32
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
19 ab93bbe2 bellard
 */
20 ab93bbe2 bellard
#ifndef CPU_DEFS_H
21 ab93bbe2 bellard
#define CPU_DEFS_H
22 ab93bbe2 bellard
23 87ecb68b pbrook
#ifndef NEED_CPU_H
24 87ecb68b pbrook
#error cpu.h included from common code
25 87ecb68b pbrook
#endif
26 87ecb68b pbrook
27 ab93bbe2 bellard
#include "config.h"
28 ab93bbe2 bellard
#include <setjmp.h>
29 ed1c0bcb bellard
#include <inttypes.h>
30 be214e6c aurel32
#include <signal.h>
31 ed1c0bcb bellard
#include "osdep.h"
32 c0ce998e aliguori
#include "sys-queue.h"
33 1ad2134f Paul Brook
#include "targphys.h"
34 ab93bbe2 bellard
35 35b66fc4 bellard
#ifndef TARGET_LONG_BITS
36 35b66fc4 bellard
#error TARGET_LONG_BITS must be defined before including this header
37 35b66fc4 bellard
#endif
38 35b66fc4 bellard
39 35b66fc4 bellard
#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
40 35b66fc4 bellard
41 ab6d960f bellard
/* target_ulong is the type of a virtual address */
42 35b66fc4 bellard
#if TARGET_LONG_SIZE == 4
43 35b66fc4 bellard
typedef int32_t target_long;
44 35b66fc4 bellard
typedef uint32_t target_ulong;
45 c27004ec bellard
#define TARGET_FMT_lx "%08x"
46 b62b461b j_mayer
#define TARGET_FMT_ld "%d"
47 71c8b8fd j_mayer
#define TARGET_FMT_lu "%u"
48 35b66fc4 bellard
#elif TARGET_LONG_SIZE == 8
49 35b66fc4 bellard
typedef int64_t target_long;
50 35b66fc4 bellard
typedef uint64_t target_ulong;
51 26a76461 bellard
#define TARGET_FMT_lx "%016" PRIx64
52 b62b461b j_mayer
#define TARGET_FMT_ld "%" PRId64
53 71c8b8fd j_mayer
#define TARGET_FMT_lu "%" PRIu64
54 35b66fc4 bellard
#else
55 35b66fc4 bellard
#error TARGET_LONG_SIZE undefined
56 35b66fc4 bellard
#endif
57 35b66fc4 bellard
58 f193c797 bellard
#define HOST_LONG_SIZE (HOST_LONG_BITS / 8)
59 f193c797 bellard
60 2be0071f bellard
#define EXCP_INTERRUPT         0x10000 /* async interruption */
61 2be0071f bellard
#define EXCP_HLT        0x10001 /* hlt instruction reached */
62 2be0071f bellard
#define EXCP_DEBUG      0x10002 /* cpu stopped after a breakpoint or singlestep */
63 5a1e3cfc bellard
#define EXCP_HALTED     0x10003 /* cpu is halted (waiting for external event) */
64 ab93bbe2 bellard
65 a316d335 bellard
#define TB_JMP_CACHE_BITS 12
66 a316d335 bellard
#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
67 a316d335 bellard
68 b362e5e0 pbrook
/* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
69 b362e5e0 pbrook
   addresses on the same page.  The top bits are the same.  This allows
70 b362e5e0 pbrook
   TLB invalidation to quickly clear a subset of the hash table.  */
71 b362e5e0 pbrook
#define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
72 b362e5e0 pbrook
#define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
73 b362e5e0 pbrook
#define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
74 b362e5e0 pbrook
#define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
75 b362e5e0 pbrook
76 84b7b8e7 bellard
#define CPU_TLB_BITS 8
77 84b7b8e7 bellard
#define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
78 ab93bbe2 bellard
79 d656469f bellard
#if TARGET_PHYS_ADDR_BITS == 32 && TARGET_LONG_BITS == 32
80 d656469f bellard
#define CPU_TLB_ENTRY_BITS 4
81 d656469f bellard
#else
82 d656469f bellard
#define CPU_TLB_ENTRY_BITS 5
83 d656469f bellard
#endif
84 d656469f bellard
85 ab93bbe2 bellard
typedef struct CPUTLBEntry {
86 0f459d16 pbrook
    /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
87 0f459d16 pbrook
       bit TARGET_PAGE_BITS-1..4  : Nonzero for accesses that should not
88 0f459d16 pbrook
                                    go directly to ram.
89 db8d7466 bellard
       bit 3                      : indicates that the entry is invalid
90 db8d7466 bellard
       bit 2..0                   : zero
91 db8d7466 bellard
    */
92 5fafdf24 ths
    target_ulong addr_read;
93 5fafdf24 ths
    target_ulong addr_write;
94 5fafdf24 ths
    target_ulong addr_code;
95 0f459d16 pbrook
    /* Addend to virtual address to get physical address.  IO accesses
96 ee50add9 pbrook
       use the corresponding iotlb value.  */
97 d656469f bellard
#if TARGET_PHYS_ADDR_BITS == 64
98 d656469f bellard
    /* on i386 Linux make sure it is aligned */
99 d656469f bellard
    target_phys_addr_t addend __attribute__((aligned(8)));
100 d656469f bellard
#else
101 5fafdf24 ths
    target_phys_addr_t addend;
102 d656469f bellard
#endif
103 d656469f bellard
    /* padding to get a power of two size */
104 d656469f bellard
    uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 
105 d656469f bellard
                  (sizeof(target_ulong) * 3 + 
106 d656469f bellard
                   ((-sizeof(target_ulong) * 3) & (sizeof(target_phys_addr_t) - 1)) + 
107 d656469f bellard
                   sizeof(target_phys_addr_t))];
108 ab93bbe2 bellard
} CPUTLBEntry;
109 ab93bbe2 bellard
110 2e70f6ef pbrook
#ifdef WORDS_BIGENDIAN
111 2e70f6ef pbrook
typedef struct icount_decr_u16 {
112 2e70f6ef pbrook
    uint16_t high;
113 2e70f6ef pbrook
    uint16_t low;
114 2e70f6ef pbrook
} icount_decr_u16;
115 2e70f6ef pbrook
#else
116 2e70f6ef pbrook
typedef struct icount_decr_u16 {
117 2e70f6ef pbrook
    uint16_t low;
118 2e70f6ef pbrook
    uint16_t high;
119 2e70f6ef pbrook
} icount_decr_u16;
120 2e70f6ef pbrook
#endif
121 2e70f6ef pbrook
122 7ba1e619 aliguori
struct kvm_run;
123 7ba1e619 aliguori
struct KVMState;
124 7ba1e619 aliguori
125 a1d1bb31 aliguori
typedef struct CPUBreakpoint {
126 a1d1bb31 aliguori
    target_ulong pc;
127 a1d1bb31 aliguori
    int flags; /* BP_* */
128 c0ce998e aliguori
    TAILQ_ENTRY(CPUBreakpoint) entry;
129 a1d1bb31 aliguori
} CPUBreakpoint;
130 a1d1bb31 aliguori
131 a1d1bb31 aliguori
typedef struct CPUWatchpoint {
132 a1d1bb31 aliguori
    target_ulong vaddr;
133 a1d1bb31 aliguori
    target_ulong len_mask;
134 a1d1bb31 aliguori
    int flags; /* BP_* */
135 c0ce998e aliguori
    TAILQ_ENTRY(CPUWatchpoint) entry;
136 a1d1bb31 aliguori
} CPUWatchpoint;
137 a1d1bb31 aliguori
138 a20e31dc blueswir1
#define CPU_TEMP_BUF_NLONGS 128
139 a316d335 bellard
#define CPU_COMMON                                                      \
140 a316d335 bellard
    struct TranslationBlock *current_tb; /* currently executing TB  */  \
141 a316d335 bellard
    /* soft mmu support */                                              \
142 2e70f6ef pbrook
    /* in order to avoid passing too many arguments to the MMIO         \
143 2e70f6ef pbrook
       helpers, we store some rarely used information in the CPU        \
144 a316d335 bellard
       context) */                                                      \
145 2e70f6ef pbrook
    unsigned long mem_io_pc; /* host pc at which the memory was         \
146 2e70f6ef pbrook
                                accessed */                             \
147 2e70f6ef pbrook
    target_ulong mem_io_vaddr; /* target virtual addr at which the      \
148 2e70f6ef pbrook
                                     memory was accessed */             \
149 9656f324 pbrook
    uint32_t halted; /* Nonzero if the CPU is in suspend state */       \
150 d6dc3d42 aliguori
    uint32_t stop;   /* Stop request */                                 \
151 d6dc3d42 aliguori
    uint32_t stopped; /* Artificially stopped */                        \
152 9656f324 pbrook
    uint32_t interrupt_request;                                         \
153 be214e6c aurel32
    volatile sig_atomic_t exit_request;                                 \
154 623a930e ths
    /* The meaning of the MMU modes is defined in the target code. */   \
155 6fa4cea9 j_mayer
    CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE];                  \
156 0f459d16 pbrook
    target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE];               \
157 a316d335 bellard
    struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];           \
158 a20e31dc blueswir1
    /* buffer for temporaries in the code generator */                  \
159 a20e31dc blueswir1
    long temp_buf[CPU_TEMP_BUF_NLONGS];                                 \
160 a316d335 bellard
                                                                        \
161 2e70f6ef pbrook
    int64_t icount_extra; /* Instructions until next timer event.  */   \
162 2e70f6ef pbrook
    /* Number of cycles left, with interrupt flag in high bit.          \
163 2e70f6ef pbrook
       This allows a single read-compare-cbranch-write sequence to test \
164 2e70f6ef pbrook
       for both decrementer underflow and exceptions.  */               \
165 2e70f6ef pbrook
    union {                                                             \
166 2e70f6ef pbrook
        uint32_t u32;                                                   \
167 2e70f6ef pbrook
        icount_decr_u16 u16;                                            \
168 2e70f6ef pbrook
    } icount_decr;                                                      \
169 2e70f6ef pbrook
    uint32_t can_do_io; /* nonzero if memory mapped IO is safe.  */     \
170 2e70f6ef pbrook
                                                                        \
171 a316d335 bellard
    /* from this point: preserved by CPU reset */                       \
172 a316d335 bellard
    /* ice debug support */                                             \
173 c0ce998e aliguori
    TAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;            \
174 a316d335 bellard
    int singlestep_enabled;                                             \
175 a316d335 bellard
                                                                        \
176 c0ce998e aliguori
    TAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;            \
177 a1d1bb31 aliguori
    CPUWatchpoint *watchpoint_hit;                                      \
178 56aebc89 pbrook
                                                                        \
179 56aebc89 pbrook
    struct GDBRegisterState *gdb_regs;                                  \
180 6658ffb8 pbrook
                                                                        \
181 9133e39b bellard
    /* Core interrupt code */                                           \
182 9133e39b bellard
    jmp_buf jmp_env;                                                    \
183 9133e39b bellard
    int exception_index;                                                \
184 9133e39b bellard
                                                                        \
185 c2764719 pbrook
    CPUState *next_cpu; /* next CPU sharing TB cache */                 \
186 6a00d601 bellard
    int cpu_index; /* CPU index (informative) */                        \
187 1e9fa730 Nathan Froyd
    uint32_t host_tid; /* host thread ID */                             \
188 268a362c aliguori
    int numa_node; /* NUMA node this cpu is belonging to  */            \
189 d5975363 pbrook
    int running; /* Nonzero if cpu is currently running(usermode).  */  \
190 a316d335 bellard
    /* user data */                                                     \
191 01ba9816 ths
    void *opaque;                                                       \
192 01ba9816 ths
                                                                        \
193 d6dc3d42 aliguori
    uint32_t created;                                                   \
194 d6dc3d42 aliguori
    struct QemuThread *thread;                                          \
195 d6dc3d42 aliguori
    struct QemuCond *halt_cond;                                         \
196 7ba1e619 aliguori
    const char *cpu_model_str;                                          \
197 7ba1e619 aliguori
    struct KVMState *kvm_state;                                         \
198 7ba1e619 aliguori
    struct kvm_run *kvm_run;                                            \
199 7ba1e619 aliguori
    int kvm_fd;
200 a316d335 bellard
201 ab93bbe2 bellard
#endif