1693d3458SArnaldo Carvalho de Melo#!/bin/sh 2693d3458SArnaldo Carvalho de Melo# SPDX-License-Identifier: LGPL-2.1 3693d3458SArnaldo Carvalho de Melo 4693d3458SArnaldo Carvalho de Meloif [ $# -ne 1 ] ; then 5693d3458SArnaldo Carvalho de Melo arch_x86_header_dir=tools/arch/x86/include/asm/ 6693d3458SArnaldo Carvalho de Meloelse 7693d3458SArnaldo Carvalho de Melo arch_x86_header_dir=$1 8693d3458SArnaldo Carvalho de Melofi 9693d3458SArnaldo Carvalho de Melo 10693d3458SArnaldo Carvalho de Melox86_msr_index=${arch_x86_header_dir}/msr-index.h 11693d3458SArnaldo Carvalho de Melo 12693d3458SArnaldo Carvalho de Melo# Support all later, with some hash table, for now chop off 13693d3458SArnaldo Carvalho de Melo# Just the ones starting with 0x00000 so as to have a simple 14693d3458SArnaldo Carvalho de Melo# array. 15693d3458SArnaldo Carvalho de Melo 16*1fc88e5aSIan Rogersprintf "static const char * const x86_MSRs[] = {\n" 17693d3458SArnaldo Carvalho de Meloregex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x00000[[:xdigit:]]+)[[:space:]]*.*' 18818448e9STiezhu Yanggrep -E $regex ${x86_msr_index} | grep -E -v 'MSR_(ATOM|P[46]|IA32_(TSC_DEADLINE|UCODE_REV)|IDT_FCR4)' | \ 19693d3458SArnaldo Carvalho de Melo sed -r "s/$regex/\2 \1/g" | sort -n | \ 20693d3458SArnaldo Carvalho de Melo xargs printf "\t[%s] = \"%s\",\n" 21693d3458SArnaldo Carvalho de Meloprintf "};\n\n" 22693d3458SArnaldo Carvalho de Melo 23693d3458SArnaldo Carvalho de Melo# Remove MSR_K6_WHCR, clashes with MSR_LSTAR 24693d3458SArnaldo Carvalho de Meloregex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0xc0000[[:xdigit:]]+)[[:space:]]*.*' 25693d3458SArnaldo Carvalho de Meloprintf "#define x86_64_specific_MSRs_offset " 26818448e9STiezhu Yanggrep -E $regex ${x86_msr_index} | sed -r "s/$regex/\2/g" | sort -n | head -1 27*1fc88e5aSIan Rogersprintf "static const char * const x86_64_specific_MSRs[] = {\n" 28818448e9STiezhu Yanggrep -E $regex ${x86_msr_index} | \ 29818448e9STiezhu Yang sed -r "s/$regex/\2 \1/g" | grep -E -vw 'K6_WHCR' | sort -n | \ 30693d3458SArnaldo Carvalho de Melo xargs printf "\t[%s - x86_64_specific_MSRs_offset] = \"%s\",\n" 31693d3458SArnaldo Carvalho de Meloprintf "};\n\n" 32693d3458SArnaldo Carvalho de Melo 33693d3458SArnaldo Carvalho de Meloregex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0xc0010[[:xdigit:]]+)[[:space:]]*.*' 34693d3458SArnaldo Carvalho de Meloprintf "#define x86_AMD_V_KVM_MSRs_offset " 35818448e9STiezhu Yanggrep -E $regex ${x86_msr_index} | sed -r "s/$regex/\2/g" | sort -n | head -1 36*1fc88e5aSIan Rogersprintf "static const char * const x86_AMD_V_KVM_MSRs[] = {\n" 37818448e9STiezhu Yanggrep -E $regex ${x86_msr_index} | \ 38693d3458SArnaldo Carvalho de Melo sed -r "s/$regex/\2 \1/g" | sort -n | \ 39693d3458SArnaldo Carvalho de Melo xargs printf "\t[%s - x86_AMD_V_KVM_MSRs_offset] = \"%s\",\n" 40693d3458SArnaldo Carvalho de Meloprintf "};\n" 41