simulavr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Simulavr-devel] Support for Visual Studio (v1)


From: Petr Hluzín
Subject: [Simulavr-devel] Support for Visual Studio (v1)
Date: Sun, 30 Jan 2011 02:35:00 +0100

Hello folks!

This patch is a first try on implementing support for compiling with
MS Visual Studio.
The MinGW and native Linux builds should not be affected.

The patch may require some changes that are not commited to Savannah
repository. (They are in my local git working copy and I do not know
what is it trying to tell me. I tried some buttons and controls and
TortoiseGit produced some messages I do not understand. One of them
probably appeared because my key is not loaded in ssh agent - it will
take few days to physically get it.)

Summary of the changes:

various #include - added paths to subdirectories.
I could have added all the subdirectories to Additional Include Paths,
but think the information should be in sources themselves. And I guess
few people like touching autoconf if they do not need to.

AvrDevice::Load() - uses BFD library

#ifdef HAVE_SYS_MINGW - added '|| defined(_MSC_VER)'

#include <getopt.h> - MSVC lacks this header, I am using Benjamin
Sittler's code [1] (MIT license)
[1] http://xent.com/~bsittler/geocities/#my_getopt

Here it goes:

 src/at4433.h                 |    4 ++--
 src/at8515.h                 |    4 ++--
 src/at90canbase.h            |    4 ++--
 src/atmega128.h              |    6 +++---
 src/atmega16_32.h            |    6 +++---
 src/atmega668base.h          |    4 ++--
 src/atmega8.h                |    6 +++---
 src/attiny2313.h             |    6 +++---
 src/avrdevice.cpp            |   14 ++++++++++++--
 src/avrerror.cpp             |    4 ++++
 src/cmd/dumpargs.cpp         |    4 ++--
 src/cmd/dumpargs.h           |    4 ++--
 src/cmd/gdb.h                |    4 ++--
 src/cmd/gdbserver.cpp        |   10 ++++++++--
 src/cmd/main.cpp             |   15 ++++++++++-----
 src/hwport.cpp               |    2 ++
 src/hwtimer/hwtimer.cpp      |    6 +++---
 src/hwtimer/icapturesrc.h    |    2 +-
 src/hwtimer/prescalermux.cpp |    3 +++
 src/hwtimer/timerprescaler.h |    8 ++++----
 src/memory.h                 |    2 +-
 src/string2.cpp              |    5 +++++
 src/ui/keyboard.cpp          |    2 +-
 src/ui/mysocket.cpp          |    2 +-
 src/ui/mysocket.h            |    5 +++--
 src/ui/scope.h               |    6 +++---
 src/ui/ui.h                  |    8 ++++----
 27 files changed, 91 insertions(+), 55 deletions(-)

diff --git a/src/at4433.h b/src/at4433.h
index 0da856d..eeaaf19 100644
--- a/src/at4433.h
+++ b/src/at4433.h
@@ -33,8 +33,8 @@ class HWMcucr;
 #include "hwad.h"
 #include "hwport.h"
 #include "hwspi.h"
-#include "timerprescaler.h"
-#include "hwtimer.h"
+#include "hwtimer/timerprescaler.h"
+#include "hwtimer/hwtimer.h"
 #include "externalirq.h"

 //! AVRDevice class for AT90S4433
diff --git a/src/at8515.h b/src/at8515.h
index 66dc318..6f5e3c0 100644
--- a/src/at8515.h
+++ b/src/at8515.h
@@ -30,8 +30,8 @@
 #include "hwspi.h"
 #include "hwuart.h"
 #include "hwacomp.h"
-#include "timerprescaler.h"
-#include "hwtimer.h"
+#include "hwtimer/timerprescaler.h"
+#include "hwtimer/hwtimer.h"
 #include "externalirq.h"
 #include "hwport.h"

diff --git a/src/at90canbase.h b/src/at90canbase.h
index b5aee15..dc83eb0 100644
--- a/src/at90canbase.h
+++ b/src/at90canbase.h
@@ -32,8 +32,8 @@
 #include "hwacomp.h"
 #include "hwport.h"
 #include "hwspi.h"
-#include "timerprescaler.h"
-#include "hwtimer.h"
+#include "hwtimer/timerprescaler.h"
+#include "hwtimer/hwtimer.h"
 #include "ioregs.h" //only for rampz here

 #include <memory>
