def setUp(self): super(TestReferencingToSelfDefinedType, self).setUp() name = type(self).__name__ hdr = Header(name.lower() + ".h") m = Macro("M_OTHER_TYPE", text="int") hdr.add_type(m) ht = Header("macro_types.h") ht.add_type(Macro("M_TYPE", text="M_OTHER_TYPE")) ht.add_reference(m) hdr.add_global_variable(Type["M_TYPE"]("var")) hdr_content = """\ /* {path} */ #ifndef INCLUDE_{fname_upper}_H #define INCLUDE_{fname_upper}_H #define M_OTHER_TYPE int #include "macro_types.h" extern M_TYPE var; #endif /* INCLUDE_{fname_upper}_H */ """.format(path=hdr.path, fname_upper=name.upper()) self.files = [(hdr, hdr_content)]
def setUp(self): super(TestMacroType, self).setUp() name = type(self).__name__ hdr = Header(name.lower() + ".h") hdr.add_type(Macro("QTAIL_ENTRY", args=["type"])) struct = Structure("StructA") struct.append_fields([ Type["QTAIL_ENTRY"]("entry", macro_initializer=Initializer({"type": struct})), Pointer(struct)("next") ]) hdr.add_type(struct) hdr_content = """\ /* {path} */ #ifndef INCLUDE_{fname_upper}_H #define INCLUDE_{fname_upper}_H #define QTAIL_ENTRY(type) typedef struct StructA StructA; struct StructA {{ QTAIL_ENTRY(StructA) entry; StructA *next; }}; #endif /* INCLUDE_{fname_upper}_H */ """.format(path=hdr.path, fname_upper=name.upper()) self.files = [(hdr, hdr_content)]
def setUp(self): super(TestOpaqueCode, self).setUp() name = type(self).__name__ hdr = Header(name.lower() + ".h", protection=False) test_var = Type["int"]("test_var") test_func = Function(name="test_func") opaque_top = OpaqueCode("""\ /* Generic comment above macros */ """, weight=0) opaque_bottom = OpaqueCode(""" /* A comment at bottom of file */ """, weight=10) opaque_middle = OpaqueCode(""" /* How to use test_var and test_func. */ """, used_variables=[test_var], used_types=[test_func] # Default weight (5) ) hdr.add_types([ # Yields #define statement with weight 1 Macro("TEST_MACRO"), # Yields function declaration with weight 6 Function(name="another_test_func"), opaque_middle, opaque_bottom, opaque_top ]) hdr_content = """\ /* {path} */ /* Generic comment above macros */ #define TEST_MACRO extern int test_var; void test_func(void); /* How to use test_var and test_func. */ void another_test_func(void); /* A comment at bottom of file */ """.format(path=hdr.path) self.files = [(hdr, hdr_content)]
def gen_property_macros(self, source): for field in self.state_fields: if not field.prop: continue if field.prop_macro_name is None: continue t = Macro(field.prop_macro_name, text = field.prop_name) source.add_type(t)
def fill_header(self): self.state_struct = self.gen_state() self.header.add_type(self.state_struct) self.type_name_macros = Macro(name=self.qtn.type_macro, text='"%s"' % self.qtn.for_id_name) self.header.add_type(self.type_name_macros) self.type_cast_macro = Macro( name=self.qtn.for_macros, args=["obj"], text="OBJECT_CHECK({Struct}, (obj), {TYPE_MACRO})".format( TYPE_MACRO=self.qtn.type_macro, Struct=self.struct_name)) self.header.add_type(self.type_cast_macro) line_origins( [self.type_name_macros, self.type_cast_macro, self.state_struct]) for mmioN in range(0, self.mmio_num): size_macro = Macro(name=self.gen_Ith_mmio_size_macro_name(mmioN), text=self.gen_mmio_size( self.mmio.get(mmioN, None))) name_macro = Macro( name=self.get_Ith_mmio_name_macro_name(mmioN), text='%s "_%s"' % (self.qtn.type_macro, self.get_Ith_mmio_id_component(mmioN))) (self.header if MACROS_2_HEADER else self.source).add_types( [size_macro, name_macro]) self.mmio_size_macros.append(size_macro) self.mmio_name_macros.append(name_macro) pio_def_size = 0x4 pio_cur_addres = 0x1000 for pioN in range(0, self.pio_num): size_macro = Macro(name=self.gen_Ith_pio_size_macro_name(pioN), text="0x%X" % pio_def_size) address_macro = Macro( name=self.gen_Ith_pio_address_macro_name(pioN), text="0x%X" % pio_cur_addres) pio_cur_addres += pio_def_size self.header.add_types([size_macro, address_macro]) self.pio_size_macros.append(size_macro) self.pio_address_macros.append(address_macro) if self.in_irq_num > 0: self.in_irq_macro = Macro(name=self.qtn.for_macros + "_IN_IRQ_NUM", text="%d" % self.in_irq_num) self.header.add_type(self.in_irq_macro) self.gen_property_macros(self.header)
def setUp(self): super(TestMacroType, self).setUp() name = type(self).__name__ Header("entry_macro.h").add_type(Macro("QTAIL_ENTRY", args=["type"])) Header("struct_end.h").add_type(Macro("END_STRUCT")) Header("header_init.h").add_type(Macro("INIT_HEADER")) hdr = Header(name.lower() + ".h") struct = Structure("StructA") struct.append_fields([ Type["QTAIL_ENTRY"]("entry", macro_initializer=Initializer({"type": struct})), Pointer(struct)("next"), Type["END_STRUCT"].gen_type() ]) hdr.add_type(struct) hdr.add_type(Type["INIT_HEADER"].gen_type()) hdr_content = """\ /* {path} */ #ifndef INCLUDE_{fname_upper}_H #define INCLUDE_{fname_upper}_H #include "entry_macro.h" #include "header_init.h" #include "struct_end.h" typedef struct StructA StructA; struct StructA {{ QTAIL_ENTRY(StructA) entry; StructA *next; END_STRUCT }}; INIT_HEADER #endif /* INCLUDE_{fname_upper}_H */ """.format(path=hdr.path, fname_upper=name.upper()) self.files = [(hdr, hdr_content)]
def generate_header(self): self.state_struct = self.gen_state() self.header.add_type(self.state_struct) self.type_name_macros = Macro(name=self.qtn.type_macro, text='"%s"' % self.qtn.for_id_name) self.header.add_type(self.type_name_macros) self.type_cast_macro = Macro( name=self.qtn.for_macros, args=["obj"], text="OBJECT_CHECK({Struct}, (obj), {TYPE_MACRO})".format( TYPE_MACRO=self.qtn.type_macro, Struct=self.struct_name)) self.header.add_type(self.type_cast_macro) line_origins( [self.type_name_macros, self.type_cast_macro, self.state_struct]) for mmioN in range(0, self.mmio_num): size_macro = Macro(name=self.gen_Ith_mmio_size_macro_name(mmioN), text=self.gen_mmio_size( self.mmio.get(mmioN, None))) self.header.add_type(size_macro) self.mmio_size_macros.append(size_macro) pio_def_size = 0x4 pio_cur_addres = 0x1000 for pioN in range(0, self.pio_num): size_macro = Macro(name=self.gen_Ith_pio_size_macro_name(pioN), text="0x%X" % pio_def_size) address_macro = Macro( name=self.gen_Ith_pio_address_macro_name(pioN), text="0x%X" % pio_cur_addres) pio_cur_addres += pio_def_size self.header.add_types([size_macro, address_macro]) self.pio_size_macros.append(size_macro) self.pio_address_macros.append(address_macro) if self.in_irq_num > 0: self.in_irq_macro = Macro(name="%s_IN_IRQ_NUM" % self.qtn.for_macros, text="%d" % self.in_irq_num) self.header.add_type(self.in_irq_macro) self.gen_property_macros(self.header) # TODO: current value of inherit_references is dictated by Qemu coding # policy. Hence, version API must be used there. header_source = self.header.generate(inherit_references=True) return header_source
def generate_header(self): self.state_struct = self.gen_state() self.header.add_type(self.state_struct) self.type_name_macros = Macro(name=self.qtn.type_macro, text='"%s"' % self.qtn.for_id_name) self.header.add_type(self.type_name_macros) self.type_cast_macro = Macro( name=self.qtn.for_macros, args=["obj"], text="OBJECT_CHECK({Struct}, (obj), {TYPE_MACRO})".format( TYPE_MACRO=self.qtn.type_macro, Struct=self.struct_name)) self.header.add_type(self.type_cast_macro) line_origins( [self.type_name_macros, self.type_cast_macro, self.state_struct]) self.vendor_macro = self.vendor.find_macro() if self.subsystem_vendor and self.subsystem: self.subsystem_vendor_macro = self.subsystem_vendor.find_macro() else: self.subsystem_vendor_macro = None try: self.device_macro = self.device.find_macro() except TypeNotRegistered: # TODO: add device id macro to pci_ids.h self.header.add_type( Macro(name="PCI_DEVICE_ID_%s_%s" % (self.vendor.name, self.device.name), text=self.device.id)) self.device_macro = self.device.find_macro() if self.subsystem_vendor and self.subsystem: try: self.subsystem_macro = self.subsystem.find_macro() except TypeNotRegistered: # TODO: add device id macro to pci_ids.h self.header.add_type( Macro(name="PCI_DEVICE_ID_%s_%s" % (self.subsystem_vendor.name, self.subsystem.name), text=self.subsystem.id)) self.subsystem_macro = self.subsystem.find_macro() else: self.subsystem_macro = None self.pci_class_macro = self.pci_class.find_macro() mem_bar_def_size = 0x100 for barN in range(0, self.mem_bar_num): size_macro = Macro(name=self.gen_Ith_mem_bar_size_macro_name(barN), text="0x%X" % mem_bar_def_size) self.mem_bar_size_macros.append(size_macro) self.header.add_type(size_macro) if self.msi_messages_num > 0: self.msi_cap_offset = Macro(name="%s_MSI_CAP_OFFSET" % self.qtn.for_macros, text="0x48") self.msi_vectors = Macro(name="%s_MSI_VECTORS" % self.qtn.for_macros, text="%u" % self.msi_messages_num) self.msi_64bit = Macro(name="%s_MSI_64BIT" % self.qtn.for_macros, text="1") self.msi_masking = Macro(name="%s_MSI_VECTOR_MASKING" % self.qtn.for_macros, text="1") self.msi_types = [ self.msi_cap_offset, self.msi_vectors, self.msi_64bit, self.msi_masking ] line_origins(self.msi_types) self.header.add_types(self.msi_types) self.gen_property_macros(self.header) # TODO: current value of inherit_references is dictated by Qemu coding # policy. Hence, version API must be used there. return self.header.generate(inherit_references=True)
class PCIExpressDeviceType(QOMDevice): __attribute_info__ = OrderedDict([ # Note that multiple NIC generation is not implemented yet. ("nic_num", { "short": _("Network interface"), "input": bool }), ("vendor", { "short": _("Vendor"), "input": PCIId }), ("device", { "short": _("Device"), "input": PCIId }), ("pci_class", { "short": _("Class"), "input": PCIId }), ("subsys_vendor", { "short": _("Subsystem vendor"), "input": PCIId }), ("subsys", { "short": _("Subsystem"), "input": PCIId }), ("irq_num", { "short": _("IRQ pin quantity"), "input": int }), ("mem_bar_num", { "short": _("BAR quantity"), "input": int }), ("msi_messages_num", { "short": _("MSI message quantity"), "input": int }), ("revision", { "short": _("Revision"), "input": int }) ]) def __init__(self, name, directory, vendor, device, pci_class, irq_num=0, mem_bar_num=0, msi_messages_num=0, revision=0, subsys=None, subsys_vendor=None, bars=None, **qomd_kw): super(PCIExpressDeviceType, self).__init__(name, directory, **qomd_kw) if get_vp("PCIE requires interface"): self.interfaces.add("INTERFACE_PCIE_DEVICE") # TODO: what about INTERFACE_CONVENTIONAL_PCI_DEVICE? self.irq_num = irq_num self.mem_bar_num = mem_bar_num self.msi_messages_num = msi_messages_num self.revision = revision self.vendor = vendor self.device = device self.pci_class = pci_class self.subsystem = subsys self.subsystem_vendor = subsys_vendor self.bars = {} if bars is None else dcp(bars) # Cast all PCI identifiers to PCIId for attr in ["vendor", "subsystem_vendor"]: val = getattr(self, attr) if (val is not None) and (not isinstance(val, PCIId)): try: val = PCIId.db.get_vendor(name=val) except PCIVendorIdNetherExistsNorCreated: val = PCIId.db.get_vendor(vid=val) setattr(self, attr, val) for attr, vendor in [("device", self.vendor), ("subsystem", self.subsystem_vendor)]: val = getattr(self, attr) if (val is not None) and (not isinstance(val, PCIId)): if vendor is None: raise Exception( "Cannot get %s ID descriptor because of no \ corresponding vendor is given" % attr) try: val = PCIId.db.get_device(name=val, vendor_name=vendor.name, vid=vendor.id) except Exception: val = PCIId.db.get_device(did=val, vendor_name=vendor.name, vid=vendor.id) setattr(self, attr, val) val = getattr(self, "pci_class") # None is not allowed there if not isinstance(val, PCIId): try: val = PCIId.db.get_class(name=val) except: val = PCIId.db.get_class(cid=val) self.pci_class = val self.mem_bar_size_macros = [] self.add_state_field_h("PCIDevice", "parent_obj") for irqN in range(0, self.irq_num): self.add_state_field_h("qemu_irq", self.get_Ith_irq_name(irqN), save=False) for barN in xrange(0, self.mem_bar_num): self.add_state_field_h("MemoryRegion", self.get_Ith_mem_bar_name(barN), save=False) self.timer_declare_fields() self.char_declare_fields() self.block_declare_fields() self.nic_declare_fields() def generate_header(self): self.state_struct = self.gen_state() self.header.add_type(self.state_struct) self.type_name_macros = Macro(name=self.qtn.type_macro, text='"%s"' % self.qtn.for_id_name) self.header.add_type(self.type_name_macros) self.type_cast_macro = Macro( name=self.qtn.for_macros, args=["obj"], text="OBJECT_CHECK({Struct}, (obj), {TYPE_MACRO})".format( TYPE_MACRO=self.qtn.type_macro, Struct=self.struct_name)) self.header.add_type(self.type_cast_macro) line_origins( [self.type_name_macros, self.type_cast_macro, self.state_struct]) self.vendor_macro = self.vendor.find_macro() if self.subsystem_vendor and self.subsystem: self.subsystem_vendor_macro = self.subsystem_vendor.find_macro() else: self.subsystem_vendor_macro = None try: self.device_macro = self.device.find_macro() except TypeNotRegistered: # TODO: add device id macro to pci_ids.h self.header.add_type( Macro(name="PCI_DEVICE_ID_%s_%s" % (self.vendor.name, self.device.name), text=self.device.id)) self.device_macro = self.device.find_macro() if self.subsystem_vendor and self.subsystem: try: self.subsystem_macro = self.subsystem.find_macro() except TypeNotRegistered: # TODO: add device id macro to pci_ids.h self.header.add_type( Macro(name="PCI_DEVICE_ID_%s_%s" % (self.subsystem_vendor.name, self.subsystem.name), text=self.subsystem.id)) self.subsystem_macro = self.subsystem.find_macro() else: self.subsystem_macro = None self.pci_class_macro = self.pci_class.find_macro() mem_bar_def_size = 0x100 for barN in range(0, self.mem_bar_num): size_macro = Macro(name=self.gen_Ith_mem_bar_size_macro_name(barN), text="0x%X" % mem_bar_def_size) self.mem_bar_size_macros.append(size_macro) self.header.add_type(size_macro) if self.msi_messages_num > 0: self.msi_cap_offset = Macro(name="%s_MSI_CAP_OFFSET" % self.qtn.for_macros, text="0x48") self.msi_vectors = Macro(name="%s_MSI_VECTORS" % self.qtn.for_macros, text="%u" % self.msi_messages_num) self.msi_64bit = Macro(name="%s_MSI_64BIT" % self.qtn.for_macros, text="1") self.msi_masking = Macro(name="%s_MSI_VECTOR_MASKING" % self.qtn.for_macros, text="1") self.msi_types = [ self.msi_cap_offset, self.msi_vectors, self.msi_64bit, self.msi_masking ] line_origins(self.msi_types) self.header.add_types(self.msi_types) self.gen_property_macros(self.header) # TODO: current value of inherit_references is dictated by Qemu coding # policy. Hence, version API must be used there. return self.header.generate(inherit_references=True) def generate_source(self): self.device_reset = Function( "%s_reset" % self.qtn.for_id_name, body="""\ __attribute__((unused))@b{Struct}@b*s@b=@s{UPPER}(dev); """.format( Struct=self.state_struct.name, UPPER=self.type_cast_macro.name, ), args=[Type.lookup("DeviceState").gen_var("dev", True)], static=True, used_types=[self.state_struct]) self.source.add_type(self.device_reset) realize_code = '' realize_used_types = set() realize_used_globals = [] s_is_used = False if self.mem_bar_num > 0: s_is_used = True realize_used_types.update([ Type.lookup("sysbus_init_mmio"), Type.lookup("memory_region_init_io"), Type.lookup("Object") ]) for barN in range(0, self.mem_bar_num): size_macro = self.mem_bar_size_macros[barN] realize_used_types.add(size_macro) component = self.get_Ith_mem_bar_id_component(barN) read_func = QOMType.gen_mmio_read( name=self.qtn.for_id_name + "_" + component + "_read", struct_name=self.state_struct.name, type_cast_macro=self.type_cast_macro.name, regs=self.bars.get(barN, None)) write_func = QOMType.gen_mmio_write( name=self.qtn.for_id_name + "_" + component + "_write", struct_name=self.state_struct.name, type_cast_macro=self.type_cast_macro.name, regs=self.bars.get(barN, None)) write_func.extra_references = {read_func} self.source.add_types([read_func, write_func]) ops_init = Initializer(used_types=[read_func, write_func], code="""{{ .read = {read}, .write = {write} }}""".format(read=read_func.name, write=write_func.name)) ops = Type.lookup("MemoryRegionOps").gen_var( name=self.gen_Ith_mem_bar_ops_name(barN), pointer=False, initializer=ops_init, static=True) self.source.add_global_variable(ops) realize_used_globals.append(ops) realize_code += """ memory_region_init_io(@a&s->{bar},@sOBJECT(dev),@s&{ops},@ss,@s{TYPE_MACRO},@s{size}); pci_register_bar(@a&s->parent_obj,@s{barN},@sPCI_BASE_ADDRESS_SPACE_MEMORY,@s&s->{bar}); """.format(barN=barN, bar=self.get_Ith_mem_bar_name(barN), ops=self.gen_Ith_mem_bar_ops_name(barN), TYPE_MACRO=self.qtn.type_macro, size=size_macro.name) if self.msi_messages_num > 0: msi_init_type = Type.lookup("msi_init") s_is_used = True realize_code += """ msi_init(dev,@s%s,@s%s,@s%s,@s%s%s); """ % (self.msi_cap_offset.gen_usage_string(), self.msi_vectors.gen_usage_string(), self.msi_64bit.gen_usage_string(), self.msi_masking.gen_usage_string(), ",@serrp" if msi_init_type.args[-1].type \ == Pointer(Pointer(Type.lookup("Error"))) else "" ) realize_used_types.update(self.msi_types) realize_used_types.add(msi_init_type) self.device_realize = self.gen_realize( "PCIDevice", code=realize_code, s_is_used=s_is_used, used_types=realize_used_types, used_globals=realize_used_globals) self.source.add_type(self.device_realize) code = "" used_types = set([self.state_struct]) used_s = False if self.msi_messages_num > 0: code += """ msi_uninit(dev); """ used_types.add(Type.lookup("msi_uninit")) if self.nic_num > 0: code += "\n" used_s = True del_nic = Type.lookup("qemu_del_nic") used_types.add(del_nic) for nicN in xrange(self.nic_num): nic_name = self.nic_name(nicN) code += " %s(s->%s);\n" % (del_nic.name, nic_name) if self.timer_num > 0: used_s = True code += "\n" used_types.update( [Type.lookup("timer_del"), Type.lookup("timer_free")]) for timerN in range(self.timer_num): code += """ timer_del(s->{timerN}); timer_free(s->{timerN}); """.format(timerN=self.timer_name(timerN)) self.device_exit = Function( name="%s_exit" % self.qtn.for_id_name, args=[Type.lookup("PCIDevice").gen_var("dev", pointer=True)], static=True, used_types=used_types, body="""\ {unused}{Struct}@b*s@b=@s{UPPER}(dev); {extra_code}\ """.format(unused="" if used_s else "__attribute__((unused))@b", Struct=self.state_struct.name, UPPER=self.type_cast_macro.name, extra_code=code)) self.source.add_type(self.device_exit) self.vmstate = self.gen_vmstate_var(self.state_struct) self.source.add_global_variable(self.vmstate) self.properties = self.gen_properties_global(self.state_struct) self.source.add_global_variable(self.properties) self.vmstate.extra_references = {self.properties} self.class_init = Function( name="%s_class_init" % self.qtn.for_id_name, body="""\ DeviceClass@b*dc@b=@sDEVICE_CLASS(oc); PCIDeviceClass@b*pc@b=@sPCI_DEVICE_CLASS(oc); pc->realize@b@b@b{pad}=@s{dev}_realize; dc->reset@b@b@b@b@b{pad}=@s{dev}_reset; pc->exit@b@b@b@b@b@b{pad}=@s{dev}_exit; pc->vendor_id@b{pad}=@s{vendor_macro}; pc->device_id@b{pad}=@s{device_macro}; pc->class_id@b@b{pad}=@s{pci_class_macro};{subsys_id}{subsys_vid} pc->revision@b@b{pad}=@s{revision}; dc->vmsd@b@b@b@b@b@b{pad}=@s&vmstate_{dev}; dc->props@b@b@b@b@b{pad}=@s{dev}_properties; """.format(dev=self.qtn.for_id_name, revision=self.revision, vendor_macro=self.vendor_macro.name, device_macro=self.device_macro.name, pci_class_macro=self.pci_class_macro.name, subsys_id='' if self.subsystem_macro is None else (""" pc->subsystem_id@b@b@b@b@b@b@b@b=@s%s;""" % self.subsystem_macro.name), subsys_vid='' if self.subsystem_vendor_macro is None else (""" pc->subsystem_vendor_id@b=@s%s;""" % self.subsystem_vendor_macro.name), pad='@b@b@b@b@b@b@b@b@b@b' if self.subsystem_vendor_macro else ''), args=[ Type.lookup("ObjectClass").gen_var("oc", True), Type.lookup("void").gen_var("opaque", True), ], static=True, used_types=[ Type.lookup("DeviceClass"), Type.lookup("PCIDeviceClass"), self.device_realize, self.device_reset, self.device_exit, self.vendor_macro, self.device_macro, self.pci_class_macro ], used_globals=[self.vmstate, self.properties]) self.source.add_type(self.class_init) instance_init_used_types = set() instance_init_code = "" s_is_used = False self.instance_init = self.gen_instance_init_fn( self.state_struct, code=instance_init_code, s_is_used=s_is_used, used_types=instance_init_used_types) self.source.add_type(self.instance_init) self.type_info = self.gen_type_info_var(self.state_struct, self.instance_init, self.class_init, parent_tn="TYPE_PCI_DEVICE") self.source.add_global_variable(self.type_info) self.register_types = self.gen_register_types_fn(self.type_info) self.source.add_type(self.register_types) type_init_usage_init = Initializer( code={"function": self.register_types}) self.source.add_type( Type.lookup("type_init").gen_usage(type_init_usage_init)) # order life cycle functions self.device_reset.extra_references = {self.device_realize} self.device_exit.extra_references = {self.device_reset} return self.source.generate() def get_Ith_mem_bar_id_component(self, i): return self.get_Ith_mem_bar_name(i) def gen_Ith_mem_bar_size_macro_name(self, i): UPPER = self.get_Ith_mem_bar_id_component(i).upper() return "%s_%s_SIZE" % (self.qtn.for_macros, UPPER) def gen_Ith_mem_bar_ops_name(self, i): return self.qtn.for_id_name + "_" \ + self.get_Ith_mem_bar_id_component(i) + "_ops" def get_Ith_mem_bar_name(self, i): if self.mem_bar_num == 1: return "mem_bar" else: return "mem_bar_%u" % i def get_Ith_irq_name(self, i): if self.irq_num == 1: return "irq" else: return "irq_{}".format(i)
def define_only_qemu_2_6_0_types(): # According to Qemu inclusion policy, each source file must include # qemu/osdep.h. This could be met using different ways. For now add a # reference to a fake type inside osdep.h. # TODO: the tweak must be handled using version API. osdep_fake_type = Type("FAKE_TYPE_IN_QEMU_OSDEP") if not get_vp("tcg_enabled is macro"): Header.lookup("qemu-common.h").add_types( [Function("tcg_enabled", ret_type=Type.lookup("bool"))]) Header.lookup("tcg.h").add_types([ Type("TCGv_i32"), Type("TCGv_i64"), Type("TCGv_ptr"), Type("TCGv_env"), Type("TCGv"), Function("tcg_global_mem_new_i32"), Function("tcg_global_mem_new_i64"), Function("tcg_op_buf_full") ]) Header.lookup("tcg-op.h").add_types([ Function("tcg_gen_insn_start"), Function("tcg_gen_goto_tb"), Function("tcg_gen_exit_tb") ]) Header.lookup("tcg-op.h").add_types([ # HLTTemp is a fake type intended to mark # variables which are to be replaced by this tool # preprocessor (still in progress) # HLTTemp is then converted to some existing QEMU types Type("HLTTemp") ]) Header.lookup("qemu/osdep.h").add_types([osdep_fake_type]) Header.lookup("exec/hwaddr.h").add_types([Type("hwaddr", False) ]).add_reference(osdep_fake_type) Header.lookup("exec/cpu-defs.h").add_types([ Type("target_ulong", False), ]) Header.lookup("exec/cpu_ldst.h").add_types([ Function("cpu_ldub_code", ret_type=Type.lookup("uint8_t")), Function("cpu_lduw_code", ret_type=Type.lookup("uint16_t")), Function("cpu_ldl_code", ret_type=Type.lookup("uint32_t")), Function("cpu_ldq_code", ret_type=Type.lookup("uint64_t")), ]) Header.lookup("qom/object.h").add_types([ Type("ObjectClass", False), Type("Object", False), Structure( "TypeInfo", fields=[ # These are required fields only Pointer(Type.lookup("const char")).gen_var("name"), Pointer(Type.lookup("const char")).gen_var("parent"), Pointer(Type.lookup("void")).gen_var("class_init") ]), Type("Type", False), Type("TypeImpl", False), Function(name="type_register_static", ret_type=Type.lookup("TypeImpl"), args=[Type.lookup("TypeInfo").gen_var("info", pointer=True)]), Function(name="type_register", ret_type=Type.lookup("TypeImpl"), args=[Type.lookup("TypeInfo").gen_var("info", pointer=True)]), Function("object_get_typename"), Function("object_property_set_str"), Function("object_property_set_link"), Function("object_property_set_bool"), Function("object_property_set_int"), Function("object_class_by_name"), Function("object_class_dynamic_cast"), Function("object_class_is_abstract") ]).add_reference(osdep_fake_type) Header.lookup("qom/cpu.h").add_types([ Type("CPUState", False), Type("CPUClass", False), Type("vaddr", False), Type("MMUAccessType", False), Type("CPUBreakpoint", False), Function("qemu_init_vcpu", args=[Type.lookup("CPUState").gen_var("cpu", pointer=True)]), Function("cpu_exec_realizefn"), Function("cpu_reset"), Function("cpu_generic_init") ]).add_reference(osdep_fake_type) Header.lookup("qapi/error.h").add_types([Type("Error") ]).add_reference(osdep_fake_type) Header.lookup("disas/bfd.h").add_types([Type("disassemble_info", False) ]).add_reference(osdep_fake_type) Header.lookup("qemu/fprintf-fn.h").add_types( [Type("fprintf_function", False)]).add_reference(osdep_fake_type) Header.lookup("exec/exec-all.h").add_types([ Type("TranslationBlock", False), Function("tlb_fill", args=[ Type.lookup("CPUState").gen_var("cs", pointer=True), Type.lookup("target_ulong").gen_var("addr"), Type.lookup("MMUAccessType").gen_var("access_type"), Type.lookup("int").gen_var("mmu_idx"), Type.lookup("uintptr_t").gen_var("retaddr") ], used_types=[]), Function("cpu_exec_init", args=[ Type.lookup("CPUState").gen_var("cs", pointer=True), Pointer(Pointer(Type.lookup("Error"))).gen_var("errp") ]), Function("gen_intermediate_code"), Function("cpu_restore_state"), Function("cpu_loop_exit"), Function("cpu_loop_exit_restore"), Function("tlb_set_page") ]).add_reference(osdep_fake_type) Header.lookup("exec/gen-icount.h").add_types( [Function("gen_tb_start"), Function("gen_tb_end")]) Header.lookup("exec/address-spaces.h").add_types( [Function("get_system_memory")]).add_reference(osdep_fake_type) Header.lookup("exec/memory.h").add_types([ Type("MemoryRegion", False), Function(name="MemoryRegionOps_read", ret_type=Type.lookup("uint64_t"), args=[ Type.lookup("void").gen_var("opaque", pointer=True), Type.lookup("hwaddr").gen_var("offset"), Type.lookup("unsigned").gen_var("size") ]), Function(name="MemoryRegionOps_write", ret_type=Type.lookup("void"), args=[ Type.lookup("void").gen_var("opaque", pointer=True), Type.lookup("hwaddr").gen_var("offset"), Type.lookup("uint64_t").gen_var("value"), Type.lookup("unsigned").gen_var("size") ]), Structure("MemoryRegionOps", [ Type.lookup("MemoryRegionOps_read").gen_var("read"), Type.lookup("MemoryRegionOps_write").gen_var("write"), ]), Function( name="memory_region_init_io", args=[ Type.lookup("MemoryRegion").gen_var("mr", pointer=True), # struct Type.lookup("Object").gen_var("owner", pointer=True), # const Type.lookup("MemoryRegionOps").gen_var("ops", pointer=True), Type.lookup("void").gen_var("opaque", pointer=True), Type.lookup("const char").gen_var("name", pointer=True), Type.lookup("uint64_t").gen_var("size") ]), Function("memory_region_init"), Function("memory_region_init_alias"), Function("memory_region_init_ram"), Function("memory_region_add_subregion_overlap"), Function("memory_region_add_subregion") ]).add_reference(osdep_fake_type) Header.lookup("exec/gdbstub.h").add_types([ Function(name="gdb_get_reg8"), Function(name="gdb_get_reg16"), Function(name="gdb_get_reg32"), Function(name="gdb_get_reg64") ]).add_reference(osdep_fake_type) Header.lookup("exec/ioport.h").add_types( [Type("pio_addr_t", incomplete=False)]).add_reference(osdep_fake_type) Header.lookup("hw/boards.h").add_types( [Structure("MachineClass"), Structure("MachineState")]).add_reference(osdep_fake_type) Header.lookup("hw/sysbus.h").add_types([ Type("SysBusDevice", False), Type("qemu_irq", False), Function(name="sysbus_init_mmio", ret_type=Type.lookup("void"), args=[ Type.lookup("SysBusDevice").gen_var("dev", pointer=True), Type.lookup("MemoryRegion").gen_var("memory", pointer=True) ]), Function(name="sysbus_init_irq", ret_type=Type.lookup("void"), args=[ Type.lookup("SysBusDevice").gen_var("dev", pointer=True), Type.lookup("qemu_irq").gen_var("p", pointer=True) ]), Function(name="sysbus_add_io", ret_type=Type.lookup("void"), args=[ Type.lookup("SysBusDevice").gen_var("dev", pointer=True), Type.lookup("hwaddr").gen_var("addr"), Type.lookup("MemoryRegion").gen_var("mem", pointer=True) ]), Function(name="sysbus_init_ioports", ret_type=Type.lookup("void"), args=[ Type.lookup("SysBusDevice").gen_var("dev", pointer=True), Type.lookup("pio_addr_t").gen_var("dev"), Type.lookup("pio_addr_t").gen_var("dev") ]), Function("sysbus_mmio_map"), Function("sysbus_connect_irq") ]).add_reference(osdep_fake_type) Header.lookup("hw/irq.h").add_types([ Function(name="qemu_irq_handler", ret_type=Type.lookup("void"), args=[ Type.lookup("void").gen_var("opaque", pointer=True), Type.lookup("int").gen_var("n"), Type.lookup("int").gen_var("level") ]), Function("qemu_irq_split") ]).add_reference(osdep_fake_type) Header.lookup("hw/qdev-core.h").add_types([ Type("DeviceClass", False), Type("DeviceState", False), Type("Property", False), Function(name="qdev_init_gpio_in", ret_type=Type.lookup("void"), args=[ Type.lookup("DeviceState").gen_var("dev", pointer=True), Type.lookup("qemu_irq_handler").gen_var("handler"), Type.lookup("int").gen_var("n") ]), Pointer( Function(name="device_realize pointee", args=[ Type.lookup("DeviceState").gen_var("dev", pointer=True), Pointer(Type.lookup("Error")).gen_var("errp", pointer=True) ]), name="DeviceRealize", ), Function(name="qdev_create"), Function(name="qdev_init_nofail"), Function(name="qdev_get_child_bus"), Structure(name="BusState"), Function(name="qdev_get_gpio_in"), Function(name="qdev_get_gpio_in_named"), Function(name="qdev_connect_gpio_out"), Function(name="qdev_connect_gpio_out_named") ]).add_reference(osdep_fake_type) Header.lookup("migration/vmstate.h").add_types([ Type("VMStateDescription", False), Type("VMStateField", False), Function("vmstate_register_ram_global") ]).add_reference(osdep_fake_type) Header.lookup("qemu/module.h").add_reference(osdep_fake_type) Header.lookup("hw/pci/pci.h").add_types([ Type("PCIDevice", False), Type("PCIDeviceClass", False), Function("pci_create_multifunction"), Type("PCIIOMMUFunc"), ]).add_reference(osdep_fake_type) Header.lookup("hw/pci/msi.h").add_types([ Function(name="msi_uninit", ret_type=Type.lookup("void"), args=[Type.lookup("PCIDevice").gen_var("dev", pointer=True)]) ]).add_reference(osdep_fake_type) Header.lookup("hw/pci/pci_bus.h").add_types([ Type("PCIBus", incomplete=True) ]).add_references([Type.lookup("PCIIOMMUFunc"), osdep_fake_type]) Header.lookup("hw/pci/pci_host.h").add_reference(osdep_fake_type) Header.lookup("qemu/typedefs.h").add_types([ # BlockBackend is defined in internal block_int.h. Its fields may not # be accessed outside internal code. Methods from block-backend.h must # be used instead. Structure("BlockBackend"), Structure("I2CBus") # the structure is defined in .c file ]).add_reference(osdep_fake_type) Header.lookup("qemu/bswap.h").add_types( [Function("bswap64"), Function("bswap32"), Function("bswap16")]).add_reference(osdep_fake_type) Header.lookup("hw/ide/internal.h").add_types( [Structure("IDEDMA")]).add_reference(osdep_fake_type) Header.lookup("hw/ide/ahci.h").add_references( [Type.lookup("IDEDMA"), osdep_fake_type]) Header.lookup("hw/block/flash.h").add_references( [Type.lookup("VMStateDescription"), osdep_fake_type]) Header.lookup("qemu/timer.h").add_types([ Structure("QEMUTimer"), Function("timer_new_ns"), Function("timer_del"), Function("timer_free"), Type("QEMU_CLOCK_VIRTUAL") # It is enumeration entry... ]).add_references([osdep_fake_type]) Header.lookup("qemu/main-loop.h").add_types([ Function("IOCanReadHandler", ret_type=Type.lookup("int"), args=[Pointer(Type.lookup("void")).gen_var("opaque")]), Function("IOReadHandler", args=[ Pointer(Type.lookup("void")).gen_var("opaque"), Pointer(Type.lookup("uint8_t"), const=True).gen_var("buf"), Type.lookup("int").gen_var("size") ]) ]).add_references([osdep_fake_type]) if get_vp()["v2.8 chardev"]: chardev_types = [ Function("qemu_chr_fe_set_handlers"), Structure("CharBackend") ] else: chardev_types = [ Function("qemu_chr_add_handlers"), Structure("CharDriverState") ] Header.lookup(get_vp("header with IOEventHandler")).add_types([ Function("IOEventHandler", args=[ Pointer(Type.lookup("void")).gen_var("opaque"), Type.lookup("int").gen_var("event") ]) ] + chardev_types).add_references([osdep_fake_type]) Header.lookup("sysemu/block-backend.h").add_types([ Structure("BlockDevOps"), ]).add_references([osdep_fake_type]) Header.lookup("hw/isa/isa.h").add_types([Type("IsaDmaTransferHandler")]) if get_vp()["include/hw/isa/i8257.h have IsaDmaTransferHandler reference"]: Header.lookup(get_vp()["i8257.h path"]).add_references([ Type.lookup("IsaDmaTransferHandler"), Type.lookup("MemoryRegion") ]) Header.lookup("net/net.h").add_types([ Type("qemu_macaddr_default_if_unset"), Type("qemu_format_nic_info_str"), Type("qemu_new_nic"), Type("qemu_del_nic"), Type("qemu_get_queue"), Structure("NICConf"), Type("NICState"), Type("NetClientState"), Function("NetCanReceive", ret_type=Type.lookup("int"), args=[Pointer(Type.lookup("NetClientState")).gen_var("nc")]), Function("NetReceive", ret_type=Type.lookup("ssize_t"), args=[ Pointer(Type.lookup("NetClientState")).gen_var("nc"), Pointer(Type.lookup("const uint8_t")).gen_var("buf"), Type.lookup("size_t").gen_var("size") ]), Function("LinkStatusChanged", args=[Pointer(Type.lookup("NetClientState")).gen_var("nc")]), Function("NetCleanup", args=[Pointer(Type.lookup("NetClientState")).gen_var("nc")]), Structure( "NetClientInfo", fields=[ # "type" field type is enum NetClientDriver, but enum is not # supported by model Type.lookup("int").gen_var("type"), Type.lookup("size_t").gen_var("size"), Type.lookup("NetReceive").gen_var("receive"), Type.lookup("NetCanReceive").gen_var("can_receive"), Type.lookup("NetCleanup").gen_var("cleanup"), Type.lookup("LinkStatusChanged").gen_var("link_status_changed") # There are other fields but they are not needed. ]), Macro("NET_CLIENT_DRIVER_NIC") # This is an enum item actually. It # is defined in auto generated "qapi-types.h" which is not presented in # registry but is included by "net.h" indirectly. ]).add_references([osdep_fake_type]) Header.lookup("exec/helper-proto.h").add_type(Macro("HELPER_PROTO_H")) Header.lookup("disas/bfd.h").add_types([ Type("bfd_vma", False), Type("bfd_byte", False), Type("const bfd_tyte", False), Function("bfd_getl64", ret_type=Type.lookup("bfd_vma"), args=[ Pointer(Type.lookup("const bfd_tyte")).gen_var( "addr", pointer=True) ]), Function("bfd_getl32", ret_type=Type.lookup("bfd_vma"), args=[ Pointer(Type.lookup("const bfd_tyte")).gen_var( "addr", pointer=True) ]), Function("bfd_getb32", ret_type=Type.lookup("bfd_vma"), args=[ Pointer(Type.lookup("const bfd_tyte")).gen_var( "addr", pointer=True) ]), Function("bfd_getl16", ret_type=Type.lookup("bfd_vma"), args=[ Pointer(Type.lookup("const bfd_tyte")).gen_var( "addr", pointer=True) ]), Function("bfd_getb16", ret_type=Type.lookup("bfd_vma"), args=[ Pointer(Type.lookup("const bfd_tyte")).gen_var( "addr", pointer=True) ]) ]) Header.lookup("disas/disas.h").add_types([Function("lookup_symbol")]) Header.lookup("qemu/log.h").add_types([ Function("qemu_loglevel_mask"), Function("qemu_log_in_addr_range"), Function("qemu_log_lock"), Function("qemu_log_unlock"), Function("qemu_log") ]) Header.lookup("exec/log.h").add_types([Function("log_target_disas")])