Index: /branches/working-0711/ccl/lisp-kernel/lisp-debug.c
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/lisp-debug.c	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/lisp-debug.c	(revision 12990)
@@ -28,5 +28,7 @@
 #include <stdio.h>
 
-#ifndef WINDOWS
+#ifdef WINDOWS
+#include <fcntl.h>
+#else
 #include <sys/socket.h>
 #include <dlfcn.h>
@@ -51,4 +53,9 @@
   if (f) {
     if (setvbuf(f, NULL, _IONBF, 0) == 0) {
+#ifdef WINDOWS
+      if (fileno(stdin) < 0) {
+        stdin->_file = 0;
+      }
+#endif
       dbgout = f;
       return true;
@@ -100,6 +107,18 @@
           (fd0stat.st_dev == devnullstat.st_dev));
 }
-
-#endif
+#endif
+
+#ifdef WINDOWS
+Boolean
+stdin_is_dev_null()
+{
+  HANDLE stdIn;
+  stdIn = GetStdHandle(STD_INPUT_HANDLE);
+  return (stdIn == NULL);
+}
+#endif
+
+
+
 
 char *
@@ -145,4 +164,6 @@
     switch(c) {
     case '\n':
+      continue;
+    case '\r':
       continue;
     case EOF:
@@ -694,4 +715,5 @@
 {
 
+
 #ifdef PPC
 #ifdef PPC64
@@ -1120,15 +1142,14 @@
   debug_command_return state = debug_continue;
 
+
+  if (stdin_is_dev_null()) {
+    return -1;
+  }
+
   va_start(args,message);
   vfprintf(dbgout, message, args);
   fprintf(dbgout, "\n");
   va_end(args);
-  
-
-#ifndef WINDOWS
-  if (stdin_is_dev_null()) {
-    return -1;
-  }
-#endif
+
   if (threads_initialized) {
     suspend_other_threads(false);
@@ -1175,4 +1196,5 @@
     fprintf(dbgout, "[%d] Clozure CL kernel debugger: ", main_thread_pid);
 #endif
+    fflush(dbgout);             /* dbgout should be unbuffered, so this shouldn't be necessary.  But it can't hurt ... */
     state = apply_debug_command(xp, readc(), info, why);
   }
Index: /branches/working-0711/ccl/lisp-kernel/lisp.h
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/lisp.h	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/lisp.h	(revision 12990)
@@ -34,7 +34,4 @@
 
 extern Boolean use_mach_exception_handling;
-#ifdef DARWIN
-extern Boolean running_under_rosetta;
-#endif
 
 extern int page_size, log2_page_size;
Index: /branches/working-0711/ccl/lisp-kernel/m4macros.m4
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/m4macros.m4	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/m4macros.m4	(revision 12990)
@@ -331,4 +331,6 @@
 equate_if_defined([DARWIN_GS_HACK])
 
+equate_if_defined([TCR_IN_GPR])
+
 /* Well, so much for that. Maybe this will go away soon ? */
 equate_if_defined([WIN32_ES_HACK])
Index: /branches/working-0711/ccl/lisp-kernel/pmcl-kernel.c
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/pmcl-kernel.c	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/pmcl-kernel.c	(revision 12990)
@@ -90,7 +90,4 @@
 #include <mach/port.h>
 #include <sys/sysctl.h>
-
-Boolean running_under_rosetta = false;
-
 #include <dlfcn.h>
 #endif
@@ -1014,4 +1011,22 @@
 
 #ifdef WINDOWS
+wchar_t *
+determine_executable_name()
+{
+  DWORD nsize = 512, result;
+  wchar_t *buf = malloc(nsize*sizeof(wchar_t));
+
+  do {
+    result = GetModuleFileNameW(NULL, buf, nsize);
+    if (result == nsize) {
+      nsize *= 2;
+      buf = realloc(buf,nsize*sizeof(wchar_t));
+    } else {
+      return buf;
+    }
+  } while (1);
+}
+
+
 wchar_t *
 ensure_real_path(wchar_t *path)
@@ -1457,16 +1472,4 @@
     exit(1);
   }
-#ifdef PPC
-#ifdef DARWIN
-  {
-    char *hosttype = getenv("HOSTTYPE");
-    if (hosttype && !strncmp("intel", hosttype, 5)) {
-      running_under_rosetta = true;
-      use_mach_exception_handling = false;
-      reserved_area_size = 1U << 30;
-    }
-  }
-#endif
-#endif
 #endif
 }
@@ -1690,5 +1693,5 @@
   check_os_version(argv[0]);
 #ifdef WINDOWS
-  real_executable_name = utf_16_argv[0];
+  real_executable_name = determine_executable_name();
 #else
   real_executable_name = determine_executable_name(argv[0]);
