Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context Switching Primitives for AArch64 #744

Merged

Conversation

NathanRoyer
Copy link
Member

@NathanRoyer NathanRoyer commented Dec 16, 2022

This builds on #701.

This draft PR contains "regular" context switching primitives for aarch64:

  • the context_switch_regular function (same signature as on x86_64):
    • saves general pupose regs,
    • saves the current SP to an arbitrary address expected to be in x0 (= parameter _prev_stack_pointer),
    • installs the new one expected to be in x1 (= parameter _next_stack_pointer_value),
    • restores GP regs from the just-installed stack
    • jumps to address in x30
  • create_stack is a utility function which allocates a 16-page long initial task stack; you have to give it a function pointer (such as the address of landing_pad) which will be executed if you use context_switch_regular with that new stack.
  • landing_pad is a "task" function which simply re-triggers a context switch to return to the original main task.

These are used in main just before infinite looping as a demonstration.

NathanRoyer and others added 30 commits November 6, 2022 15:02
…plemented the creation and filling of a new page table; Implemented the switch to the new page table
Copy link
Member

@kevinaboos kevinaboos left a comment

Choose a reason for hiding this comment

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

Looks good!

Linux only saves/restores x18 - x29 on aarch64, which apparently corresponds to the set of callee-saved registers. If you change your implementation to that, does everything still work correctly?
https://github.com/torvalds/linux/blob/69b41ac87e4a664de78a395ff97166f0b2943210/arch/arm64/kernel/entry.S#L820

aarch64/kernel/context_switch_regular/src/lib.rs Outdated Show resolved Hide resolved
aarch64/kernel/context_switch_regular/Cargo.toml Outdated Show resolved Hide resolved
aarch64/kernel/context_switch_regular/src/lib.rs Outdated Show resolved Hide resolved
@kevinaboos kevinaboos marked this pull request as ready for review January 3, 2023 19:21
@NathanRoyer
Copy link
Member Author

If you change your implementation to that, does everything still work correctly?

Indeed, it still works correctly 👌

Copy link
Member

@kevinaboos kevinaboos left a comment

Choose a reason for hiding this comment

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

Only a few nitpicks left, other than that it looks excellent.

aarch64/kernel/context_switch_regular/src/lib.rs Outdated Show resolved Hide resolved
aarch64/kernel/context_switch_regular/src/lib.rs Outdated Show resolved Hide resolved
aarch64/kernel/nano_core/context_switch.rs Outdated Show resolved Hide resolved
aarch64/kernel/context_switch_regular/Cargo.toml Outdated Show resolved Hide resolved
@kevinaboos kevinaboos merged commit b88a23a into theseus-os:theseus_main Jan 11, 2023
github-actions bot pushed a commit to tsoutsman/Theseus that referenced this pull request Jan 11, 2023
* Currently this only saves callee-saved registers, which includes
  `x19` through `x30`, in which `x29` is the frame register and
  `x30` is the link register (holds the return address).

* We designate `x28` as the register used to pass a new task's ID
  to its entry point. b88a23a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants