Skip to content
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

Merged
merged 13 commits into from Jun 29, 2020
Merged

Conversation

Aleckaj
Copy link
Contributor

@Aleckaj Aleckaj commented Jan 14, 2020

No description provided.

Copy link
Contributor

@mumbel mumbel left a 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 #####
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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));
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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:

Copy link
Contributor Author

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));
Copy link
Contributor

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+

Copy link
Contributor Author

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

Copy link
Contributor

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.

Comment on lines 6 to 7
# AND reg1, reg2 - rrrrr001010RRRRR
:or R0004, R1115 is op0510=0x0A & R0004 & R1115
Copy link
Contributor

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 ;-)

Copy link
Contributor Author

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

@esaulenka
Copy link
Contributor

@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 synce() pcodeop? How do the others synXX differ?
Please add pcodeops for disable/enable interrupts and nop's too. Sometimes it is important to understanding program logic.

@Aleckaj
Copy link
Contributor Author

Aleckaj commented Jan 17, 2020

@esaulenka You are totally right. I will add them as soon as possible and sync it with your rep ^^
Thank you for your help again

:nop is op0015=0x0
{
PC = inst_next;
__nop();
Copy link
Contributor

@mumbel mumbel Jan 18, 2020

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor

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.

@esaulenka
Copy link
Contributor

@ ghidra team
Do you need any test binaries for this MCUs ?

@esaulenka
Copy link
Contributor

@Aleckaj, please add two files in Ghidra/Processors/V850E2M/ for builder subsystem

build.gradle

apply from: "$rootProject.projectDir/gradle/distributableGhidraModule.gradle"
apply from: "$rootProject.projectDir/gradle/processorProject.gradle"
apply plugin: 'eclipse'
eclipse.project.name = 'Processors v850'

and certification.manifest

##VERSION: 2.0
Module.manifest||GHIDRA||||END|
build.gradle||GHIDRA||||END|
data/languages/V850E2M.cspec||GHIDRA||||END|
data/languages/V850E2M.ldefs||GHIDRA||||END|
data/languages/V850E2M.pspec||GHIDRA||||END|
data/languages/V850E2M.slaspec||GHIDRA||||END|
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|
data/manuals/v850.idx||GHIDRA||||END|

It can be just copied from other processor modules.

Comment on lines 6 to 8
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; }
Copy link
Contributor

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
Copy link
Contributor

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.

@esaulenka
Copy link
Contributor

@Aleckaj, thanks! I successfully parsed sample binary. Produced code works as real hardware!

@Aleckaj
Copy link
Contributor Author

Aleckaj commented Jan 24, 2020

@esaulenka I'm happy to hear that :)
I hope the pull request will be accepted soon

@EgorKin
Copy link
Contributor

EgorKin commented Jan 24, 2020

Tested on binary for v850E1. Works really good. Only 1 "not a bug" - E1 & E2 vs E2M allow use R0 as reg1 in MOV reg2, reg1 instructions. Can you add workaround for it for E1 & E2 support too?

