Index: /trunk/source/lisp-kernel/Threads.h
===================================================================
--- /trunk/source/lisp-kernel/Threads.h	(revision 8386)
+++ /trunk/source/lisp-kernel/Threads.h	(revision 8387)
@@ -17,18 +17,32 @@
 #include <stdlib.h>
 #include <unistd.h>
+#ifndef WINDOWS
 #include <sys/mman.h>
+#endif
 #include <stdio.h>
+#ifndef WINDOWS
 #include <pthread.h>
+#endif
 #include <errno.h>
 #include <limits.h>
+
 #undef USE_MACH_SEMAPHORES
-#undef USE_POSIX_SEMAPHORES
+#define USE_POSIX_SEMAPHORES
+#undef USE_WINDOWS_SEMAPHORES
+
 #ifdef DARWIN
 #define USE_MACH_SEMAPHORES 1
-#endif
-#ifndef USE_MACH_SEMAPHORES
-#define USE_POSIX_SEMAPHORES
+#undef  USE_POSIX_SEMAPHORES
+#endif
+#ifdef WINDOWS
+#define USE_WINDOWS_SEMPAHORES 1
+#undef USE_POSIX_SEMAPHORES
+#endif
+
+#ifdef USE_POSIX_SEMAPHORES
 #include <semaphore.h>
 #endif
+
+
 #ifdef USE_MACH_SEMAPHORES
 /* We have to use Mach semaphores, even if we're otherwise 
@@ -70,4 +84,9 @@
 #define TCR_FROM_TSD(tsd) ((TCR *)((natural)(tsd)-TCR_BIAS))
 
+#ifdef USE_WINDOWS_SEMAPHORES
+
+typedef void *sem_t;
+
+#endif
 #ifdef USE_POSIX_SEMAPHORES
 typedef sem_t * SEMAPHORE;
Index: /trunk/source/lisp-kernel/lisp.h
===================================================================
--- /trunk/source/lisp-kernel/lisp.h	(revision 8386)
+++ /trunk/source/lisp-kernel/lisp.h	(revision 8387)
@@ -37,13 +37,13 @@
 extern int page_size, log2_page_size;
 
-static inline unsigned long
-_align_to_power_of_2(unsigned long n, unsigned power)
+static inline natural
+_align_to_power_of_2(natural n, unsigned power)
 {
-  unsigned long align = (1<<power) -1;
+  natural align = (1<<power) -1;
 
   return (n+align) & ~align;
 }
 
-#define align_to_power_of_2(n,p) _align_to_power_of_2(((unsigned long)(n)),p)
+#define align_to_power_of_2(n,p) _align_to_power_of_2(((natural)(n)),p)
 
 static inline unsigned long
@@ -73,4 +73,5 @@
 #define PLATFORM_OS_DARWIN 3
 #define PLATFORM_OS_FREEBSD 4
+#define PLATFORM_OS_WINDOWS 6
 
 #ifdef LINUX
@@ -88,4 +89,8 @@
 #ifdef SOLARIS
 #define PLATFORM_OS PLATFORM_OS_SOLARIS
+#endif
+
+#ifdef WINDOWS
+#define PLATFORM_OS PLATFORM_OS_WINDOWS
 #endif
 
Index: /trunk/source/lisp-kernel/pmcl-kernel.c
===================================================================
--- /trunk/source/lisp-kernel/pmcl-kernel.c	(revision 8386)
+++ /trunk/source/lisp-kernel/pmcl-kernel.c	(revision 8387)
@@ -31,10 +31,14 @@
 #include <stdio.h>
 #include <stdlib.h>
+#ifndef WINDOWS
 #include <sys/mman.h>
+#endif
 #include <fcntl.h>
 #include <signal.h>
 #include <unistd.h>
 #include <errno.h>
+#ifndef WINDOWS
 #include <sys/utsname.h>
+#endif
 
 #ifdef LINUX
@@ -106,5 +110,7 @@
 
 #include <ctype.h>
+#ifndef WINDOWS
 #include <sys/select.h>
+#endif
 #include "Threads.h"
 
@@ -141,5 +147,5 @@
 {
   void * cache_start = (void *) p;
-  unsigned long ncacheflush = (unsigned long) q - (unsigned long) p;
+  natural ncacheflush = (natural) q - (natural) p;
 
   xMakeDataExecutable(cache_start, ncacheflush);  
@@ -149,4 +155,6 @@
 ensure_stack_limit(size_t stack_size)
 {
+#ifdef WINDOWS
+#else
   struct rlimit limits;
   rlim_t cur_stack_limit, max_stack_limit;
@@ -168,4 +176,5 @@
     }
   }
+#endif
   return stack_size;
 }
@@ -189,6 +198,6 @@
   void *allocate_stack(unsigned);
   void free_stack(void *);
-  unsigned size = useable+softsize+hardsize;
-  unsigned overhead;
+  natural size = useable+softsize+hardsize;
+  natural overhead;
   BytePtr base, softlimit, hardlimit;
   OSErr err;
@@ -1631,4 +1640,6 @@
 
 #ifndef DARWIN
+#ifdef WINDOWS
+#else
 void *
 xGetSharedLibrary(char *path, int mode)
@@ -1636,4 +1647,5 @@
   return dlopen(path, mode);
 }
+#else
 #else
 void *
Index: /trunk/source/lisp-kernel/win64/Makefile
===================================================================
--- /trunk/source/lisp-kernel/win64/Makefile	(revision 8386)
+++ /trunk/source/lisp-kernel/win64/Makefile	(revision 8387)
@@ -1,4 +1,4 @@
 #
-#   Copyright (C) 2005 Clozure Associates
+#   Copyright (C) 2007 Clozure Associates
 #   This file is part of OpenMCL.  
 #
@@ -17,11 +17,14 @@
 VPATH = ../
 RM = /bin/rm
-CC = x86_64-pc-mingw32-gcc
-AS = x86_64-pc-mingw32-as
+# gcc64, as64: until there's a real win64 gcc, assume that gcc and gas
+# are installed under these names
+CC = gcc64
+AS = as64
 M4 = m4
+LD = ld
 ASFLAGS = --64
 M4FLAGS = -DWIN64 -DWINDOWS -DX86 -DX8664 -DHAVE_TLS -DEMUTLS
 CDEFINES = -DWIN64 -DWINDOWS -D_REENTRANT -DX86 -DX8664 -D_GNU_SOURCE -DHAVE_TLS -DEMUTLS #-DDISABLE_EGC
-CDEBUG = -g
+CDEBUG = -gcoff
 COPT = -O2
 
@@ -40,5 +43,5 @@
 	$(M4) $(M4FLAGS) -I../ $< | $(AS)  $(ASFLAGS) -o $@
 .c.o:
-	$(CC) -c $< $(CDEFINES) $(CDEBUG) $(COPT) -m64 -o $@
+	$(CC) -c $< $(CDEFINES) $(CDEBUG) $(COPT) -fno-leading-underscore -m64 -o $@
 
 SPOBJ = pad.o x86-spjump64.o x86-spentry64.o x86-subprims64.o
