Registers

Struct Registers 

Source
#[repr(C)]
pub struct Registers { pub gprs: GeneralPurposeRegisters, error_code: u64, /* private fields */ }
Expand description

x86_64 Trap frame.

Fields§

§gprs: GeneralPurposeRegisters§error_code: u64

Implementations§

Source§

impl Registers

Source

pub fn new() -> Self

Creates a new register frame for a user thread.

This function initializes a Registers structure with default values for a new user-space thread.

§Returns
  • A Registers instance with default values for user-space execution.
§Example
let mut regs = Registers::new();
*regs.rip() = 0x400000; // Set entry point
*regs.rsp() = 0x7FFFFFFFE000; // Set user stack pointer
Source

pub fn rip(&mut self) -> &mut usize

Returns a mutable reference to the instruction pointer (RIP).

This function allows modifying the instruction pointer, which determines the next instruction the CPU will execute when the thread resumes.

§Returns
  • A mutable reference to the rip field in the interrupt stack frame.
§Example
let mut regs = Registers::new();
*regs.rip() = 0x400000; // Set the entry point
Source

pub fn rsp(&mut self) -> &mut usize

Returns a mutable reference to the stack pointer (RSP).

This function allows modifying the stack pointer, which should point to the top of the stack before execution.

§Returns
  • A mutable reference to the rsp field.
§Example
let mut regs = Registers::new();
*regs.rsp() = 0x7FFFFFFFE000; // Set the user stack pointer
Source

pub extern "C" fn launch(&self) -> !

Launch the frame.

Launches a thread by restoring its saved register state.

This function returns the never type (!), meaning that once executed, there is no way to return to the current execution context.

§Safety
  • The kernel must release all temporary resources such as locally allocated Box, [SpinLockGuard], or [InterruptGuard] before calling this function.
§Behavior
  1. Restores general-purpose registers from self.gprs.
  2. Enables interrupts.
  3. Transfers to saved execution state by executing iretq.
§Example Usage
let regs = Registers::new();
regs.launch(); // This function does not return
unreachable!() // Execution will never reach here

Trait Implementations§

Source§

impl Clone for Registers

Source§

fn clone(&self) -> Registers

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Registers

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Registers

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for Registers

Auto Trait Implementations§

§

impl Freeze for Registers

§

impl RefUnwindSafe for Registers

§

impl Send for Registers

§

impl Sync for Registers

§

impl Unpin for Registers

§

impl UnwindSafe for Registers

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.