From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jWuyn-0005Bv-RE for mharc-grub-devel@gnu.org; Fri, 08 May 2020 00:51:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWuym-00059W-IT for grub-devel@gnu.org; Fri, 08 May 2020 00:51:20 -0400 Received: from relay01.mx.bawue.net ([193.7.176.67]:48166 helo=smtp.bawue.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWuyl-0007we-4C for grub-devel@gnu.org; Fri, 08 May 2020 00:51:20 -0400 Received: from infty.fritz.box (p5B175D6A.dip0.t-ipconnect.de [91.23.93.106]) (Authenticated sender: pdim@bawue.de) by smtp.bawue.net (Postfix) with ESMTPSA id 8F72F22270; Fri, 8 May 2020 06:51:14 +0200 (CEST) From: Hans Ulrich Niedermann To: grub-devel@gnu.org Cc: Hans Ulrich Niedermann Subject: [MULTIBOOT2 SPEC PATCH v3 4/4] multiboot2: fix example kernel header tag alignment Date: Fri, 8 May 2020 06:50:49 +0200 Message-Id: <20200508045049.397997-5-hun@n-dimensional.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508045049.397997-1-hun@n-dimensional.de> References: <20200508045049.397997-1-hun@n-dimensional.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanner: SAV Dynamic Interface 2.6.0, Engine: 3.77.1, SAV: 5.74 (5BCEF015) on relay01.mx.bawue.net using milter-sssp 0.1.0 X-Virus-Scan: Found to be clean. Received-SPF: pass client-ip=193.7.176.67; envelope-from=hun@n-dimensional.de; helo=smtp.bawue.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/08 00:50:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 May 2020 04:51:20 -0000 Properly align all Multiboot2 header tags to 8 byte boundaries as per the Multiboot2 specification. Note that the assembler directive ".align 8" is machine dependent: On i386, it means "align to 8 byte boundary". On mips, it means that the lower 8 bits of address must be zero, i.e. ".align 8" aligns to a 256 byte boundary! Therefore, this changes boot_mips.S to use ".balign 8" where it had mistakenly used ".align 8" before. The boot_i386.S file keeps using ".align 8". Note also that the Multiboot2 header termination tag (unfortunately unlabeled in the source) actually needs that extra alignment to an 8 byte boundary, as the preceding tag (framebuffer_tag_start) is 20 bytes long which is not a multiple of 8. You can add "-Wa,-adhlns=$(@:.o=.lst)" to kernel_CCASFLAGS to generate a listing file which shows the offsets of the labels in the boot_*.S files to verify the alignment issues. Note also that the "grub-file --is-x86-multiboot2" utility does not recognize the wrong alignment of the Multiboot2 header tags, as it only considers the beginning of the Multiboot2 header and completely ignores the Multiboot2 header tags. Signed-off-by: Hans Ulrich Niedermann diff --git a/doc/boot_i386.S b/doc/boot_i386.S index 9ab016612..1418afe1a 100644 --- a/doc/boot_i386.S +++ b/doc/boot_i386.S @@ -56,6 +56,7 @@ multiboot_header: /* checksum */ .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header)) #ifndef __ELF__ + .align 8 address_tag_start: .short MULTIBOOT_HEADER_TAG_ADDRESS .short MULTIBOOT_HEADER_TAG_OPTIONAL @@ -69,6 +70,7 @@ address_tag_start: /* bss_end_addr */ .long _end address_tag_end: + .align 8 entry_address_tag_start: .short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS .short MULTIBOOT_HEADER_TAG_OPTIONAL @@ -77,6 +79,7 @@ entry_address_tag_start: .long multiboot_entry entry_address_tag_end: #endif /* __ELF__ */ + .align 8 framebuffer_tag_start: .short MULTIBOOT_HEADER_TAG_FRAMEBUFFER .short MULTIBOOT_HEADER_TAG_OPTIONAL @@ -85,10 +88,12 @@ framebuffer_tag_start: .long 768 .long 32 framebuffer_tag_end: + .align 8 .short MULTIBOOT_HEADER_TAG_END .short 0 .long 8 multiboot_header_end: + multiboot_entry: /* Initialize the stack pointer. */ movl $(stack + STACK_SIZE), %esp diff --git a/doc/boot_mips.S b/doc/boot_mips.S index ed604214d..e7bb7df9f 100644 --- a/doc/boot_mips.S +++ b/doc/boot_mips.S @@ -46,8 +46,8 @@ _start: nop /* Align 64 bits boundary. */ - .align 8 - + .balign 8 + /* Multiboot header. */ multiboot_header: /* magic */ @@ -59,7 +59,8 @@ multiboot_header: /* checksum */ .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_MIPS32 + (multiboot_header_end - multiboot_header)) #ifndef __ELF__ -address_tag_start: + .balign 8 +address_tag_start: .short MULTIBOOT_HEADER_TAG_ADDRESS .short MULTIBOOT_HEADER_TAG_OPTIONAL .long address_tag_end - address_tag_start @@ -72,7 +73,8 @@ address_tag_start: /* bss_end_addr */ .long _end address_tag_end: -entry_address_tag_start: + .balign 8 +entry_address_tag_start: .short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS .short MULTIBOOT_HEADER_TAG_OPTIONAL .long entry_address_tag_end - entry_address_tag_start @@ -80,7 +82,8 @@ entry_address_tag_start: .long multiboot_entry entry_address_tag_end: #endif /* __ELF__ */ -framebuffer_tag_start: + .balign 8 +framebuffer_tag_start: .short MULTIBOOT_HEADER_TAG_FRAMEBUFFER .short MULTIBOOT_HEADER_TAG_OPTIONAL .long framebuffer_tag_end - framebuffer_tag_start @@ -88,10 +91,12 @@ framebuffer_tag_start: .long 768 .long 32 framebuffer_tag_end: + .balign 8 .short MULTIBOOT_HEADER_TAG_END .short 0 .long 8 multiboot_header_end: + multiboot_entry: /* Initialize the stack pointer. */ lui $sp, %hi (stack + STACK_SIZE) @@ -114,6 +119,6 @@ loop: nop halt_message: .asciz "Halted." - .align 8 + .balign 8 /* Our stack area. */ .comm stack, STACK_SIZE -- 2.26.2