Skip to content

Adding Flexible Return and Event Delivery (FRED) support, initial sketch - #623

Closed
Amir1453 wants to merge 0 commit into
rust-osdev:masterfrom
Amir1453:master
Closed

Amir1453 wants to merge 0 commit into
rust-osdev:masterfrom
Amir1453:master

Conversation

@Amir1453

Copy link
Copy Markdown
Contributor

Hello, and thank you for developing and maintaining this crate.

I recently had a need of using Flexible Return and Event Delivery (FRED), but the crate did not implement it. So here is a pull request, in case it might be considered.

Basically, FRED is a very recent CPU architecture change, and the first commercial CPUs came out around the beginning of this year I believe. Many (nearly all) major operating systems support it. It replaces IDT-based delivery and IRET with defined entry points, a consistent event frame, separate stack levels for nested events, and the ERETS and ERETU return instructions.

For the initial PR, I did not want to do any design choices myself, and I would like opinions from the maintainers on how to shape the API (if it looks good, or if some things need changes).

What is implemented in this PR:

  • CR4.FRED leaf for enabling FRED
  • Accessors for IA32_FRED_RSP0–3, IA32_FRED_STKLVLS, IA32_FRED_SSP0–3, and IA32_FRED_CONFIG
  • Types for stack levels, configuration values, and the FRED event frame

These are all very simple wrappers around the Intel FRED specification (rev 9.0). It does not provide a software entry point, handler dispatch, or wrappers for ERETS and ERETU.

Another important problem is adding tests. QEMU has FRED support through KVM, which is not helpful if the host computer does not have FRED. Bochs could be used however.

@Freax13 Freax13 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your contribution!

Another important problem is adding tests. QEMU has FRED support through KVM, which is not helpful if the host computer does not have FRED. Bochs could be used however.

I tested this PR on some hardware that supports FRED and it seems to be working.

Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/registers/model_specific.rs Resolved
Comment thread src/registers/model_specific.rs Resolved
Comment thread src/registers/model_specific.rs Resolved
Comment thread src/registers/model_specific.rs Resolved
Comment thread src/registers/model_specific.rs Resolved
Comment thread src/registers/model_specific.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/registers/model_specific.rs Resolved
Comment thread src/registers/model_specific.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
Comment thread src/structures/fred.rs Resolved
@Amir1453

Amir1453 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for your reviews, I pushed the changes requested on the last review.
I left the event vector as u8, and currently there are no tests in the PR.

@Freax13

Freax13 commented Nov 5, 2026

Copy link
Copy Markdown
Member

Whoops, I pushed the wrong changes to your branch and GitHub automatically closed the PR. And now that the PR is closed, I can no longer push changes to your branch to fix that mistake.

Could you reset your branch to Freax13@5419a84 and then re-open the PR?

I did not mean to close this PR, I just wanted to push one small fix before merging it.

This branch was successfully deployed

1 active deployment
crates_io_release — a8634a37 Deployed Oct 28, 2026 by Freax13 via Release #190
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.

2 participants