diff --git a/CMakeLists.txt b/CMakeLists.txt index 5421534..b578892 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ if (${TARGET} STREQUAL PICO) include(pico_sdk_import.cmake) endif() -project(pjvm VERSION 0.0.4) +project(pjvm VERSION 0.0.6) include(CTest) @@ -116,7 +116,7 @@ if (${TARGET} STREQUAL PICO) DESTINATION . RENAME pjvm-${PROJECT_VERSION}.uf2 ) - install(PROGRAMS ${CMAKE_SOURCE_DIR}/tools/wrapjar.sh ${CMAKE_SOURCE_DIR}/lib/tools/preverify/bin/preverify + install(PROGRAMS ${CMAKE_SOURCE_DIR}/tools/wrapjar.sh ${BINARY_DIR}/preverify-prefix/src/preverify-build/preverify DESTINATION bin ) install(DIRECTORY ${CMAKE_BINARY_DIR}/doc diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f827139..e9eb0f7 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -10,6 +10,14 @@ include(ExternalProject) project(jvm) +# +# Build the host utilities that are used to build the classes library +# + +# +# Build ROMGEN, this is actually the VM but its built to generate a +# ROM image of the classes library +# ExternalProject_Add(romgen SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/romgen CMAKE_ARGS -DROMGEN_VERSION=${LIBJVM_VERSION} -DCMAKE_BUILD_TYPE:STRING=Release @@ -19,6 +27,20 @@ ExternalProject_Add(romgen SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/romgen INSTALL_COMMAND cmake -E echo "Skipping install step." ) ExternalProject_Get_property(romgen BINARY_DIR) +set(ROMGEN_BINARY_DIR ${BINARY_DIR}) + +# +# Build PREVERIFY to transform the classes before running on the target +# +ExternalProject_Add(preverify SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/preverify + CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=Release + USES_TERMINAL_BUILD TRUE + BUILD_ALWAYS TRUE + BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/preverify-prefix/src/preverify-build/preverify + INSTALL_COMMAND cmake -E echo "Skipping install step." +) +ExternalProject_Get_property(preverify BINARY_DIR) +set(PREVERIFY_BINARY_DIR ${BINARY_DIR}) if (${TARGET} STREQUAL PICO) set(CMAKE_C_COMPILER arm-none-eabi-gcc) @@ -136,15 +158,15 @@ set(JVM_CLASSES ) add_custom_command(OUTPUT ROMImage.cpp - DEPENDS ${JVM_CLASSES} ${BINARY_DIR}/romgen + DEPENDS ${JVM_CLASSES} ${ROMGEN_BINARY_DIR}/romgen COMMAND rm ARGS -rf ${CMAKE_BINARY_DIR}/classes ${CMAKE_BINARY_DIR}/classes.preverify COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/classes COMMAND javac ARGS -source 1.4 -target 1.4 -d ${CMAKE_BINARY_DIR}/classes -bootclasspath ${CMAKE_BINARY_DIR}/classes ${JVM_CLASSES} - COMMAND ${CMAKE_SOURCE_DIR}/tools/preverify/bin/preverify ARGS -d ${CMAKE_BINARY_DIR}/classes.preverify ${CMAKE_BINARY_DIR}/classes + COMMAND ${PREVERIFY_BINARY_DIR}/preverify ARGS -d ${CMAKE_BINARY_DIR}/classes.preverify ${CMAKE_BINARY_DIR}/classes COMMAND cd ARGS ${CMAKE_BINARY_DIR}/classes.preverify COMMAND jar ARGS -cfM0 ${CMAKE_BINARY_DIR}/classes.jar . COMMAND cd ARGS ${CMAKE_BINARY_DIR} - COMMAND ${BINARY_DIR}/romgen + COMMAND ${ROMGEN_BINARY_DIR}/romgen -cp ${CMAKE_BINARY_DIR}/classes.jar +RewriteROMConstantPool +EnableAllROMOptimizations @@ -154,7 +176,7 @@ add_custom_command(OUTPUT ROMImage.cpp -romincludepath ${CMAKE_SOURCE_DIR}/src/vm -romize ) -add_custom_target(classes ALL DEPENDS ROMImage.cpp romgen) +add_custom_target(classes ALL DEPENDS ROMImage.cpp romgen preverify) if (${TARGET} STREQUAL PICO) add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/doc diff --git a/lib/tools/preverify/CMakeLists.txt b/lib/tools/preverify/CMakeLists.txt index 6ad47a0..427dd42 100644 --- a/lib/tools/preverify/CMakeLists.txt +++ b/lib/tools/preverify/CMakeLists.txt @@ -26,4 +26,6 @@ add_executable(preverify target_compile_definitions(preverify PRIVATE UNIX JAVAVERIFY TRIMMED ARCH=i386) target_include_directories(preverify PRIVATE src) -target_compile_options(preverify PRIVATE) +target_compile_options(preverify PRIVATE -m32 -Werror) +target_link_options(preverify PRIVATE -m32) + diff --git a/lib/tools/preverify/bin/preverify b/lib/tools/preverify/bin/preverify deleted file mode 100755 index d0542d6..0000000 Binary files a/lib/tools/preverify/bin/preverify and /dev/null differ diff --git a/lib/tools/preverify/src/check_code.c b/lib/tools/preverify/src/check_code.c index 509a906..e7aa011 100644 --- a/lib/tools/preverify/src/check_code.c +++ b/lib/tools/preverify/src/check_code.c @@ -23,6 +23,9 @@ * information or have any questions. */ + /* + * Modified (C) Oren Sokoler (https://github.com/orenskl) + */ /*========================================================================= * SYSTEM: Verifier @@ -37,6 +40,8 @@ * Include files *=======================================================================*/ +#include + #include #include diff --git a/lib/tools/preverify/src/file.c b/lib/tools/preverify/src/file.c index 9529c55..4c971a4 100644 --- a/lib/tools/preverify/src/file.c +++ b/lib/tools/preverify/src/file.c @@ -23,6 +23,10 @@ * information or have any questions. */ +/* + * Modified (C) Oren Sokoler (https://github.com/orenskl) + */ + /*========================================================================= * SYSTEM: Verifier * SUBSYSTEM: Operations on class files. @@ -608,7 +612,7 @@ void WriteClass(ClassClass *cb) { int fd; - char fname[1024]; + char fname[BUFSIZ + 1024]; char buff[BUFSIZ]; char *nativeName = &buff[0]; @@ -725,7 +729,7 @@ WriteClass(ClassClass *cb) } tmpDirExists = TRUE; /* tmpDir exists with verified classes */ - write(fd, class_buf, class_index); + size_t rv = write(fd, class_buf, class_index); close(fd); free(class_buf); class_buf_size = 0; diff --git a/lib/tools/preverify/src/jar_support.c b/lib/tools/preverify/src/jar_support.c index b4b0ce4..cf1bf61 100644 --- a/lib/tools/preverify/src/jar_support.c +++ b/lib/tools/preverify/src/jar_support.c @@ -23,6 +23,10 @@ * information or have any questions. */ +/* + * Modified (C) Oren Sokoler (https://github.com/orenskl) + */ + /*========================================================================= * SYSTEM: Verifier * SUBSYSTEM: JAR support routines for the verifier. @@ -44,6 +48,7 @@ #include #include #include +#include #include #include @@ -495,7 +500,7 @@ loadJARfile(zip_t *entry, const char* filename) if (compLen != decompLen) { return NULL; } - fread(decompData, sizeof(char), decompLen, file); + size_t rv = fread(decompData, sizeof(char), decompLen, file); break; case DEFLATED: { @@ -681,7 +686,7 @@ ReadFromZip(zip_t *entry) jdstream = NULL; goto done; } - fread(decompData, sizeof(char), decompLen, file); + size_t rv = fread(decompData, sizeof(char), decompLen, file); break; case DEFLATED: { @@ -790,7 +795,7 @@ ReadFromZip(zip_t *entry) "Writing file [%s]...\n", sfname); /* write the file to the tmpdir just created */ - write(fd, decompData, decompLen); + size_t rv = write(fd, decompData, decompLen); /* check for the JAR Manifest.mf file */ diff --git a/lib/tools/preverify/src/main.c b/lib/tools/preverify/src/main.c index aa36b27..af0118b 100644 --- a/lib/tools/preverify/src/main.c +++ b/lib/tools/preverify/src/main.c @@ -23,6 +23,10 @@ * information or have any questions. */ +/* + * Modified (C) Oren Sokoler (https://github.com/orenskl) + */ + /*========================================================================= * SYSTEM: Verifier * SUBSYSTEM: main program @@ -52,8 +56,6 @@ * Globals and extern declarations *=======================================================================*/ -char str_buffer[STRINGBUFFERSIZE]; /* shared string buffer */ - int processedfile = 0; int errorCode = 0; /* Error code returned by program */ @@ -232,8 +234,7 @@ static void ProcessInputs(char *argname) * argv: arg value(s) * returns: nothing *=======================================================================*/ -int main(argc, argv) - register char **argv; +int main(int argc, char ** argv) { char *progname; char *argv0 = argv[0]; diff --git a/lib/tools/preverify/src/typedefs_md.h b/lib/tools/preverify/src/typedefs_md.h index e1a0101..b422b1d 100644 --- a/lib/tools/preverify/src/typedefs_md.h +++ b/lib/tools/preverify/src/typedefs_md.h @@ -23,6 +23,10 @@ * information or have any questions. */ +/* + * Modified (C) Oren Sokoler (https://github.com/orenskl) + */ + #ifndef _TYPES_MD_H_ #define _TYPES_MD_H_ @@ -52,12 +56,7 @@ typedef long int32_t; #endif /* SOLARIS2 */ #ifdef __linux__ -#ifndef _UINT64_T -#define _UINT64_T -typedef unsigned long long uint64_t; -#define _UINT32_T -typedef unsigned long uint32_t; -#endif +#include #endif /* __linux__ */ #ifdef DARWIN