flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Easy FPU Initialization

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 23 Nov 2007, 04:11
I've been told that initializing the FPU is a monstrous task.

However, if one reads the August 2007 Intel Manual Volume 3A, Sections 9.1 & 9.2 it is actually a very simple task and it outlines it very well.

Here's the recommended initialization for a Pentium Processor or newer with a math coprocessor:

Code:
; Enable x87 FPU! =D
mov eax, cr0
or eax, 00000000000000000000000000100010b
mov cr0, eax
finit      
    


The two bits being set in the CR0 register are the MP bit (bit 2) and the NE bit (bit 6).

The MP bit tells whether or not the WAIT/FWAIT instructions react to the setting of the Task Switch (TS) flag/bit (bit 4 in CR0 register). If this bit is cleared, then the WAIT/FWAIT instructions will ignore the TS flag. Otherwise, if this bit is set and the TS flag is set, the processor will generate a device-not-avaiable exception.

The NE bit tells whether floating point exceptions are handled internally (bit set) or via an external interrupt (bit cleared).

Another bit which is vital is bit number 3, the EM bit. If this bit is set, it means that there is no floating-point coprocessor (x87). If it is cleared, then there is a floating-point coprocessor.

For more info, check the above reference where I got this info from. Also, in sections 9.7 and 9.8 it talks a great deal about mode switching into P-Mode and Real Mode. I'd suggest that people new to 32-bit OS programming would read it. It looks good.
Post 23 Nov 2007, 04:11
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 23 Nov 2007, 04:29
Well, the complications of FPU init comes when you only want to save FPU task state per-thread if the FPU has actually been used... same goes for SSE registers.

You might also want to set up the FPU control word for rounding etc.
Post 23 Nov 2007, 04:29
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 23 Nov 2007, 05:00
f0dder wrote:
Well, the complications of FPU init comes when you only want to save FPU task state per-thread if the FPU has actually been used... same goes for SSE registers.

You might also want to set up the FPU control word for rounding etc.

Where does it mention that in the Intel Manuals or how can I do it?
Post 23 Nov 2007, 05:00
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 23 Nov 2007, 05:23
nobody knows
seriouslly, it's surelly in the system programming manual
section about all FPu, SSE.
but for sure it's not in task managment, i know this section by heart and i never saw any FPU, SSE reference with task switch

in fact, it's mostlly in the forums that you'll find how to do.

but in FPU and SSE sections, they give the manner to save and restore FPU and SSE states.
you just have to include this in a task switch
then task switch needs to be limited to the periodic style.

to switch with hardware, there are too many possibilities to make it easily reliable. jump, call, load a tss, interrupt,..., all these operations isues to a task switch

so, invalidate hardware task switch and make one software.
mans says that the software TS is faster, so why use the Hardware method?
Post 23 Nov 2007, 05:23
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.