From patchwork Tue Aug 11 02:44:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 505848 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id F3009140326 for ; Tue, 11 Aug 2015 12:45:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=DgO2x+JR; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8CBFC4BAA8; Tue, 11 Aug 2015 04:45:28 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JIS-iJFO6b4C; Tue, 11 Aug 2015 04:45:28 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F410E4BAAE; Tue, 11 Aug 2015 04:45:12 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 51F074BA60 for ; Tue, 11 Aug 2015 04:45:02 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U3YPXVUTxUYl for ; Tue, 11 Aug 2015 04:45:02 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ig0-f172.google.com (mail-ig0-f172.google.com [209.85.213.172]) by theia.denx.de (Postfix) with ESMTPS id 5E5684BA5E for ; Tue, 11 Aug 2015 04:44:58 +0200 (CEST) Received: by igfj19 with SMTP id j19so63089931igf.1 for ; Mon, 10 Aug 2015 19:44:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=PIVjKnvTE0DW8f4iEJ4uNp1MFSI4wD6geJKgWJhZS6s=; b=DgO2x+JRh7EHgYUOHQ4FT48diYdi8ziyZUnp0kaoztBW2aFP04cdN+3JxtQJ6JE7cK esB/TYDBLOnggKNSMExHRak2TPZdHOIih0h+mKvnVBLx7+31SZsIDjOmhP+b+3Ln0Ech D/E5nf51E7ANZbbmkqUC+hZMoArDyrSzlRnQw8iCbA1YksTBxc9wR21Jqeprw2zFMjnw bhKK7ATvO8Jltn0fsGoLQeMt9qD9x8AnzprbOpC0n+9aBaPAG6lZmzSSceND6SoaeZSH 93x4CTOS1ZFGmksVQdmrnd5h53cKyFsUJcLbKZn3z625Bj//XouUVQH58pllIowZypFM zofQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PIVjKnvTE0DW8f4iEJ4uNp1MFSI4wD6geJKgWJhZS6s=; b=TaeQfbQ2/UB07vQIfdbnZ34VguQ4d8jyRzHYe2TSUrjO8vGtiGx7zpXtAAnUjDc1g0 dpH7k8B98ymzeUumdVEl0HVH6UHJZY/CV0za2c9s6FfdZwYrmfspkvCwaaOeMjuA5xhE 4Rr7iXZyD/A0Vk+PBPSBJt7+7ks8vlIq6LOYjRqb39KAsnGmUdX8WeCFIHDWEH5TR7zL 25wvUYu6dElCFjjPnXkeZlTQfk/KwUZT9+jACJyaQ8Ri/SddkttDD7U0Q9LjlYiQ6tMQ xQWhzbiNXE7+MCRsXiXTAmWCARMRCu0ojwB0hmuzFQbW4W04ygyYFr3Tki8pHoH/I6iw ztjQ== X-Gm-Message-State: ALoCoQm3b23wrhzE64LTzB5ADS0dYXl9vkolittHceSgRh5gSLWC9WwmFlvvT/732V7gpp9E7ktw X-Received: by 10.50.43.131 with SMTP id w3mr15858710igl.8.1439261097102; Mon, 10 Aug 2015 19:44:57 -0700 (PDT) Received: from kaki.bld.corp.google.com ([2620:0:1005:1100:b998:35c1:1ac2:cb22]) by smtp.gmail.com with ESMTPSA id m134sm592063ioe.42.2015.08.10.19.44.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 19:44:54 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 4CBB22218CB; Mon, 10 Aug 2015 20:44:54 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 10 Aug 2015 20:44:32 -0600 Message-Id: <1439261072-1341-6-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.5.0.rc2.392.g76e840b In-Reply-To: <1439261072-1341-1-git-send-email-sjg@chromium.org> References: <1439261072-1341-1-git-send-email-sjg@chromium.org> Cc: Graeme Russ Subject: [U-Boot] [PATCH v2 5/5] x86: Switch to using generic global_data setup X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" There is quite a bit of assembler code that can be removed if we use the generic global_data setup. Less arch-specific code makes it easier to add new features and maintain the start-up code. Drop the unneeded code and adjust the hooks in board_f.c to cope. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v2: - Don't rely on value of %edx from board_init_f_mem() arch/x86/cpu/cpu.c | 4 ++- arch/x86/cpu/start.S | 95 +++++++--------------------------------------------- common/board_f.c | 3 +- 3 files changed, 18 insertions(+), 84 deletions(-) diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c index 4f57145..1b76ca1 100644 --- a/arch/x86/cpu/cpu.c +++ b/arch/x86/cpu/cpu.c @@ -136,8 +136,10 @@ static void load_gdt(const u64 *boot_gdt, u16 num_entries) asm volatile("lgdtl %0\n" : : "m" (gdt)); } -void setup_gdt(gd_t *new_gd, u64 *gdt_addr) +void arch_setup_gd(gd_t *new_gd) { + u64 *gdt_addr; + gdt_addr = new_gd->arch.gdt; /* CS: code, read/execute, 4 GB, base 0 */ diff --git a/arch/x86/cpu/start.S b/arch/x86/cpu/start.S index 313fa3f..e94ddc4 100644 --- a/arch/x86/cpu/start.S +++ b/arch/x86/cpu/start.S @@ -104,8 +104,7 @@ car_init_ret: * * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE * MRC area - * global_data - * x86 global descriptor table + * global_data with x86 global descriptor table * early malloc area * stack * bottom-> CONFIG_SYS_CAR_ADDR @@ -120,13 +119,10 @@ car_init_ret: * and esi holds the HOB list address returned by the FSP. */ #endif - - /* Reserve space on stack for global data */ - subl $GENERATED_GBL_DATA_SIZE, %esp - - /* Align global data to 16-byte boundary */ - andl $0xfffffff0, %esp - post_code(POST_START_STACK) + /* Set up global data */ + mov %esp, %eax + call board_init_f_mem + mov %eax, %esp /* * Debug UART is available here although it may not be plumbed out @@ -137,56 +133,21 @@ car_init_ret: * call printch */ - /* Zero the global data since it won't happen later */ - xorl %eax, %eax - movl $GENERATED_GBL_DATA_SIZE, %ecx - movl %esp, %edi - rep stosb - + /* Get address of global_data */ + mov %fs:0, %edx #ifdef CONFIG_HAVE_FSP + /* Store the HOB list if we have one */ test %esi, %esi jz skip_hob - - /* Store HOB list */ - movl %esp, %edx - addl $GD_HOB_LIST, %edx - movl %esi, (%edx) + movl %esi, GD_HOB_LIST(%edx) skip_hob: #else /* Store table pointer */ - movl %esp, %edx - addl $GD_TABLE, %edx - movl %esi, (%edx) + movl %esi, GD_TABLE(%edx) #endif - - /* Setup first parameter to setup_gdt, pointer to global_data */ - movl %esp, %eax - - /* Reserve space for global descriptor table */ - subl $X86_GDT_SIZE, %esp - - /* Align temporary global descriptor table to 16-byte boundary */ - andl $0xfffffff0, %esp - movl %esp, %ecx - -#if defined(CONFIG_SYS_MALLOC_F_LEN) - /* Set up the pre-relocation malloc pool */ - subl $CONFIG_SYS_MALLOC_F_LEN, %esp - movl %eax, %edx - addl $GD_MALLOC_BASE, %edx - movl %esp, (%edx) -#endif - /* Store BIST into global_data */ - movl %eax, %edx - addl $GD_BIST, %edx - movl %ebp, (%edx) - - /* Set second parameter to setup_gdt() */ - movl %ecx, %edx - - /* Setup global descriptor table so gd->xyz works */ - call setup_gdt + /* Store BIST */ + movl %ebp, GD_BIST(%edx) /* Set parameter to board_init_f() to boot flags */ post_code(POST_START_DONE) @@ -213,37 +174,7 @@ board_init_f_r_trampoline: /* Stack grows down from top of SDRAM */ movl %eax, %esp - /* Reserve space on stack for global data */ - subl $GENERATED_GBL_DATA_SIZE, %esp - - /* Align global data to 16-byte boundary */ - andl $0xfffffff0, %esp - - /* Setup first parameter to memcpy() and setup_gdt() */ - movl %esp, %eax - - /* Setup second parameter to memcpy() */ - fs movl 0, %edx - - /* Set third parameter to memcpy() */ - movl $GENERATED_GBL_DATA_SIZE, %ecx - - /* Copy global data from CAR to SDRAM stack */ - call memcpy - - /* Reserve space for global descriptor table */ - subl $X86_GDT_SIZE, %esp - - /* Align global descriptor table to 16-byte boundary */ - andl $0xfffffff0, %esp - - /* Set second parameter to setup_gdt() */ - movl %esp, %edx - - /* Setup global descriptor table so gd->xyz works */ - call setup_gdt - - /* Set if we need to disable CAR */ + /* See if we need to disable CAR */ .weak car_uninit movl $car_uninit, %eax cmpl $0, %eax diff --git a/common/board_f.c b/common/board_f.c index 37b7bf5..c959774 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -715,6 +715,7 @@ static int jump_to_copy(void) * with the stack in SDRAM and Global Data in temporary memory * (CPU cache) */ + arch_setup_gd(gd->new_gd); board_init_f_r_trampoline(gd->start_addr_sp); #else relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr); @@ -1033,6 +1034,7 @@ __weak void arch_setup_gd(struct global_data *gd_ptr) { gd = gd_ptr; } +#endif /* !CONFIG_X86 */ ulong board_init_f_mem(ulong top) { @@ -1054,4 +1056,3 @@ ulong board_init_f_mem(ulong top) return top; } -#endif /* !CONFIG_X86 */