There was a tricky bug that affected the spinlock that's used in kinit()
to prevent harts from initializing simultaneously. We used to run the BSS
zeroing code unconditionally, which in some cases ended up zeroing out
the spinlock variable after hart0 already set it to 1. Now let's run BSS
zero loop on one hart only, guarded by a bss_zero_loop_lock.
This commit also rewrites the spinlock in C, just to give the compiler a
hint to NOT decide to reorder instructions in some aggressive manner.
There was a tricky bug that affected the spinlock that's used in kinit() to prevent harts from initializing simultaneously. We used to run the BSS zeroing code unconditionally, which in some cases ended up zeroing out the spinlock variable after hart0 already set it to 1. Now let's run BSS zero loop on one hart only, guarded by a bss_zero_loop_lock.
This commit also rewrites the spinlock in C, just to give the compiler a hint to NOT decide to reorder instructions in some aggressive manner.
Tested by running a modified target:
in a loop:
and then verifying the log has an expected number of good lines: