From patchwork Thu Jun 9 20:30:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 9167885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF668607DA for ; Thu, 9 Jun 2016 20:34:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B329A28047 for ; Thu, 9 Jun 2016 20:34:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A80492833D; Thu, 9 Jun 2016 20:34:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 35CB02835D for ; Thu, 9 Jun 2016 20:34:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bB6cn-0004VI-Fy; Thu, 09 Jun 2016 20:32:21 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bB6cm-0004UC-7o for xen-devel@lists.xenproject.org; Thu, 09 Jun 2016 20:32:20 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id B8/0F-30266-352D9575; Thu, 09 Jun 2016 20:32:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsXSO6nOVTfoUmS 4QU+jtcX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmrG+/RNLQStPxaSGPUwNjF85uxg5OYQEWpkk Nn9O6WLkArK/Mkrs6j3KBuFsYJQ41/6dGcKZyCix4/IfFpAWNgEdiYtfHrKD2CICZhLPZjYwg hQxC2xilJi5bR4rSEJYIFdix47FzCA2i4CqxM1NP8AaeAXcJXbffAdmSwgoSnQ/m8AGYnMKeE gcPXyFCeImd4mXL/8wQ9QYSpx+uI1xAiPfAkaGVYzqxalFZalFukZ6SUWZ6RkluYmZObqGBmZ 6uanFxYnpqTmJScV6yfm5mxiBocIABDsYl/11OsQoycGkJMpbfyQyXIgvKT+lMiOxOCO+qDQn tfgQowwHh5IE770LQDnBotT01Iq0zBxg0MKkJTh4lER4HS4CpXmLCxJzizPTIVKnGBWlxHkNQ BICIImM0jy4NlikXGKUlRLmZQQ6RIinILUoN7MEVf4VozgHo5IwryDIFJ7MvBK46a+AFjMBLV 5+JBxkcUkiQkqqgdHj1Pv1C2fM19t1PkYrt+vbk3edT9fsjXif/4fFl3+fq7v97G+uxl1Jt7O mLQz5eXyG58JNz7lzG0LvB0aXJwb/n3HWXMu1qD3eTvXJ5abE/DMmVe+32P7lyebMj5bf9CK6 /9kNpZ+Z8xTu3Pl+R0/5zxyJuEdasrPzWzazz7u0mW2LyftKTS0lluKMREMt5qLiRAAssciRj wIAAA== X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1465504336!18228536!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3889 invoked from network); 9 Jun 2016 20:32:18 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-5.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 9 Jun 2016 20:32:18 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u59KW6Pu024781 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 9 Jun 2016 20:32:06 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u59KW5kH000573 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 9 Jun 2016 20:32:06 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u59KW3dU030204; Thu, 9 Jun 2016 20:32:04 GMT Received: from olila.local.net-space.pl (/10.175.235.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 09 Jun 2016 13:32:02 -0700 From: Daniel Kiper To: grub-devel@gnu.org, xen-devel@lists.xenproject.org Date: Thu, 9 Jun 2016 22:30:42 +0200 Message-Id: <1465504244-17175-9-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1465504244-17175-1-git-send-email-daniel.kiper@oracle.com> References: <1465504244-17175-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: jgross@suse.com, eric.snowberg@oracle.com, arvidjaar@gmail.com, andrew.cooper3@citrix.com, seth.goldberg@oracle.com, phcoder@gmail.com Subject: [Xen-devel] [MULTIBOOT2 DOC PATCH 08/10] multiboot2: Add C structure alignment and padding consideration section X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Daniel Kiper --- doc/multiboot.texi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/multiboot.texi b/doc/multiboot.texi index c81b2ea..bf02a1b 100644 --- a/doc/multiboot.texi +++ b/doc/multiboot.texi @@ -1384,6 +1384,7 @@ document, but are included for prospective operating system and boot loader writers. @menu +* C structure alignment and padding consideration:: * Notes on PC:: * BIOS device mapping techniques:: * Example OS code:: @@ -1391,6 +1392,22 @@ loader writers. @end menu +@node C structure alignment and padding consideration +@section C structure alignment and padding consideration + +Many C compilers try to optimize memory accesses aligning structure +members properly. Usually they reach the goal by adding some padding. +This is very useful thing in general. However, if you try to mix assembler +with C or use C to implement structure low level access this behavior +may lead, at least, to quite surprising results. Hence, compiler should +be instructed to not optimize such accesses. Usually it is done by special +attribute added to structure definition, e.g. GCC compatible sources use +@samp{__attribute__ ((__packed__))} for this purpose. However, this is not +required if it is known that its members are properly aligned and compiler +does not do any optimization. Very good example of this is shown below in +@file{multiboot2.h} file. + + @node Notes on PC @section Notes on PC