Skip to content

Add EL2 examples#131

Open
thejpster wants to merge 1 commit intorust-embedded:mainfrom
thejpster:fun-with-el2
Open

Add EL2 examples#131
thejpster wants to merge 1 commit intorust-embedded:mainfrom
thejpster:fun-with-el2

Conversation

@thejpster
Copy link
Copy Markdown
Contributor

@thejpster thejpster commented Feb 21, 2026

Adds another batch of examples which all run at EL2.

  • HVC calls at EL2 go into the SVC handler
  • Information about Data Aborts, Prefetch Aborts, Undefined Exceptions, etc, appear in the Hyp Syndrome Register, and not where EL1 expects to find them (DFSR, IFAR, etc)
  • You return from an IRQ, HVC, or whatever, with an eret, so a while new batch of assembly trampolines were required
  • A feature was added to aarch32-rt to enable these new EL2 trampolines. This feature also skips putting you into EL1 automatically.

@jonathanpallant jonathanpallant marked this pull request as draft March 5, 2026 10:17
@jonathanpallant

This comment was marked as outdated.

@jonathanpallant jonathanpallant changed the title Add EL2 examples (requires #127 and #119) Add EL2 examples (requires #127) Mar 8, 2026
@jonathanpallant
Copy link
Copy Markdown
Contributor

Squashed and rebased.

@jonathanpallant jonathanpallant marked this pull request as ready for review March 8, 2026 12:21
@jonathanpallant jonathanpallant changed the title Add EL2 examples (requires #127) Add EL2 examples Mar 20, 2026
Copy link
Copy Markdown

@wt wt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious. Could we use naked functions to make this a little less ugly?

@thejpster
Copy link
Copy Markdown
Contributor Author

I was curious. Could we use naked functions to make this a little less ugly?

Naked functions didn’t play nice with the interworking attribute. There was a bug and it only got fixed recently. But I guess it’s okay for the examples because they only build with a recent version of nightly.

* Adds more Hyp register details.
* A bunch of fixes to the docs
* Makes sure CI actually runs these and the SMP examples
@thejpster
Copy link
Copy Markdown
Contributor Author

I tried making some examples use naked functions, but the compiler added prologue threw off my careful counting of bytes when it comes to verifying where the exception was throw. So I don't think it makes it better.

@thejpster thejpster mentioned this pull request Mar 28, 2026
@wt
Copy link
Copy Markdown

wt commented Mar 29, 2026

Is this a bug in naked function support in the compiler?

@wt
Copy link
Copy Markdown

wt commented Mar 29, 2026

BTW, otherwise LGTM.

@thejpster
Copy link
Copy Markdown
Contributor Author

Is this a bug in naked function support in the compiler?

Ah, I was wrong. It's not the prologue (there isn't one). It's that naked functions with the instruction_set(arm::t32) attribute get marked as Arm functions in the symbol table, so the processor jumps to the function in the wrong mode. This was rust-lang/rust#151946, which is fixed if I move up to a new enough nightly version.

In this case I was testing the UDF trap as a naked function, and it did trap, but not because it hit a UDF instruction but instead because it hit a Thumb instruction in Arm mode. The trap handler didn't like the error that was reported.

TL;DR: Naked functions are OK if I use a newer nightly Rust. This is changed over in #111.

@thejpster
Copy link
Copy Markdown
Contributor Author

TFW PRs have been open so long you've forgotten about bugs, and the fact you already fixed them months ago, and debug them all over again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants