Skip to content
Permalink
Browse files

Compile CPU mining for win32 and win64

  • Loading branch information...
James Z.M. Gao
James Z.M. Gao committed Apr 4, 2013
1 parent dfea623 commit c9ae7150198e92521f530a9c1315d4d32a354b3d
Showing with 225 additions and 50 deletions.
  1. +2 −0 .gitignore
  2. +3 −7 Makefile.am
  3. +35 −0 autogen-win32.sh
  4. +36 −0 autogen-win64.sh
  5. +11 −6 cgminer.c
  6. +10 −2 compat.h
  7. +35 −6 configure.ac
  8. +5 −5 driver-bitforce.c
  9. +5 −3 driver-cpu.c
  10. +1 −1 driver-cpu.h
  11. +1 −1 driver-icarus.c
  12. +1 −1 driver-ztex.c
  13. +5 −0 elist.h
  14. +3 −2 fpgautils.c
  15. +2 −0 lib/signal.in.h
  16. +2 −1 logging.c
  17. +2 −1 miner.h
  18. +1 −1 x86_32/Makefile.am
  19. +4 −4 x86_32/sha256_xmm.asm
  20. +1 −1 x86_64/Makefile.am
  21. +35 −8 x86_64/sha256_sse4_amd64.asm
  22. +25 −0 x86_64/sha256_xmm_amd64.asm
@@ -41,3 +41,5 @@ lib/string.h
lib/warn-on-use.h

mkinstalldirs

*.swp
@@ -19,19 +19,15 @@ INCLUDES = $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES)

bin_PROGRAMS = cgminer

