Skip to content

Commit 9fbc489

Browse files
committed
Initial commit
0 parents  commit 9fbc489

25 files changed

+30798
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.pdf
2+
3+
/*
4+
5+
!/src/
6+
!/data/
7+
!/README.md
8+
!/Module.manifest
9+
!/extension.properties
10+
!/build.gradle
11+
!/.gitignore

Module.manifest

Whitespace-only changes.

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ghidra Sunplus S+core7 #
2+
3+
This extension is intended to assist in the reverse engineering of the Mattle Hyperscan and implements only the features/opcodes used in the Hyperscan firmware/games.
4+
5+
6+
### Known missing features: ###
7+
* 16-bit parallel execution
8+
* rorc, rolc, roric, rolic, lcb, lcw, lce, scb, scw, sce opcodes

build.gradle

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Builds a Ghidra Extension for a given Ghidra installation.
2+
//
3+
// An absolute path to the Ghidra installation directory must be supplied either by setting the
4+
// GHIDRA_INSTALL_DIR environment variable or Gradle project property:
5+
//
6+
// > export GHIDRA_INSTALL_DIR=<Absolute path to Ghidra>
7+
// > gradle
8+
//
9+
// or
10+
//
11+
// > gradle -PGHIDRA_INSTALL_DIR=<Absolute path to Ghidra>
12+
//
13+
// Gradle should be invoked from the directory of the project to build. Please see the
14+
// application.gradle.version property in <GHIDRA_INSTALL_DIR>/Ghidra/application.properties
15+
// for the correction version of Gradle to use for the Ghidra installation you specify.
16+
17+
//----------------------START "DO NOT MODIFY" SECTION------------------------------
18+
def ghidraInstallDir
19+
20+
if (System.env.GHIDRA_INSTALL_DIR) {
21+
ghidraInstallDir = System.env.GHIDRA_INSTALL_DIR
22+
}
23+
else if (project.hasProperty("GHIDRA_INSTALL_DIR")) {
24+
ghidraInstallDir = project.getProperty("GHIDRA_INSTALL_DIR")
25+
}
26+
27+
if (ghidraInstallDir) {
28+
apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle"
29+
}
30+
else {
31+
throw new GradleException("GHIDRA_INSTALL_DIR is not defined!")
32+
}
33+
//----------------------END "DO NOT MODIFY" SECTION-------------------------------

data/README.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The "data" directory is intended to hold data files that will be used by this module and will
2+
not end up in the .jar file, but will be present in the zip or tar file. Typically, data
3+
files are placed here rather than in the resources directory if the user may need to edit them.
4+
5+
An optional data/languages directory can exist for the purpose of containing various Sleigh language
6+
specification files and importer opinion files.
7+
8+
The data/build.xml is used for building the contents of the data/languages directory.
9+
10+
The skel language definition has been commented-out within the skel.ldefs file so that the
11+
skeleton language does not show-up within Ghidra.
12+
13+
See the Sleigh language documentation (docs/languages/sleigh.htm or sleigh.pdf) for details
14+
on Sleigh language specification syntax.
15+

data/build.xml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
+ Compile sleigh languages within this module.
5+
+ Eclipse: right-click on this file and choose menu item "Run As->Ant Build"
6+
+ From command line (requires ant install)
7+
+ - cd to data directory containing this file
8+
+ - run ant
9+
-->
10+
11+
<project name="privateBuildDeveloper" default="sleighCompile">
12+
13+
<property name="sleigh.compile.class" value="ghidra.pcodeCPort.slgh_compile.SleighCompile"/>
14+
15+
<property name="repo.dir" value="../../../.." />
16+
<property name="repo.marker.dir" value="${repo.dir}/.git" />
17+
18+
<!--Import optional ant properties. GhidraDev Eclipse plugin produces this so this file can find the Ghidra installation-->
19+
<import file="../.antProperties.xml" optional="true" />
20+
21+
<condition property="devmode">
22+
<available file="${repo.marker.dir}" type="dir" />
23+
</condition>
24+
25+
<target name="buildSleighClasspathDev" if="devmode">
26+
27+
<property name="framework.path" value="${repo.dir}/../ghidra.git/Ghidra/Framework"/>
28+
<property name="libs.path" value="${repo.dir}/../ghidra.bin.git/ExternalLibraries/libsForRuntime"/>
29+
30+
<path id="sleigh.class.path">
31+
<pathelement location="${framework.path}/SoftwareModeling/bin"/>
32+
<pathelement location="${framework.path}/Generic/bin"/>
33+
<pathelement location="${framework.path}/Utility/bin"/>
34+
<fileset dir="${libs.path}">
35+
<include name="*.jar"/>
36+
</fileset>
37+
</path>
38+
39+
<available classname="${sleigh.compile.class}" classpathref="sleigh.class.path" property="sleigh.compile.exists"/>
40+
41+
</target>
42+
43+
<target name="buildSleighClasspathDist" unless="devmode">
44+
45+
<!-- If language module is detached from installation, get Ghidra installation directory path from imported properties -->
46+
<condition property="framework.path" value="${ghidra.install.dir}/Ghidra/Framework" else="../../../Framework">
47+
<available file="${ghidra.install.dir}" type="dir" />
48+
</condition>
49+
50+
<path id="sleigh.class.path">
51+
<fileset dir="${framework.path}/SoftwareModeling/lib">
52+
<include name="*.jar"/>
53+
</fileset>
54+
<fileset dir="${framework.path}/Generic/lib">
55+
<include name="*.jar"/>
56+
</fileset>
57+
<fileset dir="${framework.path}/Utility/lib">
58+
<include name="*.jar"/>
59+
</fileset>
60+
</path>
61+
<available classname="${sleigh.compile.class}" classpathref="sleigh.class.path" property="sleigh.compile.exists"/>
62+
63+
</target>
64+
65+
<target name="sleighCompile" depends="buildSleighClasspathDist, buildSleighClasspathDev">
66+
67+
<fail unless="sleigh.compile.exists" />
68+
69+
<java classname="${sleigh.compile.class}"
70+
classpathref="sleigh.class.path"
71+
fork="true"
72+
failonerror="true">
73+
<jvmarg value="-Xmx2048M"/>
74+
<arg value="-a"/>
75+
<arg value="./languages"/>
76+
</java>
77+
78+
</target>
79+
80+
</project>

data/languages/Score7.cspec

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<compiler_spec>
4+
<data_organization>
5+
<absolute_max_alignment value="0" />
6+
<machine_alignment value="2" />
7+
<default_alignment value="1" />
8+
<default_pointer_alignment value="4" />
9+
<pointer_size value="4" />
10+
<wchar_size value="4" />
11+
<short_size value="2" />
12+
<integer_size value="4" />
13+
<long_size value="4" />
14+
<long_long_size value="8" />
15+
<float_size value="4" />
16+
<double_size value="8" />
17+
<long_double_size value="8" />
18+
<size_alignment_map>
19+
<entry size="1" alignment="1" />
20+
<entry size="2" alignment="2" />
21+
<entry size="4" alignment="4" />
22+
<entry size="8" alignment="8" />
23+
</size_alignment_map>
24+
</data_organization>
25+
<global>
26+
<range space="RAM"/>
27+
</global>
28+
<stackpointer register="r0" space="RAM" growth="negative"/>
29+
<returnaddress>
30+
<varnode space="register" offset="12" size="4"/>
31+
</returnaddress>
32+
<funcptr align="2"/>
33+
<default_proto>
34+
<prototype name="__stdcall" extrapop="0" stackshift="0" strategy="register">
35+
<input>
36+
<pentry minsize="1" maxsize="4">
37+
<register name="r4"/>
38+
</pentry>
39+
<pentry minsize="1" maxsize="4">
40+
<register name="r5"/>
41+
</pentry>
42+
<pentry minsize="1" maxsize="4">
43+
<register name="r6"/>
44+
</pentry>
45+
<pentry minsize="1" maxsize="4">
46+
<register name="r7"/>
47+
</pentry>
48+
<pentry minsize="5" maxsize="8">
49+
<addr space="join" piece1="r5" piece2="r4"/>
50+
</pentry>
51+
<pentry minsize="5" maxsize="8">
52+
<addr space="join" piece1="r6" piece2="r7"/>
53+
</pentry>
54+
<pentry minsize="1" maxsize="500" align="4">
55+
<addr offset="8" space="stack"/>
56+
</pentry>
57+
</input>
58+
<output killedbycall="true">
59+
<pentry minsize="1" maxsize="4">
60+
<register name="r4"/>
61+
</pentry>
62+
<pentry minsize="5" maxsize="8">
63+
<addr space="join" piece1="r5" piece2="r4"/>
64+
</pentry>
65+
</output>
66+
<unaffected>
67+
<register name="r0"/>
68+
<register name="r2"/>
69+
<register name="r3"/>
70+
<register name="r12"/>
71+
<register name="r13"/>
72+
<register name="r14"/>
73+
<register name="r15"/>
74+
<register name="r16"/>
75+
<register name="r17"/>
76+
<register name="r18"/>
77+
<register name="r19"/>
78+
<register name="r20"/>
79+
<register name="r21"/>
80+
<register name="r28"/>
81+
<register name="r29"/>
82+
<register name="r30"/>
83+
<register name="r31"/>
84+
</unaffected>
85+
<killedbycall>
86+
<register name="r1"/>
87+
</killedbycall>
88+
</prototype>
89+
</default_proto>
90+
</compiler_spec>

data/languages/Score7.dwarf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<dwarf>
2+
<register_mappings>
3+
<register_mapping dwarf="0" ghidra="r0" stackpointer="true"/> <!-- r0 -->
4+
<register_mapping dwarf="1" ghidra="r1" auto_count="31"/> <!-- r1..r31 -->
5+
<register_mapping dwarf="49" ghidra="PC"/>
6+
<register_mapping dwarf="54" ghidra="CEH"/>
7+
<register_mapping dwarf="55" ghidra="CEL"/>
8+
</register_mappings>
9+
</dwarf>

data/languages/Score7.ldefs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<language_definitions>
4+
<language processor="Score7"
5+
endian="little"
6+
size="32"
7+
variant="default"
8+
version="1.4"
9+
slafile="Score7_le.sla"
10+
processorspec="Score7.pspec"
11+
manualindexfile="../manuals/Score7.idx"
12+
id="Score7:LE:32:default">
13+
<description>Sunplus S+core7 little endian</description>
14+
<compiler name="default" spec="Score7.cspec" id="default"/>
15+
<external_name tool="DWARF.register.mapping.file" name="Score7.dwarf"/>
16+
</language>
17+
18+
<language processor="Score7"
19+
endian="big"
20+
size="32"
21+
variant="default"
22+
version="1.4"
23+
slafile="Score7_be.sla"
24+
processorspec="Score7.pspec"
25+
manualindexfile="../manuals/Score7.idx"
26+
id="Score7:BE:32:default">
27+
<description>Sunplus S+core7 big endian</description>
28+
<compiler name="default" spec="Score7.cspec" id="default"/>
29+
<external_name tool="DWARF.register.mapping.file" name="Score7.dwarf"/>
30+
</language>
31+
</language_definitions>

data/languages/Score7.opinion

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<opinions>
2+
<constraint loader="Executable and Linking Format (ELF)" compilerSpecID="default">
3+
<constraint primary="135" processor="Score7" endian="little" size="32" />
4+
</constraint>
5+
6+
<!-- Old Sunplus S+core7 backend magic number. Written in the absence of an ABI. -->
7+
<constraint loader="Executable and Linking Format (ELF)" compilerSpecID="default">
8+
<constraint primary="95" processor="Score7" endian="little" size="32" />
9+
</constraint>
10+
</opinions>

data/languages/Score7.pspec

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<processor_spec>
4+
<programcounter register="PC"/>
5+
6+
<default_symbols>
7+
<symbol name="reset" address="RAM:9f000000" entry="true" type="code_ptr"/>
8+
</default_symbols>
9+
</processor_spec>

data/languages/Score7.sinc

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# sleigh include file for S+core7
2+
3+
define alignment=2;
4+
5+
define space RAM type=ram_space size=4 default;
6+
define space register type=register_space size=4;
7+
8+
define register offset=0x000 size=4 [ r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31 ];
9+
define register offset=0x080 size=4 [ cr0 cr1 cr2 cr3 cr4 cr5 cr6 cr7 cr8 cr9 cr10 cr11 cr12 cr13 cr14 cr15 cr16 cr17 cr18 cr19 cr20 cr21 cr22 cr23 cr24 cr25 cr26 cr27 cr28 cr29 cr30 cr31 ];
10+
define register offset=0x100 size=4 [ PC sr0 sr1 sr2 CEL CEH ];
11+
define register offset=0x180 size=1 [ V C Z N T ];
12+
13+
14+
#------------------------------------------------------------------------------
15+
# PCODEOP
16+
#------------------------------------------------------------------------------
17+
18+
define pcodeop score7_syscall;
19+
define pcodeop score7_trap;
20+
define pcodeop score7_pflush;
21+
define pcodeop score7_sleep;
22+
define pcodeop score7_cache;
23+
define pcodeop score7_sdbbp;
24+
define pcodeop score7_ceinst;
25+
26+
27+
#------------------------------------------------------------------------------
28+
# MACROS
29+
#------------------------------------------------------------------------------
30+
31+
macro setC(value, bit)
32+
{
33+
C = ((value >> bit) & 1) != 0;
34+
}
35+
36+
macro checkNZ(result)
37+
{
38+
Z = result == 0;
39+
N = result s< 0;
40+
}
41+
42+
macro checkAddCV(op1, op2)
43+
{
44+
C = carry(op1, op2);
45+
V = scarry(op1, op2);
46+
}
47+
48+
macro checkSubCV(op1, op2)
49+
{
50+
C = op1 >= op2;
51+
V = sborrow(op1, op2);
52+
}
53+
54+
macro checkAddCarryCV(op1, op2)
55+
{
56+
local tmp:4 = zext(C);
57+
C = carry(op1, op2) || carry(op1 + op2, tmp);
58+
V = scarry(op1, op2) || scarry(op1 + op2, tmp);
59+
}
60+
61+
macro checkSubCarryCV(op1, op2)
62+
{
63+
local tmp:4 = zext(C ^ 1);
64+
C = op1 >= op2 && op1 - op2 >= tmp;
65+
V = sborrow(op1, op2) || sborrow(op1 - op2, tmp);
66+
}

0 commit comments

Comments
 (0)