📄 smbios.c
字号:
p->header.type = 0; p->header.length = sizeof(struct smbios_type_0); p->header.handle = 0; p->vendor_str = 1; p->version_str = 2; p->starting_address_segment = 0xe800; p->release_date_str = 0; p->rom_size = 0; memset(p->characteristics, 0, 8); p->characteristics[7] = 0x08; /* BIOS characteristics not supported */ p->characteristics_extension_bytes[0] = 0; p->characteristics_extension_bytes[1] = 0; p->major_release = (uint8_t) xen_major_version; p->minor_release = (uint8_t) xen_minor_version; p->embedded_controller_major = 0xff; p->embedded_controller_minor = 0xff; start += sizeof(struct smbios_type_0); strcpy((char *)start, "Xen"); start += strlen("Xen") + 1; strcpy((char *)start, xen_version); start += strlen(xen_version) + 1; *((uint8_t *)start) = 0; return start + 1;}/* Type 1 -- System Information */static void *smbios_type_1_init(void *start, const char *xen_version, uint8_t uuid[16]){ char uuid_str[37]; struct smbios_type_1 *p = (struct smbios_type_1 *)start; p->header.type = 1; p->header.length = sizeof(struct smbios_type_1); p->header.handle = 0x100; p->manufacturer_str = 1; p->product_name_str = 2; p->version_str = 3; p->serial_number_str = 4; memcpy(p->uuid, uuid, 16); p->wake_up_type = 0x06; /* power switch */ p->sku_str = 0; p->family_str = 0; start += sizeof(struct smbios_type_1); strcpy((char *)start, "Xen"); start += strlen("Xen") + 1; strcpy((char *)start, "HVM domU"); start += strlen("HVM domU") + 1; strcpy((char *)start, xen_version); start += strlen(xen_version) + 1; uuid_to_string(uuid_str, uuid); strcpy((char *)start, uuid_str); start += strlen(uuid_str) + 1; *((uint8_t *)start) = 0; return start+1; }/* Type 3 -- System Enclosure */static void *smbios_type_3_init(void *start){ struct smbios_type_3 *p = (struct smbios_type_3 *)start; p->header.type = 3; p->header.length = sizeof(struct smbios_type_3); p->header.handle = 0x300; p->manufacturer_str = 1; p->type = 0x01; /* other */ p->version_str = 0; p->serial_number_str = 0; p->asset_tag_str = 0; p->boot_up_state = 0x03; /* safe */ p->power_supply_state = 0x03; /* safe */ p->thermal_state = 0x03; /* safe */ p->security_status = 0x02; /* unknown */ start += sizeof(struct smbios_type_3); strcpy((char *)start, "Xen"); start += strlen("Xen") + 1; *((uint8_t *)start) = 0; return start+1;}/* Type 4 -- Processor Information */static void *smbios_type_4_init(void *start, unsigned int cpu_number, char *cpu_manufacturer){ char buf[80]; struct smbios_type_4 *p = (struct smbios_type_4 *)start; uint32_t eax, ebx, ecx, edx; p->header.type = 4; p->header.length = sizeof(struct smbios_type_4); p->header.handle = 0x400 + cpu_number; p->socket_designation_str = 1; p->processor_type = 0x03; /* CPU */ p->processor_family = 0x01; /* other */ p->manufacturer_str = 2; cpuid(1, &eax, &ebx, &ecx, &edx); p->cpuid[0] = eax; p->cpuid[1] = edx; p->version_str = 0; p->voltage = 0; p->external_clock = 0; p->max_speed = 0; /* unknown */ p->current_speed = 0; /* unknown */ p->status = 0x41; /* socket populated, CPU enabled */ p->upgrade = 0x01; /* other */ start += sizeof(struct smbios_type_4); strncpy(buf, "CPU ", sizeof(buf)); if ( (sizeof(buf) - strlen("CPU ")) >= 3 ) itoa(buf + strlen("CPU "), cpu_number); strcpy((char *)start, buf); start += strlen(buf) + 1; strcpy((char *)start, cpu_manufacturer); start += strlen(cpu_manufacturer) + 1; *((uint8_t *)start) = 0; return start+1;}/* Type 16 -- Physical Memory Array */static void *smbios_type_16_init(void *start, uint32_t memsize){ struct smbios_type_16 *p = (struct smbios_type_16*)start; p->header.type = 16; p->header.handle = 0x1000; p->header.length = sizeof(struct smbios_type_16); p->location = 0x01; /* other */ p->use = 0x03; /* system memory */ p->error_correction = 0x01; /* other */ p->maximum_capacity = memsize * 1024; p->memory_error_information_handle = 0xfffe; /* none provided */ p->number_of_memory_devices = 1; start += sizeof(struct smbios_type_16); *((uint16_t *)start) = 0; return start + 2;}/* Type 17 -- Memory Device */static void *smbios_type_17_init(void *start, uint32_t memory_size_mb){ struct smbios_type_17 *p = (struct smbios_type_17 *)start; p->header.type = 17; p->header.length = sizeof(struct smbios_type_17); p->header.handle = 0x1100; p->physical_memory_array_handle = 0x1000; p->total_width = 64; p->data_width = 64; /* truncate memory_size_mb to 16 bits and clear most significant bit [indicates size in MB] */ p->size = (uint16_t) memory_size_mb & 0x7fff; p->form_factor = 0x09; /* DIMM */ p->device_set = 0; p->device_locator_str = 1; p->bank_locator_str = 0; p->memory_type = 0x07; /* RAM */ p->type_detail = 0; start += sizeof(struct smbios_type_17); strcpy((char *)start, "DIMM 1"); start += strlen("DIMM 1") + 1; *((uint8_t *)start) = 0; return start+1;}/* Type 19 -- Memory Array Mapped Address */static void *smbios_type_19_init(void *start, uint32_t memory_size_mb){ struct smbios_type_19 *p = (struct smbios_type_19 *)start; p->header.type = 19; p->header.length = sizeof(struct smbios_type_19); p->header.handle = 0x1300; p->starting_address = 0; p->ending_address = (memory_size_mb-1) * 1024; p->memory_array_handle = 0x1000; p->partition_width = 1; start += sizeof(struct smbios_type_19); *((uint16_t *)start) = 0; return start + 2;}/* Type 20 -- Memory Device Mapped Address */static void *smbios_type_20_init(void *start, uint32_t memory_size_mb){ struct smbios_type_20 *p = (struct smbios_type_20 *)start; p->header.type = 20; p->header.length = sizeof(struct smbios_type_20); p->header.handle = 0x1400; p->starting_address = 0; p->ending_address = (memory_size_mb-1)*1024; p->memory_device_handle = 0x1100; p->memory_array_mapped_address_handle = 0x1300; p->partition_row_position = 1; p->interleave_position = 0; p->interleaved_data_depth = 0; start += sizeof(struct smbios_type_20); *((uint16_t *)start) = 0; return start+2;}/* Type 32 -- System Boot Information */static void *smbios_type_32_init(void *start){ struct smbios_type_32 *p = (struct smbios_type_32 *)start; p->header.type = 32; p->header.length = sizeof(struct smbios_type_32); p->header.handle = 0x2000; memset(p->reserved, 0, 6); p->boot_status = 0; /* no errors detected */ start += sizeof(struct smbios_type_32); *((uint16_t *)start) = 0; return start+2;}/* Type 127 -- End of Table */static void *smbios_type_127_init(void *start){ struct smbios_type_127 *p = (struct smbios_type_127 *)start; p->header.type = 127; p->header.length = sizeof(struct smbios_type_127); p->header.handle = 0x7f00; start += sizeof(struct smbios_type_127); *((uint16_t *)start) = 0; return start + 2;}/* * Local variables: * mode: C * c-set-style: "BSD" * c-basic-offset: 4 * tab-width: 4 * indent-tabs-mode: nil * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -