Skip to content

OpenOCD incorrectly attempts to write to read-only vector CSRs (vl, vtype, vlenb) #1305

@nadime15

Description

@nadime15

So I noticed on one of my debug sessions that OpenOCD is trying to write to read-only vector CSRs during register examination and vector register access, which violates (I think, I am not sure if a debugger can or should try writing read-only registers) the RISC-V Vector specification and causes my simulation to fail.

See the following logs:

Debug: 12742 14410 riscv-013.c:748 riscv013_execute_abstract_command(): [riscv.cpu] access register=0x320c22 {regno=0xc22 write=arg0 transfer=enabled postexec=disabled aarpostincrement=disabled aarsize=64bit}
Debug: 12743 14410 batch.c:291 riscv_batch_run_from(): [riscv.cpu] Running batch of scans [0, 3)
Debug: 12744 14410 batch.c:255 log_batch(): 41b w 00320c22 @17 -> + 00000000 @00; 3i
Debug: 12745 14410 batch.c:199 log_dmi_decoded(): write: command=0x320c22 {control=0x320c22}
Debug: 12746 14410 batch.c:255 log_batch(): 41b r 00000000 @16 -> + 00320c22 @17; 0i
Debug: 12747 14410 batch.c:255 log_batch(): 41b - 00000000 @00 -> + 1000080c @16; 0i

According to the RISC-V Vector spec, the following CSRs are read-only (URO):

vl (0xC20) - Vector length
vtype (0xC21) - Vector data type register
vlenb (0xC22) - VLEN/8 (vector register length in bytes)

These registers can only be modified via the vsetvl, vsetvli, or vsetivli instructions, not through direct CSR writes. I’m not familiar with the riscv-openocd code, but I don’t understand the rationale for changing vlenb at runtime, since it’s meant to represent a design-time constant (with VLEN being fixed).

Modifying vl/vtype should only occur through vsetvl and related instructions using the program buffer. This might be something that needs a fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions