feat: architecture helpers to set gp registers

Added functions to 'aarch64' and 'fake' architectures to safely change
values of general purpose registers within "arch_regs" structure.

Change-Id: I44342cec9b24d118148ee1612f7645cddbd3b14a
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/inc/hf/arch/cpu.h b/inc/hf/arch/cpu.h
index 0400133..135b222 100644
--- a/inc/hf/arch/cpu.h
+++ b/inc/hf/arch/cpu.h
@@ -35,6 +35,18 @@
 void arch_regs_set_pc_arg(struct arch_regs *r, ipaddr_t pc, uintreg_t arg);
 
 /**
+ * Verifies the `gp_reg_num` complies with the number of registers available in
+ * the architecture.
+ */
+bool arch_regs_reg_num_valid(const uint32_t gp_reg_num);
+
+/**
+ * Sets the value of a general purpose register.
+ */
+void arch_regs_set_gp_reg(struct arch_regs *r, uintreg_t value,
+			  const uint32_t gp_reg_num);
+
+/**
  * Updates the register holding the return value of a function.
  *
  * This function must only be called on an arch_regs that is known not be in use
diff --git a/src/arch/aarch64/hypervisor/cpu.c b/src/arch/aarch64/hypervisor/cpu.c
index 57cd8c5..05f422e 100644
--- a/src/arch/aarch64/hypervisor/cpu.c
+++ b/src/arch/aarch64/hypervisor/cpu.c
@@ -150,6 +150,18 @@
 	r->r[0] = arg;
 }
 
+bool arch_regs_reg_num_valid(const unsigned int gp_reg_num)
+{
+	return gp_reg_num < NUM_GP_REGS;
+}
+
+void arch_regs_set_gp_reg(struct arch_regs *r, const uintreg_t value,
+			  const unsigned int gp_reg_num)
+{
+	assert(arch_regs_reg_num_valid(gp_reg_num));
+	r->r[gp_reg_num] = value;
+}
+
 void arch_regs_set_retval(struct arch_regs *r, struct ffa_value v)
 {
 	r->r[0] = v.func;
diff --git a/src/arch/fake/hypervisor/cpu.c b/src/arch/fake/hypervisor/cpu.c
index cc35dd7..244bc5e 100644
--- a/src/arch/fake/hypervisor/cpu.c
+++ b/src/arch/fake/hypervisor/cpu.c
@@ -34,6 +34,20 @@
 	r->arg[0] = arg;
 }
 
+bool arch_regs_reg_num_valid(const unsigned int gp_reg_num)
+{
+	(void)gp_reg_num;
+	return false;
+}
+
+void arch_regs_set_gp_reg(struct arch_regs *r, uintreg_t value,
+			  const unsigned int gp_reg_num)
+{
+	(void)r;
+	(void)value;
+	(void)gp_reg_num;
+}
+
 void arch_regs_set_retval(struct arch_regs *r, struct ffa_value v)
 {
 	r->arg[0] = v.func;