From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] Fix board init code to use a valid C runtime environment
Date: Thu, 12 Nov 2015 08:17:03 +0100 [thread overview]
Message-ID: <20151112081703.66022f2d@lilith> (raw)
In-Reply-To: <56442AC0.2030306@wytron.com.tw>
Hello Thomas,
On Thu, 12 Nov 2015 13:59:28 +0800, Thomas Chou <thomas@wytron.com.tw>
wrote:
> Hi Albert,
>
> On 2015?11?11? 02:30, Albert ARIBAUD wrote:
> > board_init_f_mem() alters the C runtime environment's
> > stack it ls actually already using. This is not a valid
> > C runtime environment.
> >
> > Split board_init_f_mem into C functions which do not
> > alter their own stack and therefore run in a valid C
> > runtime environment.
> >
> > Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> > ---
> > For NIOS2, this patch hopefully contains all manual
> > fixes by Thomas.
> >
> > Changes in v2:
> > - Fix all checkpatch issues
> > - Fix board_init_f_malloc prototype mismatch
> > - Fix board_init_[f_]xxx typo in NIOS2
> > - Fix aarch64 asm 'sub' syntax error
> >
> > arch/arc/lib/start.S | 20 +++++++++++++---
> > arch/arm/lib/crt0.S | 10 ++++++--
> > arch/arm/lib/crt0_64.S | 10 ++++++--
> > arch/microblaze/cpu/start.S | 4 ++--
> > arch/nios2/cpu/start.S | 17 ++++++++++++--
> > arch/powerpc/cpu/ppc4xx/start.S | 18 ++++++++++----
> > arch/x86/cpu/start.S | 10 ++++++--
> > arch/x86/lib/fsp/fsp_common.c | 4 ++--
> > common/init/board_init.c | 31 ++++++++++++++----------
> > include/common.h | 52 +++++++++++++++++++++++++----------------
> > 10 files changed, 125 insertions(+), 51 deletions(-)
> >
>
> Additional fixes,
> ------------------------------------------------------------------------
> diff --git a/common/init/board_init.c b/common/init/board_init.c
> index 8839a4a..703e6d8 100644
> --- a/common/init/board_init.c
> +++ b/common/init/board_init.c
> @@ -46,6 +46,7 @@ void board_init_f_gd(struct global_data *gd_ptr)
> for (ptr = (int *)gd_ptr; ptr < (int *)(gd_ptr + 1); )
> *ptr++ = 0;
> #endif
> + arch_setup_gd(gd_ptr);
Correct -- in ARM (Thumb-1 at least) we cannot use arch_setup_gd() so
we set GD (in r9) from within arch/arm/lib/crt0.S, but for NIOS2 it
might (and apparently does) work. Where is GD stored in NIOS2?
> }
>
> ulong board_init_f_malloc_size(void)
> --------------------------------------------------------------------------
> diff --git a/arch/nios2/cpu/start.S b/arch/nios2/cpu/start.S
> index c163ce1..0adff46 100644
> --- a/arch/nios2/cpu/start.S
> +++ b/arch/nios2/cpu/start.S
> @@ -110,7 +110,7 @@ _reloc:
> movhi r2, %hi(board_init_f_gd_size at h)
> ori r2, r2, %lo(board_init_f_gd_size at h)
> callr r2
> - sub sp, sp, r4
> + sub sp, sp, r2
Sorry, didn't know / realize the NIOS2 ABI has r2 iass the function
value return register, not r4.
> mov r4, sp
> movhi r2, %hi(board_init_f_gd at h)
> ori r2, r2, %lo(board_init_f_gd at h)
> @@ -119,16 +119,12 @@ _reloc:
> movhi r2, %hi(board_init_f_malloc_size at h)
> ori r2, r2, %lo(board_init_f_malloc_size at h)
> callr r2
> - sub sp, sp, r4
> + sub sp, sp, r2
Ditto.
> mov r4, sp
> movhi r2, %hi(board_init_f_malloc at h)
> ori r2, r2, %lo(board_init_f_malloc at h)
> callr r2
>
> - /* Update stack- and frame-pointers */
> - mov sp, r2
> - mov fp, sp
> -
Oops.
> /* Call board_init_f -- never returns */
> mov r4, r0
> movhi r2, %hi(board_init_f at h)
> ----------------------------------------------------------------------------
> Otherwise,
>
> Tested-by: Thomas Chou <thomas@wytron.com.tw>
> Acked-by: Thomas Chou <thomas@wytron.com.tw>
>
> Thanks.
Thanks to you; Will send a v3 to account for your and Simon's comments.
> Best regards,
> Thomas
Amicalement,
--
Albert.
next prev parent reply other threads:[~2015-11-12 7:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-10 18:30 [U-Boot] [PATCH v2] Fix board init code to use a valid C runtime environment Albert ARIBAUD
2015-11-11 8:52 ` Albert ARIBAUD
2015-11-12 5:59 ` Thomas Chou
2015-11-12 7:17 ` Albert ARIBAUD [this message]
2015-11-12 8:28 ` Thomas Chou
2015-11-12 10:23 ` Albert ARIBAUD
2015-11-13 6:41 ` Albert ARIBAUD
2015-11-13 8:20 ` Thomas Chou
2015-11-13 9:08 ` Bin Meng
2015-11-13 12:22 ` Albert ARIBAUD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151112081703.66022f2d@lilith \
--to=albert.u.boot@aribaud.net \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox