rust-embedded / rust-embedded/riscv

Immediate operand support for CSR instructions?

Open
#393 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.1k
Forks
200
Avg merge
11d 2h
Merged PRs (30d)
2

Description

When I use riscv::register::mstatus::set_mie(); to enable global interrupts, the resulting assembly code is quite puzzling.

It does not use the csrsi instruction, but instead uses the csrs instruction.
The csrs instruction uses an additional register.

This causes two problems:

  1. Code bloat
  2. Toggling global interrupts becomes a non-atomic operation (which contradicts the RISC-V Privileges document)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the implementation of riscv::register::mstatus::set_mie() and inspect the assembly it generates. Determine how CSR writes select between register and immediate operands, then verify that enabling interrupts uses the atomic csrsi form without the extra register or code bloat.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.