Fix major problem in do_switch routine #89
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While spending more time figuring out exactly how Fiwix works, I started looking closely at the
do_switch
routine, which is used by the scheduler to switch stacks and run another task.Absolutely amazingly enough, I found that every time a task is switched back to run again, after restoring the flags then the register stack with
popa
, the restarted task actually falls through and executes thecpuid
routine every time before resuming user mode execution. And it looks like this has been occurring since v1.0.0!!!!I initially thought there must be some magic I wasn't following in the task switch. But inserting the following code will display a dot ('.) on every task switch, instead of falling through into
cpuid
:The
cpuid
routine trashes EAX and ECX. The reason the kernel isn't crashing user programs is that the actual return fromdo_switch
is back to the only placedo_switch
is normally called, the C routinecontext_switch
, where EAX and ECX are essentially scratch also, as an immediate STI and RET are executed. (Thedo_switch
calls in the KEXEC code appear to never return, so KEXEC did not likely see any register trashing either).I'm not sure if a Fiwix speedup will be seen, as the normal context switch occurs at only 100HZ, even though
cpuid
was always executed with interrupts disabled.Nothing like this one-line fix!! :)