diff --git a/src/atmega128.h b/src/atmega128.h
index 1b42a3f..5d96523 100644
--- a/src/atmega128.h
+++ b/src/atmega128.h
@@ -29,9 +29,9 @@
 #include "avrdevice.h"
 #include "hardware.h"
 #include "rwmem.h"
-#include "timerprescaler.h"
-#include "timerirq.h"
-#include "hwtimer.h"
+#include "hwtimer/timerprescaler.h"
+#include "hwtimer/timerirq.h"
+#include "hwtimer/hwtimer.h"
 #include "externalirq.h"
 #include "hwuart.h"
 #include "hwspi.h"
diff --git a/src/atmega16_32.h b/src/atmega16_32.h
index bbbf92e..399b907 100644
--- a/src/atmega16_32.h
+++ b/src/atmega16_32.h
@@ -29,9 +29,9 @@
 #include "avrdevice.h"
 #include "hardware.h"
 #include "rwmem.h"
-#include "timerprescaler.h"
-#include "timerirq.h"
-#include "hwtimer.h"
+#include "hwtimer/timerprescaler.h"
+#include "hwtimer/timerirq.h"
+#include "hwtimer/hwtimer.h"
 #include "externalirq.h"
 #include "hwuart.h"
 #include "hwspi.h"
diff --git a/src/atmega668base.h b/src/atmega668base.h
index f68e2dd..9fa19e4 100644
--- a/src/atmega668base.h
+++ b/src/atmega668base.h
@@ -31,8 +31,8 @@
 #include "hwad.h"
 #include "hwport.h"
 #include "hwspi.h"
-#include "timerprescaler.h"
-#include "hwtimer.h"
+#include "hwtimer/timerprescaler.h"
+#include "hwtimer/hwtimer.h"

 /*! AVRDevice class for ATMega48/88/168/328
   \todo This device isn't completely implemented. There is no
diff --git a/src/atmega8.h b/src/atmega8.h
index 978b7e1..793e66d 100644
--- a/src/atmega8.h
+++ b/src/atmega8.h
@@ -25,9 +25,9 @@
 #include "avrdevice.h"
 #include "hardware.h"
 #include "rwmem.h"
-#include "timerprescaler.h"
-#include "timerirq.h"
-#include "hwtimer.h"
+#include "hwtimer/timerprescaler.h"
+#include "hwtimer/timerirq.h"
+#include "hwtimer/hwtimer.h"
 #include "externalirq.h"
 #include "hwuart.h"
 #include "hwspi.h"
diff --git a/src/attiny2313.h b/src/attiny2313.h
index 1c489ba..435b563 100644
--- a/src/attiny2313.h
+++ b/src/attiny2313.h
@@ -29,10 +29,10 @@
 #include "avrdevice.h"
 #include "hardware.h"
 #include "rwmem.h"
-#include "timerprescaler.h"
-#include "timerirq.h"
+#include "hwtimer/timerprescaler.h"
+#include "hwtimer/timerirq.h"
+#include "hwtimer/hwtimer.h"
 #include "externalirq.h"
-#include "hwtimer.h"
 #include "hwuart.h"

 //! AVRDevice class for ATTiny2313
diff --git a/src/avrdevice.cpp b/src/avrdevice.cpp
index c427f43..a9cfe4c 100644
--- a/src/avrdevice.cpp
+++ b/src/avrdevice.cpp
@@ -23,8 +23,12 @@
  *  $Id$
  */

-#include "config.h"
-#include "bfd.h"
+#ifndef _MSC_VER
+#   include "config.h"
+#   include "bfd.h"
+#else
+//#   include "C:\cygwin\usr\include\bfd.h"  // binutils, /usr/include/bfd.h
+#endif

 #include "avrdevice.h"
 #include "traceval.h"
@@ -34,6 +38,7 @@
 #include "systemclock.h"
 #include "avrerror.h"
 #include "avrmalloc.h"
+#include <assert.h>

 #include "avrdevice_impl.h"

