Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
  • FPC Source FPC Source
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 1,278
    • Issues 1,278
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 59
    • Merge requests 59
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • FPC
  • FPCFPC
  • FPC SourceFPC Source
  • Issues
  • #39737
Closed
Open
Issue created May 27, 2022 by kupferstecher@kupferstecher

RISC-V riscv32 embedded - Return command in interrupts

The issue occurs on a risc-v 32bit microcontroller, namely the CH32V307 from WCH, that I currently try to add to fpc.

Functions/procedures are returned with the assembler command "JALR" and fpc also uses this command for interrupts, but there it should be the "MRET" command instead. I'm not sure if this a special case for this microcontroller model. The command is mentioned in the risc-v specification in "Volume II: Privileged Architecture". It seems interrupts automatically change the mode from user to machine mode which has to do with memory/register protection, and MRET switches the mode back while returning. For testing I added the "MRET" in inline assembler at the end of the interrupt handler and it works. But then the stackframe and pushed registers have to be cleaned up manually in inline assembler as well, and that of course is not suitable in 'productive code'. Perhaps it could be added in procedures marked with the "interrupt;" procedure directive.

Forum thread: https://forum.lazarus.freepascal.org/index.php/topic,59466.0.html

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking