FPU Support for Os

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Slasher

FPU Support for Os

Post 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
gonchuki

Re:FPU Support for Os

Post 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 ??? )
Warmaster199

Re:FPU Support for Os

Post by Warmaster199 »

FPU is easy. You need to check the MATH EMULATION bits in the eflags register. You put flags into eax by doing:

Code: Select all

pushf
pop eax
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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:FPU Support for Os

Post 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:

Code: Select all

pushf
pop eax
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 ...
Post Reply