Page MenuHomeFreeBSD

Various fixes for floating point on RISC-V.
ClosedPublic

Authored by jhb on Sep 12 2018, 10:01 PM.
Tags
None
Referenced Files
F83621135: D17141.id48244.diff
Sun, May 12, 7:27 PM
Unknown Object (File)
Sat, May 11, 7:32 AM
Unknown Object (File)
Sat, May 11, 5:27 AM
Unknown Object (File)
Fri, May 10, 8:03 PM
Unknown Object (File)
Dec 20 2023, 4:59 AM
Unknown Object (File)
Nov 11 2023, 3:38 PM
Unknown Object (File)
Nov 9 2023, 8:49 AM
Unknown Object (File)
Oct 10 2023, 2:38 PM
Subscribers

Details

Summary
  • Explicitly load an empty initial state into FP registers when taking the fault on the first FP instruction in a thread. Setting SSTATE.FS to INITIAL is just a marker to let context switch restore code know that it can load FP registers with zeroes instead of memory loads. It does not imply that the hardware will reset all registers to zero on first access. In addition, set the state to CLEAN instead of INITIAL after the first FP instruction. cpu_switch() doesn't do anything for INITIAL and only restores from the pcb if the state is CLEAN. We could perhaps change cpu_switch to call fpe_state_clear if the state was INITIAL and leave SSTATE.FS set to INITIAL instead of CLEAN after the first FP instruction. However, adding this complexity to cpu_switch() doesn't seem worth the supposed gain.
  • Only save the current FPU registers in fill_fpregs() if the request is made to save the current thread's registers. Previously if a debugger requested FP registers via ptrace() it was getting a copy of the debugger's FP registers rather than the debugee's.
  • Zero the entire FP register set structure returned for ptrace() if a thread hasn't used FP registers rather than leaking garbage in the fp_fcsr field.
  • If a debugger writes FP registers via ptrace(), always mark the pcb as having valid FP registers and set SSTATUS.FS_MASK to CLEAN so that the registers will be restored when the debugged thread resumes.
  • Be more explicit about clearing the SSTATUS.FS field before setting it to CLEAN on the first FP instruction trap.
Test Plan
  • use gdb on /bin/ls. It used to show non-zero values in 'info float' even though it wasn't using floating point.
  • use gdb on a test program using floating point variables. Previously the values in 'info float' did not match the actual values being used (e.g. single stepping and comparing the value of a FP reg in the debugger with the value just stored in memory by a floating point store instruction, or the values output via printf() vs the values in 'info float'.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable