Various questions about SLEIGH constructors and debugging them #6350
Replies: 1 comment 3 replies
-
Yes, this is possible. The easiest way is to create a single 64-bit token with the corresponding fields:
No, not that I am aware of. Maybe with a
No, that's for combining subconstructors of potentially varying size.
Rather than use t2, use 0xa
In mips64 the registers in
If you've defined your field as signed, you can resize it safely. For instance |
Beta Was this translation helpful? Give feedback.
-
I'm trying to implement some pseudo-instructions for MIPS mostly just for my own edification, and have run into a number of issues I'd love to have some clarity on. Answers to any given question will be greatly appreciated!
1. Is it possible for one token in a concatenated, variable-length instruction, to "back reference" an operand defined in a previous token for the purpose of using it as a constraint?
Say I want to implement this pseudo-instruction:
The pseudo-instruction should match so long as
rt
is the same register in all three places. I tried (very hard) to implement this pseudo-instruction like this:where
rs1
/rt1
are duplicate field definitions forrs
/rt
. I have also tried the above using the aliasRT
defined in mips.sinc which is justrt
, exported. Nothing I have tried has worked and either the pattern will not compile, complaining about redefining operands, or it compiles but the pattern always matches regardless of the requirement thatrt
be the same for both tokens, because the value ofrt
is drawn from the second token instead of the first.2. Is it possible to set context state in an instruction such that it affects the parsing of concatenated tokens in that very same instruction?
This is related to the above example, and is the second angle of attack I tried. I figured I would set local context in the first token that I could use in subsequent tokens for matching:
This did not work and the context value was always unset when parsing the second token. I tried to set the context value globally even with
instr_start
but that did not work either. Is the above possible?3. Could I somehow use the
...
operator to implement the above example?Ultimately I moved past this problem by defining a new 64-bit token with matching fields in the upper and lower parts, so that I could define the pseudo-instruction in a single line. I tried to understand the ellipses operator and every time I read the manual it seemed like it might be relevant to my problem, but I could never even get the pattern to compile if I threw an ellipses in there.
4. Why does this constructor fail to ever match an instruction?
I have a pseudo-instruction I can match where I know every bit of the token. Despite this, my constructor never matches any instructions. Here it is:
This is a special case of
:li RT, simmed
, which is itself a special case of:addiu RT32, RS32src, simmed
, defined in mips32Instructions.sinc. My constructor is defined before these constructors in an included file.I used the debugger script to find out what was going on and got this:
It looks like the
rt=t2
part is getting masked out inmatch-value
, as it is for the other two constructors, causing my constructor to fail. Why is this happening here? I have no operands defined for this constructor butrt
is being masked out as if it were.5. What is the purpose/intent of the
RS
/RT
/etc aliases in the mips.sinc file?They look like this:
There are multiple duplicate fields for
rs
already defined in the instruction token, so I don't think it's needed for that purpose. Any insight here? Most/all instructions are matched using these aliases forRS
/RT
/etc in the MIPS files.6. What is the purpose of
sext()
in the implementation oflui
in mips32Instructions.sinc?There is only one register size - 32 bits.
immed
is a 16-bit field. Whenimmed
is placed in the upper half of the word like this, what purpose couldsext()
orzext()
serve here? Wouldn't sext/zext only make sense here if the field was being shifted less than 16 bits?7. How do
sext()
/zext()
"know" how many 0s/1s to pad a value with?Do they always pad to some specific sized based on sleigh definition information? Is it contextually understood through the assignment to a 4-byte variable? Would I need to specify
simmed:2
to ensure this would work?8. How does the "signed" attribute for a field interact with
sext()
/zext()
?In the above example, since
simmed
is already defined as being signed, do I need to even specifysext()
sign extension for it? Does the signed attribute affect parsing here in some other way, or is it just for convenience?Beta Was this translation helpful? Give feedback.
All reactions