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
FPU Support for Os
Re:FPU Support for Os
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 ??? )
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
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.
Code: Select all
pushf
pop eax
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:FPU Support for Os
hum... A.F.A.I.K., the "math emulation" bit is in CR0, not in eflags...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.Code: Select all
pushf pop eax
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 ...