And I'm not sure that callt instructions shown right in decompile view - in my binary callt often use at begin & end of functions. Second callt does not shown as FUN_xxxxxxxx(); but as (*(code *)((int)pwVar2 + (uint)pwVar2[0x16]))(); and functions does not end at callt instruction and continues longer than it need.
v850E2M ghidra
In Memory Map this ROM section marked as Read & Execute (no Write). If I set Write first callt convert to(*(code *)((int)pwVar..... code too.
Is it my fault or something else?

@mumbel
Copy link
Contributor

mumbel commented Jan 24, 2020

@EgorKin callt returns to the next instruction, stored in CTPC, in the sleigh code. Does fun_00002aba() change CTPC or other control flows so it would not return to the instruction after that callt? Also is 0x2996 structured data, making that memory into a struct may help in decompiler, not 100% sure though.

Sorry untested, so maybe broken/nothing/worse, but this might improve callt

calltadr: op0005 is op0005 { local adr:4 = CTBP + (op0005 << 1); local tmp:4 = CTBP + zext(*:2 adr); export tmp; }
# CALLT imm6 - 0000001000iiiiii
:callt calltadr is op0615=0x8 & calltadr
{
	CTPC = inst_next;
	CTPSW = PSW;
	PC = calltadr;
	call [PC];
}

@EgorKin
Copy link
Contributor

EgorKin commented Jan 24, 2020

0x2996 is marked as word data:
Clipboard02
And yes, Fun_00002aba(); change CTPC reg:
Clipboard01

But Fun_000029be() is:

000029be 80 07 21 00     prepare    { lp },0x0

000029c2 e0 07 44 01     ctret

@esaulenka
Copy link
Contributor

@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.
If you can share your binary, (or, may be, part of it) it can be discussed more detail.

@EgorKin
Copy link
Contributor

EgorKin commented Jan 24, 2020

@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 (callt 0x0=>DAT_00002966 changes to callt 0x000029be for example)
But now after reanalyze:
Clipboard01
I try play a bit with callt code and if I hardcode CTBP as 0x2966 then second callt decompiled successful. But I got a * WARNING: Subroutine does not return * remark.
Clipboard02
CTBP is 0x2966 for all binary.
Clipboard03

Don't know ho to combine it to proper solution.

@emteere
Copy link
Contributor

emteere commented Jan 24, 2020

@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.
Once you have compiled them and they run, then attach them here so we can take a look. I'm sure we can probably locate a sample V850 binary, but known compiled code helps in finding issues and automating testing. If that is a tough ask, we might be able to come up with a v850 configuration and provide the test setup as we did for the tricore.

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.

@mumbel
Copy link
Contributor

mumbel commented Jan 24, 2020

@EgorKin curious if you cleared the disassembly for that instruction and re-disassembled it (was expecting to see callt 0x16 though not sure if that would change anything) and your second screenshot of decompile is actually what I was thinking would happen.
Are you certain if FUN_00002ac8() is correct as a function, doesn't that make FUN_00002aba() a little off?

@EgorKin
Copy link
Contributor

EgorKin commented Jan 25, 2020

@mumbel As I understand v850 docs callt can be end at ctret instruction or at dispose 0, {lp}, [lp].
In my example callt 0x29BE is

prepare {lp}, 0
ctret

and callt 0x2ABA is

dispose 0, {lp}, [lp]

At another part of binary another func begin from callt 0x2A12

prepare {lp}, 0
prepare {r27-r29}, 0
stsr    CTPC, r29
ctret

and end at callt 0x2B3A

dispose 0, {r27-r29}
dispose 0, {lp}, [lp]

So I decrease FUN_00002aba() length
Clipboard01
but it does not change anything.

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 callt in Special.sinc file to (hardcode 0x2966 value)

# CALLT imm6 - 0000001000iiiiii
:callt op0005 is op0615=0x8 & op0005 
{
	CTPC = inst_next;
	CTPSW = PSW;
	local adr:4 = 0x2966 + (op0005 << 1);
	PC = 0x2966 + zext(*:2 adr);
	call [PC];
}

I got second sshot with correct second callt disassembly record.

@GhidorahRex GhidorahRex self-assigned this Feb 4, 2020
Copy link
Collaborator

@GhidorahRex GhidorahRex left a 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.

@Aleckaj Aleckaj closed this Feb 17, 2020
Copy link
Collaborator

@GhidorahRex GhidorahRex left a 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

@Aleckaj
Copy link
Contributor Author

Aleckaj commented Feb 21, 2020

Hi @GhidorahRex, i fixed the little bugs and added r20-r29 in the unaffected list of .cspec. If I try to add r30 and r31 the decompiler stops working. I really dont know why.

And I got a question to your function in Macros.sinc:

macro shift_right_logic(res, var, shift_)
{
	local shift = (shift_ & 0x1f);
	local mask = (zext(shift != 0) * var & (1 << (shift - 1)) + (zext(shift == 0) * 0);
	res = var >> shift;
	set_OV0_S_Z(res);
	$(CY) = ((mask != 0) && (shift != 0));
}

In the last calculation of mask (zext(shift == 0) * 0) you always multiply with 0. Can you explain me why it's necessary?

@GhidorahRex
Copy link
Collaborator

@Aleckaj : Regarding r30 and r31 - you've named them as ep and lp in the register definitions, so try adding <register name="ep"/> and <register name="lp"/>.

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.

@Aleckaj
Copy link
Contributor Author

Aleckaj commented Feb 24, 2020

@GhidorahRex it worked out fine 👍 It's been a long time since I programmed it. Thank you for the help :)

Comment on lines 8 to 29
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|
Copy link
Contributor

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>
Copy link
Contributor

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.

@esaulenka
Copy link
Contributor

If you can provide the pcodetest configuration for compiling the pcodetest binaries for the V850, that would help verify the processor

@emteere, @GhidorahRex it is ok, if pcodetest writes some warnings in log file? I cant figure out, why nm reports about undefined symbols r10, r24-r31.

Also I found only 32-bit compiler, and I ran it on virtual machine with old 32-bit CentOS.

@GhidorahRex
Copy link
Collaborator

@esaulenka Warnings in pcodetest compilations are not a big deal. They should be evaluated but in most cases they're acceptable.

@Aleckaj
Copy link
Contributor Author

Aleckaj commented Mar 30, 2020

@GhidorahRex What is the status about the pull request?

@emteere
Copy link
Contributor

emteere commented May 7, 2020

@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've started doing a secondary review on the V850 so we can move it towards getting merged. We may not be able to do a final merge until we have more time in the office. It is the plan to merge it into master. I'm considering the processor ID, given that others might extend the processor. If this encompasses the whole line, and there isn't any conflicts in other variants, then thats great. I normally strive for a single .sla file if the instructions/addressing/memory map doesn't collide.

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.
When you compile in Eclipse with build.xml, the errors are hyperlinked in the console. Right now there are issues with sub-directories where it doesn't navigate when selected on. That should be fixed.
In the InstructionInfo action on a disassembled instruction, the name of the original file doesn't show up, just a line number. It can be difficult to locate the intruction/subconstructor in many files. This should be fixed in Ghidra as well, but right now only a line number is stored within the parse tree.

I had a few initial questions:
The memory from 0-0x20 is volatile in the .pspec is this correct for the processor?
The register space should probably be dropped back to size 2. Not a big deal, but it really doesn't need that much space.

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.
Also if the r0 register can never be used as a destination, I see places that don't restrict it's use, and are assigning to a unique (local) in this case which is probably OK. Same things goes for R2731 as a destination.
Lastly if there are more variants that create variant files (little/big/memory size/etc), the extra K adds up.

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.

@EgorKin
Copy link
Contributor

EgorKin commented May 13, 2020

Emm, guys I'm really hope finding V850 support on next Ghidra release but can someone look at add imm, reg instruction (and similar) with negative imm values?

bug

And can you fix this dumb "+ -value" to normal "-value"?
Also vote for r0 reg as destination for E1, E2 processor variants.

Thank's.

@emteere
Copy link
Contributor

emteere commented May 13, 2020

I didn't run across anything that changed the r0 from a fixed zero register to a register whose value can change.
If code allows assigning to it, and the value assignment is ignored, then no problem leaving it in.
Many processors that assign to the zero register change the nature of the instruction to a test.

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.

@Martmists-GH
Copy link

What's preventing this from getting merged right now?

@emteere
Copy link
Contributor

emteere commented Jun 26, 2020

Been reviewed and should be pushed to github today.
There were a few changes necessary to the patterns files.
We need to add some error checks for:
No actions on a pattern
Impossible totalbits and postbits numbers

I've added a comment as to what they really should be.
But Warning or error messages would be good.

@mumbel
Copy link
Contributor

mumbel commented Jun 26, 2020

Sorry, my fault on bad pattern file, guess I need to read through that schema again

@emteere
Copy link
Contributor

emteere commented Jun 26, 2020

@mumbel, no worries. I added a ticket to error check for this type of thing when the pattern file is loaded.
When it gets posted to github, I think we can close this one.

@ghidra1 ghidra1 merged commit cfc4c8c into NationalSecurityAgency:master Jun 29, 2020
@ghidra1 ghidra1 added this to the 9.2 milestone Jul 1, 2020
@Aleckaj
Copy link
Contributor Author

Aleckaj commented Jul 21, 2020

@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.
Please feel free to use and change everything you want to. I hope my "work" helped you a bit.

Best regards
Alex

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

Successfully merging this pull request may close these issues.

None yet

9 participants