cpu.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. /*
  2. * QEMU CPU model
  3. *
  4. * Copyright (c) 2012 SUSE LINUX Products GmbH
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see
  18. * <http://www.gnu.org/licenses/gpl-2.0.html>
  19. */
  20. #ifndef QEMU_CPU_H
  21. #define QEMU_CPU_H
  22. #include "hw/qdev-core.h"
  23. #include "disas/dis-asm.h"
  24. #include "exec/breakpoint.h"
  25. #include "exec/hwaddr.h"
  26. #include "exec/vaddr.h"
  27. #include "exec/memattrs.h"
  28. #include "exec/mmu-access-type.h"
  29. #include "exec/tlb-common.h"
  30. #include "qapi/qapi-types-machine.h"
  31. #include "qapi/qapi-types-run-state.h"
  32. #include "qemu/bitmap.h"
  33. #include "qemu/rcu_queue.h"
  34. #include "qemu/queue.h"
  35. #include "qemu/lockcnt.h"
  36. #include "qemu/thread.h"
  37. #include "qom/object.h"
  38. typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
  39. void *opaque);
  40. /**
  41. * SECTION:cpu
  42. * @section_id: QEMU-cpu
  43. * @title: CPU Class
  44. * @short_description: Base class for all CPUs
  45. */
  46. #define TYPE_CPU "cpu"
  47. /* Since this macro is used a lot in hot code paths and in conjunction with
  48. * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
  49. * an unchecked cast.
  50. */
  51. #define CPU(obj) ((CPUState *)(obj))
  52. /*
  53. * The class checkers bring in CPU_GET_CLASS() which is potentially
  54. * expensive given the eventual call to
  55. * object_class_dynamic_cast_assert(). Because of this the CPUState
  56. * has a cached value for the class in cs->cc which is set up in
  57. * cpu_exec_realizefn() for use in hot code paths.
  58. */
  59. typedef struct CPUClass CPUClass;
  60. DECLARE_CLASS_CHECKERS(CPUClass, CPU,
  61. TYPE_CPU)
  62. /**
  63. * OBJECT_DECLARE_CPU_TYPE:
  64. * @CpuInstanceType: instance struct name
  65. * @CpuClassType: class struct name
  66. * @CPU_MODULE_OBJ_NAME: the CPU name in uppercase with underscore separators
  67. *
  68. * This macro is typically used in "cpu-qom.h" header file, and will:
  69. *
  70. * - create the typedefs for the CPU object and class structs
  71. * - register the type for use with g_autoptr
  72. * - provide three standard type cast functions
  73. *
  74. * The object struct and class struct need to be declared manually.
  75. */
  76. #define OBJECT_DECLARE_CPU_TYPE(CpuInstanceType, CpuClassType, CPU_MODULE_OBJ_NAME) \
  77. typedef struct ArchCPU CpuInstanceType; \
  78. OBJECT_DECLARE_TYPE(ArchCPU, CpuClassType, CPU_MODULE_OBJ_NAME);
  79. typedef struct CPUWatchpoint CPUWatchpoint;
  80. /* see physmem.c */
  81. struct CPUAddressSpace;
  82. /* see accel/tcg/tb-jmp-cache.h */
  83. struct CPUJumpCache;
  84. /* see accel-cpu.h */
  85. struct AccelCPUClass;
  86. /* see sysemu-cpu-ops.h */
  87. struct SysemuCPUOps;
  88. /**
  89. * CPUClass:
  90. * @class_by_name: Callback to map -cpu command line model name to an
  91. * instantiatable CPU type.
  92. * @parse_features: Callback to parse command line arguments.
  93. * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
  94. * @has_work: Callback for checking if there is work to do.
  95. * @mmu_index: Callback for choosing softmmu mmu index;
  96. * may be used internally by memory_rw_debug without TCG.
  97. * @memory_rw_debug: Callback for GDB memory access.
  98. * @dump_state: Callback for dumping state.
  99. * @query_cpu_fast:
  100. * Fill in target specific information for the "query-cpus-fast"
  101. * QAPI call.
  102. * @get_arch_id: Callback for getting architecture-dependent CPU ID.
  103. * @set_pc: Callback for setting the Program Counter register. This
  104. * should have the semantics used by the target architecture when
  105. * setting the PC from a source such as an ELF file entry point;
  106. * for example on Arm it will also set the Thumb mode bit based
  107. * on the least significant bit of the new PC value.
  108. * If the target behaviour here is anything other than "set
  109. * the PC register to the value passed in" then the target must
  110. * also implement the synchronize_from_tb hook.
  111. * @get_pc: Callback for getting the Program Counter register.
  112. * As above, with the semantics of the target architecture.
  113. * @gdb_read_register: Callback for letting GDB read a register.
  114. * @gdb_write_register: Callback for letting GDB write a register.
  115. * @gdb_adjust_breakpoint: Callback for adjusting the address of a
  116. * breakpoint. Used by AVR to handle a gdb mis-feature with
  117. * its Harvard architecture split code and data.
  118. * @gdb_num_core_regs: Number of core registers accessible to GDB or 0 to infer
  119. * from @gdb_core_xml_file.
  120. * @gdb_core_xml_file: File name for core registers GDB XML description.
  121. * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
  122. * before the insn which triggers a watchpoint rather than after it.
  123. * @gdb_arch_name: Optional callback that returns the architecture name known
  124. * to GDB. The caller must free the returned string with g_free.
  125. * @disas_set_info: Setup architecture specific components of disassembly info
  126. * @adjust_watchpoint_address: Perform a target-specific adjustment to an
  127. * address before attempting to match it against watchpoints.
  128. * @deprecation_note: If this CPUClass is deprecated, this field provides
  129. * related information.
  130. *
  131. * Represents a CPU family or model.
  132. */
  133. struct CPUClass {
  134. /*< private >*/
  135. DeviceClass parent_class;
  136. /*< public >*/
  137. ObjectClass *(*class_by_name)(const char *cpu_model);
  138. void (*parse_features)(const char *typename, char *str, Error **errp);
  139. bool (*has_work)(CPUState *cpu);
  140. int (*mmu_index)(CPUState *cpu, bool ifetch);
  141. int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
  142. uint8_t *buf, int len, bool is_write);
  143. void (*dump_state)(CPUState *cpu, FILE *, int flags);
  144. void (*query_cpu_fast)(CPUState *cpu, CpuInfoFast *value);
  145. int64_t (*get_arch_id)(CPUState *cpu);
  146. void (*set_pc)(CPUState *cpu, vaddr value);
  147. vaddr (*get_pc)(CPUState *cpu);
  148. int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
  149. int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
  150. vaddr (*gdb_adjust_breakpoint)(CPUState *cpu, vaddr addr);
  151. const char *gdb_core_xml_file;
  152. const gchar * (*gdb_arch_name)(CPUState *cpu);
  153. void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
  154. const char *deprecation_note;
  155. struct AccelCPUClass *accel_cpu;
  156. /* when system emulation is not available, this pointer is NULL */
  157. const struct SysemuCPUOps *sysemu_ops;
  158. /* when TCG is not available, this pointer is NULL */
  159. const TCGCPUOps *tcg_ops;
  160. /*
  161. * if not NULL, this is called in order for the CPUClass to initialize
  162. * class data that depends on the accelerator, see accel/accel-common.c.
  163. */
  164. void (*init_accel_cpu)(struct AccelCPUClass *accel_cpu, CPUClass *cc);
  165. /*
  166. * Keep non-pointer data at the end to minimize holes.
  167. */
  168. int reset_dump_flags;
  169. int gdb_num_core_regs;
  170. bool gdb_stop_before_watchpoint;
  171. };
  172. /*
  173. * Fix the number of mmu modes to 16, which is also the maximum
  174. * supported by the softmmu tlb api.
  175. */
  176. #define NB_MMU_MODES 16
  177. /* Use a fully associative victim tlb of 8 entries. */
  178. #define CPU_VTLB_SIZE 8
  179. /*
  180. * The full TLB entry, which is not accessed by generated TCG code,
  181. * so the layout is not as critical as that of CPUTLBEntry. This is
  182. * also why we don't want to combine the two structs.
  183. */
  184. struct CPUTLBEntryFull {
  185. /*
  186. * @xlat_section contains:
  187. * - in the lower TARGET_PAGE_BITS, a physical section number
  188. * - with the lower TARGET_PAGE_BITS masked off, an offset which
  189. * must be added to the virtual address to obtain:
  190. * + the ram_addr_t of the target RAM (if the physical section
  191. * number is PHYS_SECTION_NOTDIRTY or PHYS_SECTION_ROM)
  192. * + the offset within the target MemoryRegion (otherwise)
  193. */
  194. hwaddr xlat_section;
  195. /*
  196. * @phys_addr contains the physical address in the address space
  197. * given by cpu_asidx_from_attrs(cpu, @attrs).
  198. */
  199. hwaddr phys_addr;
  200. /* @attrs contains the memory transaction attributes for the page. */
  201. MemTxAttrs attrs;
  202. /* @prot contains the complete protections for the page. */
  203. uint8_t prot;
  204. /* @lg_page_size contains the log2 of the page size. */
  205. uint8_t lg_page_size;
  206. /* Additional tlb flags requested by tlb_fill. */
  207. uint8_t tlb_fill_flags;
  208. /*
  209. * Additional tlb flags for use by the slow path. If non-zero,
  210. * the corresponding CPUTLBEntry comparator must have TLB_FORCE_SLOW.
  211. */
  212. uint8_t slow_flags[MMU_ACCESS_COUNT];
  213. /*
  214. * Allow target-specific additions to this structure.
  215. * This may be used to cache items from the guest cpu
  216. * page tables for later use by the implementation.
  217. */
  218. union {
  219. /*
  220. * Cache the attrs and shareability fields from the page table entry.
  221. *
  222. * For ARMMMUIdx_Stage2*, pte_attrs is the S2 descriptor bits [5:2].
  223. * Otherwise, pte_attrs is the same as the MAIR_EL1 8-bit format.
  224. * For shareability and guarded, as in the SH and GP fields respectively
  225. * of the VMSAv8-64 PTEs.
  226. */
  227. struct {
  228. uint8_t pte_attrs;
  229. uint8_t shareability;
  230. bool guarded;
  231. } arm;
  232. } extra;
  233. };
  234. /*
  235. * Data elements that are per MMU mode, minus the bits accessed by
  236. * the TCG fast path.
  237. */
  238. typedef struct CPUTLBDesc {
  239. /*
  240. * Describe a region covering all of the large pages allocated
  241. * into the tlb. When any page within this region is flushed,
  242. * we must flush the entire tlb. The region is matched if
  243. * (addr & large_page_mask) == large_page_addr.
  244. */
  245. vaddr large_page_addr;
  246. vaddr large_page_mask;
  247. /* host time (in ns) at the beginning of the time window */
  248. int64_t window_begin_ns;
  249. /* maximum number of entries observed in the window */
  250. size_t window_max_entries;
  251. size_t n_used_entries;
  252. /* The next index to use in the tlb victim table. */
  253. size_t vindex;
  254. /* The tlb victim table, in two parts. */
  255. CPUTLBEntry vtable[CPU_VTLB_SIZE];
  256. CPUTLBEntryFull vfulltlb[CPU_VTLB_SIZE];
  257. CPUTLBEntryFull *fulltlb;
  258. } CPUTLBDesc;
  259. /*
  260. * Data elements that are shared between all MMU modes.
  261. */
  262. typedef struct CPUTLBCommon {
  263. /* Serialize updates to f.table and d.vtable, and others as noted. */
  264. QemuSpin lock;
  265. /*
  266. * Within dirty, for each bit N, modifications have been made to
  267. * mmu_idx N since the last time that mmu_idx was flushed.
  268. * Protected by tlb_c.lock.
  269. */
  270. uint16_t dirty;
  271. /*
  272. * Statistics. These are not lock protected, but are read and
  273. * written atomically. This allows the monitor to print a snapshot
  274. * of the stats without interfering with the cpu.
  275. */
  276. size_t full_flush_count;
  277. size_t part_flush_count;
  278. size_t elide_flush_count;
  279. } CPUTLBCommon;
  280. /*
  281. * The entire softmmu tlb, for all MMU modes.
  282. * The meaning of each of the MMU modes is defined in the target code.
  283. * Since this is placed within CPUNegativeOffsetState, the smallest
  284. * negative offsets are at the end of the struct.
  285. */
  286. typedef struct CPUTLB {
  287. #ifdef CONFIG_TCG
  288. CPUTLBCommon c;
  289. CPUTLBDesc d[NB_MMU_MODES];
  290. CPUTLBDescFast f[NB_MMU_MODES];
  291. #endif
  292. } CPUTLB;
  293. /*
  294. * Low 16 bits: number of cycles left, used only in icount mode.
  295. * High 16 bits: Set to -1 to force TCG to stop executing linked TBs
  296. * for this CPU and return to its top level loop (even in non-icount mode).
  297. * This allows a single read-compare-cbranch-write sequence to test
  298. * for both decrementer underflow and exceptions.
  299. */
  300. typedef union IcountDecr {
  301. uint32_t u32;
  302. struct {
  303. #if HOST_BIG_ENDIAN
  304. uint16_t high;
  305. uint16_t low;
  306. #else
  307. uint16_t low;
  308. uint16_t high;
  309. #endif
  310. } u16;
  311. } IcountDecr;
  312. /**
  313. * CPUNegativeOffsetState: Elements of CPUState most efficiently accessed
  314. * from CPUArchState, via small negative offsets.
  315. * @can_do_io: True if memory-mapped IO is allowed.
  316. * @plugin_mem_cbs: active plugin memory callbacks
  317. * @plugin_mem_value_low: 64 lower bits of latest accessed mem value.
  318. * @plugin_mem_value_high: 64 higher bits of latest accessed mem value.
  319. */
  320. typedef struct CPUNegativeOffsetState {
  321. CPUTLB tlb;
  322. #ifdef CONFIG_PLUGIN
  323. /*
  324. * The callback pointer are accessed via TCG (see gen_empty_mem_helper).
  325. */
  326. GArray *plugin_mem_cbs;
  327. uint64_t plugin_mem_value_low;
  328. uint64_t plugin_mem_value_high;
  329. #endif
  330. IcountDecr icount_decr;
  331. bool can_do_io;
  332. } CPUNegativeOffsetState;
  333. struct KVMState;
  334. struct kvm_run;
  335. /* work queue */
  336. /* The union type allows passing of 64 bit target pointers on 32 bit
  337. * hosts in a single parameter
  338. */
  339. typedef union {
  340. int host_int;
  341. unsigned long host_ulong;
  342. void *host_ptr;
  343. vaddr target_ptr;
  344. } run_on_cpu_data;
  345. #define RUN_ON_CPU_HOST_PTR(p) ((run_on_cpu_data){.host_ptr = (p)})
  346. #define RUN_ON_CPU_HOST_INT(i) ((run_on_cpu_data){.host_int = (i)})
  347. #define RUN_ON_CPU_HOST_ULONG(ul) ((run_on_cpu_data){.host_ulong = (ul)})
  348. #define RUN_ON_CPU_TARGET_PTR(v) ((run_on_cpu_data){.target_ptr = (v)})
  349. #define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL)
  350. typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
  351. struct qemu_work_item;
  352. #define CPU_UNSET_NUMA_NODE_ID -1
  353. /**
  354. * struct CPUState - common state of one CPU core or thread.
  355. *
  356. * @cpu_index: CPU index (informative).
  357. * @cluster_index: Identifies which cluster this CPU is in.
  358. * For boards which don't define clusters or for "loose" CPUs not assigned
  359. * to a cluster this will be UNASSIGNED_CLUSTER_INDEX; otherwise it will
  360. * be the same as the cluster-id property of the CPU object's TYPE_CPU_CLUSTER
  361. * QOM parent.
  362. * Under TCG this value is propagated to @tcg_cflags.
  363. * See TranslationBlock::TCG CF_CLUSTER_MASK.
  364. * @tcg_cflags: Pre-computed cflags for this cpu.
  365. * @nr_cores: Number of cores within this CPU package.
  366. * @nr_threads: Number of threads within this CPU core.
  367. * @thread: Host thread details, only live once @created is #true
  368. * @sem: WIN32 only semaphore used only for qtest
  369. * @thread_id: native thread id of vCPU, only live once @created is #true
  370. * @running: #true if CPU is currently running (lockless).
  371. * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
  372. * valid under cpu_list_lock.
  373. * @created: Indicates whether the CPU thread has been successfully created.
  374. * @halt_cond: condition variable sleeping threads can wait on.
  375. * @interrupt_request: Indicates a pending interrupt request.
  376. * @halted: Nonzero if the CPU is in suspended state.
  377. * @stop: Indicates a pending stop request.
  378. * @stopped: Indicates the CPU has been artificially stopped.
  379. * @unplug: Indicates a pending CPU unplug request.
  380. * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
  381. * @singlestep_enabled: Flags for single-stepping.
  382. * @icount_extra: Instructions until next timer event.
  383. * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
  384. * AddressSpaces this CPU has)
  385. * @num_ases: number of CPUAddressSpaces in @cpu_ases
  386. * @as: Pointer to the first AddressSpace, for the convenience of targets which
  387. * only have a single AddressSpace
  388. * @gdb_regs: Additional GDB registers.
  389. * @gdb_num_regs: Number of total registers accessible to GDB.
  390. * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
  391. * @node: QTAILQ of CPUs sharing TB cache.
  392. * @opaque: User data.
  393. * @mem_io_pc: Host Program Counter at which the memory was accessed.
  394. * @accel: Pointer to accelerator specific state.
  395. * @kvm_fd: vCPU file descriptor for KVM.
  396. * @work_mutex: Lock to prevent multiple access to @work_list.
  397. * @work_list: List of pending asynchronous work.
  398. * @plugin_state: per-CPU plugin state
  399. * @ignore_memory_transaction_failures: Cached copy of the MachineState
  400. * flag of the same name: allows the board to suppress calling of the
  401. * CPU do_transaction_failed hook function.
  402. * @kvm_dirty_gfns: Points to the KVM dirty ring for this CPU when KVM dirty
  403. * ring is enabled.
  404. * @kvm_fetch_index: Keeps the index that we last fetched from the per-vCPU
  405. * dirty ring structure.
  406. *
  407. * @neg_align: The CPUState is the common part of a concrete ArchCPU
  408. * which is allocated when an individual CPU instance is created. As
  409. * such care is taken is ensure there is no gap between between
  410. * CPUState and CPUArchState within ArchCPU.
  411. *
  412. * @neg: The architectural register state ("cpu_env") immediately follows
  413. * CPUState in ArchCPU and is passed to TCG code. The @neg structure holds
  414. * some common TCG CPU variables which are accessed with a negative offset
  415. * from cpu_env.
  416. */
  417. struct CPUState {
  418. /*< private >*/
  419. DeviceState parent_obj;
  420. /* cache to avoid expensive CPU_GET_CLASS */
  421. CPUClass *cc;
  422. /*< public >*/
  423. int nr_cores;
  424. int nr_threads;
  425. struct QemuThread *thread;
  426. #ifdef _WIN32
  427. QemuSemaphore sem;
  428. #endif
  429. int thread_id;
  430. bool running, has_waiter;
  431. struct QemuCond *halt_cond;
  432. bool thread_kicked;
  433. bool created;
  434. bool stop;
  435. bool stopped;
  436. /* Should CPU start in powered-off state? */
  437. bool start_powered_off;
  438. bool unplug;
  439. bool crash_occurred;
  440. bool exit_request;
  441. int exclusive_context_count;
  442. uint32_t cflags_next_tb;
  443. /* updates protected by BQL */
  444. uint32_t interrupt_request;
  445. int singlestep_enabled;
  446. int64_t icount_budget;
  447. int64_t icount_extra;
  448. uint64_t random_seed;
  449. sigjmp_buf jmp_env;
  450. QemuMutex work_mutex;
  451. QSIMPLEQ_HEAD(, qemu_work_item) work_list;
  452. struct CPUAddressSpace *cpu_ases;
  453. int cpu_ases_count;
  454. int num_ases;
  455. AddressSpace *as;
  456. MemoryRegion *memory;
  457. struct CPUJumpCache *tb_jmp_cache;
  458. GArray *gdb_regs;
  459. int gdb_num_regs;
  460. int gdb_num_g_regs;
  461. QTAILQ_ENTRY(CPUState) node;
  462. /* ice debug support */
  463. QTAILQ_HEAD(, CPUBreakpoint) breakpoints;
  464. QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
  465. CPUWatchpoint *watchpoint_hit;
  466. void *opaque;
  467. /* In order to avoid passing too many arguments to the MMIO helpers,
  468. * we store some rarely used information in the CPU context.
  469. */
  470. uintptr_t mem_io_pc;
  471. /* Only used in KVM */
  472. int kvm_fd;
  473. struct KVMState *kvm_state;
  474. struct kvm_run *kvm_run;
  475. struct kvm_dirty_gfn *kvm_dirty_gfns;
  476. uint32_t kvm_fetch_index;
  477. uint64_t dirty_pages;
  478. int kvm_vcpu_stats_fd;
  479. bool vcpu_dirty;
  480. /* Use by accel-block: CPU is executing an ioctl() */
  481. QemuLockCnt in_ioctl_lock;
  482. #ifdef CONFIG_PLUGIN
  483. CPUPluginState *plugin_state;
  484. #endif
  485. /* TODO Move common fields from CPUArchState here. */
  486. int cpu_index;
  487. int cluster_index;
  488. uint32_t tcg_cflags;
  489. uint32_t halted;
  490. int32_t exception_index;
  491. AccelCPUState *accel;
  492. /* Used to keep track of an outstanding cpu throttle thread for migration
  493. * autoconverge
  494. */
  495. bool throttle_thread_scheduled;
  496. /*
  497. * Sleep throttle_us_per_full microseconds once dirty ring is full
  498. * if dirty page rate limit is enabled.
  499. */
  500. int64_t throttle_us_per_full;
  501. bool ignore_memory_transaction_failures;
  502. /* Used for user-only emulation of prctl(PR_SET_UNALIGN). */
  503. bool prctl_unalign_sigbus;
  504. /* track IOMMUs whose translations we've cached in the TCG TLB */
  505. GArray *iommu_notifiers;
  506. /*
  507. * MUST BE LAST in order to minimize the displacement to CPUArchState.
  508. */
  509. char neg_align[-sizeof(CPUNegativeOffsetState) % 16] QEMU_ALIGNED(16);
  510. CPUNegativeOffsetState neg;
  511. };
  512. /* Validate placement of CPUNegativeOffsetState. */
  513. QEMU_BUILD_BUG_ON(offsetof(CPUState, neg) !=
  514. sizeof(CPUState) - sizeof(CPUNegativeOffsetState));
  515. static inline CPUArchState *cpu_env(CPUState *cpu)
  516. {
  517. /* We validate that CPUArchState follows CPUState in cpu-all.h. */
  518. return (CPUArchState *)(cpu + 1);
  519. }
  520. typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
  521. extern CPUTailQ cpus_queue;
  522. #define first_cpu QTAILQ_FIRST_RCU(&cpus_queue)
  523. #define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node)
  524. #define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus_queue, node)
  525. #define CPU_FOREACH_SAFE(cpu, next_cpu) \
  526. QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus_queue, node, next_cpu)
  527. extern __thread CPUState *current_cpu;
  528. /**
  529. * qemu_tcg_mttcg_enabled:
  530. * Check whether we are running MultiThread TCG or not.
  531. *
  532. * Returns: %true if we are in MTTCG mode %false otherwise.
  533. */
  534. extern bool mttcg_enabled;
  535. #define qemu_tcg_mttcg_enabled() (mttcg_enabled)
  536. /**
  537. * cpu_paging_enabled:
  538. * @cpu: The CPU whose state is to be inspected.
  539. *
  540. * Returns: %true if paging is enabled, %false otherwise.
  541. */
  542. bool cpu_paging_enabled(const CPUState *cpu);
  543. /**
  544. * cpu_get_memory_mapping:
  545. * @cpu: The CPU whose memory mappings are to be obtained.
  546. * @list: Where to write the memory mappings to.
  547. * @errp: Pointer for reporting an #Error.
  548. *
  549. * Returns: %true on success, %false otherwise.
  550. */
  551. bool cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
  552. Error **errp);
  553. #if !defined(CONFIG_USER_ONLY)
  554. /**
  555. * cpu_write_elf64_note:
  556. * @f: pointer to a function that writes memory to a file
  557. * @cpu: The CPU whose memory is to be dumped
  558. * @cpuid: ID number of the CPU
  559. * @opaque: pointer to the CPUState struct
  560. */
  561. int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
  562. int cpuid, void *opaque);
  563. /**
  564. * cpu_write_elf64_qemunote:
  565. * @f: pointer to a function that writes memory to a file
  566. * @cpu: The CPU whose memory is to be dumped
  567. * @cpuid: ID number of the CPU
  568. * @opaque: pointer to the CPUState struct
  569. */
  570. int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  571. void *opaque);
  572. /**
  573. * cpu_write_elf32_note:
  574. * @f: pointer to a function that writes memory to a file
  575. * @cpu: The CPU whose memory is to be dumped
  576. * @cpuid: ID number of the CPU
  577. * @opaque: pointer to the CPUState struct
  578. */
  579. int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
  580. int cpuid, void *opaque);
  581. /**
  582. * cpu_write_elf32_qemunote:
  583. * @f: pointer to a function that writes memory to a file
  584. * @cpu: The CPU whose memory is to be dumped
  585. * @cpuid: ID number of the CPU
  586. * @opaque: pointer to the CPUState struct
  587. */
  588. int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  589. void *opaque);
  590. /**
  591. * cpu_get_crash_info:
  592. * @cpu: The CPU to get crash information for
  593. *
  594. * Gets the previously saved crash information.
  595. * Caller is responsible for freeing the data.
  596. */
  597. GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
  598. #endif /* !CONFIG_USER_ONLY */
  599. /**
  600. * CPUDumpFlags:
  601. * @CPU_DUMP_CODE:
  602. * @CPU_DUMP_FPU: dump FPU register state, not just integer
  603. * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
  604. * @CPU_DUMP_VPU: dump VPU registers
  605. */
  606. enum CPUDumpFlags {
  607. CPU_DUMP_CODE = 0x00010000,
  608. CPU_DUMP_FPU = 0x00020000,
  609. CPU_DUMP_CCOP = 0x00040000,
  610. CPU_DUMP_VPU = 0x00080000,
  611. };
  612. /**
  613. * cpu_dump_state:
  614. * @cpu: The CPU whose state is to be dumped.
  615. * @f: If non-null, dump to this stream, else to current print sink.
  616. *
  617. * Dumps CPU state.
  618. */
  619. void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
  620. #ifndef CONFIG_USER_ONLY
  621. /**
  622. * cpu_get_phys_page_attrs_debug:
  623. * @cpu: The CPU to obtain the physical page address for.
  624. * @addr: The virtual address.
  625. * @attrs: Updated on return with the memory transaction attributes to use
  626. * for this access.
  627. *
  628. * Obtains the physical page corresponding to a virtual one, together
  629. * with the corresponding memory transaction attributes to use for the access.
  630. * Use it only for debugging because no protection checks are done.
  631. *
  632. * Returns: Corresponding physical page address or -1 if no page found.
  633. */
  634. hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
  635. MemTxAttrs *attrs);
  636. /**
  637. * cpu_get_phys_page_debug:
  638. * @cpu: The CPU to obtain the physical page address for.
  639. * @addr: The virtual address.
  640. *
  641. * Obtains the physical page corresponding to a virtual one.
  642. * Use it only for debugging because no protection checks are done.
  643. *
  644. * Returns: Corresponding physical page address or -1 if no page found.
  645. */
  646. hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
  647. /** cpu_asidx_from_attrs:
  648. * @cpu: CPU
  649. * @attrs: memory transaction attributes
  650. *
  651. * Returns the address space index specifying the CPU AddressSpace
  652. * to use for a memory access with the given transaction attributes.
  653. */
  654. int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs);
  655. /**
  656. * cpu_virtio_is_big_endian:
  657. * @cpu: CPU
  658. * Returns %true if a CPU which supports runtime configurable endianness
  659. * is currently big-endian.
  660. */
  661. bool cpu_virtio_is_big_endian(CPUState *cpu);
  662. #endif /* CONFIG_USER_ONLY */
  663. /**
  664. * cpu_list_add:
  665. * @cpu: The CPU to be added to the list of CPUs.
  666. */
  667. void cpu_list_add(CPUState *cpu);
  668. /**
  669. * cpu_list_remove:
  670. * @cpu: The CPU to be removed from the list of CPUs.
  671. */
  672. void cpu_list_remove(CPUState *cpu);
  673. /**
  674. * cpu_reset:
  675. * @cpu: The CPU whose state is to be reset.
  676. */
  677. void cpu_reset(CPUState *cpu);
  678. /**
  679. * cpu_class_by_name:
  680. * @typename: The CPU base type.
  681. * @cpu_model: The model string without any parameters.
  682. *
  683. * Looks up a concrete CPU #ObjectClass matching name @cpu_model.
  684. *
  685. * Returns: A concrete #CPUClass or %NULL if no matching class is found
  686. * or if the matching class is abstract.
  687. */
  688. ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
  689. /**
  690. * cpu_model_from_type:
  691. * @typename: The CPU type name
  692. *
  693. * Extract the CPU model name from the CPU type name. The
  694. * CPU type name is either the combination of the CPU model
  695. * name and suffix, or same to the CPU model name.
  696. *
  697. * Returns: CPU model name or NULL if the CPU class doesn't exist
  698. * The user should g_free() the string once no longer needed.
  699. */
  700. char *cpu_model_from_type(const char *typename);
  701. /**
  702. * cpu_create:
  703. * @typename: The CPU type.
  704. *
  705. * Instantiates a CPU and realizes the CPU.
  706. *
  707. * Returns: A #CPUState or %NULL if an error occurred.
  708. */
  709. CPUState *cpu_create(const char *typename);
  710. /**
  711. * parse_cpu_option:
  712. * @cpu_option: The -cpu option including optional parameters.
  713. *
  714. * processes optional parameters and registers them as global properties
  715. *
  716. * Returns: type of CPU to create or prints error and terminates process
  717. * if an error occurred.
  718. */
  719. const char *parse_cpu_option(const char *cpu_option);
  720. /**
  721. * cpu_has_work:
  722. * @cpu: The vCPU to check.
  723. *
  724. * Checks whether the CPU has work to do.
  725. *
  726. * Returns: %true if the CPU has work, %false otherwise.
  727. */
  728. static inline bool cpu_has_work(CPUState *cpu)
  729. {
  730. CPUClass *cc = CPU_GET_CLASS(cpu);
  731. g_assert(cc->has_work);
  732. return cc->has_work(cpu);
  733. }
  734. /**
  735. * qemu_cpu_is_self:
  736. * @cpu: The vCPU to check against.
  737. *
  738. * Checks whether the caller is executing on the vCPU thread.
  739. *
  740. * Returns: %true if called from @cpu's thread, %false otherwise.
  741. */
  742. bool qemu_cpu_is_self(CPUState *cpu);
  743. /**
  744. * qemu_cpu_kick:
  745. * @cpu: The vCPU to kick.
  746. *
  747. * Kicks @cpu's thread.
  748. */
  749. void qemu_cpu_kick(CPUState *cpu);
  750. /**
  751. * cpu_is_stopped:
  752. * @cpu: The CPU to check.
  753. *
  754. * Checks whether the CPU is stopped.
  755. *
  756. * Returns: %true if run state is not running or if artificially stopped;
  757. * %false otherwise.
  758. */
  759. bool cpu_is_stopped(CPUState *cpu);
  760. /**
  761. * do_run_on_cpu:
  762. * @cpu: The vCPU to run on.
  763. * @func: The function to be executed.
  764. * @data: Data to pass to the function.
  765. * @mutex: Mutex to release while waiting for @func to run.
  766. *
  767. * Used internally in the implementation of run_on_cpu.
  768. */
  769. void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
  770. QemuMutex *mutex);
  771. /**
  772. * run_on_cpu:
  773. * @cpu: The vCPU to run on.
  774. * @func: The function to be executed.
  775. * @data: Data to pass to the function.
  776. *
  777. * Schedules the function @func for execution on the vCPU @cpu.
  778. */
  779. void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
  780. /**
  781. * async_run_on_cpu:
  782. * @cpu: The vCPU to run on.
  783. * @func: The function to be executed.
  784. * @data: Data to pass to the function.
  785. *
  786. * Schedules the function @func for execution on the vCPU @cpu asynchronously.
  787. */
  788. void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
  789. /**
  790. * async_safe_run_on_cpu:
  791. * @cpu: The vCPU to run on.
  792. * @func: The function to be executed.
  793. * @data: Data to pass to the function.
  794. *
  795. * Schedules the function @func for execution on the vCPU @cpu asynchronously,
  796. * while all other vCPUs are sleeping.
  797. *
  798. * Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
  799. * BQL.
  800. */
  801. void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
  802. /**
  803. * cpu_in_exclusive_context()
  804. * @cpu: The vCPU to check
  805. *
  806. * Returns true if @cpu is an exclusive context, for example running
  807. * something which has previously been queued via async_safe_run_on_cpu().
  808. */
  809. static inline bool cpu_in_exclusive_context(const CPUState *cpu)
  810. {
  811. return cpu->exclusive_context_count;
  812. }
  813. /**
  814. * qemu_get_cpu:
  815. * @index: The CPUState@cpu_index value of the CPU to obtain.
  816. *
  817. * Gets a CPU matching @index.
  818. *
  819. * Returns: The CPU or %NULL if there is no matching CPU.
  820. */
  821. CPUState *qemu_get_cpu(int index);
  822. /**
  823. * cpu_exists:
  824. * @id: Guest-exposed CPU ID to lookup.
  825. *
  826. * Search for CPU with specified ID.
  827. *
  828. * Returns: %true - CPU is found, %false - CPU isn't found.
  829. */
  830. bool cpu_exists(int64_t id);
  831. /**
  832. * cpu_by_arch_id:
  833. * @id: Guest-exposed CPU ID of the CPU to obtain.
  834. *
  835. * Get a CPU with matching @id.
  836. *
  837. * Returns: The CPU or %NULL if there is no matching CPU.
  838. */
  839. CPUState *cpu_by_arch_id(int64_t id);
  840. /**
  841. * cpu_interrupt:
  842. * @cpu: The CPU to set an interrupt on.
  843. * @mask: The interrupts to set.
  844. *
  845. * Invokes the interrupt handler.
  846. */
  847. void cpu_interrupt(CPUState *cpu, int mask);
  848. /**
  849. * cpu_set_pc:
  850. * @cpu: The CPU to set the program counter for.
  851. * @addr: Program counter value.
  852. *
  853. * Sets the program counter for a CPU.
  854. */
  855. static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
  856. {
  857. CPUClass *cc = CPU_GET_CLASS(cpu);
  858. cc->set_pc(cpu, addr);
  859. }
  860. /**
  861. * cpu_reset_interrupt:
  862. * @cpu: The CPU to clear the interrupt on.
  863. * @mask: The interrupt mask to clear.
  864. *
  865. * Resets interrupts on the vCPU @cpu.
  866. */
  867. void cpu_reset_interrupt(CPUState *cpu, int mask);
  868. /**
  869. * cpu_exit:
  870. * @cpu: The CPU to exit.
  871. *
  872. * Requests the CPU @cpu to exit execution.
  873. */
  874. void cpu_exit(CPUState *cpu);
  875. /**
  876. * cpu_pause:
  877. * @cpu: The CPU to pause.
  878. *
  879. * Pauses CPU, i.e. puts CPU into stopped state.
  880. */
  881. void cpu_pause(CPUState *cpu);
  882. /**
  883. * cpu_resume:
  884. * @cpu: The CPU to resume.
  885. *
  886. * Resumes CPU, i.e. puts CPU into runnable state.
  887. */
  888. void cpu_resume(CPUState *cpu);
  889. /**
  890. * cpu_remove_sync:
  891. * @cpu: The CPU to remove.
  892. *
  893. * Requests the CPU to be removed and waits till it is removed.
  894. */
  895. void cpu_remove_sync(CPUState *cpu);
  896. /**
  897. * free_queued_cpu_work() - free all items on CPU work queue
  898. * @cpu: The CPU which work queue to free.
  899. */
  900. void free_queued_cpu_work(CPUState *cpu);
  901. /**
  902. * process_queued_cpu_work() - process all items on CPU work queue
  903. * @cpu: The CPU which work queue to process.
  904. */
  905. void process_queued_cpu_work(CPUState *cpu);
  906. /**
  907. * cpu_exec_start:
  908. * @cpu: The CPU for the current thread.
  909. *
  910. * Record that a CPU has started execution and can be interrupted with
  911. * cpu_exit.
  912. */
  913. void cpu_exec_start(CPUState *cpu);
  914. /**
  915. * cpu_exec_end:
  916. * @cpu: The CPU for the current thread.
  917. *
  918. * Record that a CPU has stopped execution and exclusive sections
  919. * can be executed without interrupting it.
  920. */
  921. void cpu_exec_end(CPUState *cpu);
  922. /**
  923. * start_exclusive:
  924. *
  925. * Wait for a concurrent exclusive section to end, and then start
  926. * a section of work that is run while other CPUs are not running
  927. * between cpu_exec_start and cpu_exec_end. CPUs that are running
  928. * cpu_exec are exited immediately. CPUs that call cpu_exec_start
  929. * during the exclusive section go to sleep until this CPU calls
  930. * end_exclusive.
  931. */
  932. void start_exclusive(void);
  933. /**
  934. * end_exclusive:
  935. *
  936. * Concludes an exclusive execution section started by start_exclusive.
  937. */
  938. void end_exclusive(void);
  939. /**
  940. * qemu_init_vcpu:
  941. * @cpu: The vCPU to initialize.
  942. *
  943. * Initializes a vCPU.
  944. */
  945. void qemu_init_vcpu(CPUState *cpu);
  946. #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
  947. #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
  948. #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
  949. /**
  950. * cpu_single_step:
  951. * @cpu: CPU to the flags for.
  952. * @enabled: Flags to enable.
  953. *
  954. * Enables or disables single-stepping for @cpu.
  955. */
  956. void cpu_single_step(CPUState *cpu, int enabled);
  957. /* Breakpoint/watchpoint flags */
  958. #define BP_MEM_READ 0x01
  959. #define BP_MEM_WRITE 0x02
  960. #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
  961. #define BP_STOP_BEFORE_ACCESS 0x04
  962. /* 0x08 currently unused */
  963. #define BP_GDB 0x10
  964. #define BP_CPU 0x20
  965. #define BP_ANY (BP_GDB | BP_CPU)
  966. #define BP_HIT_SHIFT 6
  967. #define BP_WATCHPOINT_HIT_READ (BP_MEM_READ << BP_HIT_SHIFT)
  968. #define BP_WATCHPOINT_HIT_WRITE (BP_MEM_WRITE << BP_HIT_SHIFT)
  969. #define BP_WATCHPOINT_HIT (BP_MEM_ACCESS << BP_HIT_SHIFT)
  970. int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
  971. CPUBreakpoint **breakpoint);
  972. int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
  973. void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
  974. void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
  975. /* Return true if PC matches an installed breakpoint. */
  976. static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
  977. {
  978. CPUBreakpoint *bp;
  979. if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
  980. QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
  981. if (bp->pc == pc && (bp->flags & mask)) {
  982. return true;
  983. }
  984. }
  985. }
  986. return false;
  987. }
  988. #if defined(CONFIG_USER_ONLY)
  989. static inline int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
  990. int flags, CPUWatchpoint **watchpoint)
  991. {
  992. return -ENOSYS;
  993. }
  994. static inline int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
  995. vaddr len, int flags)
  996. {
  997. return -ENOSYS;
  998. }
  999. static inline void cpu_watchpoint_remove_by_ref(CPUState *cpu,
  1000. CPUWatchpoint *wp)
  1001. {
  1002. }
  1003. static inline void cpu_watchpoint_remove_all(CPUState *cpu, int mask)
  1004. {
  1005. }
  1006. #else
  1007. int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
  1008. int flags, CPUWatchpoint **watchpoint);
  1009. int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
  1010. vaddr len, int flags);
  1011. void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
  1012. void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
  1013. #endif
  1014. /**
  1015. * cpu_get_address_space:
  1016. * @cpu: CPU to get address space from
  1017. * @asidx: index identifying which address space to get
  1018. *
  1019. * Return the requested address space of this CPU. @asidx
  1020. * specifies which address space to read.
  1021. */
  1022. AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
  1023. G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...)
  1024. G_GNUC_PRINTF(2, 3);
  1025. /* $(top_srcdir)/cpu.c */
  1026. void cpu_class_init_props(DeviceClass *dc);
  1027. void cpu_exec_initfn(CPUState *cpu);
  1028. bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
  1029. void cpu_exec_unrealizefn(CPUState *cpu);
  1030. void cpu_exec_reset_hold(CPUState *cpu);
  1031. const char *target_name(void);
  1032. #ifdef COMPILING_PER_TARGET
  1033. #ifndef CONFIG_USER_ONLY
  1034. extern const VMStateDescription vmstate_cpu_common;
  1035. #define VMSTATE_CPU() { \
  1036. .name = "parent_obj", \
  1037. .size = sizeof(CPUState), \
  1038. .vmsd = &vmstate_cpu_common, \
  1039. .flags = VMS_STRUCT, \
  1040. .offset = 0, \
  1041. }
  1042. #endif /* !CONFIG_USER_ONLY */
  1043. #endif /* COMPILING_PER_TARGET */
  1044. #define UNASSIGNED_CPU_INDEX -1
  1045. #define UNASSIGNED_CLUSTER_INDEX -1
  1046. #endif