Page 1 of 1
FPU Support for Os
Posted: Sat Sep 07, 2002 1:12 pm
by Slasher
I've been looking at some Os dev posts on the web and have seen people mention FPU and MMX support in an Os. I've read the 386intel manual but haven't seen(or noticed) any place explaining how to add these to an os? Any one with ideas or info on this.
Thanks
Re:FPU Support for Os
Posted: Sat Sep 07, 2002 9:16 pm
by gonchuki
a good paper by amd can be found at
http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/20726.pdf
it's a good start for MMX. Note that it bases it's explanations by mentioning the AMD-K6 processor all the time but the paper just describes generic MMX... hope you find it useful (i'm trying to do so ??? )
Re:FPU Support for Os
Posted: Sun Sep 08, 2002 9:40 am
by Warmaster199
FPU is easy. You need to check the MATH EMULATION bits in the eflags register. You put flags into eax by doing:
If the FPU is present, then you are able to use things like "fsin" and "fcos" as opcodes in assembly. You are also able to use the "float" and "double" types. If there is no FPU, then you need to create a software FPU math emulation library. Then, I believe you tie it(The library) into an interrupt, and set a flag in the eflags reg.
Re:FPU Support for Os
Posted: Mon Sep 09, 2002 2:57 am
by Pype.Clicker
Warmaster199 wrote:
FPU is easy. You need to check the MATH EMULATION bits in the eflags register. You put flags into eax by doing:
If the FPU is present, then you are able to use things like "fsin" and "fcos" as opcodes in assembly. You are also able to use the "float" and "double" types. If there is no FPU, then you need to create a software FPU math emulation library. Then, I believe you tie it(The library) into an interrupt, and set a flag in the eflags reg.
hum... A.F.A.I.K., the "math emulation" bit is in CR0, not in eflags...
What the OS is required to do in order to support coprocessors like FPU or MMX is to save/restore those processor's state as well as CPU state when task switching. This is helped by the fact that the access to a coprocessor with TaskSwitched bit set will raise an exception (check intel manual to know which one
).
So when this exception rises, you should remember what was the last thread that used FPU, save the FPU context in that thread and then restore the current thread's FPU context and clear task switch (CLTS instruction)
Another option is to do the save/restore systematically, but it may become an excessive overhead as it requires many CPU cycles ...