[PATCH 17/17] bsp/riscv: Add SMP startup synchronization

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jun 22 11:59:14 UTC 2018


Update #3433.
---
 bsps/riscv/riscv/start/start.S | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/bsps/riscv/riscv/start/start.S b/bsps/riscv/riscv/start/start.S
index 2794213307..af439dd5b9 100644
--- a/bsps/riscv/riscv/start/start.S
+++ b/bsps/riscv/riscv/start/start.S
@@ -44,7 +44,7 @@ PUBLIC(bsp_start_vector_table_begin)
 PUBLIC(bsp_start_vector_table_end)
 PUBLIC(_start)
 
-	.section	.bsp_start_text, "ax", @progbits
+	.section	.bsp_start_text, "wax", @progbits
 TYPE_FUNC(_start)
 SYM(_start):
 	/* Load global pointer */
@@ -55,7 +55,7 @@ SYM(_start):
 
 #ifdef RTEMS_SMP
 	csrr	s0, mhartid
-	bnez	s0, .Lloop_forever
+	bnez	s0, .Lwait_for_go
 #endif
 
 	/* load stack and frame pointers */
@@ -75,6 +75,13 @@ SYM(_start):
 	la	a2, bsp_section_bss_size
 	call	memset
 
+#ifdef RTEMS_SMP
+	/* Give go to secondary processors */
+	la	t0, .Lsecondary_processor_go
+	fence	iorw,ow
+	amoswap.w	zero, zero, 0(t0)
+#endif
+
 	/* Init FPU unit if it's there */
 	li	t0, MSTATUS_FS
 	csrs	mstatus, t0
@@ -82,8 +89,19 @@ SYM(_start):
 	j	boot_card
 
 #ifdef RTEMS_SMP
+	/* Wait for go issued by the boot processor (mhartid == 0) */
+.Lwait_for_go:
+	la	t0, .Lsecondary_processor_go
+.Lwait_for_go_again:
+	lw	t1, 0(t0)
+	fence	iorw, iorw
+	sext.w	t1, t1
+	bnez	t1, .Lwait_for_go_again
 .Lloop_forever:
 	j	.Lloop_forever
+
+.Lsecondary_processor_go:
+	.word	0xdeadbeef
 #endif
 
 	.align	4
-- 
2.13.7




More information about the devel mailing list