Skip to content

Ghidra is a software reverse engineering (SRE) framework

Added Manual and syncronised Code with @esaulenka

Aleckaj392b38bf244b
diff --git a/Ghidra/Processors/V850E2M/data/languages/Helpers/Extras.sinc b/Ghidra/Processors/V850E2M/data/languages/Helpers/Extras.sinc
index 88e17721b8..dbfdde0841 100644
--- a/Ghidra/Processors/V850E2M/data/languages/Helpers/Extras.sinc
+++ b/Ghidra/Processors/V850E2M/data/languages/Helpers/Extras.sinc
@@ -20,6 +20,12 @@ adr9: res is op0406 & s1115
export *:4 res;
}
+adr22: res is s0005; op1631 & op1616=0
+[ res = ((s0005 << 16) | op1631) + inst_start; ]
+{
+ export *:4 res;
+}
+
adr32: res is op1631 & op1616=0; op3247
[ res = ((op3247 << 16) | op1631) + inst_start; ]
{
diff --git a/Ghidra/Processors/V850E2M/data/languages/Helpers/Macros.sinc b/Ghidra/Processors/V850E2M/data/languages/Helpers/Macros.sinc
index a8cd4f6c04..5fdfc4e58d 100644
--- a/Ghidra/Processors/V850E2M/data/languages/Helpers/Macros.sinc
+++ b/Ghidra/Processors/V850E2M/data/languages/Helpers/Macros.sinc
@@ -120,24 +120,32 @@ macro set_OV0_S_Z(var)
##### General-Macros #####
-macro either_or(res, cond, true, false)
+macro either_or(res, cond, var_true, var_false) # if condition is != 0
{
- res = (true * zext(cond != 0)) + (false * zext(cond == 0));
-}
+ if (cond != 0)
+ goto <true>;
+
+ res = var_false;
+ goto <end>;
+
+ <true>
+ res = var_true;
-macro either_or1(res, cond, true, false)
-{
- res = (true * zext(cond == 1)) + (false * zext(cond != 1));
+ <end>
}
-macro either_or_float(res, cond, true, false)
+macro either_or1(res, cond, var_true, var_false) # if condition is == 1
{
- res = (true f* zext(cond != 0)) f+ (false f* zext(cond == 0));
-}
+ if (cond == 1)
+ goto <true>;
+
+ res = var_false;
+ goto <end>;
+
+ <true>
+ res = var_true;
-macro either_or1_float(res, cond, true, false)
-{
- res = (true f* zext(cond == 1)) f+ (false f* zext(cond != 1));
+ <end>
}
macro shift_right_logic(res, var, shift)
@@ -235,14 +243,14 @@ macro saturate(var)
goto <end>;
<pos_sat>
- var = 0x7FFFFFFF;
- goto <end>;
+ var = 0x7FFFFFFF;
+ goto <end>;
<neg_sat>
- var = -0x80000000;
- goto <end>;
+ var = -0x80000000;
+ goto <end>;
- <end>
+ <end>
}
diff --git a/Ghidra/Processors/V850E2M/data/languages/Helpers/Register.sinc b/Ghidra/Processors/V850E2M/data/languages/Helpers/Register.sinc
index 131931b441..599aed893c 100644
--- a/Ghidra/Processors/V850E2M/data/languages/Helpers/Register.sinc
+++ b/Ghidra/Processors/V850E2M/data/languages/Helpers/Register.sinc
@@ -19,9 +19,9 @@ define register offset=0x0 size=0x4 # offset = 0 because it's the st
define register offset=0x80 size=0x4 # offset = 0x80(128) = PreOffset+PreRegister*Size = 0+32*4 = 128
[
- EIPC EIPSW FEPC FEPSW ECR PSW FPSR _ FPST FPCC
- FPCFG SCCFG SCBP EIIC FEIC DBIC CTPC CTPSW DBPC DBPSW
- CTBP DIR _ _ _ _ _ _ EIWR FEWR
+ EIPC EIPSW FEPC FEPSW ECR PSW FPSR FPEPC FPST FPCC
+ FPCFG SCCFG SCBP EIIC FEIC DBIC CTPC CTPSW DBPC DBPSW
+ CTBP DIR DBG22 DBG23 DBG24 DBG25 DBG26 DBG27 EIWR FEWR
DBWR BSEL
];
@@ -33,4 +33,4 @@ define register offset=0x0 size=0x8
_
];
-define register offset=0x100 size=4 [ PC ]; # offset = 0x100(256) = PreOffset+PreRegister*Size = 128+32*4 = 256
\ No newline at end of file
+define register offset=0x100 size=0x4 [ PC ]; # offset = 0x100(256) = PreOffset+PreRegister*Size = 128+32*4 = 256
\ No newline at end of file
diff --git a/Ghidra/Processors/V850E2M/data/languages/Helpers/Variables.sinc b/Ghidra/Processors/V850E2M/data/languages/Helpers/Variables.sinc
index 0d44e9a847..b917966a23 100644
--- a/Ghidra/Processors/V850E2M/data/languages/Helpers/Variables.sinc
+++ b/Ghidra/Processors/V850E2M/data/languages/Helpers/Variables.sinc
@@ -27,6 +27,14 @@ attach variables [ R0004x2 R1115x2 R1620x2 R2731x2 ]
_ _
];
+attach variables [ SR0004 SR1115 ]
+[
+ EIPC EIPSW FEPC FEPSW ECR PSW FPSR FPEPC FPST FPCC
+ FPCFG SCCFG SCBP EIIC FEIC DBIC CTPC CTPSW DBPC DBPSW
+ CTBP DIR DBG22 DBG23 DBG24 DBG25 DBG26 DBG27 EIWR FEWR
+ DBWR BSEL
+];
+
attach variables [op0_1720] [r0 r2 gp r6 r8 r10 r12 r14 r16 r18 r20 r22 r24 r26 r28 ep];
attach variables [op1_1720] [r1 sp tp r7 r9 r11 r13 r15 r17 r19 r21 r23 r25 r27 r29 lp];
@@ -46,7 +54,4 @@ attach names [fcond2730]
@define Z "PSW[0,1]"
@define EICC "ECR[0,16]"
-@define FECC "ECR[16,16]"
-
-
-define pcodeop synce;
\ No newline at end of file
+@define FECC "ECR[16,16]"
\ No newline at end of file
diff --git a/Ghidra/Processors/V850E2M/data/languages/Instructions/Branch.sinc b/Ghidra/Processors/V850E2M/data/languages/Instructions/Branch.sinc
index a9618c068d..ea9a02682c 100644
--- a/Ghidra/Processors/V850E2M/data/languages/Instructions/Branch.sinc
+++ b/Ghidra/Processors/V850E2M/data/languages/Instructions/Branch.sinc
@@ -3,7 +3,7 @@
#####################################################
-#Bcond addr9 - ddddd1011dddcccc
+#Bcond adr9 - ddddd1011dddcccc
:b^c0003 adr9 is op0710=0xB & c0003 & adr9
{
if (c0003)
@@ -15,20 +15,18 @@
}
# JARL disp22, reg2 - rrrrr11110dddddd|ddddddddddddddd0
-:jarl disp22, r1115 is op0610=0x1E & s0005 & r1115; op1631 & op1616=0
-[ disp22 = ((s0005 << 16) | op1631) + inst_start; ]
+:jarl adr22, r1115 is (op0610=0x1E & r1115) ... & adr22
{
r1115 = inst_next;
- local adr:4 = disp22;
- PC = adr;
- call [adr];
+ PC = & adr22;
+ call adr22;
}
# JARL disp32, reg1 - 00000010111RRRRR|ddddddddddddddd0|DDDDDDDDDDDDDDDD
:jarl adr32, r0004 is op0515=0x017 & r0004; adr32
{
r0004 = inst_next;
- PC = adr32;
+ PC = & adr32;
call adr32;
}
@@ -39,12 +37,6 @@
return [R0004];
}
-:jmp [R0004] is op0515=0x003 & R0004 & op0004!=0x1F
-{
- PC = R0004;
- call [R0004];
-}
-
# JMP disp32[reg1] - 00000110111RRRRR|ddddddddddddddd0|DDDDDDDDDDDDDDDD
:jmp adr32[R0004] is op0515=0x037 & R0004; adr32
{
@@ -53,17 +45,15 @@
}
# JR disp22 - 00000111110ddddd|ddddddddddddddd0
-:jr disp22 is op0615=0x1E & s0005; op1631 & op1616=0
-[ disp22 = ((s0005 << 16) | op1631) + inst_start; ]
+:jr adr22 is op0615=0x1E ... & adr22
{
- local adr:4 = disp22;
- PC = adr;
- goto [adr];
+ PC = & adr22;
+ goto adr22;
}
-# JR disp32
+# JR disp32 - 0000001011100000|ddddddddddddddd0|DDDDDDDDDDDDDDDD
:jr adr32 is op0015=0x2E0; adr32
{
- PC = adr32;
+ PC = & adr32;
goto adr32;
}
\ No newline at end of file
diff --git a/Ghidra/Processors/V850E2M/data/languages/Instructions/Float.sinc b/Ghidra/Processors/V850E2M/data/languages/Instructions/Float.sinc
index d6398b0ad4..71d132b775 100644
--- a/Ghidra/Processors/V850E2M/data/languages/Instructions/Float.sinc
+++ b/Ghidra/Processors/V850E2M/data/languages/Instructions/Float.sinc
@@ -56,7 +56,8 @@
# CEILF.SL reg2, reg3 - rrrrr11111100010|wwww010001000100
:ceilf.sl R1115, R2731x2 is R1115 & op0510=0x3F & op0004=0b00010; R2731x2 & op2126=0b100010 & op1620=0b00100
{
- R2731x2 = ceil(sext(R1115));
+ local var:8 = ceil(float2float(R1115));
+ R2731x2 = trunc(var);
}
# CEILF.SUL reg2, reg3 - rrrrr11111110010|wwwww10001000100
@@ -83,14 +84,14 @@
{
#CC0 = Bit 24
local bit = (FPSR >> (fcbit1719 + 24:1)) & 0x1;
- either_or1_float(R2731x2, bit, R0004x2, R1115x2);
+ either_or1(R2731x2, bit, R0004x2, R1115x2);
}
# CMOVF.S fcbit, reg1, reg2, reg3 - rrrrr111111RRRRR|wwwww1000000fff0
:cmovf.s fcbit1719, R1115, R0004, R2731 is R1115 & op0510=0x3F & R0004; R2731 & op2126=0b100000 & op2020=0 & fcbit1719 & op1616=0
{
local bit = (FPSR >> (fcbit1719 + 24:1)) & 0x1;
- either_or1_float(R2731, bit, R0004, R1115);
+ either_or1(R2731, bit, R0004, R1115);
}
# CMPF.D fcond, reg2, reg1, fcbit - rrrr0111111RRRRR|0FFFF1000011fff0
@@ -270,7 +271,8 @@
# FLOORF.SL reg2, reg3 - rrrrr11111100011|wwww010001000100
:floorf.sl R1115, R2731x2 is R1115 & op0510=0x3F & op0004=0b00011; R2731x2 & op2126=0b100010 & op1620=0b00100
{
- R2731x2 = floor(sext(R1115));
+ local var:8 = floor(float2float(R1115));
+ R2731x2 = trunc(var);
}
# FLOORF.SUL reg2, reg3 - rrrrr11111110011|wwwww10001000100
@@ -302,28 +304,28 @@
:maxf.d R0004x2, R1115x2, R2731x2 is R0004x2 & op0510=0x3F & R1115x2; R2731x2 & op2126=0b100011 & op1620=0b11000
{
local bigger:1 = R1115x2 f> R0004x2;
- either_or_float(R2731x2, bigger, R1115x2, R0004x2);
+ either_or(R2731x2, bigger, R1115x2, R0004x2);
}
# MAXF.S reg1, reg2, reg3 - rrrrr111111RRRRR|wwwww10001101000
:maxf.s R0004, R1115, R2731 is R0004 & op0510=0x3F & R1115; R2731 & op2126=0b100011 & op1620=0b01000
{
local bigger:1 = R1115 f> R0004;
- either_or_float(R2731, bigger, R1115, R0004);
+ either_or(R2731, bigger, R1115, R0004);
}
# MINF.D reg1, reg2, reg3 - rrrr0111111RRRR0|wwww010001111010
:minf.d R0004x2, R1115x2, R2731x2 is R0004x2 & op0510=0x3F & R1115x2; R2731x2 & op2126=0b100011 & op1620=0b11010
{
local bigger:1 = R1115x2 f< R0004x2;
- either_or_float(R2731x2, bigger, R1115x2, R0004x2);
+ either_or(R2731x2, bigger, R1115x2, R0004x2);
}
# MINF.S reg1, reg2, reg3 - rrrr0111111RRRRR|wwwww10001101010
:minf.s R0004, R1115, R2731 is R0004 & op0510=0x3F & R1115; R2731 & op2126=0b100011 & op1620=0b01010
{
local bigger:1 = R1115 f< R0004;
- either_or_float(R2731, bigger, R1115, R0004);
+ either_or(R2731, bigger, R1115, R0004);
}
# MSUBF.S reg1, reg2, reg3, reg4 - rrrrr111111RRRRR|wwwww101W01WWWW0
diff --git a/Ghidra/Processors/V850E2M/data/languages/Instructions/Logic.sinc b/Ghidra/Processors/V850E2M/data/languages/Instructions/Logic.sinc
index 05e22a00f6..f23264e9f2 100644
--- a/Ghidra/Processors/V850E2M/data/languages/Instructions/Logic.sinc
+++ b/Ghidra/Processors/V850E2M/data/languages/Instructions/Logic.sinc
@@ -4,7 +4,7 @@
# AND reg1, reg2 - rrrrr001010RRRRR
-:or R0004, R1115 is op0510=0x0A & R0004 & R1115
+:and R0004, R1115 is op0510=0x0A & R0004 & R1115
{
R1115 = R1115 & R0004;
set_OV0_S_Z(R1115);
diff --git a/Ghidra/Processors/V850E2M/data/languages/Instructions/Special.sinc b/Ghidra/Processors/V850E2M/data/languages/Instructions/Special.sinc
index 1923a6efc8..c6a2b91772 100644
--- a/Ghidra/Processors/V850E2M/data/languages/Instructions/Special.sinc
+++ b/Ghidra/Processors/V850E2M/data/languages/Instructions/Special.sinc
@@ -32,9 +32,11 @@
}
# DI - 0000011111100000|0000000101100000
+define pcodeop __disable_irq;
:di is op0015=0x7E0; op1631=0x160
{
$(ID) = 1;
+ __disable_irq();
}
# DISPOSE imm5, list12 - 0000011001iiiiiL|LLLLLLLLLLL00000
@@ -54,9 +56,11 @@
}
# EI - 1000011111100000|0000000101100000
+define pcodeop __enable_irq;
:ei is op0015=0x87E0; op1631=0x160
{
$(ID) = 0;
+ __enable_irq();
}
# EIRET - 0000011111100000|0000000101001000
@@ -90,9 +94,10 @@
}
# HALT - 0000011111100000|0000000100100000
+define pcodeop __halt;
:halt is op0015=0x7E0; op1631=0x120
{
-
+ __halt();
}
# LDSR reg2, regID - rrrrr111111RRRRR|0000000000100000
@@ -102,9 +107,10 @@
}
# NOP - 0000000000000000
+define pcodeop __nop;
:nop is op0015=0x0
{
- PC = inst_next;
+ __nop();
}
# PREPARE list12, imm5 - 0000011110iiiiiL|LLLLLLLLLLL00001
@@ -212,21 +218,22 @@
}
# SYNCE - 0000000000011101
+define pcodeop __synchronize;
:synce is op0015=0x1D
{
- synce();
+ __synchronize();
}
# SYNCM - 0000000000011110
:syncm is op0015=0x1E
{
-
+ __synchronize();
}
# SYNCP - 0000000000011111
:syncp is op0015=0x1F
{
-
+ __synchronize();
}
# SYSCALL vector8 - 11010111111vvvvv|00VVV00101100000
diff --git a/Ghidra/Processors/V850E2M/data/languages/V850E2M.ldefs b/Ghidra/Processors/V850E2M/data/languages/V850E2M.ldefs
index f64dc5f9ae..acc1a92e82 100644
--- a/Ghidra/Processors/V850E2M/data/languages/V850E2M.ldefs
+++ b/Ghidra/Processors/V850E2M/data/languages/V850E2M.ldefs
@@ -8,6 +8,7 @@
version="1.0"
slafile="V850E2M.sla"
processorspec="V850E2M.pspec"
+ manualindexfile="../manuals/v850.idx"
id="V850:LE:32:default">
<description>Renesas V850E2M</description>
<compiler name="default" spec="V850E2M.cspec" id="default"/>
diff --git a/Ghidra/Processors/V850E2M/data/languages/V850E2M.slaspec b/Ghidra/Processors/V850E2M/data/languages/V850E2M.slaspec
index b2b9526898..21cc5b2d09 100644
--- a/Ghidra/Processors/V850E2M/data/languages/V850E2M.slaspec
+++ b/Ghidra/Processors/V850E2M/data/languages/V850E2M.slaspec
@@ -5,6 +5,7 @@
#####################################################
define endian = little;
+define alignment = 2;
# Size & default are required
define space ram type=ram_space size=4 default;
diff --git a/Ghidra/Processors/V850E2M/data/manuals/v850.idx b/Ghidra/Processors/V850E2M/data/manuals/v850.idx
new file mode 100644
index 0000000000..b09c169a04
--- /dev/null
+++ b/Ghidra/Processors/V850E2M/data/manuals/v850.idx
@@ -0,0 +1,174 @@
+@r01us0001ej0100_v850e2m.pdf [V850E2M User�s Manual: Architecture RENESAS MCU V850E2M Microprocessor Core]
+
+ADD, 71
+ADDI, 72
+ADF, 73
+AND, 74
+ANDI, 75
+Bcond, 76
+BSH, 78
+BSW, 79
+CALLT, 80
+CAXI, 81
+CLR1, 82
+CMOV, 84
+CMP, 86
+CTRET, 87
+DI, 88
+DISPOSE, 89
+DIV, 91
+DIVH, 92
+DIVHU, 94
+DIVQ, 95
+DIVQU, 96
+DIVU, 97
+EI, 98
+EIRET, 99
+FERET, 100
+FETRAP, 101
+HALT, 102
+HSH, 103
+HSW, 104
+JARL, 105
+JMP, 107
+JR, 108
+LD.B, 109
+LD.BU, 110
+LD.H, 111
+LD.HU, 112
+LD.W, 113
+LDSR, 114
+MAC, 115
+MACU, 116
+MOV, 117
+MOVEA, 118
+MOVHI, 119
+MUL, 120
+MULH, 121
+MULHI, 122
+MULU, 123
+NOP, 124
+NOT, 125
+NOT1, 126
+OR, 128
+ORI, 129
+PREPARE, 130
+RETI, 132
+RIE, 134
+SAR, 135
+SASF, 137
+SATADD, 138
+SATSUB, 140
+SATSUBI, 141
+SATSUBR, 142
+SBF, 143
+SCH0L, 144
+SCH0R, 145
+SCH1L, 146
+SCH1R, 147
+SET1, 148
+SETF, 150
+SHL, 152
+SHR, 154
+SLD.B, 156
+SLD.BU, 157
+SLD.H, 158
+SLD.HU, 159
+SLD.W, 160
+SST.B, 161
+SST.H, 162
+SST.W, 163
+ST.B, 164
+ST.H, 165
+ST.W, 166
+STSR, 167
+SUB, 168
+SUBR, 169
+SWITCH, 170
+SXB, 171
+SXH, 172
+SYNCE, 173
+SYNCM, 174
+SYNCP, 175
+SYSCALL, 176
+TRAP, 178
+TST, 179
+TST1, 180
+XOR, 181
+XORI, 182
+ZXB, 183
+ZXH, 184
+
+ABSF.D, 326
+ABSF.S, 327
+ADDF.D, 328
+ADDF.S, 329
+CEILF.DL, 330
+CEILF.DUL, 331
+CEILF.DUW, 332
+CEILF.DW, 333
+CEILF.SL, 334
+CEILF.SUL, 335
+CEILF.SUW, 336
+CEILF.SW, 337
+CMOVF.D, 338
+CMOVF.S, 339
+CMPF.D, 340
+CMPF.S, 343
+CVTF.DL, 346
+CVTF.DS, 347
+CVTF.DUL, 348
+CVTF.DUW, 349
+CVTF.DW, 350
+CVTF.LD, 351
+CVTF.LS, 352
+CVTF.SD, 353
+CVTF.SL, 354
+CVTF.SUL, 355
+CVTF.SUW, 356
+CVTF.SW, 357
+CVTF.ULD, 358
+CVTF.ULS, 359
+CVTF.UWD, 360
+CVTF.UWS, 361
+CVTF.WD, 362
+CVTF.WS, 363
+DIVF.D, 364
+DIVF.S, 365
+FLOORF.DL, 366
+FLOORF.DUL, 367
+FLOORF.DUW, 368
+FLOORF.DW, 369
+FLOORF.SL, 370
+FLOORF.SUL, 371
+FLOORF.SUW, 372
+FLOORF.SW, 373
+MADDF.S, 374
+MAXF.D, 376
+MAXF.S, 377
+MINF.D, 378
+MINF.S, 379
+MSUBF.S, 380
+MULF.D, 382
+MULF.S, 383
+NEGF.D, 384
+NEGF.S, 385
+NMADDF.S, 386
+NMSUBF.S, 388
+RECIPF.D, 390
+RECIPF.S, 391
+RSQRTF.D, 392
+RSQRTF.S, 393
+SQRTF.D, 394
+SQRTF.S, 395
+SUBF.D, 396
+SUBF.S, 397
+TRFSR, 398
+TRNCF.DL, 399
+TRNCF.DUL, 400
+TRNCF.DUW, 401
+TRNCF.DW, 402
+TRNCF.SL, 403
+TRNCF.SUL, 404
+TRNCF.SUW, 405
+TRNCF.SW, 406