limine/common/gensyms.sh

50 lines
992 B
Bash
Raw Normal View History

2022-01-21 04:24:36 +03:00
#! /bin/sh
2021-02-25 03:24:54 +03:00
set -e
2022-02-01 10:04:55 +03:00
LC_ALL=C
export LC_ALL
2022-01-21 04:24:36 +03:00
TMP0=$(mktemp)
2021-08-07 08:26:34 +03:00
cat >"$TMP0" <<EOF
#! /bin/sh
set -e
set -o pipefail 2>/dev/null
EOF
chmod +x "$TMP0"
"$TMP0" && set -o pipefail
rm "$TMP0"
2021-02-25 03:24:54 +03:00
TMP1=$(mktemp)
TMP2=$(mktemp)
TMP3=$(mktemp)
TMP4=$(mktemp)
2022-02-01 10:04:55 +03:00
"$LIMINE_OBJDUMP" -t "$1" | ( "$SED" '/[[:<:]]d[[:>:]]/d' 2>/dev/null || "$SED" '/\bd\b/d' ) | sort > "$TMP1"
2022-04-20 05:00:00 +03:00
"$GREP" "$4" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
"$GREP" "$4" < "$TMP1" | "$AWK" 'NF{ print $NF }' > "$TMP3"
2021-02-25 03:24:54 +03:00
2022-02-01 10:04:55 +03:00
echo "section .$2_map" > "$TMP4"
echo "global $2_map" >> "$TMP4"
echo "$2_map:" >> "$TMP4"
2021-02-25 03:24:54 +03:00
2022-02-01 10:04:55 +03:00
if [ "$3" = "32" ]; then
paste -d'$' "$TMP2" "$TMP3" | "$SED" 's/^/dd 0x/g;s/$/", 0/g;s/\$/\
2021-07-26 19:27:05 +03:00
db "/g' >> "$TMP4"
2021-04-08 02:15:35 +03:00
echo "dd 0xffffffff" >> "$TMP4"
2022-02-01 10:04:55 +03:00
nasm -f elf32 "$TMP4" -o $2.map.o
elif [ "$3" = "64" ]; then
paste -d'$' "$TMP2" "$TMP3" | "$SED" 's/^/dq 0x/g;s/$/", 0/g;s/\$/\
2021-07-26 19:27:05 +03:00
db "/g' >> "$TMP4"
2021-04-08 02:15:35 +03:00
echo "dq 0xffffffffffffffff" >> "$TMP4"
2022-02-01 10:04:55 +03:00
nasm -f elf64 "$TMP4" -o $2.map.o
2021-04-08 02:15:35 +03:00
fi
2021-02-25 03:24:54 +03:00
rm "$TMP1" "$TMP2" "$TMP3" "$TMP4"