Xilinx / Xilinx/embeddedsw

Where is r0 set in SVC handler?

Open
#355 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
1.2k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi there,

I noticed that in the SVCHandler you check r0 for the CPSR T bit.

https://github.com/Xilinx/embeddedsw/blob/45a18907084e77bb3a450a035d280130d7ff6e26/lib/bsp/standalone/src/arm/cortexa9/armcc/asm_vectors.s#L113-L119

Since control flow comes directly from the vector table, presumably r0 is still set to whatever the user code had stored in it, which could be some value other than CPSR.

Is it possible there is missing logic to load CPSR into r0 before line 115, e.g. ?

mrs r0, spsr
str r0, [sp, #-4]!

Could the current behavior cause issues if you had user code that sets r0 to an arbitrary value with the T bit set to a certain state, like this?

mov r0, #0x1234
svc #1

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 with lib/bsp/standalone/src/arm/cortexa9/armcc/asm_vectors.s around lines 113-119 and trace the vector-table path into SVCHandler. Check the ARM exception-state semantics for r0, CPSR, and SPSR, then reproduce the handler with an SVC caller that sets r0 to 0x1234. Done means confirming whether the T-bit check uses the intended state and documenting or correcting the behavior accordingly.

Written by the indexing model from the issue text.

Assessment

Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.