#include <xenguest.h>
#include <xen-tools/common-macros.h>
+#include <xen/lib/x86/cpuid-autogen.h>
static uint32_t nr_features;
#define COL_ALIGN "24"
+static const char *const feature_names[] = INIT_FEATURE_VAL_TO_NAME;
+
static const char *const fs_names[] = {
[XEN_SYSCTL_cpu_featureset_raw] = "Raw",
[XEN_SYSCTL_cpu_featureset_host] = "Host",
{
unsigned i;
- if ( !strs )
- {
- printf(" ???");
- return;
- }
-
for ( i = 0; i < 32; ++i )
if ( leaf & (1u << i) )
{
{
unsigned int i;
+ /* If this trips, you probably need to extend leaf_info[] above. */
+ BUILD_BUG_ON(ARRAY_SIZE(leaf_info) != FEATURESET_NR_ENTRIES);
+ BUILD_BUG_ON(ARRAY_SIZE(feature_names) != FEATURESET_NR_ENTRIES * 32);
+
printf("%-"COL_ALIGN"s ", name);
for ( i = 0; i < length; ++i )
printf("%08x%c", features[i],
for ( i = 0; i < length && i < ARRAY_SIZE(leaf_info); ++i )
{
printf(" [%02u] %-"COL_ALIGN"s", i, leaf_info[i].name ?: "<UNKNOWN>");
- if ( leaf_info[i].name )
- dump_leaf(features[i], leaf_info[i].strs);
+ dump_leaf(features[i], &feature_names[i * 32]);
printf("\n");
}
}
state.output.write(
"""}
+""")
+
+ state.output.write(
+"""
+#define INIT_FEATURE_VAL_TO_NAME { \\
+""")
+
+ for name, bit in sorted(state.values.items()):
+ state.output.write(
+ ' [%s] = "%s",\\\n' % (bit, name)
+ )
+
+ # Add the other alias for 1d/e1d common bits. 64 is the difference
+ # between 1d and e1d.
+ if bit in state.common_1d:
+ state.output.write(
+ ' [%s] = "%s",\\\n' % (64 + bit, name)
+ )
+
+ # Pad to an exact multiple of FEATURESET_SIZE if necessary
+ pad_feat = state.nr_entries * 32 - 1
+ if not state.names.get(pad_feat):
+ state.output.write(
+ ' [%s] = NULL,\\\n' % (pad_feat, )
+ )
+
+ state.output.write(
+"""}
+
""")
for idx, text in enumerate(state.bitfields):