aboutsummaryrefslogtreecommitdiff
path: root/debug/programs/entry.S
diff options
context:
space:
mode:
Diffstat (limited to 'debug/programs/entry.S')
-rwxr-xr-xdebug/programs/entry.S53
1 files changed, 44 insertions, 9 deletions
diff --git a/debug/programs/entry.S b/debug/programs/entry.S
index ff8ae30..a2ea955 100755
--- a/debug/programs/entry.S
+++ b/debug/programs/entry.S
@@ -1,9 +1,8 @@
-#ifndef ENTRY_S
-#define ENTRY_S
-
#include "encoding.h"
-#define STACK_SIZE 512
+// Enough stack to store every register in case a trap handler is executed,
+// plus 33 more values.
+#define STACK_SIZE (64 * XLEN / 8)
#if XLEN == 64
# define LREG ld
@@ -61,8 +60,15 @@ handle_reset:
la gp, __global_pointer$
.option pop
- # initialize stack pointer
- la sp, stack_top
+ # Initialize stack pointer.
+ # Give each hart STACK_SIZE of stack.
+ # Assume hart IDs are contiguous and start at 0.
+ csrr t0, CSR_MHARTID
+ addi t0, t0, 1
+ li t1, STACK_SIZE
+ mul t0, t0, t1
+ la sp, stack_bottom
+ add sp, sp, t0
# Clear all hardware triggers
li t0, ~0
@@ -73,8 +79,33 @@ handle_reset:
csrr t1, CSR_TSELECT
beq t0, t1, 1b
+#ifdef MULTICORE
+ csrr t0, CSR_MHARTID
+ bnez t0, wait_until_initialized
+#endif
+
+ la t0, __bss_start
+ la t1, __bss_end
+1:
+ bge t0, t1, 2f
+ sb zero, 0(t0)
+ addi t0, t0, 1
+ j 1b
+2:
+#ifdef MULTICORE
+ la t0, initialized
+ li t1, 1
+ sw t1, 0(t0)
+
+wait_until_initialized: # Wait for hart 0 to perform initialization.
+ la t0, initialized
+1:
+ lw t1, 0(t0)
+ beqz t1, 1b
+#endif
+
# perform the rest of initialization in C
- j _init
+ j _init
trap_entry:
@@ -157,9 +188,13 @@ trap_entry:
addi sp, sp, 32*REGBYTES
mret
+loop_forever:
+ j loop_forever
+
// Fill the stack with data so we can see if it was overrun.
.align 4
stack_bottom:
- .fill STACK_SIZE/4, 4, 0x22446688
+ .fill NHARTS * STACK_SIZE/4, 4, 0x22446688
stack_top:
-#endif
+initialized:
+ .word 0