162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# SPDX-License-Identifier: LGPL-2.1
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciif [ $# -ne 1 ] ; then
562306a36Sopenharmony_ci	arch_x86_header_dir=tools/arch/x86/include/asm/
662306a36Sopenharmony_cielse
762306a36Sopenharmony_ci	arch_x86_header_dir=$1
862306a36Sopenharmony_cifi
962306a36Sopenharmony_ci
1062306a36Sopenharmony_cix86_msr_index=${arch_x86_header_dir}/msr-index.h
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci# Support all later, with some hash table, for now chop off
1362306a36Sopenharmony_ci# Just the ones starting with 0x00000 so as to have a simple
1462306a36Sopenharmony_ci# array.
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ciprintf "static const char * const x86_MSRs[] = {\n"
1762306a36Sopenharmony_ciregex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x00000[[:xdigit:]]+)[[:space:]]*.*'
1862306a36Sopenharmony_cigrep -E $regex ${x86_msr_index} | grep -E -v 'MSR_(ATOM|P[46]|IA32_(TSC_DEADLINE|UCODE_REV)|IDT_FCR4)' | \
1962306a36Sopenharmony_ci	sed -r "s/$regex/\2 \1/g" | sort -n | \
2062306a36Sopenharmony_ci	xargs printf "\t[%s] = \"%s\",\n"
2162306a36Sopenharmony_ciprintf "};\n\n"
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci# Remove MSR_K6_WHCR, clashes with MSR_LSTAR
2462306a36Sopenharmony_ciregex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0xc0000[[:xdigit:]]+)[[:space:]]*.*'
2562306a36Sopenharmony_ciprintf "#define x86_64_specific_MSRs_offset "
2662306a36Sopenharmony_cigrep -E $regex ${x86_msr_index} | sed -r "s/$regex/\2/g" | sort -n | head -1
2762306a36Sopenharmony_ciprintf "static const char * const x86_64_specific_MSRs[] = {\n"
2862306a36Sopenharmony_cigrep -E $regex ${x86_msr_index} | \
2962306a36Sopenharmony_ci	sed -r "s/$regex/\2 \1/g" | grep -E -vw 'K6_WHCR' | sort -n | \
3062306a36Sopenharmony_ci	xargs printf "\t[%s - x86_64_specific_MSRs_offset] = \"%s\",\n"
3162306a36Sopenharmony_ciprintf "};\n\n"
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciregex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0xc0010[[:xdigit:]]+)[[:space:]]*.*'
3462306a36Sopenharmony_ciprintf "#define x86_AMD_V_KVM_MSRs_offset "
3562306a36Sopenharmony_cigrep -E $regex ${x86_msr_index} | sed -r "s/$regex/\2/g" | sort -n | head -1
3662306a36Sopenharmony_ciprintf "static const char * const x86_AMD_V_KVM_MSRs[] = {\n"
3762306a36Sopenharmony_cigrep -E $regex ${x86_msr_index} | \
3862306a36Sopenharmony_ci	sed -r "s/$regex/\2 \1/g" | sort -n | \
3962306a36Sopenharmony_ci	xargs printf "\t[%s - x86_AMD_V_KVM_MSRs_offset] = \"%s\",\n"
4062306a36Sopenharmony_ciprintf "};\n"
41