Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jcRsu-00017a-4C for mharc-grub-devel@gnu.org; Sat, 23 May 2020 07:00:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcRss-00017U-NH for grub-devel@gnu.org; Sat, 23 May 2020 07:00:06 -0400 Received: from relay01.mx.bawue.net ([193.7.176.67]:34536 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 1jcRsr-0006wW-Ax for grub-devel@gnu.org; Sat, 23 May 2020 07:00:06 -0400 Received: from n-dimensional.de (p5b17584c.dip0.t-ipconnect.de [91.23.88.76]) (Authenticated sender: pdim@bawue.de) by smtp.bawue.net (Postfix) with ESMTPSA id B5A47224F5 for ; Sat, 23 May 2020 12:59:59 +0200 (CEST) Date: Sat, 23 May 2020 12:59:58 +0200 From: Hans Ulrich Niedermann To: grub-devel@gnu.org Subject: MB2 spec: Endianness weirdness in definition of terms Message-ID: <20200523125958.39e2c2c0@n-dimensional.de> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanner: SAV Dynamic Interface 2.6.0, Engine: 3.77.1, SAV: 5.75 (90A0ABD) 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/23 06:17:28 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 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: Sat, 23 May 2020 11:00:06 -0000 The MB2 spec "definition of terms used through the specification" defines terms like "must", "should", but also "u8", "u16", "u32", and "u64": > "u8" > The type of unsigned 8-bit data. > > "u16" > The type of unsigned 16-bit data. Because the target architecture > is little-endian, u16 is coded in little-endian. > > "u32" > The type of unsigned 32-bit data. Because the target architecture > is little-endian, u32 is coded in little-endian. > > "u64" > The type of unsigned 64-bit data. Because the target architecture > is little-endian, u64 is coded in little-endian. Does the sentence about the target architecture being LE, and thusly the integer value being LE as well still make sense in Multiboot2? To me this looks like a copy-and-paste error from the Multiboot1 specification. The description of the MB2 header layout says that the values in the OS image are in native endianness, not LE: > 3.1.1 The layout of Multiboot2 header > ------------------------------------- > > The layout of the Multiboot2 header must be as follows: > > Offset Type Field Name Note > 0 u32 magic required > 4 u32 architecture required > 8 u32 header_length required > 12 u32 checksum required > 16-XX tags required > > The fields 'magic', 'architecture', 'header_length' and 'checksum' > are defined in *note Header magic fields::, 'tags' are defined in > *note Header tags::. All fields are in native endianness. On > bi-endian platforms native-endianness means the endiannes OS image > starts in. And for the Boot Information, there appears to be no mention of endianness for the values the bootloader gives to the OS image. If we were to take the existing definitions of u16, u32, u64 seriously, the values the bootloader gives to the OS image would be in little endian, even if the OS image with the MB2 header is big endian. That appears to be somewhere between weird and wrong. If weird, it should be mentioned explicitly, and if wrong, it should be corrected. AFAICT, the u16, u32, u64 definitions should be corrected to state that those values are in native endianness (maybe unless specifically stated otherwise). I have to admit I have not checked whether the grub code actually stores values for the OS image in little endian regardless of native endianness. That would surprise me very much, though. Uli