Skip to content

Commit 65f9abe

Browse files
cyrilbur-ibmstewartsmith
authored andcommittedNov 21, 2017
libpore: Fix incorrect mtspr instruction generation
>From coverity defect 173758: CID 173758 (#1 of 1): Unused value (UNUSED_VALUE) assigned_value: Assigning value from (uint8_t)i_Rs << 21 to mtsprInstOpcode here, but that stored value is overwritten before it can be used. This causes the generated mtspr to always move from register r0 as opposed to the function parameter i_Rs. Luckily the only call to getMtsprInstruction is: getMtsprInstruction( 0, (uint16_t)i_regId ); the first parameter is the register so in an incredible stroke of luck, the requirement is to generate a mtspr from r0. Therefore no bug exists today, this is still a fairly important fix because if anyone uses getMtsprInstruction() with a non zero first parameter, it will cause them endless headache. Fixes: CID 173758 Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
1 parent c2e404a commit 65f9abe

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed
 

‎libpore/p9_stop_api.C

+4-6
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,10 @@ static uint32_t getOrisInstruction( const uint16_t i_Rs, const uint16_t i_Ra,
255255
*/
256256
static uint32_t getMtsprInstruction( const uint16_t i_Rs, const uint16_t i_Spr )
257257
{
258-
uint32_t mtsprInstOpcode = 0;
259-
uint32_t temp = (( i_Spr & 0x03FF ) << 11);
260-
mtsprInstOpcode = (uint8_t)i_Rs << 21;
261-
mtsprInstOpcode = ( temp & 0x0000F800 ) << 5;
262-
mtsprInstOpcode |= ( temp & 0x001F0000 ) >> 5;
263-
mtsprInstOpcode |= MTSPR_BASE_OPCODE;
258+
uint32_t mtsprInstOpcode = MTSPR_BASE_OPCODE;
259+
uint32_t temp = ((i_Spr & 0x1F) << 5) | ((i_Spr & 0x8F) >> 5);
260+
261+
mtsprInstOpcode |= ((i_Rs & 0x1F) << 21) | ((temp & 0x03FF) << 11);
264262

265263
return SWIZZLE_4_BYTE(mtsprInstOpcode);
266264
}

0 commit comments

Comments
 (0)
Please sign in to comment.