-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add V850E2M Architecture #1430
Add V850E2M Architecture #1430
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just read through really quick, didn't ref the manual much, so hopefully most of my comments are applicable. one suggestion is you could make more tables for your actions to reduce some code duplication.
|
||
|
||
|
||
##### Prep/Disp Loop ##### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might clean up whitespace in this area
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, I worked with VSCode. I will 'fix' that
:div R0004, R1115, R2731 is op0510=0x3F & R0004 & R1115; op1626=0x2C0 & R2731 | ||
{ | ||
$(OV) = ((R1115 == 0x80000000 && R0004 == 0xFFFFFFFF) || R0004 == 0x0); | ||
R2731 = R1115 s% R0004; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is tricky, if 2731 == 1115 or 2731 == 0004 then the divide is corrupted. I would save the registers into locals and then you can safely do the right hand side of modulus and div calculation with those.
:divh R0004, R1115, R2731 is op0510=0x3F & R0004 & R1115; op1626=0x280 & R2731 | ||
{ | ||
$(OV) = ((R1115 == 0x80000000 && R0004 == 0xFFFFFFFF) || R0004 == 0x0); | ||
R2731 = R1115 s% R0004; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as div
:divhu R0004, R1115, R2731 is op0510=0x3F & R0004 & R1115; op1626=0x282 & R2731 | ||
{ | ||
$(OV) = (R0004 == 0); | ||
R2731 = R1115 s% R0004; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as div
:divu R0004, R1115, R2731 is op0510=0x3F & R0004 & R1115; op1626=0x2C2 & R2731 | ||
{ | ||
$(OV) = (R0004 == 0); | ||
R2731 = R1115 s% R0004; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as div
# CEILF.SL reg2, reg3 - rrrrr11111100010|wwww010001000100 | ||
:ceilf.sl R1115, R2731x2 is R1115 & op0510=0x3F & op0004=0b00010; R2731x2 & op2126=0b100010 & op1620=0b00100 | ||
{ | ||
local var:8 = ceil(float2float(R1115)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not great at float code in SLEIGH, but is the float2float
needed here?, i think its used to move between precision, but it looks like you're starting with 8-byte and ending in 8-byte
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current code is correct, because R1115
(and any other register without x2
suffix) is 32-bits wide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, thanks @esaulenka, I commented on wrong line. ceilf.dul
and ceilf.dl
for example though
:div R0004, R1115, R2731 is op0510=0x3F & R0004 & R1115; op1626=0x2FC & R2731 | ||
{ | ||
$(OV) = ((R1115 == 0x80000000 && R0004 == 0xFFFFFFFF) || R0004 == 0x0); | ||
R2731 = R1115 s% R0004; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as the other div
:divqu R0004, R1115, R2731 is op0510=0x3F & R0004 & R1115; op1626=0x2FE & R2731 | ||
{ | ||
$(OV) = (R0004 == 0); | ||
R2731 = R1115 s% R0004; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as div
# SYNCE - 0000000000011101 | ||
:synce is op0015=0x1D | ||
{ | ||
#I don't know that either |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might add a pcodeop synce
and just call it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find the Operation synce
in the P-code Table of SLEIGH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can define your own: define pcodeop synce;
In the function you can then call it:
{
synce(); // you can have args here if you want, like an immediate or register
}
And then if it comes across that instruction the decompiler will insert synce()
. Just a suggestion so you can at least see the instruction hitting instead of a NOP
just for example, you can see their toy processor:
define pcodeop cop1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, thank you!
|
||
macro either_or(res, cond, true, false) | ||
{ | ||
res = (true * zext(cond != 0)) + (false * zext(cond == 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like some float functions pass through here, you would need another set for f+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh alright, if I multiply a float number with an integer, it gets an integer afterwords with the Symbol '*'. I still had the old view from C
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, its better to change to variant with if (...) goto <...>
conditions.
It much easer for a man to understand.
# AND reg1, reg2 - rrrrr001010RRRRR | ||
:or R0004, R1115 is op0510=0x0A & R0004 & R1115 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am already fixed this typo ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats crazy. I was 100% sure that I fixed that too :D
@Aleckaj, sorry, I forgot to reply to your email. I will definitely do it. Please, sync your code with latest changes: added index for manual and fixed some bugs. Also, why you added only |
@esaulenka You are totally right. I will add them as soon as possible and sync it with your rep ^^ |
:nop is op0015=0x0 | ||
{ | ||
PC = inst_next; | ||
__nop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not do this. I don't know the processor, but any sort of using nop for alignment is going to make for terrible decompiler output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I leave PC = inst_next;
or let this Implementation clean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be good, I kinda like that.
I have done something like:
local tmp = 0;
tmp = tmp;
To remove bookmarks about empty implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but any sort of using nop for alignment
I am still not familiar with all compilers, but three V850 binaries, that i am tested, uses NOPs only as very small delays in low-level drivers.
BTW, it also applies to Infineon binaries.
@ ghidra team |
@Aleckaj, please add two files in
and
It can be just copied from other processor modules. |
c0003: "V" is op0003=0x0 { tmp:1 = ($(OV)) == 1; export tmp; } | ||
c0003: "NV" is op0003=0x8 { tmp:1 = ($(OV)) == 0; export tmp; } | ||
c0003: "C_L" is op0003=0x1 { tmp:1 = ($(CY)) == 1; export tmp; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rewrite all names of conditions in lower case, so that they match the rest of the code.
} | ||
|
||
# JMP [reg1] - 00000000011RRRRR | ||
:jmp [R0004] is op0515=0x003 & R0004 & op0004=0x1F |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is should be second jmp [reg1]
table, without op0004=0x1F condition. It is used for GOTOs, specifed in any register.
@Aleckaj, thanks! I successfully parsed sample binary. Produced code works as real hardware! |
@esaulenka I'm happy to hear that :) |
@EgorKin Sorry untested, so maybe broken/nothing/worse, but this might improve
|
@EgorKin, in your case 0x0? 0x00 is a not instruction, it is data, showing stack offset for current function. It should be used in CallT subroutines, but now I can not achive correct handling of CALLT instruction. |
@esaulenka Hi Alex, I already sent you this binary then we discuss your v850 proc support code a few days before. @mumbel, your modification fixes now func length. It's a bit strange for me because I expected that callt offset changes to address ( Don't know ho to combine it to proper solution. |
@esaulenka If you can provide the pcodetest configuration for compiling the pcodetest binaries for the V850, that would help verify the processor. We try not to put binary files into the repository. Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py I'd like to see the pcodetest configuration files eventually split into each processor directory, but for now this is what we have. |
@EgorKin curious if you cleared the disassembly for that instruction and re-disassembled it (was expecting to see |
@mumbel As I understand v850 docs callt can be end at
and callt 0x2ABA is
At another part of binary another func begin from callt 0x2A12
and end at callt 0x2B3A
So I decrease I try re-disassembled code at 0x27aee but it still as at first sshot. I also try make new project with same binary and after first Auto Analyze I got too long code as I mention early. But if I made Auto Analyze again (with same settings) - func length fixed. So I back to original code from this pull request and got same result - second Analyze gave right func size at Decompile view. Only when I changed
I got second sshot with correct second callt disassembly record. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the sleigh is very well done. A few minor changes and a couple more significant ones.
The project should be moved to Processors/V850 rather than V850E2M, to support the entire processor family under a single umbrella. Most of the .sinc files should be combined together to reduce clutter and make it easier to find instructions.
Ghidra/Processors/V850E2M/data/languages/Helpers/Conditions.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850E2M/data/languages/Instructions/Divide.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850E2M/data/languages/Instructions/Divide.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850E2M/data/languages/Instructions/HighSpeedDivide.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850E2M/data/languages/Instructions/Special.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850E2M/data/languages/Instructions/Store.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850E2M/data/languages/Instructions/BitSearch.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850E2M/data/languages/Instructions/BitSearch.sinc
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple additional changes based on the update
Ghidra/Processors/V850/data/languages/Instructions/Arithmetic.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850/data/languages/Instructions/Arithmetic.sinc
Outdated
Show resolved
Hide resolved
Ghidra/Processors/V850/data/languages/Instructions/Arithmetic.sinc
Outdated
Show resolved
Hide resolved
Hi @GhidorahRex, i fixed the little bugs and added r20-r29 in the unaffected list of And I got a question to your function in
In the last calculation of mask |
@Aleckaj : Regarding r30 and r31 - you've named them as ep and lp in the register definitions, so try adding See mumbel's comment on my comment for the mask. I wrote down the short-circuiting math wrong. Sorry! One final word that should be addressed: you need to add newlines to the end of your files. |
@GhidorahRex it worked out fine 👍 It's been a long time since I programmed it. Thank you for the help :) |
data/languages/Helpers/Conditions.sinc||GHIDRA||||END| | ||
data/languages/Helpers/Extras.sinc||GHIDRA||||END| | ||
data/languages/Helpers/Macros.sinc||GHIDRA||||END| | ||
data/languages/Helpers/Register.sinc||GHIDRA||||END| | ||
data/languages/Helpers/Tokens.sinc||GHIDRA||||END| | ||
data/languages/Helpers/Variables.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Arithmetic.sinc||GHIDRA||||END| | ||
data/languages/Instructions/BitSearch.sinc||GHIDRA||||END| | ||
data/languages/Instructions/BitManipulation.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Branch.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Conditional.sinc||GHIDRA||||END| | ||
data/languages/Instructions/DataManipulation.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Divide.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Float.sinc||GHIDRA||||END| | ||
data/languages/Instructions/HighSpeedDivide.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Load.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Logic.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Multiply.sinc||GHIDRA||||END| | ||
data/languages/Instructions/MultiplyAccumulate.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Saturated.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Special.sinc||GHIDRA||||END| | ||
data/languages/Instructions/Store.sinc||GHIDRA||||END| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aleckaj, please fill manifest with new file list.
diff --git a/Ghidra/Processors/V850/certification.manifest b/Ghidra/Processors/V850/certification.manifest
index ed4cb836..6355d369 100644
--- a/Ghidra/Processors/V850/certification.manifest
+++ b/Ghidra/Processors/V850/certification.manifest
@@ -12,19 +12,8 @@ data/languages/Helpers/Register.sinc||GHIDRA||||END|
data/languages/Helpers/Tokens.sinc||GHIDRA||||END|
data/languages/Helpers/Variables.sinc||GHIDRA||||END|
data/languages/Instructions/Arithmetic.sinc||GHIDRA||||END|
-data/languages/Instructions/BitSearch.sinc||GHIDRA||||END|
-data/languages/Instructions/BitManipulation.sinc||GHIDRA||||END|
-data/languages/Instructions/Branch.sinc||GHIDRA||||END|
-data/languages/Instructions/Conditional.sinc||GHIDRA||||END|
-data/languages/Instructions/DataManipulation.sinc||GHIDRA||||END|
-data/languages/Instructions/Divide.sinc||GHIDRA||||END|
data/languages/Instructions/Float.sinc||GHIDRA||||END|
-data/languages/Instructions/HighSpeedDivide.sinc||GHIDRA||||END|
-data/languages/Instructions/Load.sinc||GHIDRA||||END|
+data/languages/Instructions/Load_Store.sinc||GHIDRA||||END|
data/languages/Instructions/Logic.sinc||GHIDRA||||END|
-data/languages/Instructions/Multiply.sinc||GHIDRA||||END|
-data/languages/Instructions/MultiplyAccumulate.sinc||GHIDRA||||END|
-data/languages/Instructions/Saturated.sinc||GHIDRA||||END|
data/languages/Instructions/Special.sinc||GHIDRA||||END|
-data/languages/Instructions/Store.sinc||GHIDRA||||END|
-data/manuals/v850.idx||GHIDRA||||END|
\ No newline at end of file
+data/manuals/v850.idx||GHIDRA||||END|
<pentry minsize="1" maxsize="4"> | ||
<register name="r10"/> | ||
</pentry> | ||
</output> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some small tests with pcodetest
utility. GCC seems to be able to handle 64-values. Please add
<pentry minsize="5" maxsize="8">
<addr space="join" piece1="r10" piece2="r11"/>
</pentry>
in output
section.
Unfortunately, I didnt know how to correctly specify this for input values.
@emteere, @GhidorahRex it is ok, if pcodetest writes some warnings in log file? I cant figure out, why Also I found only 32-bit compiler, and I ran it on virtual machine with old 32-bit CentOS. |
initial V850 patterns
@esaulenka Warnings in pcodetest compilations are not a big deal. They should be evaluated but in most cases they're acceptable. |
@GhidorahRex What is the status about the pull request? |
@Aleckaj Thanks for submitting the pull request. Hopefully you are well, and I appologize for the world wide interruption. This was in the review pipeline before we became constrained. I do have some initial queries about the processor that I noticed. Most processors aren't split up into so many sections. It can make it difficult to find where the information is defined. I see from prior reviews that they have been collapsed into a smaller number. My personal preference is one larger file so the instructions map to the processor manual in alphabetical order so you can see what is missing, or what instructions are special to a processor. More of an organization for a maintenance. I'm using the SleighEditor in Eclipse which works for xrefs on definitions across files, so it isn't so difficult. I had a few initial questions: There are many patterns of the form R1115 & op1115!=0. In general the "!=", ">", "<" type match patterns should be avoided. This can cause the sleigh files to become large especially used on a 5-bit field. I believe the parse tree enumerates all the separate cases. This is a small processor so the .sla file is only 1.5Meg, so it isn't a huge issue, and removing the "!=0"s only dropped the .sla file to 1.3Meg. If you can put the logic into a DestR1115 variable match where the zero register is "_", then the value won't match. Doing it this way can cause issues with other instructions collisions if there aren't enough bits in common with two different instructions, for example if when R1115 is the destination, the instruction is a "TEST" instruction. Do you have the sample PCODEUNIT test binary compiled for the V850? I saw earlier that it had been tested with it. Would also be good to have a .o/obj for the processor as well. I would like to review the decompiler results. What I saw in the above review looked good. |
I didn't run across anything that changed the r0 from a fixed zero register to a register whose value can change. There were instructions that specifically forbid assigning to the r0, others that didn't forbid it, but didn't say what happened if you used it as a destination. When forbidden, it is possible when r0 was part of the target the assembly was a different instruction. |
What's preventing this from getting merged right now? |
Been reviewed and should be pushed to github today. I've added a comment as to what they really should be. |
Sorry, my fault on bad pattern file, guess I need to read through that schema again |
@mumbel, no worries. I added a ticket to error check for this type of thing when the pattern file is loaded. |
@emteere Thank you for your assistance and merge :) I'm sorry that I'm only now replying, my student email has expired and because of that i got no more notifications. I added this processor for my bachelor degree and because of that I don't have that much knowledge about reverse engineering/memory mapping/etc. Best regards |
No description provided.