#!/usr/bin/python3 import json import sys filefd = open(sys.argv[1]) jsonstr = filefd.read() filefd.close() j = json.loads(jsonstr) print("static struct tdx_global_metadata tgm") print("{") def find_field(name): for f in j['Fields']: if f['Field Name'] == name: return f return None fields = """ TDX_FEATURES0 BUILD_DATE BUILD_NUM MINOR_VERSION """.strip().split("\n") for fn in fields: f = find_field(fn) name = f['Field Name'] element_bytes = int(f['Element Size (Bytes)']) element_bits = element_bytes * 8 print("\tu%d %s;" % (element_bits, name)) print("}") print("static void read_gunk()") print("{") print("\tint ret = 0;") print("") for fn in fields: f = find_field(fn) print("\tret |= read_sys_metadata_field(%s, &tgm.%s);" % (f['Base FIELD_ID (Hex)'], f['Field Name'])) print("") print("\treturn ret;") print("}")