Implement fninit - #2778
Open
emkey1 wants to merge 1 commit into
Open
Conversation
fninit (DB E3) is missing from the x87 decode table, so it raises SIGILL, while its immediate neighbour fnclex (DB E2) is there. Reported in ish-app#2415, where it kills the Free Pascal compiler at startup: fpc emits fninit in its FPU setup, so nothing compiled with it runs. It resets the control word to 0x037f and clears the status word. Clearing fsw also resets TOP, since TOP is a field of it, which is what empties the register stack; there is no tag word to write because none is modelled. The control word changing means the live rounding mode has to follow it, the same way fldcw does. Verified against real Linux with the same static i386 binary, after dirtying the FPU with a non-default control word and a non-empty stack: before after / real Linux fninit SIGILL runs control word -- 0x037f status word (incl TOP) -- 0x0000 FPU usable afterwards -- yes (The test reads the status word with fnstsw ax rather than fnstsw m16, because the memory form is also unimplemented -- a separate gap.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fninit(DB E3) is missing from the x87 decode table, so it raises SIGILL, while its immediate neighbourfnclex(DB E2) is there.Reported in #2415, where it kills the Free Pascal compiler at startup: fpc emits
fninitin its FPU setup, so nothing compiled with it runs.What it does
Resets the control word to
0x037fand clears the status word. Clearingfswalso resets TOP, since TOP is a field of it, which is what empties the register stack; there is no tag word to write because none is modelled. The control word changing means the live rounding mode has to follow it, the same wayfldcwdoes.Verification
Same static i386 binary run on real Linux and on iSH, after dirtying the FPU with a non-default control word and a non-empty register stack:
fninit0x037f0x0000Reproduced on the Alpine 3.19.0 rootfs the App Store build downloads (
ROOTFS_URLinapp/iSH.xcconfig), against master 7864dd6.Note that
fpcis not packaged for x86 in 3.19, so this is the instruction on its own rather than that program; #2415 is the report, the table above is the check.The test reads the status word with
fnstsw axrather thanfnstsw m16, because the memory form is also unimplemented. That is a separate gap.