diff options
Diffstat (limited to 'x86-bare-metal/multiboot/scripts')
-rw-r--r-- | x86-bare-metal/multiboot/scripts/check_mbhdr.awk | 36 | ||||
-rw-r--r-- | x86-bare-metal/multiboot/scripts/check_sse.awk | 12 |
2 files changed, 48 insertions, 0 deletions
diff --git a/x86-bare-metal/multiboot/scripts/check_mbhdr.awk b/x86-bare-metal/multiboot/scripts/check_mbhdr.awk new file mode 100644 index 0000000..1471d69 --- /dev/null +++ b/x86-bare-metal/multiboot/scripts/check_mbhdr.awk @@ -0,0 +1,36 @@ +BEGIN { + # > xxd -d -e -c 4 IMG + # 00004096: 1badb002 .... + # + # Split at colon to easily extract file offset. + FS = ":" + + # An OS image must contain an additional header called Multiboot header, + # besides the headers of the format used by the OS image. The Multiboot + # header must be contained completely within the first 8192 bytes of the OS + # image, and must be longword (32-bit) aligned. In general, it should come + # as early as possible, and may be embedded in the beginning of the text + # segment after the real executable header. + # + # https://www.gnu.org/software/grub/manual/multiboot/multiboot.html + MBHDR_LIMIT = 8192; + MBHDR_ALIGN = 4; + + MBHDR_SIZE = 3 * 4; +} + +/1badb002/ { + print $0" off="$1 + + if ($1 > MBHDR_LIMIT - MBHDR_SIZE) { + print "FAIL: multiboot header must be in the first "$MBHDR_SIZE" bytes of the image!" + exit 1 + } + + if ($1 % MBHDR_ALIGN != 0) { + print "FAIL: multiboot header must be 32bit aligned!" + exit 1 + } + + exit 0 +} diff --git a/x86-bare-metal/multiboot/scripts/check_sse.awk b/x86-bare-metal/multiboot/scripts/check_sse.awk new file mode 100644 index 0000000..91fb389 --- /dev/null +++ b/x86-bare-metal/multiboot/scripts/check_sse.awk @@ -0,0 +1,12 @@ +# Utility to check the disassembly for sse instructions. This uses a +# simple heuristic by checking if there are any usaged of xmm, ymm or +# zmm register. +# +# We want to build our kernel w/o sse instruction, as those first need +# to be enabled in the cpus control register as well the sse state +# needs to be initialized. + +/[xyz]mm[0-9]/ { + print "FAIL: no sse insns allowed in binary, found: "$0 + exit 1 +} |