From: Martin Aberg <mab...@gaisler.com>

Remember the initial stack pointer in start.S. It can later be used to
determine top of RAM.
---
 bsps/riscv/shared/start/bspgetworkarea-fromstack.c | 55 ++++++++++++++++++++++
 bsps/riscv/shared/start/start.S                    | 15 ++++++
 2 files changed, 70 insertions(+)
 create mode 100644 bsps/riscv/shared/start/bspgetworkarea-fromstack.c

diff --git a/bsps/riscv/shared/start/bspgetworkarea-fromstack.c 
b/bsps/riscv/shared/start/bspgetworkarea-fromstack.c
new file mode 100644
index 0000000..b8a915e
--- /dev/null
+++ b/bsps/riscv/shared/start/bspgetworkarea-fromstack.c
@@ -0,0 +1,55 @@
+/*
+ *  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.
+ */
+
+#include <bsp.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[];
+
+/* Set by BSP early start code. */
+extern uintptr_t bsp_sp_at_entry;
+
+static Memory_Area _Memory_Areas[ 1 ];
+
+static void bsp_memory_initialize( void )
+{
+  char *end;
+
+  /* top of RAM inidicated by initial stack pointer */
+  end = (char *) bsp_sp_at_entry;
+  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..0bb5ddb 100644
--- a/bsps/riscv/shared/start/start.S
+++ b/bsps/riscv/shared/start/start.S
@@ -59,6 +59,9 @@ SYM(_start):
        LADDR   t0, _RISCV_Exception_handler
        csrw    mtvec, t0
 
+       /* Save stack pointer so it can mark end of work area later on */
+       mv      t3, sp
+
        /* Load stack pointer and branch to secondary processor start if 
necessary */
 #ifdef RTEMS_SMP
        LADDR   sp, _ISR_Stack_area_begin
@@ -74,6 +77,9 @@ SYM(_start):
        LADDR   sp, _ISR_Stack_area_end
 #endif
 
+       LADDR   t0, bsp_sp_at_entry
+       SREG    t3, 0(t0)
+
 #ifdef BSP_START_COPY_FDT_FROM_U_BOOT
        mv      a0, a1
        call    bsp_fdt_copy
@@ -145,3 +151,12 @@ SYM(_start):
 #endif
 
 #endif /* RTEMS_SMP */
+
+       .section        .data, "aw"
+       .align  3
+
+       .globl  bsp_sp_at_entry
+       .type   bsp_sp_at_entry, @object
+       .size   bsp_sp_at_entry, 8
+bsp_sp_at_entry:
+       .dword  0
-- 
2.7.4

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to