diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/README.txt b/Ghidra/Extensions/SleighDevTools/pcodetest/README.txt index 93b02bea36..e28849b495 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/README.txt +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/README.txt @@ -13,6 +13,9 @@ options needed to build the pcode test. The defaults.py script should be modified to suit your environment reflecting the installation location of your toolchains, build artifacts, etc. +Options and parameters for building individual pcodetests are contained +in the pcode_defs.py script. + USAGE ----- @@ -23,9 +26,14 @@ arguments. It is possible to build everything from scratch with this command: -./build --pcodetest-all +./build -a Typically, pcode test binaries are built individually per processor, such as: -./build --pcodetest MIPS16 +./build -t MIPS16 + +To see a list of all processor tests, run with the --list options: + +./build -l + diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/build b/Ghidra/Extensions/SleighDevTools/pcodetest/build index 0e3b899ea6..de63e96e86 100755 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/build +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/build @@ -13,7 +13,6 @@ from pcodetest import * # set default properties first, then update values from the command # line before they are instantiated. - def test_action(action_class, deprecate=False): class pcodeTestAction(action_class): def __call__(self, parser, namespace, values, option_string=None): @@ -25,7 +24,7 @@ def test_action(action_class, deprecate=False): action_class.__call__(self, parser, namespace, values, option_string) return pcodeTestAction -exec(compile(open('defaults.py', "rb").read(), 'defaults.py', 'exec')) +from defaults import * parser = argparse.ArgumentParser(description='''Build pcodetests. One and only one of the following options must be given: @@ -48,48 +47,52 @@ required_group.add_argument('--pcodetest-list', dest='list', action=test_action( # all-applicable arguments -parser.add_argument('-f', '--force', action='store_true', help='force a build') +parser.add_argument('-f', '--force', action='store_true', default=pcodeTestDefaults.force, help='force a build') parser.add_argument('-v', '--verbose', action='store_true', help='verbose output where available ') -parser.add_argument('--toolchain-root', default=PCodeTest.defaults.toolchain_root, help='directory where toolchain directories can be found (*)') -parser.add_argument('--build-root', default=PCodeTest.defaults.build_root, help='temporary directory to hold build files (*)') -parser.add_argument('--gcc-version', default=PCodeTest.defaults.gcc_version, help='default version of gcc (*)') - +parser.add_argument('--toolchain-root', default=pcodeTestDefaults.toolchain_root, help='directory where toolchain directories can be found (*)') +parser.add_argument('--build-root', default=pcodeTestDefaults.build_root, help='temporary directory to hold build files (*)') +parser.add_argument('--gcc-version', default=pcodeTestDefaults.gcc_version, help='default version of gcc (*)') +parser.add_argument('--gcc-config', default=pcodeTestDefaults.gcc_version, help='default configuration of gcc (*)') # pcodetest arguments pcodetest_group = parser.add_argument_group('Pcodetest Options') pcodetest_group.add_argument('--no-publish', action='store_true', help='do not publish pcode test binaries to pcode test root') -pcodetest_group.add_argument('--pcodetest-root', default=PCodeTest.defaults.pcodetest_root, help='location to publish pcode tests binaries (*)') -pcodetest_group.add_argument('--pcodetest-src', default=PCodeTest.defaults.pcodetest_src, help='location of pcode test .c and .h source files (*)') -pcodetest_group.add_argument('--skip-files', nargs='+', default=PCodeTest.defaults.skip_files, help='default .c files to remove from the pcode test image (*)') +pcodetest_group.add_argument('--export-root', default=pcodeTestDefaults.export_root, help='location to publish pcode tests binaries (*)') +pcodetest_group.add_argument('--pcodetest-src', default=pcodeTestDefaults.pcodetest_src, help='location of pcode test .c and .h source files (*)') +pcodetest_group.add_argument('--skip-files', nargs='+', default=pcodeTestDefaults.skip_files, help='default .c files to remove from the pcode test image (*)') pcodetest_group.add_argument('--strip-symbols', action='store_true', help='strip symbols from image') pcodetest_group.add_argument('--add-ccflags', default='', help='additional flags to pass to compiler (must be quoted)') +pcodetest_group.add_argument('--gcc-libdir', default='', help='location of gcc libraries') +pcodetest_group.add_argument('--add-cclibs', default='', help='additional libraries to pass to the linker') pcodetest_group.add_argument('--add-info', action='store_true', help='add data to binary with information about types and symbols') pcodetest_group.add_argument('--build-exe', action='store_true', help='build a guest executable binary (exe)') -pcodetest_group.add_argument('--variants', default=json.dumps(PCodeTest.defaults.variants, sort_keys=True, separators=(',',':')), type=json.loads, help='build the (optimization) variants, encoded as a json dict') +pcodetest_group.add_argument('--variants', default=json.dumps(pcodeTestDefaults.variants, sort_keys=True, separators=(',',':')), type=json.loads, help='build the (optimization) variants, encoded as a json dict') sys.argv.pop(0) args = parser.parse_args(sys.argv) -PCodeTest.defaults.skip_files = args.skip_files -PCodeTest.defaults.pcodetest_root = args.pcodetest_root -PCodeTest.defaults.pcodetest_src = args.pcodetest_src -PCodeTest.defaults.strip_symbols = args.strip_symbols -PCodeTest.defaults.add_ccflags = args.add_ccflags -PCodeTest.defaults.add_info = args.add_info -PCodeTest.defaults.build_exe = args.build_exe -PCodeTest.defaults.variants = args.variants -PCodeTest.defaults.verbose = args.verbose -PCodeTest.defaults.force = args.force -PCodeTest.defaults.no_publish = args.no_publish -PCodeTest.defaults.toolchain_root = args.toolchain_root -PCodeTest.defaults.build_root = args.build_root -PCodeTest.defaults.gcc_version = args.gcc_version +pcodeTestDefaults.skip_files = args.skip_files +pcodeTestDefaults.export_root = args.export_root +pcodeTestDefaults.pcodetest_src = args.pcodetest_src +pcodeTestDefaults.strip_symbols = args.strip_symbols +pcodeTestDefaults.add_ccflags = args.add_ccflags +pcodeTestDefaults.gcc_libdir = args.gcc_libdir +pcodeTestDefaults.add_cclibs = args.add_cclibs +pcodeTestDefaults.add_info = args.add_info +pcodeTestDefaults.build_exe = args.build_exe +pcodeTestDefaults.variants = args.variants +pcodeTestDefaults.verbose = args.verbose +pcodeTestDefaults.force = args.force +pcodeTestDefaults.no_publish = args.no_publish +pcodeTestDefaults.toolchain_root = args.toolchain_root +pcodeTestDefaults.build_root = args.build_root +pcodeTestDefaults.gcc_version = args.gcc_version +pcodeTestDefaults.gcc_config = args.gcc_config # load the known pcodetests - -exec(compile(open('pcode_defs.py', "rb").read(), 'pcode_defs.py', 'exec')) +from pcode_defs import * cwd = os.getcwd() diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/build.py b/Ghidra/Extensions/SleighDevTools/pcodetest/build.py index 00023bfcc5..68f9a6483a 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/build.py +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/build.py @@ -1,17 +1,17 @@ ## ### -# IP: GHIDRA -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. ## import os import shutil @@ -20,6 +20,7 @@ import sys import pwd import grp import re +from types import SimpleNamespace class BuildUtil: @@ -286,7 +287,10 @@ class Config: def format(self, val): if isinstance(val, str) and '%' in val: - return val % self.__dict__ + try: + return val % self.__dict__ + except KeyError: + return val elif isinstance(val, dict): return {k: self.format(v) for k, v in val.items()} else: return val diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/arm/arm_BODY.c b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/arm/arm_BODY.c index 35c5c44803..3968ed53d6 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/arm/arm_BODY.c +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/arm/arm_BODY.c @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,23 +21,35 @@ u4 u4_adc_carry(u4 a, u4 b, u1 carry) u4 x = 0xffffffff; u4 y = 1; if (carry == 1) { - __asm__( + __asm__( ".syntax unified\n" +#ifdef THUMB + "adds %[x_res],%[y]\n" /* set the carry flag */ +#else "adds %[x_res],%[x],%[y]\n" /* set the carry flag */ +#endif : [x_res] "=r" (x) : [x] "r" (x), [y] "r" (y) ); } else { __asm__( ".syntax unified\n" +#ifdef THUMB + "adds %[x_res],%[y]\n" /* clear the carry flag */ +#else "adds %[x_res],%[y],%[y]\n" /* clear the carry flag */ +#endif : [x_res] "=r" (x) : [y] "r" (y) ); } __asm__( ".syntax unified\n" +#ifdef THUMB + "adcs %[input_a],%[input_b]\n" +#else "adcs %[input_a],%[input_a],%[input_b]\n" +#endif "bcc adc_nocarry\n" "ldr %[result], =0x1\n" "b adc_end\n" @@ -58,21 +70,33 @@ u4 u4_adc_overflow(u4 a, u4 b, u1 carry) if (carry == 1) { __asm__( ".syntax unified\n" - "adds %[x_res],%[x],%[y]\n" /* set the carry flag */ +#ifdef THUMB + "adds %[x_res],%[y]\n" /* clear the carry flag */ +#else + "adds %[x_res],%[y],%[y]\n" /* clear the carry flag */ +#endif : [x_res] "=r" (x) : [x] "r" (x), [y] "r" (y) ); } else { __asm__( ".syntax unified\n" +#ifdef THUMB + "adds %[x_res],%[y]\n" /* clear the carry flag */ +#else "adds %[x_res],%[y],%[y]\n" /* clear the carry flag */ +#endif : [x_res] "=r" (x) : [y] "r" (y) ); } __asm__( ".syntax unified\n" - "adcs %[input_a],%[input_a],%[input_b], lsr #1\n" +#ifdef THUMB + "adcs %[input_a],%[input_b]\n" +#else + "adcs %[input_a],%[input_a],%[input_b]\n" +#endif "bvc adc_noover\n" "ldr %[result], =0x1\n" "b adc_o_end\n" diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/types.h b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/types.h index d02681a4ee..96a673e2ec 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/types.h +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/types.h @@ -4,15 +4,17 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ + + #if defined(__GNUC__) && !defined(__llvm__) #define HAS_GNU_ATTRIBUTES 1 @@ -82,192 +84,110 @@ #define IS_COMPILER_UNKNOWN #endif -#if defined(IS_COMPILER_UNKNOWN) || defined(IS_COMPILER_PRE48_GCC) - -/* Catch specific platforms */ -#ifdef __AVR_ARCH__ /* defined(IS_COMPILER_UNKNOWN) || defined(IS_COMPILER_PRE48_GCC) && defined(__AVR_ARCH__) */ -typedef unsigned char u1; -typedef signed char i1; -typedef unsigned short u2; -typedef signed short i2; -typedef unsigned long u4; -typedef signed long i4; -typedef long long i8; -typedef unsigned long long u8; -typedef float f4; -#ifdef HAS_DOUBLE -#endif -typedef i4 size_t; -#elif __AVR32__ -typedef unsigned char u1; -typedef signed char i1; -typedef unsigned short u2; -typedef signed short i2; -typedef unsigned int u4; -typedef signed int i4; -#ifdef HAS_LONGLONG -typedef long long i8; -#endif -#if defined(HAS_LONGLONG) || defined(HAS__DOUBLE) -typedef unsigned long long u8; -#endif -#ifdef HAS_FLOAT -typedef float f4; -#endif -#ifdef HAS_DOUBLE -typedef double f8; -#endif - -typedef __SIZE_TYPE__ size_t; -#else /* defined(IS_COMPILER_UNKNOWN) || defined(IS_COMPILER_PRE48_GCC) && !defined(__AVR_ARCH__) */ -/* This is for non-GNU non CodeComposerStudio generic case. */ -typedef unsigned char u1; -typedef signed char i1; -typedef unsigned short u2; -typedef signed short i2; -#ifdef INT4_IS_LONG -typedef unsigned long u4; -typedef signed long i4; +#if defined(U1) +typedef U1 u1; #else -typedef unsigned int u4; -typedef signed int i4; -#endif -#ifdef HAS_LONGLONG -typedef long long i8; -#endif -#if defined(HAS_LONGLONG) || defined(HAS__DOUBLE) -typedef unsigned long long u8; -#endif -#ifdef HAS_FLOAT -typedef float f4; -#endif -#ifdef HAS_DOUBLE -#ifdef dsPIC30 -typedef long double f8; -#else -typedef double f8; -#endif -#endif - -#ifdef HAS_LONGLONG -typedef i8 size_t; -#else -typedef i4 size_t; -#endif -#endif - -#endif /* #if defined(IS_COMPILER_UNKNOWN) || defined(IS_COMPILER_PRE48_GCC) */ - -/* For CodeComposerStudio */ -#if defined(IS_COMPILER_CODECOMPOSERSTUDIO) - -#if defined(__MSP430__) /* defined(IS_COMPILER_CODECOMPOSERSTUDIO) && defined(__MSP430__) */ - -typedef unsigned char u1; -typedef signed char i1; -typedef unsigned short u2; -typedef signed short i2; -typedef unsigned long u4; -typedef signed long i4; - -#undef HAS_FLOAT -#undef HAS_DOUBLE -#undef HAS_LONGLONG -#undef HAS_GNU_ATTRIBUTES - -typedef unsigned int size_t; - -#endif /* #if defined(__MSP430__) */ - -#endif /* #if defined(IS_COMPILER_CODECOMPOSERSTUDIO) */ - -/* For GNU compilers */ -/* Modern GNU compilers > 4.7 have size macros to uses to give us definitions. */ - -#if defined(IS_COMPILER_POST48_GCC) - -typedef __SIZE_TYPE__ size_t; - -typedef __INT8_TYPE__ i1; -typedef __INT16_TYPE__ i2; -typedef __INT32_TYPE__ i4; -#if defined(__INT64_TYPE__) -#ifdef HAS_LONGLONG -typedef __INT64_TYPE__ i8; -#endif -#endif - +#if defined(__UINT8_TYPE__) typedef __UINT8_TYPE__ u1; +#else +typedef unsigned char u1; +#endif +#endif + +#if defined(I1) +typedef I1 i1; +#else +#if defined(__INT8_TYPE__) +typedef __INT8_TYPE__ i1; +#else +typedef signed char i1; +#endif +#endif + +#if defined(U2) +typedef U2 u2; +#else +#if defined(__UINT16_TYPE__) typedef __UINT16_TYPE__ u2; +#else +typedef unsigned short u2; +#endif +#endif + +#if defined(I2) +typedef I2 i2; +#else +#if defined(__INT16_TYPE__) +typedef __INT16_TYPE__ i2; +#else +typedef signed short i2; +#endif +#endif + +#if defined(U4) +typedef U4 u4; +#else +#if defined(__UINT32_TYPE__) typedef __UINT32_TYPE__ u4; +#else +typedef unsigned long u4; +#endif +#endif + +#if defined(I4) +typedef I4 i4; +#else +#if defined(__INT32_TYPE__) +typedef __INT32_TYPE__ i4; +#else +typedef signed long i4; +#endif +#endif + +#if defined(U8) +typedef U8 u8; +#else #if defined(__UINT64_TYPE__) typedef __UINT64_TYPE__ u8; +#else +typedef unsigned long long u8; +#endif #endif -#ifdef __SIZEOF_FLOAT__ -#ifdef HAS_FLOAT +#if defined(I8) +typedef I8 i8; +#else +#if defined(__INT64_TYPE__) +typedef __INT64_TYPE__ i8; +#else +typedef signed long long i8; +#endif +#endif + +#if defined(F4) +typedef F4 f4; +#else typedef float f4; #endif -#endif -#ifdef __SIZEOF_DOUBLE__ -#ifdef HAS_DOUBLE +#if defined(F8) +typedef F8 f8; +#else typedef double f8; #endif + +#if defined(F16) +typedef F16 f16; +#else +typedef long double f16; #endif -#define TYPES_ARE_DEFINED 1 -#endif /* #if defined(IS_COMPILER_POST48_GCC) */ -/* Microsoft VisualC++ compiler */ -#if defined(IS_COMPILER_MSVC) - -/* ARM on Visual C++ */ -#if defined(_M_ARM_FP) /* defined(IS_COMPILER_MSVC) && defined(_M_ARM_FP) */ -typedef unsigned char u1; -typedef signed char i1; -typedef unsigned short u2; -typedef signed short i2; -typedef unsigned long u4; -typedef signed long i4; - -#undef HAS_FLOAT -#undef HAS_DOUBLE -#undef HAS_LONGLONG -#undef HAS_GNU_ATTRIBUTES - -typedef unsigned int size_t; - -#endif /* #if defined(IS_COMPILER_MSVC) */ - -#endif /* #if defined(_M_ARM_FP) */ +#if defined(__SIZE_TYPE__) +typedef __SIZE_TYPE__ size_t; +#else #ifdef IS_COMPILER_LLVM -typedef unsigned char u1; -typedef signed char i1; -typedef unsigned short u2; -typedef signed short i2; -typedef unsigned __INT32_TYPE__ u4; -typedef signed __INT32_TYPE__ i4; -#ifdef __INT64_TYPE__ -typedef unsigned long long u8; -typedef signed long long i8; -#define HAS_LONGLONG -#else -#undef HAS_LONGLONG -#endif /* LONGLONG */ -#ifdef __SIZEOF_FLOAT__ -typedef float f4; -#define HAS_FLOAT -#else -#undef HAS_FLOAT -#endif /* FLOAT */ -#ifdef __SIZEOF_DOUBLE__ -typedef double f8; -#define HAS_DOUBLE -#else -#undef HAS_DOUBLE -#endif /* DOUBLE */ /* __is_identifier __has_feature */ #ifdef __has_feature /* LLVM clang magic (see clang docs) */ @@ -290,7 +210,26 @@ typedef i1 size_t; #pragma message "has NOT __has_feature" #endif /* #ifdef __has_feature */ +#else + +#if defined(HAS_LONGLONG) +typedef u8 size_t; +#else +typedef u4 size_t; +#endif /* HAS_LONGLONG */ #endif /* #ifdef IS_COMPILER_LLVM */ +#endif /* defined(__SIZE_TYPE__) */ + + +/* For CodeComposerStudio */ +#if defined(IS_COMPILER_CODECOMPOSERSTUDIO) || defined(IS_COMPILER_MSVC) + +#undef HAS_GNU_ATTRIBUTES + +#endif /* #if defined(IS_COMPILER_CODECOMPOSERSTUDIO) || defined(IS_COMPILER_MSVC) */ + + + /* Simulated limit.h */ #define U1_MAX 0xFF diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/defaults.py b/Ghidra/Extensions/SleighDevTools/pcodetest/defaults.py index e397992c1f..91cd62de33 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/defaults.py +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/defaults.py @@ -1,51 +1,58 @@ ## ### -# IP: GHIDRA -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. ## # Default values can be modified here, or (in # some cases) on the build command line (see ./build --help) -# PCodeTest.defaults that can be overridden on command line +# defaults that can be overridden on command line -PCodeTest.defaults.toolchain_root = '/local/ToolChains' -PCodeTest.defaults.build_root = '/local/build-pcodetest' -PCodeTest.defaults.gcc_version = '9.2.0' -PCodeTest.defaults.skip_files = [] -PCodeTest.defaults.export_root = os.getcwd() + '/../../../../../ghidra.bin/Ghidra/Test/TestResources/data/pcodetests/' -PCodeTest.defaults.pcodetest_src = os.getcwd() + '/c_src' +from types import SimpleNamespace +import os -# PCodeTest.defaults that cannot be overridden on the command line +filePath = os.path.abspath(os.path.dirname(__file__)) +pcodeTestDefaults = SimpleNamespace() + +pcodeTestDefaults.toolchain_root = '/data/ToolChains' +pcodeTestDefaults.build_root = '/data/build' +pcodeTestDefaults.gcc_version = 'latest' +pcodeTestDefaults.gcc_config = pcodeTestDefaults.gcc_version +pcodeTestDefaults.skip_files = [] +pcodeTestDefaults.export_root = os.path.join(filePath, '../../../../../ghidra.bin/Ghidra/Test/TestResources/data/pcodetests/') +pcodeTestDefaults.pcodetest_src = os.path.join(filePath, 'c_src') +# defaults that cannot be overridden on the command line # These are set by processor test definitions in the pcode_defs.py file -PCodeTest.defaults.build_all = 0 -PCodeTest.defaults.ccflags = '' -PCodeTest.defaults.has_decimal128 = 0 -PCodeTest.defaults.has_decimal32 = 0 -PCodeTest.defaults.has_decimal64 = 0 -PCodeTest.defaults.has_double = 1 -PCodeTest.defaults.has_float = 1 -PCodeTest.defaults.has_longlong = 1 -PCodeTest.defaults.has_shortfloat = 0 -PCodeTest.defaults.has_vector = 0 -PCodeTest.defaults.small_build = 0 -PCodeTest.defaults.ld_library_path = '' -PCodeTest.defaults.toolchain_type = 'gcc' -PCodeTest.defaults.compile_exe = 'bin/gcc' -PCodeTest.defaults.objdump_exe = 'bin/objdump' -PCodeTest.defaults.objdump_option = '' -PCodeTest.defaults.readelf_exe = 'bin/readelf' -PCodeTest.defaults.nm_exe = 'bin/nm' -PCodeTest.defaults.strip_exe = 'bin/strip' -PCodeTest.defaults.variants = {'O0': '-O0', 'O3': '-O3'} -PCodeTest.defaults.proc_test = '' - +pcodeTestDefaults.build_all = 0 +pcodeTestDefaults.ccflags = '' +pcodeTestDefaults.cclibs = '' +pcodeTestDefaults.has_decimal128 = 0 +pcodeTestDefaults.has_decimal32 = 0 +pcodeTestDefaults.has_decimal64 = 0 +pcodeTestDefaults.has_double = 1 +pcodeTestDefaults.has_float = 1 +pcodeTestDefaults.has_longlong = 1 +pcodeTestDefaults.has_shortfloat = 0 +pcodeTestDefaults.has_vector = 0 +pcodeTestDefaults.small_build = 0 +pcodeTestDefaults.ld_library_path = '' +pcodeTestDefaults.toolchain_type = 'gcc' +pcodeTestDefaults.compile_exe = 'bin/gcc' +pcodeTestDefaults.objdump_exe = 'bin/objdump' +pcodeTestDefaults.objdump_option = '' +pcodeTestDefaults.readelf_exe = 'bin/readelf' +pcodeTestDefaults.nm_exe = 'bin/nm' +pcodeTestDefaults.strip_exe = 'bin/strip' +pcodeTestDefaults.variants = {'O0': '-O0', 'O3': '-O3'} +pcodeTestDefaults.proc_test = '' +pcodeTestDefaults.force = False diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py b/Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py index 10f2658e68..6c9ddaa373 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py @@ -1,20 +1,21 @@ ## ### -# IP: GHIDRA -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. ## # The available pcode tests are recorded here as instances of the 'name' # python class. +from pcodetest import PCodeTest PCodeTest({ 'name': 'ARM', @@ -23,7 +24,7 @@ PCodeTest({ 'qemu_command': 'qemu-arm', 'toolchain': 'ARM/arm-eabi', 'language_id': 'ARM:LE:32:v7', - 'ccflags': '-L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s -lgcc', + 'cclibs': '-lgcc', 'proc_test': 'arm', }) @@ -34,7 +35,8 @@ PCodeTest({ 'qemu_command': 'qemu-armbe', 'toolchain': 'ARM/armbe-eabi', 'language_id': 'ARM:BE:32:v7', - 'ccflags': '-mbig-endian -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s -lgcc', + 'ccflags': '-mbig-endian', + 'cclibs': '-lgcc', 'proc_test': 'arm', 'has_float': 0, 'has_double': 0, @@ -45,7 +47,8 @@ PCodeTest({ PCodeTest({ 'name': 'ARM2', 'toolchain': 'ARM/arm-eabi', - 'ccflags': '-mcpu=arm2 -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=arm2', + 'cclibs': '-lgcc', 'language_id': 'ARM:LE:32:v7', 'proc_test': 'arm', }) @@ -57,13 +60,27 @@ PCodeTest({ 'qemu_command': 'qemu-arm', 'toolchain': 'ARM/arm-eabi', 'language_id': 'ARM:LE:32:v5', - 'ccflags': '-march=armv5 -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s -lgcc', + 'gcc_version': '7.3.0', + 'ccflags': '-march=armv5', + 'cclibs': '-lgcc', +}) + +PCodeTest({ + 'name': 'ARMv6', + 'build_all': 1, + 'build_exe': 1, + 'qemu_command': 'qemu-arm', + 'toolchain': 'ARM/arm-eabi', + 'language_id': 'ARM:LE:32:v6', + 'ccflags': '-march=armv6+fp', + 'cclibs': '-lgcc', }) PCodeTest({ 'name': 'ARM7', 'toolchain': 'ARM/arm-eabi', - 'ccflags': '-mcpu=arm7 -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s -lgcc', + 'ccflags': '-march=armv7-a+simd', + 'cclibs': '-lgcc', 'language_id': 'ARM:LE:32:v7', 'proc_test': 'arm', }) @@ -71,7 +88,8 @@ PCodeTest({ PCodeTest({ 'name': 'ARM8', 'toolchain': 'ARM/arm-eabi', - 'ccflags': '-mcpu=arm8 -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=arm8', + 'cclibs': '-lgcc', 'language_id': 'ARM:LE:32:v7', 'proc_test': 'arm', }) @@ -79,7 +97,8 @@ PCodeTest({ PCodeTest({ 'name': 'ARM9', 'toolchain': 'ARM/arm-eabi', - 'ccflags': '-mcpu=arm9 -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=arm9', + 'cclibs': '-lgcc', 'language_id': 'ARM:LE:32:v7', 'proc_test': 'arm', }) @@ -90,7 +109,8 @@ PCodeTest({ 'build_exe': 1, 'qemu_command': 'qemu-arm', 'toolchain': 'ARM/arm-eabi', - 'ccflags': '-mcpu=arm10e -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=arm10e', + 'cclibs': '-lgcc', 'language_id': 'ARM:LE:32:v7', 'proc_test': 'arm', }) @@ -101,7 +121,9 @@ PCodeTest({ 'build_exe': 1, 'qemu_command': 'qemu-arm -cpu cortex-a8', 'toolchain': 'ARM/arm-eabi', - 'ccflags': '-mthumb -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s/thumb -lgcc', + 'ccflags': '-mthumb -DTHUMB -march=armv7-a+simd', + 'gcc_libdir': '%(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s/thumb', + 'cclibs': '-lgcc', 'language_id': 'ARM:LE:32:v7', 'proc_test': 'arm', }) @@ -110,7 +132,9 @@ PCodeTest({ 'name': 'ARM_BE_thumb', 'build_all': 1, 'toolchain': 'ARM/armbe-eabi', - 'ccflags': '-mthumb -mbig-endian -L %(toolchain_dir)s/lib/gcc/armbe-eabi/%(gcc_version)s/thumb -lgcc', + 'ccflags': '-mthumb -DTHUMB -mbig-endian', + 'gcc_libdir': '%(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s/thumb', + 'cclibs': '-lgcc', 'language_id': 'ARM:BE:32:v7', 'proc_test': 'arm', 'has_float': 0, @@ -124,7 +148,9 @@ PCodeTest({ 'build_exe': 1, 'qemu_command': 'qemu-arm -cpu cortex-a8', 'toolchain': 'ARM/arm-eabi', - 'ccflags': '-mthumb -mcpu=cortex-a8 -mfloat-abi=softfp -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s/thumb -lgcc', + 'ccflags': '-mthumb -DTHUMB -mcpu=cortex-a8 -mfloat-abi=softfp', + 'gcc_libdir': '%(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s/thumb', + 'cclibs': '-lgcc', 'language_id': 'ARM:LE:32:v7', 'proc_test': 'arm', }) @@ -135,7 +161,9 @@ PCodeTest({ 'build_exe': 1, 'qemu_command': 'qemu-arm -cpu cortex-m33', 'toolchain': 'ARM/arm-eabi', - 'ccflags': '-mthumb -march=armv8-m.main -mfloat-abi=softfp -L %(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s/thumb -lgcc', + 'ccflags': '-mthumb -DTHUMB -march=armv8-m.main -mfloat-abi=softfp', + 'gcc_libdir': '%(toolchain_dir)s/lib/gcc/arm-eabi/%(gcc_version)s/thumb', + 'cclibs': '-lgcc', 'language_id': 'ARM:LE:32:Cortexv8m', }) @@ -174,6 +202,7 @@ PCodeTest({ 'build_all': 1, 'toolchain': 'AVR/avr-elf', 'ccflags': '-mmcu=avr6 -lgcc', + 'cclibs': '-lgcc', 'language_id': 'avr32:BE:32:default', 'processor': 'Atmel', 'has_float': 0, @@ -184,6 +213,7 @@ PCodeTest({ 'name': 'AVR8_31', 'toolchain': 'AVR/avr-elf', 'ccflags': '-mmcu=avr31 -lgcc', + 'cclibs': '-lgcc', 'language_id': 'avr8:LE:16:default', 'has_float': 0, 'has_double': 0, @@ -206,6 +236,7 @@ PCodeTest({ 'name': 'AVR8_6', 'toolchain': 'AVR/avr-elf', 'ccflags': '-mmcu=avr6 -lgcc', + 'cclibs': '-lgcc', 'language_id': 'avr8:LE:16:atmega256', 'has_float': 0, 'has_double': 0, @@ -223,7 +254,19 @@ PCodeTest({ 'name': 'HPPA1.1', 'build_all': 1, 'toolchain': 'HPPA/hppa-linux', - 'ccflags': '-march=1.1 -static -mlong-calls -L %(toolchain_dir)s/lib/gcc/hppa-linux/%(gcc_version)s -lgcc', + 'ccflags': '-march=1.1 -static -mlong-calls', + 'cclibs': '-lgcc', + 'language_id': 'pa-risc:BE:32:default', + 'processor': 'PA-RISC', + 'architecture_test': 'PARISC', +}) + +PCodeTest({ + 'name': 'HPPA2.0', + 'build_all': 1, + 'toolchain': 'HPPA/hppa-linux', + 'ccflags': '-march=2.0 -static -mlong-calls', + 'cclibs': '-lgcc', 'language_id': 'pa-risc:BE:32:default', 'processor': 'PA-RISC', 'architecture_test': 'PARISC', @@ -233,11 +276,9 @@ PCodeTest({ 'name': 'Loongarch64', 'build_all': 1, 'build_exe': 0, - 'gcc_version': '12.3.0', 'qemu_command': 'qemu-loongarch64', - 'target': 'loongson-linux', - 'toolchain': '%(name)s/%(target)s', #%(toolchain_dir)s/lib/gcc/loongarch64-linux/%(gcc_version)s - 'ccflags': '-march=loongarch64 -mabi=lp64d -L /local/cross/lib/gcc/loongarch64-linux/12.3.0/ -lgcc', + 'toolchain': 'LoongArch/loongarch64-linux-gnu', + 'ccflags': '-march=loongarch64 -mabi=lp64d', 'language_id': 'Loongarch:LE:64:default', #'has_longlong': 0, }) @@ -249,8 +290,9 @@ PCodeTest({ 'gcc_version': '12.3.0', 'qemu_command': 'qemu-loongarch64', 'target': 'loongson-linux', - 'toolchain': 'Loongarch64/%(target)s', #%(toolchain_dir)s/lib/gcc/loongarch64-linux/%(gcc_version)s - 'ccflags': '-march=loongarch64 -mabi=lp64f -mfpu=32 -L /local/cross/lib/gcc/loongarch64-linux/12.3.0/ -lgcc', + 'toolchain': 'LoongArch/loongarch64-linux-gnu', + 'ccflags': '-march=loongarch64 -mabi=lp64f', + #'cclibs': '-lgcc', 'language_id': 'Loongarch:LE:64:lp64f', 'has_double': 0, }) @@ -264,7 +306,8 @@ PCodeTest({ 'build_exe': 0, 'qemu_command': 'qemu-m68k', # qemu: fatal: Illegal instruction 'toolchain': 'm68k/m68k-elf', - 'ccflags': '-mcpu=68020 -m68020 -L %(toolchain_dir)s/lib/gcc/m68k-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=68020 -m68020', + 'cclibs': '-lgcc', 'language_id': '68000:BE:32:default', }) @@ -274,7 +317,9 @@ PCodeTest({ 'build_exe': 1, 'qemu_command': 'qemu-mips', 'toolchain': 'MIPS/mips-elf', - 'ccflags': '-L %(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_version)s -lgcc -mno-gpopt', + 'ccflags': '-mno-gpopt', + 'gcc_libdir': '%(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_actual_version)s', + 'cclibs': '-lgcc', 'language_id': 'MIPS:BE:32:default', }) @@ -283,7 +328,9 @@ PCodeTest({ 'build_all': 1, 'build_exe': 1, 'toolchain': 'MIPS/mips-elf', - 'ccflags': '-L %(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_version)s/el -lgcc -mno-gpopt -mel', + 'ccflags': '-mno-gpopt -mel', + 'gcc_libdir': '%(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_actual_version)s/el', + 'cclibs': '-lgcc', 'language_id': 'MIPS:LE:32:default', }) @@ -317,7 +364,9 @@ PCodeTest({ 'name': 'MIPSMIC', 'build_all': 1, 'toolchain': 'MIPS/mips-elf', - 'ccflags': '-mmicromips -L %(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_version)s/micromips -lgcc', + 'ccflags': '-mmicromips', + 'gcc_libdir': '%(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_actual_version)s/micromips', + 'cclibs': '-lgcc', 'language_id': 'MIPS:BE:32:micro', 'architecture_test': 'MIPSMICRO', }) @@ -326,7 +375,9 @@ PCodeTest({ 'name': 'MIPSMICMIX', 'build_all': 1, 'toolchain': 'MIPS/mips-elf', - 'ccflags': '-minterlink-compressed -D BODYNEW=micromips -L %(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_version)s/micromips -lgcc', + 'ccflags': '-minterlink-compressed -D BODYNEW=micromips', + 'gcc_libdir': '%(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_actual_version)s/micromips', + 'cclibs': '-lgcc', 'language_id': 'MIPS:BE:32:micro', 'architecture_test': 'MIPSMICROMIX', }) @@ -367,7 +418,9 @@ PCodeTest({ 'name': 'MIPSR6', 'build_all': 1, 'toolchain': 'MIPS/mipsr6-elf', - 'ccflags': '-mips32r6 -L %(toolchain_dir)s/lib/gcc/mips-mti-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mips32r6', + 'gcc_libdir': '-L %(toolchain_dir)s/lib/gcc/mips-img-elf/%(gcc_actual_version)s', + 'cclibs': '-lgcc', 'language_id': 'MIPS:BE:32:R6', }) @@ -383,7 +436,8 @@ PCodeTest({ 'name': 'NDS32BE', 'build_all': 1, 'toolchain': 'NDS32/nds32be-elf', - 'ccflags': '-L %(toolchain_dir)s/lib/gcc/nds32be-linux-elf/%(gcc_version)s -lgcc', + 'ccflags': '', + 'cclibs': '-lgcc', 'language_id': 'NDS32:BE:32:default', }) @@ -391,14 +445,16 @@ PCodeTest({ 'name': 'NDS32LE', 'build_all': 1, 'toolchain': 'NDS32/nds32le-elf', - 'ccflags': '-L %(toolchain_dir)s/lib/gcc/nds32le-linux-elf/%(gcc_version)s -lgcc', + 'ccflags': '', + 'cclibs': '-lgcc', 'language_id': 'NDS32:LE:32:default', }) PCodeTest({ 'name': 'power6', 'toolchain': 'PPC/powerpc-elf', - 'ccflags': '-mcpu=G5 -m32 -mno-relocatable -L %(toolchain_dir)s/lib/gcc/powerpc-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=G5 -m32 -mno-relocatable', + 'cclibs': '-lgcc', 'language_id': 'PowerPC:BE:32:default', }) @@ -408,7 +464,8 @@ PCodeTest({ 'build_exe': 1, 'qemu_command': 'qemu-ppc64abi32', 'toolchain': 'PPC/powerpc-elf', - 'ccflags': '-mcpu=powerpc -m32 -maltivec -mno-relocatable -L %(toolchain_dir)s/lib/gcc/powerpc-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=powerpc -m32 -maltivec -mno-relocatable', + 'cclibs': '-lgcc', 'language_id': 'PowerPC:BE:32:default', 'architecture_test': 'PPC', }) @@ -419,7 +476,8 @@ PCodeTest({ 'build_exe': 1, 'qemu_command': 'qemu-ppc64', 'toolchain': 'PPC/powerpc64-linux', - 'ccflags': '-mabi=elfv1 -maltivec -mno-relocatable -L %(toolchain_dir)s/lib/gcc/powerpc-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mabi=elfv1 -maltivec -mno-relocatable', + 'cclibs': '-lgcc', 'language_id': 'PowerPC:BE:64:default', 'architecture_test': 'PPC64', }) @@ -427,7 +485,8 @@ PCodeTest({ PCodeTest({ 'name': 'powerpc64v2', 'toolchain': 'PPC/powerpc64-linux', - 'ccflags': '-mabi=elfv2 -maltivec -mno-relocatable -L %(toolchain_dir)s/lib/gcc/powerpc-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mabi=elfv2 -maltivec -mno-relocatable', + 'cclibs': '-lgcc', 'language_id': 'PowerPC:BE:64:default', }) @@ -435,7 +494,8 @@ PCodeTest({ 'name': 'ppcA2', 'build_all': 1, 'toolchain': 'PPC/powerpc-elf', - 'ccflags': '-mcpu=a2 -L %(toolchain_dir)s/lib/gcc/powerpc-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=a2', + 'cclibs': '-lgcc', 'language_id': 'PowerPC:BE:32:A2', 'architecture_test': 'PPCA2', }) @@ -444,7 +504,8 @@ PCodeTest({ 'name': 'ppcA2Alt', 'build_all': 1, 'toolchain': 'PPC/powerpc-elf', - 'ccflags': '-mcpu=a2 -maltivec -L %(toolchain_dir)s/lib/gcc/powerpc-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=a2 -maltivec', + 'cclibs': '-lgcc', 'language_id': 'PowerPC:BE:32:A2ALT', 'architecture_test': 'PPCA2Alt', }) @@ -453,7 +514,8 @@ PCodeTest({ 'name': 'ppcP8Alt', 'build_all': 1, 'toolchain': 'PPC/powerpc-elf', - 'ccflags': '-mcpu=power8 -mvsx -maltivec -L %(toolchain_dir)s/lib/gcc/powerpc-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=power8 -mvsx -maltivec', + 'cclibs': '-lgcc', 'language_id': 'PowerPC:BE:32:A2ALT', 'architecture_test': 'PPCP8Alt', }) @@ -462,7 +524,8 @@ PCodeTest({ 'name': 'ppcP9Alt', 'build_all': 1, 'toolchain': 'PPC/powerpc-elf', - 'ccflags': '-mcpu=power9 -mvsx -maltivec -L %(toolchain_dir)s/lib/gcc/powerpc-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mcpu=power9 -mvsx -maltivec', + 'cclibs': '-lgcc', 'language_id': 'PowerPC:BE:32:A2ALT', 'architecture_test': 'PPCP9Alt', }) @@ -470,8 +533,9 @@ PCodeTest({ PCodeTest({ 'name': 'msp430x', 'build_all': 1, - 'toolchain': 'TI/msp430-gcc-9.3.1.11_linux64', - 'ccflags': '-g -mcpu=msp430x -mlarge -mhwmult=none -fno-builtin -Wl,-T,msp430x.ld -L %(toolchain_dir)s/lib/gcc/msp430-elf/%(gcc_version)s/large/ -lgcc -lmul_none', + 'toolchain': 'TI/msp430-elf', + 'ccflags': '-g -mcpu=msp430x -mlarge -mhwmult=none -fno-builtin -Wl,-T,msp430x.ld', + 'cclibs': '-lgcc -lmul_none', 'language_id': 'TI_MSP430X:LE:32:default', 'processor': 'TI', 'architecture_test': 'MSP430X', @@ -485,8 +549,9 @@ PCodeTest({ PCodeTest({ 'name': 'msp430', 'build_all': 1, - 'toolchain': 'TI/msp430-gcc-9.3.1.11_linux64', - 'ccflags': '-g -mcpu=msp430 -fno-builtin -mhwmult=none -lgcc -lmul_none', + 'toolchain': 'TI/msp430-elf', + 'ccflags': '-g -mcpu=msp430 -fno-builtin -mhwmult=none', + 'cclibs': '-lgcc -lmul_none', 'language_id': 'TI_MSP430:LE:16:default', 'processor': 'TI', 'architecture_test': 'MSP430', @@ -502,7 +567,8 @@ PCodeTest({ 'build_exe': 0, 'qemu_command': 'qemu-sh4eb', # qemu gets "Invalid argument" error 'toolchain': 'SuperH4/sh4-elf', - 'ccflags': '-mb -mrenesas -m4 -L %(toolchain_dir)s/lib/gcc/sh4-elf/%(gcc_version)s -lgcc', + 'ccflags': '-mb -mrenesas -m4', + 'cclibs': '-lgcc', 'language_id': 'SuperH4:BE:32:default', 'architecture_test': 'SuperH4_BE', }) @@ -511,7 +577,8 @@ PCodeTest({ 'name': 'SH4_LE', 'build_all': 1, 'toolchain': 'SuperH4/sh4le-elf', - 'ccflags': '-ml -mrenesas -m4 -L %(toolchain_dir)s/lib/gcc/sh4le-elf/%(gcc_version)s -lgcc', + 'ccflags': '-ml -mrenesas -m4', + 'cclibs': '-lgcc', 'language_id': 'SuperH4:LE:32:default', 'architecture_test': 'SuperH4', }) @@ -548,7 +615,8 @@ PCodeTest({ 'build_exe': 1, 'qemu_command': 'qemu-i386', 'toolchain': 'x86/i386-elf-linux', - 'ccflags': '-march=pentium -m32 -L %(toolchain_dir)s/lib/gcc/i386-elf-linux/%(gcc_version)s -lgcc', + 'ccflags': '-march=pentium -m32', + 'cclibs': '-lgcc', 'objdump_option': '-M intel', 'language_id': 'x86:LE:32:default', 'architecture_test': 'X86m32', @@ -559,7 +627,7 @@ PCodeTest({ 'name': 'i386_CLANG', 'toolchain': 'LLVM/llvm', 'toolchain_type': 'llvm', - 'ccflags': '--target=i386', + 'ccflags': '--target=i386 -DU4="unsigned __INT32_TYPE__" -DI4="signed __INT32_TYPE__', 'objdump_option': '-M intel', 'language_id': 'x86:LE:32:default', }) @@ -568,7 +636,7 @@ PCodeTest({ 'name': 'i686_CLANG', 'toolchain': 'LLVM/llvm', 'toolchain_type': 'llvm', - 'ccflags': '--target=i686', + 'ccflags': '--target=i686 -DU4="unsigned __INT32_TYPE__" -DI4="signed __INT32_TYPE__', 'objdump_option': '-M intel', 'language_id': 'x86:LE:32:default', }) @@ -640,7 +708,9 @@ PCodeTest({ 'objdump_exe': 'bin/xc16-objdump', 'readelf_exe': 'bin/xc16-readelf', 'nm_exe': 'bin/xc16-nm', - 'ccflags': '-mcpu=30F2011 -DINT4_IS_LONG -Xlinker --defsym -Xlinker _main=0x0 -L %(toolchain_dir)s/lib -lpic30 -lc -lm', + 'ccflags': '-mcpu=30F2011 -DI4="signed long" -DU4="unsigned long" -DF8="long double" -Xlinker --defsym -Xlinker _main=0x0', + 'gcc_libdir': '%(toolchain_dir)s/lib', + 'cclibs': '-lpic30 -lc -lm', 'language_id': 'dsPIC30F:LE:24:default', 'skip_files': ['misc.test'], 'variants': {'O0': '-O0'}, @@ -652,7 +722,9 @@ PCodeTest({ 'toolchain': 'PIC/xc8', 'compile_exe': 'bin/xc8', 'objdump_exe': 'bin/dump', - 'ccflags': '-chip=16C57 -DINT4_IS_LONG -DSTATIC_MAIN -L %(toolchain_dir)s/lib -lpic30 -lc -lm', + 'ccflags': '-chip=16C57 -DI4="signed long" -DU4="unsigned long" -DSTATIC_MAIN', + 'gcc_libdir': '%(toolchain_dir)s/lib', + 'cclibs': '-lpic30 -lc -lm', 'language_id': 'dsPIC16F:LE:24:default', 'small_build': 1, }) @@ -674,7 +746,7 @@ PCodeTest({ 'toolchain': 'SDCC/z80', 'toolchain_type': 'sdcc', 'compile_exe': 'bin/sdcc', - 'ccflags': '-mz80 -V --verbose --std-sdcc11 -DINT4_IS_LONG', + 'ccflags': '-mz80 -V --verbose --std-sdcc11 -DI4="signed long" -DU4="unsigned long"', 'language_id': 'z80:LE:16:default', 'variants': {'OX':''}, 'has_float': 0, @@ -714,6 +786,33 @@ PCodeTest({ 'has_longlong': 0, }) +PCodeTest({ + 'name': 'V850', + 'build_all': 1, + 'build_exe': 1, + 'toolchain': 'V850/v850-elf', + 'language_id': 'V850:LE:32:default', + 'ccflags': '-mv850e2v3 -lgcc', +}) + +PCodeTest({ + 'name': 'RH850', + 'build_all': 1, + 'build_exe': 1, + 'toolchain': 'V850/v850-elf', + 'language_id': 'V850:LE:32:v850e3v5', + 'ccflags': '-mv850e3v5 -mloop -mrh850-abi -lgcc', +}) + +PCodeTest({ + 'name': 'Xtensa', + 'build_all': 1, + 'build_exe': 1, + 'toolchain': 'Xtensa/xtensa-elf', + 'language_id': 'Xtensa:LE:32:default', + 'ccflags': '-lgcc', +}) + PCodeTest({ 'name': 'Xtensa_LE', 'build_all': 1, diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/pcodetest.py b/Ghidra/Extensions/SleighDevTools/pcodetest/pcodetest.py index 3580e40a20..76a48ef3ba 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/pcodetest.py +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/pcodetest.py @@ -1,17 +1,17 @@ ## ### -# IP: GHIDRA -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. ## import os import glob @@ -19,6 +19,7 @@ import re import fnmatch from build import Config, BuildUtil +from defaults import * class PCodeTest(BuildUtil): @@ -27,10 +28,9 @@ class PCodeTest(BuildUtil): def __init__(self, conf): super(PCodeTest, self).__init__() - self.config = Config(PCodeTest.defaults, conf) - + self.config = Config(pcodeTestDefaults, conf) # calculate the toolchain_dir - self.config.toolchain_dir = self.config.format('%(toolchain_root)s/%(toolchain)s-gcc-%(gcc_version)s') + self.config.toolchain_dir = self.config.format('%(toolchain_root)s/%(toolchain)s-gcc-%(gcc_config)s') if not self.isdir(self.config.toolchain_dir): self.config.toolchain_dir = self.config.format('%(toolchain_root)s/%(toolchain)s') @@ -39,16 +39,13 @@ class PCodeTest(BuildUtil): # can default the Processor directory name, usually the # initial string of 'language_id' (otherwise unused). - if self.config.language_id: self.config.processor = self.config.language_id.split(':')[0] # expand all of the variables with printf escapes - self.config.expand() # save the new PCodeTest in a dictionary for auto-enumeration - PCodeTest.list[self.config.name] = self @classmethod @@ -97,10 +94,11 @@ class PCodeTestBuild(BuildUtil): return # save path to tpp - tpp_py = os.getcwd() + '/tpp.py' + tpp_py = os.path.join(os.path.dirname(os.path.abspath(__file__)),'tpp.py') # Get a list of strings to filter input files available_files = sorted(glob.glob(self.config.format('%(pcodetest_src)s/*'))) + if self.config.proc_test: available_files.extend(sorted(glob.glob(self.config.format('%(pcodetest_src)s/%(proc_test)s/*')))) @@ -127,7 +125,6 @@ class PCodeTestBuild(BuildUtil): # This is the base name of the binary file, or for small # build, the directory name that will hold the small # binaries - out_name = '%s_%s_%s_pcodetest' % (self.config.name, self.config.toolchain_type.upper(), opt_name) if self.config.architecture_test: pcodetest_base_name = self.config.architecture_test else: pcodetest_base_name = self.config.architecture @@ -137,8 +134,8 @@ class PCodeTestBuild(BuildUtil): # This does not rebuild if the output directory is newer than the # input files. So it needs to know where the build # directory would be, before it is recreated. - build_dir = self.build_dir(self.config.build_root, kind, out_name) + need_to_build = self.config.force or not self.isdir(build_dir) if not need_to_build: mtime = self.getmtime(build_dir) @@ -157,11 +154,9 @@ class PCodeTestBuild(BuildUtil): for f in available_files: self.copy(f, '.', verbose=False) # if requested, add an info file - if self.config.add_info: self.mkinfo('INFO.c') # make tests, if needed - for f_test in glob.glob('*.test'): f_h = re.sub(r'[.]test', '.h', f_test) if self.isfile(f_h) and self.getmtime(f_test) <= self.getmtime(f_h): continue @@ -184,14 +179,12 @@ class PCodeTestBuild(BuildUtil): self.log_info('**** SMALL BUILD ****') # Remove the previous directory, if it was there - build_dir = '%s/build-PCodeTest-%s/%s' % (self.config.build_root, out_name, out_name) try: self.rmtree(build_dir) except: pass # Each small file ends with _BODY.c and it has a # companion without _BODY. - for body_file in smallFiles: small_name = body_file.replace('_BODY.c', '') companion_file = small_name + '.c' @@ -240,20 +233,20 @@ class PCodeBuildSDCC(PCodeTestBuild): f += ['-DNAME=NAME:%s' % output_file] - f += self.config.ccflags.split() - f += self.config.add_ccflags.split() + f += [self.config.format(g) for g in self.config.ccflags.split()] + f += [self.config.format(g) for g in self.config.add_ccflags.split()] + f += [self.config.format(g) for g in self.config.cclibs.split()] + f += [self.config.format(g) for g in self.config.add_cclibs.split()] return f def compile(self, input_files, opt_cflag, output_base): # Name the output file, and delete it if it exists - output_file = '%s.out' % (output_base) self.remove(output_file) # Construct the compile command line and execute it - cmp = self.which('compile_exe') cmd = [cmp] + input_files + self.cflags(output_file) if opt_cflag: cmd += [opt_cflag] @@ -265,7 +258,6 @@ class PCodeBuildSDCC(PCodeTestBuild): if err: self.log_warn(err) # return now if the error preempted the binary - if not self.is_readable_file(output_file): self.log_err('output not created %s' % output_file) return @@ -289,9 +281,11 @@ class PCodeBuildCCS(PCodeTestBuild): f += ['-DNAME=NAME:%s' % output_file] - f += self.config.ccflags.split() - f += self.config.add_ccflags.split() - + f += [self.config.format(g) for g in self.config.ccflags.split()] + f += [self.config.format(g) for g in self.config.add_ccflags.split()] + f += [self.config.format(g) for g in self.config.cclibs.split()] + f += [self.config.format(g) for g in self.config.add_cclibs.split()] + return f def compile(self, input_files, opt_cflag, output_base): @@ -302,11 +296,9 @@ class PCodeBuildCCS(PCodeTestBuild): self.remove(output_file) # Construct the compile command line and execute it - cmp = self.which('compile_exe') cmd = [cmp] + input_files + self.cflags(output_file) + [opt_cflag] - cmd += ['-z', '-h', '-e', 'printf5'] - cmd += [self.config.format('%(toolchain_dir)s/tools/compiler/ti-cgt-msp430_16.9.0.LTS/lib/libc.a')] + cmd += ['-z', '-off', '-llibc.a', '--make_global=noteTestMain', '--retain=*_main', '-cr', '-m', '%s.map'%(output_base), '-h', '--unused_section_elimination=off'] cmd += ['-o', output_file] out, err = self.run(cmd) if out: self.log_info(out) @@ -315,7 +307,6 @@ class PCodeBuildCCS(PCodeTestBuild): if err: self.log_warn(err) # return now if the error preempted the binary - if not self.is_readable_file(output_file): self.log_err('output not created %s' % output_file) return @@ -345,7 +336,7 @@ class PCodeBuildGCC(PCodeTestBuild): out, err = self.run([self.which('objdump_exe')] + self.config.objdump_option.split() - + ['-d', bin], stdout=('%s.d' % base)) + + ['-S','-d', bin], stdout=('%s.d' % base)) if err: self.log_warn(err) out, err = self.run([self.which('objdump_exe')] @@ -374,7 +365,7 @@ class PCodeBuildGCC(PCodeTestBuild): if err: self.log_warn(err) out, err = self.run(['grep', ' U ', '%s.nm' % base]) - if out: self.log_warn('** UNRESOLVED:\n' + out + '**END') + if out: self.log_warn('** UNRESOLVED:\n' + str(out) + '**END') if err: self.log_warn(err) # Set options for compiler depending on needs. @@ -389,9 +380,26 @@ class PCodeBuildGCC(PCodeTestBuild): if self.config.has_decimal32: f += ['-DHAS_DECIMAL32=1'] if self.config.has_decimal64: f += ['-DHAS_DECIMAL64=1'] + if self.config.gcc_version == 'latest': + self.config.gcc_actual_version = os.readlink(self.config.toolchain_dir).split('gcc-')[1] + else: + self.config.gcc_actual_version = self.config.gcc_version + + if not self.config.gcc_libdir: + if self.config.gcc_version == 'latest': + # latest gcc version needs to point to the right libgcc location + toolchain_dir = self.config.format('%(toolchain_root)s/%(toolchain)s-gcc-%(gcc_config)s') + toolchain_suffix = self.config.toolchain.split('/')[-1] + self.config.gcc_libdir = os.path.join(self.config.toolchain_dir, 'lib', 'gcc', toolchain_suffix, self.config.gcc_actual_version) + else: + toolchain_suffix = self.config.toolchain.split('/')[-1] + self.config.gcc_libdir = os.path.join(self.config.toolchain_dir, 'lib', 'gcc', toolchain_suffix, self.config.gcc_version) + + f += ['-DNAME=NAME:%s' % output_file] # turn off -g because dwarf, not needed - f += ['-dA', '-w'] + #f += ['-dA', '-w'] + f += ['-Wno-discarded-qualifiers',] # for xc26: f += ['--no-data-init'] # or maybe f += ['-Xlinker', '--no-data-init'] # This helps to alleviate undefined main, etc @@ -400,25 +408,25 @@ class PCodeBuildGCC(PCodeTestBuild): # can pass this if weak symbols aren't defined # f += ['-Xlinker', '--unresolved-symbols=ignore-all'] - f +=[self.config.format(g) for g in self.config.ccflags.split()] + f += [self.config.format(g) for g in self.config.ccflags.split()] f += [self.config.format(g) for g in self.config.add_ccflags.split()] - + f += ['-L ' + self.config.format(self.config.gcc_libdir)] + f += [self.config.format(g) for g in self.config.cclibs.split()] + f += [self.config.format(g) for g in self.config.add_cclibs.split()] + self.log_info('Compiler flags: %s' % f) return f def compile(self, input_files, opt_cflag, output_base): # Name the output file, and delete it if it exists - output_file = '%s.out' % (output_base) self.remove(output_file) # set the library path - self.set_library_path(self.config.ld_library_path) # Construct the compile/link command line and execute it - cmp = self.which('compile_exe') cmd = [cmp] + input_files + self.cflags(output_file) + [opt_cflag, '-B', self.dirname(cmp), '-o', output_file] out, err = self.run(cmd) @@ -428,13 +436,11 @@ class PCodeBuildGCC(PCodeTestBuild): if err: self.log_warn(err) # but return now if the error preempted the binary - if not self.is_readable_file(output_file): self.log_err('output not created %s' % output_file) return # strip - if self.config.strip_symbols: str = self.which('strip_exe') cmd = [str, '-s', output_file] @@ -443,11 +449,9 @@ class PCodeBuildGCC(PCodeTestBuild): # Get associated information (identify file, output-file.d, # .li, .nm, and .readelf, identify file, unresolves symbols) - self.associated_info(output_file, output_base) # build a BUILD_EXE version - if self.config.build_exe: cmp = self.which('compile_exe') cmd = [cmp] + input_files + self.cflags(output_file)\ diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/tpp.py b/Ghidra/Extensions/SleighDevTools/pcodetest/tpp.py index 6c6246eabe..02d8f3456c 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/tpp.py +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/tpp.py @@ -1,18 +1,18 @@ #!/usr/bin/python ## ### -# IP: GHIDRA -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. ## import re @@ -213,7 +213,7 @@ parser = argparse.ArgumentParser(description='Precompile test file', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('test_file', nargs='*', help='Test file to preprocess, must end with .test') -parser.add_argument('--entry', default='', help='Create file ENTRY contianing a main function that calls all MAIN functions') +parser.add_argument('--entry', default='', help='Create file ENTRY containing a main function that calls all MAIN functions') sys.argv.pop(0) args = parser.parse_args(sys.argv)