Skip to content

Commit

Permalink
Add FreeBSD support
Browse files Browse the repository at this point in the history
  • Loading branch information
ocochard committed May 10, 2024
1 parent 82538f7 commit 9f42d56
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions x86-64-level
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ read_input() {
if ${stdin}; then
data=$(< /dev/stdin)
else
data=$(< /proc/cpuinfo)
if [ -r /proc/cpuinfo ]; then
data=$(< /proc/cpuinfo)
elif [ -r /var/run/dmesg.boot ]; then
# FreeBSD
data=$(< /var/run/dmesg.boot)
else
echo >&2 "ERROR: Unsupported system"
exit 1
fi
fi
if [[ -z ${data} ]]; then
echo >&2 "ERROR: Input data is empty"
Expand All @@ -98,8 +106,19 @@ get_cpu_name() {
get_cpu_flags() {
local flags
flags=$(grep "^flags[[:space:]]*:" <<< "${data}" | head -n 1)
flags="${flags#*:}"
flags="${flags## }"
if [ -z "${flags}" ]; then
# FreeBSD
flags=$(grep "Features.*=" <<< "${data}" | sort | uniq | cut -d '<' -f 2 | cut -d '>' -f 1)
flags=$(paste -s -d ',' - <<< "${flags}")
flags=$(echo "${flags//MMX+/mmxext}")
flags=$(echo "${flags//LAHF/lahf_lm}")
flags=$(echo "${flags//./_}")
flags=$(echo "${flags//,/ }")
flags=$(echo "${flags@L}")
else
flags="${flags#*:}"
flags="${flags## }"
fi
if grep -v -q -E "^[[:lower:][:digit:]_ ]+$" <<< "${flags}"; then
echo >&2 "ERROR: Cannot reliably infer the CPU x86-64 level, because the format of the CPU flags comprise of other symbols than only lower-case letters, digits, and underscores: '${flags}'"
exit 1
Expand Down

0 comments on commit 9f42d56

Please sign in to comment.