Skip to content

Commit

Permalink
Compile CPU mining for win32 and win64
Browse files Browse the repository at this point in the history
  • Loading branch information
James Z.M. Gao committed Apr 4, 2013
1 parent dfea623 commit c9ae715
Show file tree
Hide file tree
Showing 22 changed files with 225 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ lib/string.h
lib/warn-on-use.h

mkinstalldirs

*.swp
10 changes: 3 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
35 changes: 35 additions & 0 deletions autogen-win32.sh
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions autogen-win64.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 11 additions & 6 deletions cgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}

Expand Down
12 changes: 10 additions & 2 deletions compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
Expand Down
41 changes: 35 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ esac

case $target in
*-*-mingw*)
have_x86_64=false
have_win32=true
PTHREAD_FLAGS=""
DLOPEN_FLAGS=""
Expand Down Expand Up @@ -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)

Expand All @@ -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])
Expand Down Expand Up @@ -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`
Expand All @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions driver-bitforce.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* any later version. See COPYING for more details.
*/

#include "config.h"

#include <limits.h>
#include <pthread.h>
#include <stdint.h>
Expand All @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions driver-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion driver-cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion driver-icarus.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

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

#include <limits.h>
#include <pthread.h>
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion driver-ztex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions elist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit c9ae715

Please sign in to comment.