Page MenuHomeFreeBSD

RISC-V: fix global pointer assignment at boot

Authored by mhorne on Jan 11 2020, 11:52 PM.



As part of the RISC-V ABI, the gp register is expected to initialized
with the address of __global_pointer$ as early as possible. This allows
loads and stores from .sdata to be relaxed based on the value of gp. In
locore.S we do this initialization twice, once each for va and mpva.
However, in both cases the initialization is preceded by an la
instruction, which in theory could be relaxed by the linker.

Move the initialization of gp to be slightly earlier (before la
cpu_exception_handler), and add an additional gp initialization at the
very beginning of _start, before virtual memory is set up.

Reported by: jrtc27

Diff Detail

Lint OK
No Unit Test Coverage
Build Status
Buildable 28612
Build 26646: arc lint + arc unit

Event Timeline

mhorne created this revision.Jan 11 2020, 11:52 PM

Yep, this is what I was thinking of (with the lla fixed). Thanks!


This needs to be an lla.

jrtc27 added inline comments.Jan 11 2020, 11:56 PM

Maybe add the again, this time with the virtual address. comment to match the BSP case (and to make it clear that mpentry itself is inheriting the physical gp from _start)?

mhorne updated this revision to Diff 66636.Jan 12 2020, 12:03 AM

Use lla, not la. Use longer comment for mpva as well.

Ping. Are you happy with this?

jrtc27 accepted this revision.Jan 16 2020, 8:34 PM

Yes, looks good.

This revision is now accepted and ready to land.Jan 16 2020, 8:34 PM
This revision was automatically updated to reflect the committed changes.