From: Graeme Russ Date: Sat, 5 Nov 2011 13:21:49 +1100 Subject: [U-Boot] [PATCH v0 5/7] x86: Ensure IDT and GDT remain 16-byte aligned post relocation In-Reply-To: <1320459711-20257-1-git-send-email-graeme.russ@gmail.com> References: <1320459711-20257-1-git-send-email-graeme.russ@gmail.com> Message-ID: <1320459711-20257-6-git-send-email-graeme.russ@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Some CPUs have strict alignment requirements for these tables Signed-off-by: Graeme Russ --- arch/x86/cpu/interrupts.c | 2 +- arch/x86/lib/board.c | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/x86/cpu/interrupts.c b/arch/x86/cpu/interrupts.c index c6e72ea..b501fed 100644 --- a/arch/x86/cpu/interrupts.c +++ b/arch/x86/cpu/interrupts.c @@ -172,7 +172,7 @@ struct desc_ptr { unsigned short segment; } __attribute__((packed)); -struct idt_entry idt[256]; +struct idt_entry idt[256] __attribute__((aligned(16))); struct desc_ptr idt_ptr; diff --git a/arch/x86/lib/board.c b/arch/x86/lib/board.c index 0938104..c5a0b71 100644 --- a/arch/x86/lib/board.c +++ b/arch/x86/lib/board.c @@ -180,19 +180,26 @@ gd_t *gd; static int calculate_relocation_address(void) { - void *text_start = &__text_start; - void *bss_end = &__bss_end; - void *dest_addr; + ulong text_start = (ulong)&__text_start; + ulong bss_end = (ulong)&__bss_end; + ulong dest_addr; ulong rel_offset; /* Calculate destination RAM Address and relocation offset */ - dest_addr = (void *)gd->ram_size; + dest_addr = gd->ram_size; dest_addr -= CONFIG_SYS_STACK_SIZE; dest_addr -= (bss_end - text_start); + + /* + * Round destination address down to 16-byte boundary to keep + * IDT and GDT 16-byte aligned + */ + dest_addr &= ~15; + rel_offset = dest_addr - text_start; gd->start_addr_sp = gd->ram_size; - gd->relocaddr = (ulong)dest_addr; + gd->relocaddr = dest_addr; gd->reloc_off = rel_offset; return 0; -- 1.7.5.2.317.g391b14