linux-user/arm/nwfpe: Check coprocessor number for FPA emulation
PATCH 1/1 linux-user/arm/nwfpe: Check coprocessor number for FPA emulation
Our copy of the nwfpe code for emulating of the old FPA11 floating point unit doesn't check the coprocessor number in the instruction when it emulates it. This means that we might treat some instructions which should really UNDEF as being FPA11 instructions by accident.
The kernel's copy of the nwfpe code doesn't make this error; I suspect the bug was noticed and fixed as part of the process of mainlining the nwfpe code more than a decade ago.
Add a check that the coprocessor number (which is always in bits [11:8] of the instruction) is either 1 or 2, which is where the FPA11 lives.
---
Tested with a chroot of arm debian lenny, which is the last one that still used the calling convention that mandated use of the old FPA11 FPU and thus needs nwfpe emulation.
--- linux-user/arm/nwfpe/fpa11.c | 9 +++++++++ 1 file changed, 9 insertions(+)
linux-user/arm/nwfpe/fpa11.c +9 -0
@@ -137,8 +137,17 @@ unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, CPUARMState* qregs)unsigned int nRc =0 ;// unsigned long flags; FPA11 *fpa11; +unsigned int cp;// save_flags(flags); sti(); +/* Check that this is really an FPA11 instruction: the coprocessor +* field in bits [11:8] must be 1 or 2. +*/ + cp = (opcode >>8 ) &0xf ; +if (cp !=1 && cp !=2 ) { +return 0 ; + } + qemufpa=qfpa; user_registers=qregs;
Signature · 1 line
2.7.4
Quoted 16 lines · Peter Maydell
Our copy of the nwfpe code for emulating of the old FPA11 floating point unit doesn't check the coprocessor number in the instruction when it emulates it. This means that we might treat some instructions which should really UNDEF as being FPA11 instructions by accident.
The kernel's copy of the nwfpe code doesn't make this error; I suspect the bug was noticed and fixed as part of the process of mainlining the nwfpe code more than a decade ago.
Add a check that the coprocessor number (which is always in bits [11:8] of the instruction) is either 1 or 2, which is where the FPA11 lives.
Reported-by Richard Henderson <[email protected]>Signed-off-by Peter Maydell <[email protected]>
Quoted 7 lines
---
Tested with a chroot of arm debian lenny, which is the last one that still used the calling convention that mandated use of the old FPA11 FPU and thus needs nwfpe emulation.--- linux-user/arm/nwfpe/fpa11.c | 9 +++++++++ 1 file changed, 9 insertions(+)
r~
Quoted 25 lines · Richard Henderson
Quoted 16 lines · Peter Maydell
Our copy of the nwfpe code for emulating of the old FPA11 floating point unit doesn't check the coprocessor number in the instruction when it emulates it. This means that we might treat some instructions which should really UNDEF as being FPA11 instructions by accident.
The kernel's copy of the nwfpe code doesn't make this error; I suspect the bug was noticed and fixed as part of the process of mainlining the nwfpe code more than a decade ago.
Add a check that the coprocessor number (which is always in bits [11:8] of the instruction) is either 1 or 2, which is where the FPA11 lives.
Reported-by Richard Henderson <[email protected]>Signed-off-by Peter Maydell <[email protected]>Quoted 7 lines
---
Tested with a chroot of arm debian lenny, which is the last one that still used the calling convention that mandated use of the old FPA11 FPU and thus needs nwfpe emulation.--- linux-user/arm/nwfpe/fpa11.c | 9 +++++++++ 1 file changed, 9 insertions(+)
Quoted 1 line
Reviewed-by Richard Henderson <[email protected]>
Thanks; applied to target-arm.next (since it's as much an arm patch as a linux-user one).
-- PMM