fpu.rs 671 B

1234567891011121314151617181920212223242526272829303132
  1. use core::arch::asm;
  2. use eonix_hal_traits::fpu::RawFpuState;
  3. #[derive(Clone, Copy)]
  4. #[repr(align(16))]
  5. pub struct FpuState([u8; 512]);
  6. impl RawFpuState for FpuState {
  7. fn new() -> Self {
  8. Self([0; 512])
  9. }
  10. fn save(&mut self) {
  11. unsafe {
  12. asm!(
  13. "fxsave ({0})",
  14. in(reg) &mut self.0,
  15. options(att_syntax, nostack, preserves_flags)
  16. )
  17. }
  18. }
  19. fn restore(&mut self) {
  20. unsafe {
  21. asm!(
  22. "fxrstor ({0})",
  23. in(reg) &mut self.0,
  24. options(att_syntax, nostack, preserves_flags)
  25. )
  26. }
  27. }
  28. }