Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

SLLI: Possibly wrong decoding? #172

Open
mablinov opened this issue Aug 6, 2019 · 2 comments
Open

SLLI: Possibly wrong decoding? #172

mablinov opened this issue Aug 6, 2019 · 2 comments

Comments

@mablinov
Copy link

mablinov commented Aug 6, 2019

This concerns the SLLI encoding. From the spec, the rv32i SLLI instruction is encoded as follows:

slli-32
So, the leftmost field has 7 bits of opcode space, and then theres a 5 bit shamt field.

As for the 64 bit variant, its encoded differently:
slli-64

Now we only have 6 bits of opcode space on the left, because we steal one bit for the 64-bit shift amount encoding.

Now consider the following opcode:
0000000 11111 00000 001 00000 0010011 = 0x1F01013

The test.s:

.attribute arch, "rv32i"
start:
	.word 0x1F01013

disassembly:

00000000 <start>:
   0:	01f01013          	slli	zero,zero,0x1f

Ok, makes sense, we shift left by an immedate amount of 31 bits.
If we do the following however:

0000001 00000 00000 001 00000 0010011 = 0x2001013
We've "incremented" the shamt by one, but as per the rv32i v2.2 spec, the shamt is 0, and bit 0 of the leftmost opcode[6:0] field is now set, so it shouldn't be a "SLLI" anymore (atleast not in rv32i).

test.s:

.attribute arch, "rv32i"

start:
	.word 0x2001013

disassembling test.o:

test:
00000000 <start>:
   0:	02001013          	slli	zero,zero,0x20

That is SLLI in rv64i, but not in rv32i, right?

@mablinov
Copy link
Author

mablinov commented Aug 6, 2019

Sorry if anyone saw the half-finished post, I accidently pressed ctrl-enter...

@mablinov mablinov changed the title Possibly wrong decoding? SLLI: Possibly wrong decoding? Aug 6, 2019
@aswaterman
Copy link
Contributor

It's a "feature" of objdump that it will attempt to disassemble the instruction even though it's illegal in RV32I.
Yes, 0x02001013 is an illegal instruction in RV32I. GAS won't let you assemble the instruction slli x0,x0,32, but if objdump encounters the bit pattern that corresponds to that illegal instruction, it will still disassemble it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants