# TYPE\_CPU

Qemu中所有CPU类型都有一个父类TYPE\_CPU。所以研究这个结构是开展后续研究的基础。

## 继承关系

按照老规矩，我们还是先看一下类型的继承层次关系。

```
  TYPE_OBJECT
  +-------------------------------+
  |class_init                     | = object_class_init
  |                               |
  |instance_size                  | = sizeof(Object)
  +-------------------------------+


  TYPE_DEVICE
  +-------------------------------+
  |class_size                     | = sizeof(DeviceClass)
  |class_init                     | = device_class_init
  |                               |
  |instance_size                  | = sizeof(Object)
  |instance_init                  | = device_initfn
  |instance_finalize              | = device_finalize
  |                               |
  |realize                        | = cpu_common_realizefn
  +-------------------------------+


  TYPE_CPU
  +-------------------------------+
  |class_size                     | = sizeof(CPUClass)
  |class_init                     | = cpu_class_init
  |                               |
  |instance_size                  | = sizeof(CPUState)
  |instance_init                  | = cpu_common_initfn
  |instance_finalize              | = cpu_common_finalize
  +-------------------------------+
```

可以看到，TYPE\_CPU是TYPE\_DEVICE的子类，也就是CPU类型的初始化遵从[Device类型初始化的方法](/understanding_qemu/00-devices/04-deviceclass_instance.md)。

大家可以看到realize函数也被我着重标出了。

## 初始化

针对TYPE\_CPU，我们能看到的初始化过程就是普通的类型初始化的流程，以及Device类型realize时所做的工作。

具体的工作流程将根据不同的CPU类型而有所不同，还需要按照不同的CPU和Machine类型来处理。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://richardweiyang-2.gitbook.io/understanding_qemu/00-vcpu/01-type_cpu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
