Modifying the stack (multitasking) using x86_64 crate
Posted: Fri May 15, 2026 1:32 pm
Is anyone using the x86_64 crate for 64-bit osdev in rust?
It provides a nice layer on top of the IDT, which I'm using but, for-the-life-of-me, I can't see how to implement multitasking using the API.
I have a timer interrupt working by setting up the x2apic and then setting the interrupt handler:
```
idt[InterruptIndex::Timer as u8].set_handler_fn(timer_interrupt_handler);
```
But that assumes that timer_interrupt_handler looks like:
```
pub extern "x86-interrupt" fn timer_interrupt_handler(
stack_frame: InterruptStackFrame)
```
Which provides me the values I want for the current task (eg. cs:rip, rflags, ss:rsp) but it doesn't allow me to modify them (and the abstraction has modified the stack in a non-determinant way, so I don't think I can easily just modify in place).
It *seems* like the API has made provisions for modifying these values:
https://docs.rs/x86_64/latest/x86_64/st ... hod.as_mut
But that can't be called because the API enforces that the frame is immutable.
I feel like I'm missing something.
I could just write everything natively, but I'd prefer to use the abstractions in the crate if I can.
Thanks,
Jeff
It provides a nice layer on top of the IDT, which I'm using but, for-the-life-of-me, I can't see how to implement multitasking using the API.
I have a timer interrupt working by setting up the x2apic and then setting the interrupt handler:
```
idt[InterruptIndex::Timer as u8].set_handler_fn(timer_interrupt_handler);
```
But that assumes that timer_interrupt_handler looks like:
```
pub extern "x86-interrupt" fn timer_interrupt_handler(
stack_frame: InterruptStackFrame)
```
Which provides me the values I want for the current task (eg. cs:rip, rflags, ss:rsp) but it doesn't allow me to modify them (and the abstraction has modified the stack in a non-determinant way, so I don't think I can easily just modify in place).
It *seems* like the API has made provisions for modifying these values:
https://docs.rs/x86_64/latest/x86_64/st ... hod.as_mut
But that can't be called because the API enforces that the frame is immutable.
I feel like I'm missing something.
I could just write everything natively, but I'd prefer to use the abstractions in the crate if I can.
Thanks,
Jeff