Skip to content

Ghidra is a software reverse engineering (SRE) framework

PIC 30 code review fixes. Changed "repeat 0x12" to "repeat 0x11". Modified plain division instructions to use pcodeops since we can't implement the normal instructions.

ghidorahrex6a75b66995e3
diff --git a/Ghidra/Processors/PIC/data/languages/PIC24.sinc b/Ghidra/Processors/PIC/data/languages/PIC24.sinc
index 77c9df2d41..de56567ad9 100644
--- a/Ghidra/Processors/PIC/data/languages/PIC24.sinc
+++ b/Ghidra/Processors/PIC/data/languages/PIC24.sinc
@@ -3562,7 +3562,7 @@ cond1: "z" is TOK_CCCC=0x2 { tmpBool:1 = (SRL_Z); export tmpBool; }
@endif
@if defined(PIC24F) || defined(PIC24H) || defined(PIC24E) || defined(dsPIC30F) || defined(dsPIC33F) || defined(dsPIC33E)
-:repeat" 0x12 div.sw" TOK_10_7_Wreg,TOK_3_0_Wreg is
+:repeat" 0x11 div.sw" TOK_10_7_Wreg,TOK_3_0_Wreg is
OP_31_0=0x090011;
OP_23_20=0xD & OP_19_16=0x8 & OP_15=0x0 & TOK_10_7_Wreg & TOK_W=0 & OP_5_4=0x0 & TOK_3_0_Wreg {
@@ -3585,22 +3585,19 @@ cond1: "z" is TOK_CCCC=0x2 { tmpBool:1 = (SRL_Z); export tmpBool; }
SRL_C = 0;
}
+define pcodeop pic30_div;
+define pcodeop pic30_rem;
:div.sw TOK_10_7_Wreg,TOK_3_0_Wreg is
OP_23_20=0xD & OP_19_16=0x8 & OP_15=0x0 & TOK_10_7_Wreg & TOK_W=0 & OP_5_4=0x0 & TOK_3_0_Wreg {
-
- # Note: this implementation is not iterative, like the actual op.
- # Rather, it will decompile accurately and emulate correctly using the Sleigh divide support.
- local div:2 = sext(TOK_10_7_Wreg) s/ sext(TOK_3_0_Wreg);
- local rem:2 = sext(TOK_10_7_Wreg) s% sext(TOK_3_0_Wreg);
+ local div:2 = pic30_div(sext(TOK_10_7_Wreg),sext(TOK_3_0_Wreg));
+ local rem:2 = pic30_rem(sext(TOK_10_7_Wreg),sext(TOK_3_0_Wreg));
W0 = div:1;
W1 = rem:1;
testSRL_N ( W1 );
-
# overflow as defined in note 2
SRL_OV = (TOK_10_7_Wreg == 0x8000) && (TOK_3_0_Wreg == 0xFFFF);
-
testSRL_Z ( W1 );
# Carry is modified, but modification is not defined, just assign to 0 for data flow analysis
@@ -3609,7 +3606,7 @@ cond1: "z" is TOK_CCCC=0x2 { tmpBool:1 = (SRL_Z); export tmpBool; }
define pcodeop isDivideOverflow;
-:repeat" 0x12 div.sd" TOK_10_8_Dregn,TOK_3_0_Wreg is
+:repeat" 0x11 div.sd" TOK_10_8_Dregn,TOK_3_0_Wreg is
OP_31_0=0x090011;
OP_23_20=0xD & OP_19_16=0x8 & OP_15=0x0 &
TOK_10_8_Dreg & TOK_10_8_Dregn & OP_7=0 & TOK_W=1 & OP_5_4=0x0 & TOK_3_0_Wreg {
@@ -3637,11 +3634,9 @@ define pcodeop isDivideOverflow;
# overflow as defined in note 2
SRL_OV = isDivideOverflow(TOK_10_8_Dreg, TOK_3_0_Wreg);
-
- # Note: this implementation is not iterative, like the actual op.
- # Rather, it will decompile accurately and emulate correctly using the Sleigh divide support.
- local div:4 = TOK_10_8_Dreg s/ sext(TOK_3_0_Wreg);
- local rem:4 = TOK_10_8_Dreg s% sext(TOK_3_0_Wreg);
+
+ local div:4 = pic30_div(sext(TOK_10_8_Dreg),sext(TOK_3_0_Wreg));
+ local rem:4 = pic30_rem(sext(TOK_10_8_Dreg),sext(TOK_3_0_Wreg));
W0 = div:2;
W1 = rem:2;
@@ -3655,15 +3650,15 @@ define pcodeop isDivideOverflow;
@if defined(PIC24F) || defined(PIC24H) || defined(PIC24E) || defined(dsPIC30F) || defined(dsPIC33F) || defined(dsPIC33E)
-:repeat" 0x12 div.uw" TOK_10_7_Wreg,TOK_3_0_Wreg is
+:repeat" 0x11 div.uw" TOK_10_7_Wreg,TOK_3_0_Wreg is
OP_31_0=0x090011;
OP_23_20=0xD & OP_19_16=0x8 & OP_15=0x1 &
TOK_10_7_Wreg & TOK_W=0 & OP_5_4=0x0 & TOK_3_0_Wreg {
# Note: this implementation is not iterative, like the actual op.
# Rather, it will decompile accurately and emulate correctly using the Sleigh divide support.
- local div:2 = sext(TOK_10_7_Wreg) / sext(TOK_3_0_Wreg);
- local rem:2 = sext(TOK_10_7_Wreg) % sext(TOK_3_0_Wreg);
+ local div:2 = zext(TOK_10_7_Wreg) / zext(TOK_3_0_Wreg);
+ local rem:2 = zext(TOK_10_7_Wreg) % zext(TOK_3_0_Wreg);
W0 = div:1;
W1 = rem:1;
@@ -3682,11 +3677,8 @@ define pcodeop isDivideOverflow;
:div.uw TOK_10_7_Wreg,TOK_3_0_Wreg is
OP_23_20=0xD & OP_19_16=0x8 & OP_15=0x1 &
TOK_10_7_Wreg & TOK_W=0 & OP_5_4=0x0 & TOK_3_0_Wreg {
-
- # Note: this implementation is not iterative, like the actual op.
- # Rather, it will decompile accurately and emulate correctly using the Sleigh divide support.
- local div:2 = sext(TOK_10_7_Wreg) / sext(TOK_3_0_Wreg);
- local rem:2 = sext(TOK_10_7_Wreg) % sext(TOK_3_0_Wreg);
+ local div:2 = pic30_div(zext(TOK_10_7_Wreg),zext(TOK_3_0_Wreg));
+ local rem:2 = pic30_rem(zext(TOK_10_7_Wreg),zext(TOK_3_0_Wreg));
W0 = div:1;
W1 = rem:1;
@@ -3702,7 +3694,7 @@ define pcodeop isDivideOverflow;
SRL_C = 0;
}
-:repeat" 0x12 div.ud" TOK_10_8_Dregn,TOK_3_0_Wreg is
+:repeat" 0x11 div.ud" TOK_10_8_Dregn,TOK_3_0_Wreg is
OP_31_0=0x090011;
OP_23_20=0xD & OP_19_16=0x8 & OP_15=0x1 &
TOK_10_8_Dreg & TOK_10_8_Dregn & OP_7=0 & TOK_W=1 & OP_5_4=0x0 & TOK_3_0_Wreg {
@@ -3731,13 +3723,12 @@ define pcodeop isDivideOverflow;
# overflow as defined in note 2
SRL_OV = isDivideOverflow(TOK_10_8_Dreg, TOK_3_0_Wreg);
- # Note: this implementation is not iterative, like the actual op.
- # Rather, it will decompile accurately and emulate correctly using the Sleigh divide support.
- local div:4 = TOK_10_8_Dreg / sext(TOK_3_0_Wreg);
- local rem:4 = TOK_10_8_Dreg % sext(TOK_3_0_Wreg);
+ local div:4 = pic30_div(zext(TOK_10_8_Dreg),zext(TOK_3_0_Wreg));
+ local rem:4 = pic30_rem(zext(TOK_10_8_Dreg),zext(TOK_3_0_Wreg));
W0 = div:2;
W1 = rem:2;
+
testSRL_N ( W1 );
testSRL_Z ( W1 );
@@ -3748,7 +3739,7 @@ define pcodeop isDivideOverflow;
@if defined(dsPIC30F) || defined(dsPIC33F) || defined(dsPIC33E)
-:repeat" 0x12 divf" TOK_14_11_Wreg,TOK_3_0_Wreg is
+:repeat" 0x11 divf" TOK_14_11_Wreg,TOK_3_0_Wreg is
OP_31_0=0x090011;
OP_23_20=0xD & OP_19_16=0x9 & OP_15=0x0 &
TOK_14_11_Wreg & OP_10_8=0x0 & OP_7_4=0x0 & TOK_3_0_Wreg {
@@ -3779,9 +3770,9 @@ define pcodeop isDivideOverflow;
# Note: this implementation is not iterative, like the actual op.
# Rather, it will decompile accurately and emulate correctly using the Sleigh divide support.
dividend:4 = (sext(TOK_14_11_Wreg) << 16);
- local tmp0:4 = dividend s/ sext(TOK_3_0_Wreg);
+ local tmp0:4 = pic30_div(dividend,zext(TOK_3_0_Wreg));
W0 = tmp0:2;
- local tmp1 = dividend s% sext(TOK_3_0_Wreg);
+ local tmp1 = pic30_rem(dividend,zext(TOK_3_0_Wreg));
W1 = tmp1:2;
testSRL_N ( W1 );