+.option push
+.option norelax
+ la gp, __global_pointer$
+.option pop
+
+ # 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
+1:
+ addi t0, t0, 1
+ csrw CSR_TSELECT, t0
+ csrw CSR_TDATA1, zero
+ csrr t1, CSR_TSELECT
+ beq t0, t1, 1b
+
+#ifdef MULTICORE
+ csrr t0, CSR_MHARTID
+ bnez t0, wait_until_initialized
+#endif