@@ -1951,4 +1954,5 @@
 xMakeDataExecutable(void *start, unsigned long nbytes)
 {
+#ifndef X86
   extern void flush_cache_lines();
   natural ustart = (natural) start, base, end;
@@ -1956,14 +1960,4 @@
   base = (ustart) & ~(cache_block_size-1);
   end = (ustart + nbytes + cache_block_size - 1) & ~(cache_block_size-1);
-#ifdef DARWIN
-  if (running_under_rosetta) {
-    /* We probably need to flush something's cache even if running
-       under Rosetta, but (a) this is agonizingly slow and (b) we're
-       dying before we get to the point where this would matter.
-    */
-    return;
-  }
-#endif
-#ifndef X86
   flush_cache_lines(base, (end-base)/cache_block_size, cache_block_size);
 #endif
Index: /branches/working-0711/ccl/lisp-kernel/thread_manager.c
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/thread_manager.c	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/thread_manager.c	(revision 12990)
@@ -2046,4 +2046,5 @@
         }
       }
+#if 0
     } else {
       if (tcr->valence == TCR_STATE_EXCEPTION_RETURN) {
@@ -2055,4 +2056,5 @@
         tcr->valence = TCR_STATE_LISP;
       }
+#endif
     }
     tcr->suspend_context = pcontext;
Index: /branches/working-0711/ccl/lisp-kernel/x86-asmutils64.s
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/x86-asmutils64.s	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/x86-asmutils64.s	(revision 12990)
@@ -171,4 +171,7 @@
 _endfn
 
+_exportfn(C(put_vector_registers))
+_endfn				
+        
 	__ifdef([DARWIN])
 _exportfn(C(darwin_sigreturn))
@@ -185,6 +188,4 @@
 	__endif
 
-_exportfn(C(put_vector_registers))
-_endfn				
 	
         
Index: /branches/working-0711/ccl/lisp-kernel/x86-constants.s
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/x86-constants.s	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/x86-constants.s	(revision 12990)
@@ -69,9 +69,9 @@
 	
 	_struct(lisp_globals,lisp_globals_limit-(num_lisp_globals*node_size))
-	 _node(initial_tcr)	        /* initial thread tcr   */
-	 _node(image_name)	        /* --image-name argument   */
-	 _node(BADfpscr_save_high)      /* high word of FP reg used to save FPSCR   */
+	 _node(initial_tcr)	        /* initial thread tcr */
+	 _node(image_name)	        /* --image-name argument */
+	 _node(BADfpscr_save_high)      /* high word of FP reg used to save FPSCR */
 	 _node(unwind_resume)           /* _Unwind_Resume */
-	 _node(batch_flag)	        /* -b   */
+	 _node(batch_flag)	        /* -b */
 	 _node(host_platform)	        /* for runtime platform-specific stuff   */
 	 _node(argv)			/* address of argv[0]   */
