Commit 68145d4c7b3aa83d74c2dc904a39fab17cee1691

Authored by Andreas Bießmann
1 parent 4db896236c

common/board_f: factor out reserve_stacks

Introduce arch_reserve_stacks() to tailor gd->start_addr_sp and gd->irq_sp to
the architecture needs.

Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 6 changed files with 102 additions and 35 deletions Side-by-side Diff

arch/arm/lib/Makefile
... ... @@ -35,6 +35,7 @@
35 35 obj-$(CONFIG_SEMIHOSTING) += semihosting.o
36 36  
37 37 obj-y += sections.o
  38 +obj-y += stack.o
38 39 ifdef CONFIG_ARM64
39 40 obj-y += gic_64.o
40 41 obj-y += interrupts_64.o
arch/arm/lib/stack.c
  1 +/*
  2 + * Copyright (c) 2015 Andreas Bießmann <andreas.devel@googlemail.com>
  3 + *
  4 + * Copyright (c) 2011 The Chromium OS Authors.
  5 + * (C) Copyright 2002-2006
  6 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7 + *
  8 + * (C) Copyright 2002
  9 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  10 + * Marius Groeger <mgroeger@sysgo.de>
  11 + *
  12 + * SPDX-License-Identifier: GPL-2.0+
  13 + */
  14 +#include <common.h>
  15 +
  16 +DECLARE_GLOBAL_DATA_PTR;
  17 +
  18 +int arch_reserve_stacks(void)
  19 +{
  20 +#ifdef CONFIG_SPL_BUILD
  21 + gd->start_addr_sp -= 128; /* leave 32 words for abort-stack */
  22 + gd->irq_sp = gd->start_addr_sp;
  23 +#else
  24 + /* setup stack pointer for exceptions */
  25 + gd->irq_sp = gd->start_addr_sp;
  26 +
  27 +# if !defined(CONFIG_ARM64)
  28 +# ifdef CONFIG_USE_IRQ
  29 + gd->start_addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ);
  30 + debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
  31 + CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ, gd->start_addr_sp);
  32 +
  33 + /* 8-byte alignment for ARM ABI compliance */
  34 + gd->start_addr_sp &= ~0x07;
  35 +# endif
  36 + /* leave 3 words for abort-stack, plus 1 for alignment */
  37 + gd->start_addr_sp -= 16;
  38 +# endif
  39 +#endif
  40 +
  41 + return 0;
  42 +}
arch/powerpc/lib/Makefile
... ... @@ -40,6 +40,7 @@
40 40 obj-y += interrupts.o
41 41 obj-$(CONFIG_CMD_KGDB) += kgdb.o
42 42 obj-$(CONFIG_CMD_IDE) += ide.o
  43 +obj-y += stack.o
43 44 obj-y += time.o
44 45  
45 46 # Don't include the MPC5xxx special memcpy into the
arch/powerpc/lib/stack.c
  1 +/*
  2 + * Copyright (c) 2015 Andreas Bießmann <andreas.devel@googlemail.com>
  3 + *
  4 + * Copyright (c) 2011 The Chromium OS Authors.
  5 + * (C) Copyright 2002-2006
  6 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7 + *
  8 + * (C) Copyright 2002
  9 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  10 + * Marius Groeger <mgroeger@sysgo.de>
  11 + *
  12 + * SPDX-License-Identifier: GPL-2.0+
  13 + */
  14 +#include <common.h>
  15 +
  16 +DECLARE_GLOBAL_DATA_PTR;
  17 +
  18 +int arch_reserve_stacks(void)
  19 +{
  20 + ulong *s;
  21 +
  22 + /* setup stack pointer for exceptions */
  23 + gd->irq_sp = gd->start_addr_sp;
  24 +
  25 + /* Clear initial stack frame */
  26 + s = (ulong *)gd->start_addr_sp;
  27 + *s = 0; /* Terminate back chain */
  28 + *++s = 0; /* NULL return address */
  29 +
  30 + return 0;
  31 +}
... ... @@ -573,48 +573,22 @@
573 573 return 0;
574 574 }
575 575  
576   -static int reserve_stacks(void)
  576 +int arch_reserve_stacks(void)
577 577 {
578   -#ifdef CONFIG_SPL_BUILD
579   -# ifdef CONFIG_ARM
580   - gd->start_addr_sp -= 128; /* leave 32 words for abort-stack */
581   - gd->irq_sp = gd->start_addr_sp;
582   -# endif
583   -#else
584   -# ifdef CONFIG_PPC
585   - ulong *s;
586   -# endif
  578 + return 0;
  579 +}
587 580  
588   - /* setup stack pointer for exceptions */
  581 +static int reserve_stacks(void)
  582 +{
  583 + /* make stack pointer 16-byte aligned */
589 584 gd->start_addr_sp -= 16;
590 585 gd->start_addr_sp &= ~0xf;
591   - gd->irq_sp = gd->start_addr_sp;
592 586  
593 587 /*
594   - * Handle architecture-specific things here
595   - * TODO(sjg@chromium.org): Perhaps create arch_reserve_stack()
596   - * to handle this and put in arch/xxx/lib/stack.c
  588 + * let the architecture specific code tailor gd->start_addr_sp and
  589 + * gd->irq_sp
597 590 */
598   -# if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
599   -# ifdef CONFIG_USE_IRQ
600   - gd->start_addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ);
601   - debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
602   - CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ, gd->start_addr_sp);
603   -
604   - /* 8-byte alignment for ARM ABI compliance */
605   - gd->start_addr_sp &= ~0x07;
606   -# endif
607   - /* leave 3 words for abort-stack, plus 1 for alignment */
608   - gd->start_addr_sp -= 16;
609   -# elif defined(CONFIG_PPC)
610   - /* Clear initial stack frame */
611   - s = (ulong *) gd->start_addr_sp;
612   - *s = 0; /* Terminate back chain */
613   - *++s = 0; /* NULL return address */
614   -# endif /* Architecture specific code */
615   -
616   - return 0;
617   -#endif
  591 + return arch_reserve_stacks();
618 592 }
619 593  
620 594 static int display_new_sp(void)
... ... @@ -253,6 +253,24 @@
253 253 int arch_early_init_r(void);
254 254  
255 255 /**
  256 + * Reserve all necessary stacks
  257 + *
  258 + * This is used in generic board init sequence in common/board_f.c. Each
  259 + * architecture could provide this function to tailor the required stacks.
  260 + *
  261 + * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
  262 + * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
  263 + * require only this can leave it untouched.
  264 + *
  265 + * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
  266 + * positions of the stack. The stack pointer(s) will be set to this later.
  267 + * gd->irq_sp is only required, if the architecture needs it.
  268 + *
  269 + * @return 0 if no error
  270 + */
  271 +__weak int arch_reserve_stacks(void);
  272 +
  273 +/**
256 274 * Show the DRAM size in a board-specific way
257 275 *
258 276 * This is used by boards to display DRAM information in their own way.