cactus: Reorganize stack
Create a new section for the stacks inside of BSS. SPM zeroes the
memory in any region marked as BSS, so it isn't needed to do it here.
Note that now each region (text, rodata, data, bss) need to be aligned
to a page boundary so that they can be different regions in the resource
description.
Previously the memory to be used as stack was passed in the boot info
struct. Now this is not needed as the partition can define all regions
it wants to use.
Change-Id: If330e27b0b27dde93b6c9e63b7136d23bdc7dd9e
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/spm/cactus/aarch64/cactus_entrypoint.S b/spm/cactus/aarch64/cactus_entrypoint.S
index 46450e1..4323d0e 100644
--- a/spm/cactus/aarch64/cactus_entrypoint.S
+++ b/spm/cactus/aarch64/cactus_entrypoint.S
@@ -5,35 +5,24 @@
*/
#include <asm_macros.S>
-#include <secure_partition.h>
-#include <spm_svc.h>
-#include <xlat_tables_defs.h>
+#include <cactus_def.h>
+#include <platform_def.h>
.globl cactus_entrypoint
-func cactus_entrypoint
+.section .bss.stacks
+ .balign CACHE_WRITEBACK_GRANULE
+ .fill CACTUS_STACKS_SIZE
+stacks_end:
- /*
- * All the information needed to remap the memory of the Secure
- * Partition is in the buffer whose pointer is passed on X0 and size on
- * X1. If the size is 0, return with an error.
- */
- cmp x1, #0
- beq .return_error
+func cactus_entrypoint
/* Save the base address and size of the buffer. */
mov x20, x0
mov x21, x1
- adr x0, __BSS_START__
- adr x1, __BSS_END__
- sub x1, x1, x0
- bl zeromem16
-
/* Setup the stack pointer. */
- ldr x0, [x20, SP_BOOT_INFO_STACK_BASE_OFFSET]
- ldr x1, [x20, SP_BOOT_INFO_PCPU_STACK_SIZE_OFFSET]
- add x0, x0, x1
+ adr x0, stacks_end
mov sp, x0
/* And do the rest in C code */
@@ -41,13 +30,4 @@
mov x1, x21
b cactus_main
-.return_error:
- /* Tell SPM that the initialization failed. */
- mov_imm x0, SP_EVENT_COMPLETE_AARCH64
- mov x1, #-1
- svc #0
-
- /* Loop forever */
- b .
-
endfunc cactus_entrypoint
diff --git a/spm/cactus/cactus.h b/spm/cactus/cactus.h
index 966b154..94d214c 100644
--- a/spm/cactus/cactus.h
+++ b/spm/cactus/cactus.h
@@ -19,9 +19,9 @@
#define CACTUS_RODATA_START ((uintptr_t)&__RODATA_START__)
#define CACTUS_RODATA_END ((uintptr_t)&__RODATA_END__)
-extern uintptr_t __RWDATA_START__, __RWDATA_END__;
-#define CACTUS_RWDATA_START ((uintptr_t)&__RWDATA_START__)
-#define CACTUS_RWDATA_END ((uintptr_t)&__RWDATA_END__)
+extern uintptr_t __DATA_START__, __DATA_END__;
+#define CACTUS_DATA_START ((uintptr_t)&__DATA_START__)
+#define CACTUS_DATA_END ((uintptr_t)&__DATA_END__)
extern uintptr_t __BSS_START__, __BSS_END__;
#define CACTUS_BSS_START ((uintptr_t)&__BSS_START__)
diff --git a/spm/cactus/cactus.ld.S b/spm/cactus/cactus.ld.S
index b33f591..58553ac 100644
--- a/spm/cactus/cactus.ld.S
+++ b/spm/cactus/cactus.ld.S
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <cactus_def.h>
#include <platform_def.h>
#include <xlat_tables_defs.h>
@@ -33,20 +34,20 @@
__RODATA_END__ = .;
}
-
.data : {
. = ALIGN(PAGE_SIZE);
- __RWDATA_START__ = .;
+ __DATA_START__ = .;
*(.data*)
+ . = NEXT(PAGE_SIZE);
+ __DATA_END__ = .;
}
- .bss : {
- . = ALIGN(16);
+ .bss (NOLOAD) : {
+ . = ALIGN(PAGE_SIZE);
__BSS_START__ = .;
*(SORT_BY_ALIGNMENT(.bss*))
*(COMMON)
. = NEXT(PAGE_SIZE);
__BSS_END__ = .;
- __RWDATA_END__ = .;
}
}
diff --git a/spm/cactus/cactus_def.h b/spm/cactus/cactus_def.h
index 4983215..ef813d2 100644
--- a/spm/cactus/cactus_def.h
+++ b/spm/cactus/cactus_def.h
@@ -17,6 +17,9 @@
#define CACTUS_IMAGE_BASE ULL(0x80000000)
#define CACTUS_IMAGE_SIZE ULL(0x200000)
+/* Memory reserved for stacks */
+#define CACTUS_STACKS_SIZE ULL(0x1000)
+
/* Memory shared between EL3 and S-EL0 (64 KiB). */
#define CACTUS_SPM_BUF_BASE (CACTUS_IMAGE_BASE + CACTUS_IMAGE_SIZE)
#define CACTUS_SPM_BUF_SIZE ULL(0x10000)
diff --git a/spm/cactus/cactus_tests_memory_attributes.c b/spm/cactus/cactus_tests_memory_attributes.c
index 1a3072b..9b1e84a 100644
--- a/spm/cactus/cactus_tests_memory_attributes.c
+++ b/spm/cactus/cactus_tests_memory_attributes.c
@@ -156,7 +156,7 @@
announce_test_start(test_desc1);
attributes = mem_access_perm(SP_MEMORY_ATTRIBUTES_EXEC, SP_MEMORY_ATTRIBUTES_ACCESS_RW);
- ret = request_mem_attr_changes(CACTUS_RWDATA_START, 1, attributes);
+ ret = request_mem_attr_changes(cactus_tests_start, 1, attributes);
expect(ret, SPM_INVALID_PARAMETER);
announce_test_end(test_desc1);
@@ -164,7 +164,7 @@
announce_test_start(test_desc2);
attributes = mem_access_perm(SP_MEMORY_ATTRIBUTES_NON_EXEC, SP_MEMORY_ATTRIBUTES_ACCESS_RW);
- ret = request_mem_attr_changes(CACTUS_RWDATA_START, 0, attributes);
+ ret = request_mem_attr_changes(cactus_tests_start, 0, attributes);
expect(ret, SPM_INVALID_PARAMETER);
announce_test_end(test_desc2);