@@ -59,6 +64,10 @@ void AvrDevice::RemoveFromCycleList(Hardware *hw) {
 void AvrDevice::Load(const char* fname) {
     actualFilename = fname;

+#ifdef _MSC_VER
+    fprintf(stderr, "Fatal: BDF library is not supported on MS Windows\n");
+    assert(false);  // TODO: Port BDF library to MS Windows
+#else
     bfd *abfd;
     asection *sec;

@@ -154,6 +163,7 @@ void AvrDevice::Load(const char* fname) {
     }

     bfd_close(abfd);
+#endif
 }

 #ifdef VI_BUG
diff --git a/src/avrerror.cpp b/src/avrerror.cpp
index 70a86c9..9c54226 100644
--- a/src/avrerror.cpp
+++ b/src/avrerror.cpp
@@ -42,6 +42,10 @@
 #include "avrerror.h"
 #include "helper.h"

+#ifdef _MSC_VER
+#  define snprintf _snprintf
+#endif
+
 SystemConsoleHandler::SystemConsoleHandler() {
     useExitAndAbort = true;
     nullStream = new std::ostream(0);
diff --git a/src/cmd/dumpargs.cpp b/src/cmd/dumpargs.cpp
index 3642f7e..b8db71e 100644
--- a/src/cmd/dumpargs.cpp
+++ b/src/cmd/dumpargs.cpp
@@ -28,8 +28,8 @@
 #include <stdlib.h>

 #include "dumpargs.h"
-#include "helper.h"
-#include "avrerror.h"
+#include "../helper.h"
+#include "../avrerror.h"

 using namespace std;

diff --git a/src/cmd/dumpargs.h b/src/cmd/dumpargs.h
index 65dc541..d1f38f9 100644
--- a/src/cmd/dumpargs.h
+++ b/src/cmd/dumpargs.h
@@ -29,8 +29,8 @@
 #include <iostream>
 #include <vector>

-#include "avrdevice.h"
-#include "traceval.h"
+#include "../avrdevice.h"
+#include "../traceval.h"

 //! Parse given trace options and open Dumper
 extern void SetDumpTraceArgs(const std::vector<std::string>
&traceopts, AvrDevice *dev);
diff --git a/src/cmd/gdb.h b/src/cmd/gdb.h
index 7d5d52d..69a318b 100644
--- a/src/cmd/gdb.h
+++ b/src/cmd/gdb.h
@@ -29,7 +29,7 @@

 #include "config.h"

-#ifdef HAVE_SYS_MINGW
+#if defined(HAVE_SYS_MINGW) || defined(_MSC_VER)
 #   include <winsock2.h>
 #   include <sys/types.h>
 #else
@@ -66,7 +66,7 @@ class GdbServerSocket {
         virtual void CloseConnection(void)=0;
 };

-#ifdef HAVE_SYS_MINGW
+#if defined(HAVE_SYS_MINGW) || defined(_MSC_VER)

 //! Interface implementation for server socket wrapper on MingW
systems (windows)
 class GdbServerSocketMingW: public GdbServerSocket {
diff --git a/src/cmd/gdbserver.cpp b/src/cmd/gdbserver.cpp
index 05d1a8e..071e00e 100644
--- a/src/cmd/gdbserver.cpp
+++ b/src/cmd/gdbserver.cpp
@@ -29,7 +29,9 @@ using namespace std;
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#ifndef _MSC_VER
 #include <unistd.h>
+#endif
 #include <fcntl.h>
 #include <time.h>
 #include <signal.h>
@@ -46,6 +48,10 @@ using namespace std;
 #include "avrdevice_impl.h"
 #include "gdb.h"

+#ifdef _MSC_VER
+#  define snprintf _snprintf
+#endif
+
 #ifndef DOXYGEN /* have doxygen system ignore this. */
 enum {
     MAX_READ_RETRY = 50,          /* Maximum number of retries if a
read is incomplete. */
@@ -68,7 +74,7 @@ enum {
 };
 #endif /* not DOXYGEN */

-#ifdef HAVE_SYS_MINGW
+#if defined(HAVE_SYS_MINGW) || defined(_MSC_VER)

 int GdbServerSocketMingW::socketCount = 0;

@@ -288,7 +294,7 @@ GdbServer::GdbServer(AvrDevice *c, int _port, int
debug, int _waitForGdbConnecti
     lastCoreStepFinished = true;
     connState = false;

-#ifdef HAVE_SYS_MINGW
+#if defined(HAVE_SYS_MINGW) || defined(_MSC_VER)
     server = new GdbServerSocketMingW(_port);
 #else
     server = new GdbServerSocketUnix(_port);
diff --git a/src/cmd/main.cpp b/src/cmd/main.cpp
index 1b250ed..d4f2551 100644
--- a/src/cmd/main.cpp
+++ b/src/cmd/main.cpp
@@ -31,7 +31,12 @@ using namespace std;

 #include <stdio.h>
 #include <stdlib.h>
-#include <getopt.h>
+#ifndef _MSC_VER
+#  include <getopt.h>
+#else
+#  include "../getopt/getopt.h"
+#  define VERSION "(git-snapshot)"
+#endif

 #include "config.h"

@@ -40,12 +45,12 @@ using namespace std;
 #include "avrdevice.h"
 #include "avrfactory.h"
 #include "gdb.h"
-#include "ui.h"
+#include "ui/ui.h"
 #include "systemclock.h"
-#include "lcd.h"
-#include "keyboard.h"
+#include "ui/lcd.h"
+#include "ui/keyboard.h"
 #include "traceval.h"
-#include "scope.h"
+#include "ui/scope.h"
 #include "string2.h"
 #include "helper.h"
 #include "specialmem.h"
diff --git a/src/hwport.cpp b/src/hwport.cpp
index 003bfd5..bbfc634 100644
--- a/src/hwport.cpp
+++ b/src/hwport.cpp
@@ -29,6 +29,7 @@ using namespace std;
 #include "hwport.h"
 #include "avrdevice.h"
 #include "avrerror.h"
+#include <assert.h>

 HWPort::HWPort(AvrDevice *core, const string &name, bool portToggle, int size):
     Hardware(core),
@@ -134,6 +135,7 @@ void HWPort::CalcOutputs(void) { //Calculate the
new output value to be transmit
 string HWPort::GetPortString(void) {
     string dummy;
     dummy.resize(portSize);
+    assert(portSize < sizeof(p)/sizeof(p[0]));
     for(int tt = 0; tt < portSize; tt++)
         dummy[portSize - 1 - tt] = p[tt];  // calls Pin::operator char()

diff --git a/src/hwtimer/hwtimer.cpp b/src/hwtimer/hwtimer.cpp
index 32b2bd5..1835e29 100644
--- a/src/hwtimer/hwtimer.cpp
+++ b/src/hwtimer/hwtimer.cpp
@@ -23,11 +23,11 @@
  *  $Id$
  */

-#include "hardware.h"
-#include "avrdevice.h"
+#include "../hardware.h"
+#include "../avrdevice.h"
 #include "timerprescaler.h"
 #include "hwtimer.h"
-#include "helper.h"
+#include "../helper.h"

 using namespace std;

diff --git a/src/hwtimer/icapturesrc.h b/src/hwtimer/icapturesrc.h
index 87dbf4c..ff3abd0 100644
--- a/src/hwtimer/icapturesrc.h
+++ b/src/hwtimer/icapturesrc.h
@@ -26,7 +26,7 @@
 #ifndef ICAPTURESRC
 #define ICAPTURESRC

-#include "pinatport.h"
+#include "../pinatport.h"

 //! Class, which provides input capture source for 16bit timers
 class ICaptureSource {
diff --git a/src/hwtimer/prescalermux.cpp b/src/hwtimer/prescalermux.cpp
index fcb0831..f0d6605 100644
--- a/src/hwtimer/prescalermux.cpp
+++ b/src/hwtimer/prescalermux.cpp
@@ -25,6 +25,7 @@

 #include "prescalermux.h"
 #include "avrerror.h"
+#include <assert.h>

 PrescalerMultiplexer::PrescalerMultiplexer(HWPrescaler *ps):
     prescaler(ps) {}
@@ -59,6 +60,7 @@ bool PrescalerMultiplexer::isClock(unsigned int cs) {

     default:
         avr_error("wrong prescaler multiplex value: %d", cs);
+        assert(false);
     }
 }

@@ -103,6 +105,7 @@ bool PrescalerMultiplexerExt::isClock(unsigned int cs) {

     default:
         avr_error("wrong prescaler multiplex value: %d", cs);
+        assert(false);
     }
 }

diff --git a/src/hwtimer/timerprescaler.h b/src/hwtimer/timerprescaler.h
index 821f15b..31587f8 100644
--- a/src/hwtimer/timerprescaler.h
+++ b/src/hwtimer/timerprescaler.h
@@ -26,10 +26,10 @@
 #ifndef TIMERPRESCALER
 #define TIMERPRESCALER

-#include "hardware.h"
-#include "avrdevice.h"
-#include "rwmem.h"
-#include "pinatport.h"
+#include "../hardware.h"
+#include "../avrdevice.h"
+#include "../rwmem.h"
+#include "../pinatport.h"

 //! Prescaler unit for support timers with clock
 /*! This is a prescaler unit without external clock input, features reset and
diff --git a/src/memory.h b/src/memory.h
index 47338fa..c57925a 100644
--- a/src/memory.h
+++ b/src/memory.h
@@ -38,7 +38,7 @@
 class Memory {
     protected:

-        unsigned int size; /*!< allocated size of memory block */
+        unsigned int size; /*!< allocated size (in bytes) of myMemory */

     public:

diff --git a/src/string2.cpp b/src/string2.cpp
index eba04a2..c0ce607 100644
--- a/src/string2.cpp
+++ b/src/string2.cpp
@@ -27,6 +27,11 @@
 #include <stdlib.h>
 #include <limits.h>

+#ifdef _MSC_VER
+#  define strtoll _strtoi64
+#  define strtoull _strtoui64
+#endif
+
 /*
  *  Instantiate an error checking wrapper for strtol (unsigned char)
  */
diff --git a/src/ui/keyboard.cpp b/src/ui/keyboard.cpp
index 8b5b6e9..0034e6d 100644
--- a/src/ui/keyboard.cpp
+++ b/src/ui/keyboard.cpp
@@ -27,7 +27,7 @@
 #include <sstream>
 #include <stdlib.h>

-#include "avrerror.h"
+#include "../avrerror.h"
 #include "ui.h"
 using namespace std;

diff --git a/src/ui/mysocket.cpp b/src/ui/mysocket.cpp
index 0b086fe..f02f5ea 100644
--- a/src/ui/mysocket.cpp
+++ b/src/ui/mysocket.cpp
@@ -9,7 +9,7 @@

 using namespace std;

-#ifdef HAVE_SYS_MINGW
+#if defined(_MSC_VER) || defined(HAVE_SYS_MINGW)

 int Socket::socketCount = 0;

diff --git a/src/ui/mysocket.h b/src/ui/mysocket.h
index 4f75d16..28822a1 100644
--- a/src/ui/mysocket.h
+++ b/src/ui/mysocket.h
@@ -33,10 +33,11 @@
 #include <string>
 #include "config.h"

-#ifdef HAVE_SYS_MINGW
+#if defined(_MSC_VER) || defined(HAVE_SYS_MINGW)

 #include <winsock2.h>
 #include <sys/types.h>
+#define ssize_t size_t

 class Socket {

@@ -131,7 +132,7 @@ class Socket: public sockstream {
         }
 };

-#endif
+#endif  // !HAVE_SYS_MINGW

 #endif

diff --git a/src/ui/scope.h b/src/ui/scope.h
index 7051bc2..3a59d30 100644
--- a/src/ui/scope.h
+++ b/src/ui/scope.h
@@ -31,10 +31,10 @@
 #include <string>
 #include <vector>

-#include "systemclocktypes.h"
-#include "simulationmember.h"
+#include "../systemclocktypes.h"
+#include "../simulationmember.h"
 #include "ui.h"
-#include "pin.h"
+#include "../pin.h"


 class Scope : public SimulationMember {
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 9bf06c8..26ec001 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -29,11 +29,11 @@
 #include <map>
 #include <sstream>

-#include "systemclocktypes.h"
-#include "simulationmember.h"
+#include "../systemclocktypes.h"
+#include "../simulationmember.h"
 #include "mysocket.h"
-#include "pin.h"
-#include "externaltype.h"
+#include "../pin.h"
+#include "../externaltype.h"

 class UserInterface: public SimulationMember, public Socket, public
ExternalType {
     protected:


(Notes for myself: In TortoiseGit do not use Create Patch Serial,
instead use Show Log, Working dir changes, right click, Show Changes
as Unified Diff.)

-- 
Petr Hluzin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]