summaryrefslogtreecommitdiff
path: root/x86-bare-metal/multiboot/scripts/check_mbhdr.awk
diff options
context:
space:
mode:
Diffstat (limited to 'x86-bare-metal/multiboot/scripts/check_mbhdr.awk')
-rw-r--r--x86-bare-metal/multiboot/scripts/check_mbhdr.awk36
1 files changed, 36 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
+}