bin_SCRIPTS = *.cl
bin_SCRIPTS = $(top_srcdir)/*.cl

cgminer_LDFLAGS = $(PTHREAD_FLAGS)
cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
@OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
@UDEV_LIBS@ @LIBUSB_LIBS@ \
@MATH_LIBS@ lib/libgnu.a ccan/libccan.a

if HAVE_WINDOWS
cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib @OPENCL_FLAGS@ @LIBUSB_CFLAGS@
else
cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib @OPENCL_FLAGS@ @LIBUSB_CFLAGS@ @LIBCURL_CFLAGS@
endif

# common sources
cgminer_SOURCES := cgminer.c
@@ -101,11 +97,11 @@ endif
if HAS_MODMINER
cgminer_SOURCES += driver-modminer.c
bitstreamsdir = $(bindir)/bitstreams
dist_bitstreams_DATA = bitstreams/*
dist_bitstreams_DATA = $(top_srcdir)/bitstreams/*
endif

if HAS_ZTEX
cgminer_SOURCES += driver-ztex.c libztex.c libztex.h
bitstreamsdir = $(bindir)/bitstreams
dist_bitstreams_DATA = bitstreams/*
dist_bitstreams_DATA = $(top_srcdir)/bitstreams/*
endif
@@ -0,0 +1,35 @@
#!/bin/bash

bs_dir="$(dirname $(readlink -f $0))"
build_dir="$PWD"
rm -rf "${bs_dir}"/autom4te.cache
rm -f "${bs_dir}"/aclocal.m4 "${bs_dir}"/ltmain.sh

echo 'Running autoreconf -ifv...'
autoreconf -ifv -I "/usr/local/share/aclocal/" "$bs_dir" || exit 1

if test -z "$NOCONFIGURE" ; then
echo 'Configuring...'

if [[ "$bs_dir" != "`pwd`" ]]; then
export CPPFLAGS+=" -I $bs_dir"
fi

if [[ ! -z "$CGMINER_SDK" ]]; then
export CPPFLAGS="-I $CGMINER_SDK/include $CPPFLAGS"
export LDFLAGS="-L $CGMINER_SDK/lib $LDFLAGS"
export PKG_CONFIG_PATH="$CGMINER_SDK/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
export ADL_SDK="$CGMINER_SDK/include/ADL_SDK"
fi

CFLAGS="-O3 -msse2" \
"$bs_dir"/configure \
--prefix="$build_dir"/opt \
--enable-cpumining \
--enable-scrypt \
--enable-bitforce \
--enable-icarus \
--enable-modminer \
--enable-ztex \
$@
fi
@@ -0,0 +1,36 @@
#!/bin/bash

bs_dir="$(dirname $(readlink -f $0))"
build_dir="$PWD"
rm -rf "${bs_dir}"/autom4te.cache
rm -f "${bs_dir}"/aclocal.m4 "${bs_dir}"/ltmain.sh

echo 'Running autoreconf -ifv...'
autoreconf -ifv -I "/usr/local/share/aclocal/" "$bs_dir" || exit 1

if test -z "$NOCONFIGURE" ; then
echo 'Configuring...'

if [[ "$bs_dir" != "`pwd`" ]]; then
export CPPFLAGS+=" -I $bs_dir"
fi

if [[ ! -z "$CGMINER_SDK" ]]; then
export CPPFLAGS="-I $CGMINER_SDK/include $CPPFLAGS"
export LDFLAGS="-L $CGMINER_SDK/lib64 $LDFLAGS"
export PKG_CONFIG_PATH="$CGMINER_SDK/lib64/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
export ADL_SDK="$CGMINER_SDK/include/ADL_SDK"
fi

CFLAGS="-O3 -msse4" \
"$bs_dir"/configure \
--target=x86_64-w64-mingw32 \
--prefix="$build_dir"/opt \
--enable-cpumining \
--enable-scrypt \
--enable-bitforce \
--enable-icarus \
--enable-modminer \
--enable-ztex \
$@
fi
@@ -318,7 +318,8 @@ static bool should_run(void)
return true;

gettimeofday(&tv, NULL);
tm = localtime(&tv.tv_sec);
const time_t tmp_time = tv.tv_sec;
tm = localtime(&tmp_time);
if (schedstart.enable) {
if (!schedstop.enable) {
if (time_before(tm, &schedstart.tm))
@@ -350,7 +351,8 @@ void get_datestamp(char *f, struct timeval *tv)
{
struct tm *tm;

tm = localtime(&tv->tv_sec);
const time_t tmp_time = tv->tv_sec;
tm = localtime(&tmp_time);
sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]",
tm->tm_year + 1900,
tm->tm_mon + 1,
@@ -364,7 +366,8 @@ void get_timestamp(char *f, struct timeval *tv)
{
struct tm *tm;

tm = localtime(&tv->tv_sec);
const time_t tmp_time = tv->tv_sec;
tm = localtime(&tmp_time);
sprintf(f, "[%02d:%02d:%02d]",
tm->tm_hour,
tm->tm_min,
@@ -2584,9 +2587,11 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
double submit_time = tdiff(&tv_submit_reply, &tv_submit);
int diffplaces = 3;

tm = localtime(&(work->tv_getwork.tv_sec));
time_t tmp_time = work->tv_getwork.tv_sec;
tm = localtime(&tmp_time);
memcpy(&tm_getwork, tm, sizeof(struct tm));
tm = localtime(&(tv_submit_reply.tv_sec));
tmp_time = tv_submit_reply.tv_sec;
tm = localtime(&tmp_time);
memcpy(&tm_submit_reply, tm, sizeof(struct tm));

if (work->clone) {
@@ -2957,7 +2962,7 @@ void app_restart(void)
}
#endif

execv(initial_args[0], initial_args);
execv(initial_args[0], (EXECV_2ND_ARG_TYPE)initial_args);
applog(LOG_WARNING, "Failed to restart application");
}

@@ -2,15 +2,17 @@
#define __COMPAT_H__

#ifdef WIN32
#include "config.h"
#include <errno.h>
#include <time.h>
#include <pthread.h>
#include <sys/time.h>

#include <windows.h>

#include "miner.h" // for timersub

#include <windows.h>

#ifndef HAVE_LIBWINPTHREAD
static inline int nanosleep(const struct timespec *req, struct timespec *rem)
{
struct timeval tstart;
@@ -42,6 +44,7 @@ static inline int nanosleep(const struct timespec *req, struct timespec *rem)
}
return 0;
}
#endif

static inline int sleep(unsigned int secs)
{
@@ -71,7 +74,12 @@ typedef unsigned int uint;
typedef long suseconds_t;
#endif

#ifdef HAVE_LIBWINPTHREAD
#define PTH(thr) ((thr)->pth)
#else
#define PTH(thr) ((thr)->pth.p)
#endif

#else
#define PTH(thr) ((thr)->pth)
#endif /* WIN32 */
@@ -81,7 +81,6 @@ esac

case $target in
*-*-mingw*)
have_x86_64=false
have_win32=true
PTHREAD_FLAGS=""
DLOPEN_FLAGS=""
@@ -166,9 +165,18 @@ else
OPENCL_LIBS=""
fi

AC_CHECK_LIB(pthread, pthread_create, ,
AC_MSG_ERROR([Could not find pthread library - please install libpthread]))
PTHREAD_LIBS=-lpthread
has_winpthread=false
if test "x$have_win32" = xtrue; then
has_winpthread=true
AC_CHECK_LIB(winpthread, nanosleep, , has_winpthread=false)
PTHREAD_LIBS=-lwinpthread
fi

if test "x$has_winpthread" != xtrue; then
AC_CHECK_LIB(pthread, pthread_create, ,
AC_MSG_ERROR([Could not find pthread library - please install libpthread]))
PTHREAD_LIBS=-lpthread
fi

AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true)

@@ -181,7 +189,7 @@ scrypt="no"

