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

fix(x86_64): don't set CR0Flags::TASK_SWITCHED #1501

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sarahspberrypi
Copy link
Contributor

As previously mentioned, the manual setting of this flag seems to be unnecessary, so I propose to remove it from the code.

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

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

I have done some digging on why this was added:

// Call the IRQ7 handler on the first FPU access.
cr0.insert(CR0_TASK_SWITCHED);

extern "x86-interrupt" fn device_not_available_exception(stack_frame: &mut ExceptionStackFrame) {
// We set the CR0_TASK_SWITCHED flag every time we switch to a task.
// This causes the "Device Not Available" Exception (int #7) to be thrown as soon as we use the FPU for the first time.
// We have to clear the CR0_TASK_SWITCHED here and save the FPU context of the old task.
unsafe { asm!("clts"); }
panic!("FPU ToDo");
}

If the processor executes a floating-point instruction while the TS flag in control register CR0 was set and the EM flag is clear, a device-not-available exception is generated.
I understand this was added intentionally to ensure the behavior for the initial task is the same as for subsequent tasks that were switched to and have set the TS flag implicitly.

I have not done enough digging to say whether it would be fine to remove this, but maybe you don't have a problem with the TS flag but with running interrupts in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants