sifive / freedom-metal

Bare Metal Compatibility Library for the Freedom Platform
Other
152 stars 47 forks source link

Vector unit fails to initialize for Zve* targets #429

Open nick-knight opened 2 years ago

nick-knight commented 2 years ago

The following code fails to execute when using the Zve* (embedded vector) extensions, because they don't set misa.V:

https://github.com/sifive/freedom-metal/blob/e21891cad8365b21a961444adb3d40b2aab39e93/gloss/crt0.S#L255-L268

(This code should continue to work for the V extension.)

Unfortunately, the RISC-V standard discovery mechanism hasn’t been finalized yet. In the meanwhile, @aswaterman has suggested a workaround that can be used in this case: 1) Unconditionally initialize mstatus.VS to Dirty. This is safe on any processor. 2) Read back mstatus.VS and see if it’s set to Off. If so, there is no vector unit, and you should skip initialization.

This works for both V and Zve*.

paul-walmsley-sifive commented 2 years ago

Looks like we need to expand the test

ifdef __riscv_v

to be something like

if defined(__riscv_v) || defined(__risc_zve64f)

The expectation is that the compiler needs to define the __riscv_zve64f macro. @issuehsu , do you know if the compiler will set this one?

nick-knight commented 2 years ago

@paul-walmsley-sifive The preprocessor macro is one part of the problem. We're solving that problem here: https://github.com/riscv-non-isa/riscv-c-api-doc/pull/22

The bigger problem is misa.V. I sketched a workaround for that above.