if test "$found_opencl" = 1; then
if test "x$adl" != xno; then
AC_CHECK_FILE([ADL_SDK/adl_sdk.h], have_adl=true, have_adl=false,)
AC_CHECK_FILE([${ADL_SDK:-ADL_SDK}/adl_sdk.h], have_adl=true, have_adl=false,)
if test x$have_adl = xtrue
then
AC_DEFINE([HAVE_ADL], [1], [Defined if ADL headers were found])
@@ -305,7 +313,7 @@ has_yasm=false
AC_PATH_PROG([YASM],[yasm],[false])
if test "x$YASM" != "xfalse" ; then
AC_MSG_CHECKING([if yasm version is greater than 1.0.1])
yasmver=`yasm --version | head -1 | cut -d\ -f2`
yasmver=`"$YASM" --version | head -1 | cut -d\ -f2`
yamajor=`echo $yasmver | cut -d. -f1`
yaminor=`echo $yasmver | cut -d. -f2`
yamini=`echo $yasmver | cut -d. -f3`
@@ -332,6 +340,18 @@ if test "x$YASM" != "xfalse" ; then
fi
if test "x$has_yasm" = "xfalse" ; then
AC_MSG_NOTICE([yasm is required for the assembly algorithms. They will be skipped.])
else
if test "x$have_x86_64" = xtrue; then
if test "x$have_win32" = xtrue; then
YASM_FMT="win64"
else
YASM_FMT="elf64"
fi
elif test "x$have_win32" = xtrue; then
YASM_FMT="coff"
else
YASM_FMT="elf32"
fi
fi

AM_CONDITIONAL([HAS_YASM], [test x$has_yasm = xtrue])
@@ -382,6 +402,14 @@ else
fi
AC_SUBST(LIBCURL_LIBS)

#check execv signature
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <process.h>
int execv(const char*, const char*const*);
])],
AC_DEFINE([EXECV_2ND_ARG_TYPE], [const char* const*], [int execv(const char*, const char*const*);]),
AC_DEFINE([EXECV_2ND_ARG_TYPE], [char* const*], [int execv(const char*, char*const*);]))

dnl CCAN wants to know a lot of vars.
# All the configuration checks. Regrettably, the __attribute__ checks will
# give false positives on old GCCs, since they just cause warnings. But that's
@@ -438,6 +466,7 @@ AC_SUBST(PDCURSES_LIBS)
AC_SUBST(WS2_LIBS)
AC_SUBST(MATH_LIBS)
AC_SUBST(UDEV_LIBS)
AC_SUBST(YASM_FMT)

AC_CONFIG_FILES([
Makefile
@@ -9,6 +9,8 @@
* any later version. See COPYING for more details.
*/

#include "config.h"

#include <limits.h>
#include <pthread.h>
#include <stdint.h>
@@ -17,16 +19,14 @@
#include <sys/time.h>
#include <unistd.h>

#include "config.h"
#include "compat.h"
#include "miner.h"
#include "usbutils.h"

#ifdef WIN32
#include <windows.h>
#endif /* WIN32 */

#include "compat.h"
#include "miner.h"
#include "usbutils.h"

#define BITFORCE_IDENTIFY "ZGX"
#define BITFORCE_IDENTIFY_LEN (sizeof(BITFORCE_IDENTIFY)-1)
#define BITFORCE_FLASH "ZMX"
@@ -202,7 +202,9 @@ static const sha256_func sha256_funcs[] = {


#ifdef WANT_CPUMINE
#if defined(WANT_X8664_SSE2) && defined(__SSE2__)
#if defined(WANT_X8664_SSE4) && defined(__SSE4_1__)
enum sha256_algos opt_algo = ALGO_SSE4_64;
#elif defined(WANT_X8664_SSE2) && defined(__SSE2__)
enum sha256_algos opt_algo = ALGO_SSE2_64;
#elif defined(WANT_X8632_SSE2) && defined(__SSE2__)
enum sha256_algos opt_algo = ALGO_SSE2_32;
@@ -720,8 +722,8 @@ static void cpu_detect()
// Reckon number of cores in the box
#if defined(WIN32)
{
DWORD system_am;
DWORD process_am;
DWORD_PTR system_am;
DWORD_PTR process_am;
BOOL ok = GetProcessAffinityMask(
GetCurrentProcess(),
&system_am,
@@ -30,7 +30,7 @@
#define WANT_X8664_SSE2 1
#endif

#if defined(__x86_64__) && defined(HAS_YASM)
#if defined(__x86_64__) && defined(HAS_YASM) && defined(__SSE4_1__)
#define WANT_X8664_SSE4 1
#endif

@@ -30,6 +30,7 @@
*/

#include "config.h"
#include "miner.h"

#include <limits.h>
#include <pthread.h>
@@ -51,7 +52,6 @@
#endif

#include "elist.h"
#include "miner.h"
#include "fpgautils.h"

// The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h
@@ -23,9 +23,9 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, see http://www.gnu.org/licenses/.
**/
#include "miner.h"
#include <unistd.h>
#include <sha2.h>
#include "miner.h"
#include "libztex.h"

#define GOLDEN_BACKLOG 5
@@ -180,8 +180,13 @@ static inline void list_splice_init(struct list_head *list,
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#ifndef _WIN64
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
#else
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long long)(&((type *)0)->member)))
#endif

/**
* list_for_each - iterate over a list

0 comments on commit c9ae715

Please sign in to comment.
You can’t perform that action at this time.