Permalink
Browse files

Compiles clean on Win32 now

Doesn't find callbacks due to stdcall @nn naming. -Wl,--kill-at is
supposed to address this, but doesn't seem to be having its effect.
  • Loading branch information...
1 parent d54bdb4 commit 17a41bf73aa8eca468f3051f37d8317bc06e51f8 @kulp committed Aug 1, 2012
Showing with 59 additions and 16 deletions.
  1. +1 −0 Makefile.Win32
  2. +3 −0 src/common.h
  3. +2 −5 src/devices/spi.c
  4. +6 −5 src/devices/spi.h
  5. +5 −4 src/devices/spidummy.c
  6. +0 −2 src/os/Linux/plugin.h
  7. +42 −0 src/os/Win32/plugin.h
View
@@ -12,3 +12,4 @@ else
CROSS_COMPILE ?= x86_64-w64-mingw32-
endif
INCLUDE_OS = src/os/Win32
+LDFLAGS += -Wl,--kill-at
View
@@ -76,5 +76,8 @@ static void traverse_##Tag(const void *node, VISIT order, int level) \
} \
}
+#define ALIASING_CAST(Type,Expr) \
+ *(Type * MAY_ALIAS *)&(Expr)
+
#endif
View
@@ -13,15 +13,12 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#include <dlfcn.h>
+#include "plugin.h"
#include "common.h"
#include "device.h"
#include "spi.h"
-#define FPTR_FROM_VPTR(Type,Expr) \
- *(Type * MAY_ALIAS *)&(Expr)
-
#define SPI_BASE 0x200
#define SPI_LEN (0x7 * 4) /* seven registers at four addresses each) */
#define SPI_END (SPI_BASE + SPI_LEN - 1)
@@ -135,7 +132,7 @@ static int spi_emu_init(struct sim_state *s, void *cookie, ...)
char buf[64]; \
snprintf(buf, sizeof buf, "%s_spi_"#Stem, implstem); \
void *ptr = dlsym(libhandle, buf); \
- spi->impls[inst].Stem = FPTR_FROM_VPTR(spi_##Stem,ptr); \
+ spi->impls[inst].Stem = ALIASING_CAST(spi_##Stem,ptr); \
} while (0) \
//
View
@@ -1,11 +1,12 @@
#ifndef DEVICES_SPI_H_
#define DEVICES_SPI_H_
-typedef int spi_init(void *pcookie);
-typedef int spi_select(void *cookie, int _ss);
-/// @p in and @c *out must be 0 or 1
-typedef int spi_clock(void *cookie, int _ss, int in, int *out);
-typedef int spi_fini(void *cookie);
+#include "plugin.h"
+
+typedef int EXPORT_CALLING spi_init(void *pcookie);
+typedef int EXPORT_CALLING spi_select(void *cookie, int _ss);
+typedef int EXPORT_CALLING spi_clock(void *cookie, int _ss, int in, int *out); ///< @p in and @c *out must be 0 or 1
+typedef int EXPORT_CALLING spi_fini(void *cookie);
struct spi_ops {
spi_init *init;
View
@@ -1,29 +1,30 @@
#include "spi.h"
+#include "plugin.h"
#include <stdio.h>
-int spidummy_spi_init(void *pcookie)
+int EXPORT spidummy_spi_init(void *pcookie)
{
printf("%s(pcookie=%p)\n", __func__, pcookie);
// point to self ; this will make tracing instances in debug output easy
*(void**)pcookie = pcookie;
return 0;
}
-int spidummy_spi_select(void *cookie, int _ss)
+int EXPORT spidummy_spi_select(void *cookie, int _ss)
{
printf("%s(cookie=%p, _ss=%i)\n", __func__, cookie, _ss);
return 0;
}
-int spidummy_spi_clock(void *cookie, int _ss, int in, int *out)
+int EXPORT spidummy_spi_clock(void *cookie, int _ss, int in, int *out)
{
printf("%s(cookie=%p, _ss=%i, in=%i, out=%p)\n", __func__, cookie, _ss, in, (void*)out);
*out = in; // just echo back
return 0;
}
-int spidummy_spi_fini(void *cookie)
+int EXPORT spidummy_spi_fini(void *cookie)
{
printf("%s(cookie=%p)\n", __func__, cookie);
return 0;
View
@@ -5,7 +5,5 @@
#define EXPORT
#define EXPORT_CALLING
-#define GENERIC
-
#endif
View
@@ -2,8 +2,50 @@
#define PLUGIN_H_
#include <windows.h>
+
#define EXPORT_CALLING __stdcall
#define EXPORT __declspec(dllexport) EXPORT_CALLING
+#include "common.h"
+
+// just defined to make compilation work ; ignored
+#define RTLD_DEFAULT NULL
+#define RTLD_LOCAL -1
+#define RTLD_LAZY -1
+
+static inline void *dlopen(const char *name, int flags)
+{
+ // TODO use LoadLibraryEx() and flags ?
+ return LoadLibrary(name);
+}
+
+static inline void *dlsym(void *handle, const char *name)
+{
+ FARPROC g = GetProcAddress(handle, name);
+ void *h;
+ *(FARPROC*)&h = g;
+ return h;
+}
+
+static inline char *dlerror(void)
+{
+ static __thread char buf[1024];
+
+ FormatMessage(
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR)&buf,
+ sizeof buf, NULL);
+
+ return buf;
+}
+
+static inline int dlclose(void *handle)
+{
+ return !FreeLibrary(handle);
+}
+
#endif

0 comments on commit 17a41bf

Please sign in to comment.