Statistics
| Branch: | Revision:

root / cpu-defs.h @ 72cf2d4f

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