Index: /branches/working-0711/ccl/lisp-kernel/x86-constants64.s
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/x86-constants64.s	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/x86-constants64.s	(revision 12990)
@@ -222,5 +222,5 @@
 
 
-ifdef([WINDOWS],[
+ifdef([TCR_IN_GPR],[
 /* We keep the TCR pointer in r11 */
 	define([rcontext_reg], r11)
Index: /branches/working-0711/ccl/lisp-kernel/x86-exceptions.c
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/x86-exceptions.c	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/x86-exceptions.c	(revision 12990)
@@ -2259,5 +2259,5 @@
 #ifdef X8664
 opcode load_allocptr_reg_from_tcr_save_allocptr_instruction[] =
-#ifdef WINDOWS
+#ifdef TCR_IN_GPR
   {0x49,0x8b,0x9b,0xd8,0x00,0x00,0x00}
 #else
@@ -2266,5 +2266,5 @@
 ;
 opcode compare_allocptr_reg_to_tcr_save_allocbase_instruction[] =
-#ifdef WINDOWS
+#ifdef TCR_IN_GPR
   {0x49,0x3b,0x9b,0xe0,0x00,0x00,0x00}
 #else
@@ -2278,5 +2278,5 @@
   {0xcd,0xc5};
 opcode clear_tcr_save_allocptr_tag_instruction[] =
-#ifdef WINDOWS
+#ifdef TCR_IN_GPR
   {0x41,0x80,0xa3,0xd8,0x00,0x00,0x00,0xf0}
 #else
Index: /branches/working-0711/ccl/lisp-kernel/x86-spentry64.s
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/x86-spentry64.s	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/x86-spentry64.s	(revision 12990)
@@ -1234,5 +1234,5 @@
 	__(movq catch_frame._save1(%temp0),%save1)
 	__(movq catch_frame._save2(%temp0),%save2)
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(movq catch_frame._save3(%temp0),%save3)
 	__endif
@@ -1280,5 +1280,5 @@
 	__(movq catch_frame._save1(%temp0),%save1)
 	__(movq catch_frame._save2(%temp0),%save2)
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(movq catch_frame._save3(%temp0),%save3)
 	__endif
@@ -1337,5 +1337,5 @@
 	__(movq %save2,%rsp)
 	__(movq catch_frame.rbp(%temp0),%rbp)
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(movq catch_frame._save3(%temp0),%save3)
 	__endif
@@ -1359,5 +1359,5 @@
 	__(push catch_frame._save1(%temp0))
 	__(push catch_frame._save2(%temp0))
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(push catch_frame._save3(%temp0))
 	__endif
@@ -1391,5 +1391,5 @@
 	__(jns local_label(_nthrowv_tpushloop))
 	__(pop %xfn)
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(pop %save3)
 	__endif
@@ -1469,5 +1469,5 @@
 	__(movq catch_frame.rsp(%temp0),%rsp)
 	__(movq catch_frame.rbp(%temp0),%rbp)
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(movq catch_frame._save3(%temp0),%save3)
 	__endif
@@ -1493,5 +1493,5 @@
 	__(movq catch_frame._save1(%temp0),%save1)
 	__(movq catch_frame._save2(%temp0),%save2)
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(movq catch_frame._save3(%temp0),%save3)
 	__endif
@@ -4016,5 +4016,5 @@
          __(movq %csave2,%imm0)
         __endif
-	__ifdef([WINDOWS])
+	__ifdef([TCR_IN_GPR])
 	/* Preserve TCR pointer */
 	__(movq %rcontext_reg, %csave0)
@@ -4054,9 +4054,9 @@
          __(movq %csave2,%rdx)
         __endif
-	__ifdef([WINDOWS])
+	__ifdef([TCR_IN_GPR])
 	__(movq %csave0, %rcontext_reg)
 	__endif
 	__(movq %rsp,rcontext(tcr.foreign_sp))
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(clr %save3)
 	__endif
@@ -4236,5 +4236,5 @@
          __(movq %csave3,%imm1)
         __endif
-	__ifdef([WINDOWS])
+	__ifdef([TCR_IN_GPR])
 	/* Preserve TCR pointer */
 	__(movq %rcontext_reg, %csave1)
@@ -4274,9 +4274,9 @@
          __(movsd 24(%csave0),%xmm1)
         __endif
-	__ifdef([WINDOWS])
+	__ifdef([TCR_IN_GPR])
 	__(movq %csave1, %rcontext_reg)
 	__endif
 	__(movq %rsp,rcontext(tcr.foreign_sp))        
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(clr %save3)
 	__endif
@@ -4427,6 +4427,8 @@
 	__(movq (%rsp),%rbp)
 	__(addq $2*node_size,%rsp)
+        __ifdef([TCR_IN_GPR])
+         __(movq %rcontext_reg,%csave0)
+        __endif
         __ifdef([WINDOWS])
-         __(movq %rcontext_reg,%csave0)
          __(pop %carg0)
          __(pop %carg1)
@@ -4451,10 +4453,10 @@
          __endif
         __endif
-        __ifdef([WINDOWS])
+        __ifdef([TCR_IN_GPR])
          __(movq %csave0,%rcontext_reg)
         __endif
 	__(movq %rbp,%rsp)
 	__(movq %rsp,rcontext(tcr.foreign_sp))
-        __ifndef([WINDOWS])
+        __ifndef([TCR_IN_GPR])
 	 __(clr %save3)
         __endif
@@ -4610,5 +4612,5 @@
         __ifdef([HAVE_TLS])
 	 /* TCR initialized for lisp ?   */
-	 __ifndef([WINDOWS]) /* FIXME */
+	 __ifndef([TCR_IN_GPR]) /* FIXME */
 	 __(movq %fs:current_tcr@TPOFF+tcr.linear,%rax)
 	 __(testq %rax,%rax)
@@ -4624,4 +4626,6 @@
 	__ifdef([WINDOWS])
 	__(add $0x20, %rsp)
+        __endif
+        __ifdef([TCR_IN_GPR])
 	__(movq %rax, %rcontext_reg)
 	__endif	
@@ -4637,5 +4641,5 @@
 	__(movq %csave0,%rax)
 	__(movq %rsp,rcontext(tcr.foreign_sp))
-	__ifndef([WINDOWS])
+	__ifndef([TCR_IN_GPR])
 	__(clr %save3)
 	__endif
@@ -4659,5 +4663,5 @@
         __(movq 8(%rsp),%save1)
         __(movq 16(%rsp),%save2)
-        __ifndef([WINDOWS])
+        __ifndef([TCR_IN_GPR])
          __(movq 24(%rsp),%save3)
         __endif
Index: /branches/working-0711/ccl/lisp-kernel/x86-subprims64.s
===================================================================
--- /branches/working-0711/ccl/lisp-kernel/x86-subprims64.s	(revision 12989)
+++ /branches/working-0711/ccl/lisp-kernel/x86-subprims64.s	(revision 12990)
@@ -97,4 +97,6 @@
 	__(push %csave5)
 	__(push %csave6)
+        __endif
+        __ifdef([TCR_IN_GPR])
 	__(movq %carg0,%rcontext_reg)
 	__endif
@@ -115,5 +117,5 @@
 	__(clr %save1)
 	__(clr %save2)
-	__ifndef([WINDOWS]) /* no %save3, r11 is %rcontext_reg */
+	__ifndef([TCR_IN_GPR]) /* no %save3, r11 is %rcontext_reg */
 	__(clr %save3)
 	__endif
