Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 839689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:30:22+00:00 2026-05-15T05:30:22+00:00

Where in Linux would you look to find out what registers are saved on

  • 0

Where in Linux would you look to find out what registers are saved on a context switch? I’m wondering, for example, if it is safe to use FP or vector registers in kernel-mode driver code (mostly interested in x86-64 and ARM, but I’m hoping for an architecture-independent answer).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:30:23+00:00Added an answer on May 15, 2026 at 5:30 am

    Since no one seems to have answered this, let me venture.

    Take a look at the _math_restore_cpu and __unlazy_fpu methods.

    You can find them here:

    • http://www.cs.fsu.edu/~baker/devices/lxr/http/ident?i=math_state_restore
    • http://www.cs.fsu.edu/~baker/devices/lxr/http/ident?i=__unlazy_fpu

    The x86 like processors have separate instructions for saving (fnsave) and restore (frstor) FPU state and so it looks like the OS is burdened with saving/restoring them.

    I presume unless the FPU unit has been used by the usermode process, linux context switch will not save it for you.

    So you need to do it yourself (in your driver) to be sure. You can use kernel_fpu_begin/end to do it in your driver, but is generally not a good idea.

    • http://www.cs.fsu.edu/~baker/devices/lxr/http/ident?i=kernel_fpu_begin
    • http://www.cs.fsu.edu/~baker/devices/lxr/http/ident?i=kernel_fpu_end

    Why it is not a good idea? From Linus himself: http://lkml.indiana.edu/hypermail/linux/kernel/0405.3/1620.html

    Quoted:

    You can do it “safely” on x86 using

    kernel_fpu_begin(); …
    kernel_fpu_end();

    and make sure that all the FP stuff
    is in between those two things, and
    that you don’t do anything that
    might fault or sleep.

    The kernel_fpu_xxx() macros make sure
    that preemption is turned off etc, so
    the above should always be safe.

    Even then, of course, using FP in the
    kernel assumes that you actually
    have an FPU, of course. The in-kernel FP emulation package is
    not supposed to work with kernel FP instructions.

    Oh, and since the kernel doesn’t link
    with libc, you can’t use anything
    even remotely fancy. It all has to be
    stuff that gcc can do in-line,
    without any function calls.

    In other words: the rule is that you
    really shouldn’t use FP in the
    kernel. There are ways to do it, but
    they tend to be for some real
    special cases, notably for doing
    MMX/XMM work. Ie the only “proper” FPU
    user is actually the RAID checksumming
    MMX stuff.

    Linus

    In any case, do you really want to rely on Intel’s floating point unit? http://en.wikipedia.org/wiki/Pentium_FDIV_bug (just kidding :-)).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just wondering where in the source files of a linux kernel I would
Which version of Linux would be my best choice if I want to use
What Linux commands would you use successively, for a bunch of files, to count
I would like to find the files containing specific string under linux. I tried
I would like to use JNDI to look up Kerberos SRV records in a
I'm new in writing Linux device driver, and I'm wondering how the kernel Makefile
In Linux I would like to run a program but only for a limited
Is there a tool on Linux that would allow me to preview Unicode fonts.
I would like to be able to spawn a linux process that would only
I am writing a video player on Linux and I would like to separate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.