diff -aurN a/SamTFE/Sources/CMakeLists.txt b/SamTFE/Sources/CMakeLists.txt --- a/SamTFE/Sources/CMakeLists.txt 2022-05-29 23:38:44.637615000 +0300 +++ b/SamTFE/Sources/CMakeLists.txt 2022-06-01 14:15:52.118403541 +0300 @@ -278,6 +278,11 @@ add_definitions(-DPLATFORM_PYRA=1) endif() +option(RPI4 "Raspberry PI 4" FALSE) +if(RPI4) + add_definitions(-DPLATFORM_RPI4=1) +endif() + option(USE_TREMOR "Use Tremor instead of Vorbis" FALSE) if (USE_TREMOR) add_definitions(-DUSE_TREMOR=1) diff -aurN a/SamTFE/Sources/Engine/Base/Timer.cpp b/SamTFE/Sources/Engine/Base/Timer.cpp --- a/SamTFE/Sources/Engine/Base/Timer.cpp 2022-05-29 23:18:11.604401775 +0300 +++ b/SamTFE/Sources/Engine/Base/Timer.cpp 2022-06-01 14:55:04.242015242 +0300 @@ -53,7 +53,7 @@ } return mmRet; -#elif (defined __GNU_INLINE_X86_32__ ) +#elif (defined __GNU_INLINE_X86_32__ ) && !defined(PLATFORM_RPI4) __int64 mmRet; __asm__ __volatile__ ( "rdtsc \n\t" @@ -64,7 +64,7 @@ : "memory", "eax", "edx" ); return(mmRet); -#elif (defined __GNU_INLINE_X86_64__ ) +#elif (defined __GNU_INLINE_X86_64__ ) && !defined(PLATFORM_RPI4) uint64_t x; asm volatile ( ".intel_syntax noprefix \n\t" // switch to prettier syntax @@ -89,6 +89,18 @@ : // input operands : "rdx"); // additional clobbers (with cpuid also: rbx, rcx) return x; +#elif (defined PLATFORM_RPI4) + // TODO: Raspberry PI 4 + volatile unsigned cc; + static int init = 0; + if(!init) { + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 2" :: "r"(1<<31)); /* stop the cc */ + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 0" :: "r"(5)); /* initialize */ + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 1" :: "r"(1<<31)); /* start the cc */ + init = 1; + } + __asm__ __volatile__ ("mrc p15, 0, %0, c9, c13, 0" : "=r"(cc)); + return (uint64_t)cc; #else #error Please implement for your platform/compiler. #endif @@ -121,7 +133,8 @@ void cpu_rdtsc(uint64_t* result) { uint32_t low_part, hi_part; -#if defined( __GNU_INLINE_X86_32__ ) || defined( __GNU_INLINE_X86_64__ ) + +#if (defined( __GNU_INLINE_X86_32__ ) || defined( __GNU_INLINE_X86_64__ )) && !defined(PLATFORM_RPI4) __asm __volatile ( " rdtsc\n" " mov %%eax, %0\n" @@ -137,6 +150,19 @@ mov low_part, eax mov hi_part, edx }; +#elif (defined PLATFORM_RPI4) + // TODO: Raspberry PI 4 + volatile unsigned cc; + static int init = 0; + if(!init) { + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 2" :: "r"(1<<31)); /* stop the cc */ + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 0" :: "r"(5)); /* initialize */ + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 1" :: "r"(1<<31)); /* start the cc */ + init = 1; + } + __asm__ __volatile__ ("mrc p15, 0, %0, c9, c13, 0" : "=r"(cc)); + *result = (uint64_t)сс; + return; #else # error "Unsupported compiler" #endif diff -aurN a/SamTSE/Sources/CMakeLists.txt b/SamTSE/Sources/CMakeLists.txt --- a/SamTSE/Sources/CMakeLists.txt 2022-05-29 23:38:44.637615000 +0300 +++ b/SamTSE/Sources/CMakeLists.txt 2022-06-01 14:15:52.118403541 +0300 @@ -278,6 +278,11 @@ add_definitions(-DPLATFORM_PYRA=1) endif() +option(RPI4 "Raspberry PI 4" FALSE) +if(RPI4) + add_definitions(-DPLATFORM_RPI4=1) +endif() + option(USE_TREMOR "Use Tremor instead of Vorbis" FALSE) if (USE_TREMOR) add_definitions(-DUSE_TREMOR=1) diff -aurN a/SamTSE/Sources/Engine/Base/Timer.cpp b/SamTSE/Sources/Engine/Base/Timer.cpp --- a/SamTSE/Sources/Engine/Base/Timer.cpp 2022-05-29 23:18:11.604401775 +0300 +++ b/SamTSE/Sources/Engine/Base/Timer.cpp 2022-06-01 14:55:04.242015242 +0300 @@ -53,7 +53,7 @@ } return mmRet; -#elif (defined __GNU_INLINE_X86_32__ ) +#elif (defined __GNU_INLINE_X86_32__ ) && !defined(PLATFORM_RPI4) __int64 mmRet; __asm__ __volatile__ ( "rdtsc \n\t" @@ -64,7 +64,7 @@ : "memory", "eax", "edx" ); return(mmRet); -#elif (defined __GNU_INLINE_X86_64__ ) +#elif (defined __GNU_INLINE_X86_64__ ) && !defined(PLATFORM_RPI4) uint64_t x; asm volatile ( ".intel_syntax noprefix \n\t" // switch to prettier syntax @@ -89,6 +89,18 @@ : // input operands : "rdx"); // additional clobbers (with cpuid also: rbx, rcx) return x; +#elif (defined PLATFORM_RPI4) + // TODO: Raspberry PI 4 + volatile unsigned cc; + static int init = 0; + if(!init) { + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 2" :: "r"(1<<31)); /* stop the cc */ + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 0" :: "r"(5)); /* initialize */ + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 1" :: "r"(1<<31)); /* start the cc */ + init = 1; + } + __asm__ __volatile__ ("mrc p15, 0, %0, c9, c13, 0" : "=r"(cc)); + return (uint64_t)cc; #else #error Please implement for your platform/compiler. #endif @@ -121,7 +133,8 @@ void cpu_rdtsc(uint64_t* result) { uint32_t low_part, hi_part; -#if defined( __GNU_INLINE_X86_32__ ) || defined( __GNU_INLINE_X86_64__ ) + +#if (defined( __GNU_INLINE_X86_32__ ) || defined( __GNU_INLINE_X86_64__ )) && !defined(PLATFORM_RPI4) __asm __volatile ( " rdtsc\n" " mov %%eax, %0\n" @@ -137,6 +150,19 @@ mov low_part, eax mov hi_part, edx }; +#elif (defined PLATFORM_RPI4) + // TODO: Raspberry PI 4 + volatile unsigned cc; + static int init = 0; + if(!init) { + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 2" :: "r"(1<<31)); /* stop the cc */ + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 0" :: "r"(5)); /* initialize */ + __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 1" :: "r"(1<<31)); /* start the cc */ + init = 1; + } + __asm__ __volatile__ ("mrc p15, 0, %0, c9, c13, 0" : "=r"(cc)); + *result = (uint64_t)сс; + return; #else # error "Unsupported compiler" #endif