[PATCH 3/4 v2] bsp/riscv: work area size based on stack pointer
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Feb 16 06:41:25 UTC 2021
On 12/02/2021 09:50, Daniel Hellstrom wrote:
> From: Martin Aberg <maberg at gaisler.com>
>
> Remember the initial stack pointer in start.S. It can later be used to
> determine top of RAM.
> ---
> bsps/riscv/include/bsp/start.h | 65 ++++++++++++++++++++++
> bsps/riscv/shared/start/bspgetworkarea-fromstack.c | 53 ++++++++++++++++++
> bsps/riscv/shared/start/start.S | 25 +++++++++
> 3 files changed, 143 insertions(+)
> create mode 100644 bsps/riscv/include/bsp/start.h
> create mode 100644 bsps/riscv/shared/start/bspgetworkarea-fromstack.c
>
> diff --git a/bsps/riscv/include/bsp/start.h b/bsps/riscv/include/bsp/start.h
> new file mode 100644
> index 0000000..6c9d57d
> --- /dev/null
> +++ b/bsps/riscv/include/bsp/start.h
> @@ -0,0 +1,65 @@
> +/**
> + * @file
> + *
> + * @ingroup RTEMSBSPsRISCVSharedStart
> + *
> + * @brief RISC-V start definitions.
> + */
> +
> +/*
> + * Copyright (c) 2021 Cobham Gaisler AB.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + * notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + * notice, this list of conditions and the following disclaimer in the
> + * documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#ifndef LIBBSP_RISCV_SHARED_START_H
> +#define LIBBSP_RISCV_SHARED_START_H
> +
> +/**
> + * @defgroup RTEMSBSPsRISCVSharedStart Start Support
> + *
> + * @ingroup RTEMSBSPsRISCVShared
> + *
> + * @brief Start support.
> + *
> + * @{
> + */
> +
> +#include <stdint.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/*
> + * This variable is initialized by the first CPU entering the BSP start code.
> + * The value is the stack pointer at entry.
> + */
> +extern uintptr_t riscv_start_stack_pointer;
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +/** @} */
> +
> +#endif /* LIBBSP_RISCV_SHARED_START_H */
> diff --git a/bsps/riscv/shared/start/bspgetworkarea-fromstack.c b/bsps/riscv/shared/start/bspgetworkarea-fromstack.c
> new file mode 100644
> index 0000000..6885a77
> --- /dev/null
> +++ b/bsps/riscv/shared/start/bspgetworkarea-fromstack.c
> @@ -0,0 +1,53 @@
> +/*
> + * This set of routines are the BSP specific initialization
> + * support routines.
> + *
> + * COPYRIGHT (c) 1989-2020.
> + * On-Line Applications Research Corporation (OAR),
> + * Cobham Gaisler AB.
> + *
> + * The license and distribution terms for this file may be
> + * found in the file LICENSE in this distribution or at
> + * http://www.rtems.org/license/LICENSE.
> + */
Could we please use a BSD-2-Clause license for this. The comment is
probably all which was copied from somewhere else. The riscv target is a
new target. It would be good if we are able to use BSD-2-Clause at least
for new stuff.
> +
> +#include <bsp.h>
> +#include <bsp/start.h>
> +#include <bsp/bootcard.h>
> +
> +#include <rtems/sysinit.h>
> +
> +/*
> + * These are provided by the linkcmds for ALL of the BSPs which use this file.
> + */
> +extern char WorkAreaBase[];
> +extern char RamEnd[];
> +
> +static Memory_Area _Memory_Areas[ 1 ];
> +
> +static void bsp_memory_initialize( void )
> +{
> + char *end;
> +
> + /* top of RAM inidicated by initial stack pointer */
> + end = (char *) riscv_start_stack_pointer;
> + if (end == 0) {
> + /* fall back to linker symbol if not set */
> + end = RamEnd;
> + }
> + _Memory_Initialize( &_Memory_Areas[ 0 ], WorkAreaBase, end );
> +}
> +
> +RTEMS_SYSINIT_ITEM(
> + bsp_memory_initialize,
> + RTEMS_SYSINIT_MEMORY,
> + RTEMS_SYSINIT_ORDER_MIDDLE
> +);
> +
> +static const Memory_Information _Memory_Information =
> + MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
> +
> +const Memory_Information *_Memory_Get( void )
> +{
> + return &_Memory_Information;
> +}
> diff --git a/bsps/riscv/shared/start/start.S b/bsps/riscv/shared/start/start.S
> index 04a62a2..6f40279 100644
> --- a/bsps/riscv/shared/start/start.S
> +++ b/bsps/riscv/shared/start/start.S
> @@ -35,6 +35,16 @@
> #include <bsp/linker-symbols.h>
> #include <bspopts.h>
>
> +#if __riscv_xlen == 32
> +#define PTR_ALIGN 2
> +#define PTR_SIZE 4
> +#define PTR_VALUE .word
> +#elif __riscv_xlen == 64
> +#define PTR_ALIGN 3
> +#define PTR_SIZE 8
> +#define PTR_VALUE .dword
> +#endif
This should move to:
cpukit/score/cpu/riscv/include/rtems/asm.h
--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber at embedded-brains.de
phone: +49-89-18 94 741 - 16
fax: +49-89-18 94 741 - 08
Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
More information about the devel
mailing list