Create generic FF-A SP environment
Currently the boot method of SPs is SPMC specific. Each SPMC uses a
different binary format and different boot method. An SPMC agonistic
binary format and boot method has been defined, to remove
fragmentation. This is called "generic FF-A SP" here. All SPMC
implementations developed or contributed by Arm will add support for
this format. This change adds a new environment to capture the SPMC
independent binary format and boot method specifics.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I60b6a7103ee2a8188b0676a0ded5fe2a8bdf9cf9
diff --git a/environments/sp/entry.S b/environments/sp/entry.S
new file mode 100644
index 0000000..5fc0af3
--- /dev/null
+++ b/environments/sp/entry.S
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+ */
+
+#include <asm.S>
+
+#define R_AARCH64_RELATIVE 1027
+
+/**
+ * The following code is responsible for setting the initial value of the stack
+ * pointer and doing relocation on SP boot.
+ */
+FUNC __sp_entry, :
+ /* Use __stack_end linker symbol to set the load relative stack address. */
+ adrp x4, __stack_end
+ add x4, x4, :lo12:__stack_end
+ mov sp, x4
+
+ /*
+ * X4 = load address
+ * X5 = relocation table start
+ * X6 = relocation table end
+ */
+ adr x4, __sp_entry
+ adrp x5, __rela_start
+ add x5, x5, :lo12:__rela_start
+ adrp x6, __rela_end
+ add x6, x6, :lo12:__rela_end
+
+ /* Iterating through relocation entries */
+ cmp x5, x6
+ beq 2f
+
+ /*
+ * Loading relocation entry
+ * X7 = r_offset
+ * X8 = r_info
+ * X9 = r_addend
+ */
+1: ldp x7, x8, [x5], #16
+ ldr x9, [x5], #8
+
+ /* Only R_AARCH64_RELATIVE type is supported */
+ cmp w8, #R_AARCH64_RELATIVE
+ bne 3f /* Error */
+
+ /*
+ * Apply relative adjustment on address
+ * *(load_address + r_offset) = load_address + r_addend
+ */
+ add x9, x9, x4
+ str x9, [x7, x4]
+
+ cmp x5, x6
+ bne 1b
+
+2:
+ b _sp_entry
+
+3:
+ adr X0, error_invalid_relocation
+ bl trace_puts
+ b .
+
+ .align 8
+error_invalid_relocation:
+ .asciz "Only R_AARCH64_RELATIVE type relocation is supported"
+ .align 8
+END_FUNC __sp_entry