--- common/Makefile	Tue Feb  6 22:02:00 2007
+++ common/Makefile	Sat Sep  8 18:33:00 2007
@@ -28,17 +28,20 @@
               /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi  ;) 
 
 HOST_CC=gcc
-MON_CC=gcc
-MON_LD=ld
 ifdef CONFIG_WIN32
 TARGET=../kqemu-mod-$(ARCH)-win32.o
-CC=i386-mingw32-gcc
-LD=i386-mingw32-ld
+CROSS_PREFIX=i386-mingw32-
+CC=$(CROSS_PREFIX)gcc
+LD=$(CROSS_PREFIX)ld
+LD_POSTFIX=-win32
 else
 TARGET=../kqemu-mod-$(ARCH).o
 CC=gcc
 LD=ld
+LD_POSTFIX=
 endif
+MON_CC=$(CROSS_PREFIX)gcc
+MON_LD=$(CROSS_PREFIX)ld
 
 DEFINES=-D__KERNEL__
 INCLUDES=-nostdinc -iwithprefix include -I. -I..
@@ -84,7 +87,7 @@
 	objcopy -O binary $< $@
 
 monitor-image.out: $(ARCH)/nexus_asm.o $(ARCH)/monitor_asm.o monitor.o monitor-utils.o interp.o
-	$(MON_LD) -T $(ARCH)/monitor.ld -o $@ $^
+	$(MON_LD) -T $(ARCH)/monitor$(LD_POSTFIX).ld -o $@ $^
 
 $(ARCH)/nexus_asm.o: $(ARCH)/nexus_asm.S monitor_def.h
 
--- common/genmon.c	Tue Feb  6 22:02:00 2007
+++ common/genmon.c	Sat Sep  8 02:52:39 2007
@@ -18,11 +18,17 @@
  */
 #include <stdlib.h>
 #include <stdio.h>
+#ifdef _WIN32
+#include <sys/fcntl.h>
+#endif
 
 int main(int argc, char **argv)
 {
     int i, c;
 
+#ifdef _WIN32
+    setmode(0, O_BINARY);
+#endif
     printf("const uint8_t monitor_code[] = {\n");
     i = 0;
     for(;;) {
--- common/i386/monitor-win32.ld	Thu Jan  1 01:00:00 1970
+++ common/i386/monitor-win32.ld	Sat Sep  8 02:42:26 2007
@@ -0,0 +1,20 @@
+ENTRY(__start)
+SECTIONS
+{
+  . = 0xf0000000;
+  .text      : { *(.text) }
+  .rodata    : { *(.rodata) }
+  . = ALIGN(4);
+  ___start_seg_ex_table = . ;
+  seg_ex_table : { *(seg_ex_table) }
+  ___stop_seg_ex_table = . ;
+  .data    : { *(.data) }
+  .plt      : { *(.plt)	}
+  .got           : { *(.got.plt) *(.got) }
+  .bss       : {
+     *(.bss)
+      *(COMMON)
+  }   
+  . = ALIGN(4096);
+  _end = . ;
+}
--- common/i386/monitor_asm.S	Tue Feb  6 22:02:00 2007
+++ common/i386/monitor_asm.S	Sat Sep  8 18:21:31 2007
@@ -151,9 +151,9 @@
         jmp *%eax
                         
 #define SEG_EXCEPTION(label) \
-    .section "seg_ex_table", "a" ; \
+    .section seg_ex_table, "a" ; \
     .long label ; \
-    .previous
+    .section .text
 
 #ifdef USE_SEG_GP        
 /* %ebx contains the kqemu_state pointer, %eax the selector, 
--- common/i386/nexus_asm.S	Tue Feb  6 22:02:00 2007
+++ common/i386/nexus_asm.S	Sat Sep  8 02:41:15 2007
@@ -24,14 +24,14 @@
 .globl ASM_NAME(monitor2kernel)
 .globl ASM_NAME(kernel2monitor_jmp_offset)
 .globl ASM_NAME(monitor2kernel_jmp_offset)
-.global _start
+.global ASM_NAME(_start)
         
-_start:
-        .long ASM_NAME(kernel2monitor) - _start
-        .long ASM_NAME(interrupt_table) - _start
-        .long ASM_NAME(kernel2monitor_jmp_offset) - _start
-        .long ASM_NAME(monitor2kernel_jmp_offset) - _start
-        .long ASM_NAME(monitor_exec) - _start
+ASM_NAME(_start):
+        .long ASM_NAME(kernel2monitor) - ASM_NAME(_start)
+        .long ASM_NAME(interrupt_table) - ASM_NAME(_start)
+        .long ASM_NAME(kernel2monitor_jmp_offset) - ASM_NAME(_start)
+        .long ASM_NAME(monitor2kernel_jmp_offset) - ASM_NAME(_start)
+        .long ASM_NAME(monitor_exec) - ASM_NAME(_start)
 /*
  * Assumptions when entering kernel2monitor:      
  * %ss, %ds, %es, %cs are 4G flat 32 bit segments
@@ -147,7 +147,7 @@
 2:
 
         movl KQEMU_STATE_nexus_kaddr(%ebx), %eax
-        addl $monitor2kernel_jmp_offset1 - _start, %eax
+        addl $monitor2kernel_jmp_offset1 - ASM_NAME(_start), %eax
         jmp *%eax
 monitor2kernel_jmp_offset1:     
         
--- common/kqemu_int.h	Tue Feb  6 22:02:00 2007
+++ common/kqemu_int.h	Sat Sep  8 13:13:12 2007
@@ -1063,14 +1063,14 @@
 
 #ifdef __x86_64__
 #define MMU_EXCEPTION(label) \
-    ".section \"mmu_ex_table\", \"a\"\n"\
+    ".section mmu_ex_table, \"a\"\n"\
     ".quad " #label "\n"\
-    ".previous\n"
+    ".section .text\n"
 #else
 #define MMU_EXCEPTION(label) \
-    ".section \"mmu_ex_table\", \"a\"\n"\
+    ".section mmu_ex_table, \"a\"\n"\
     ".long " #label "\n"\
-    ".previous\n"
+    ".section .text\n"
 #endif
 
 extern char _start;
@@ -1226,14 +1226,14 @@
 
 #ifdef __x86_64__
 #define SEG_EXCEPTION(label) \
-    ".section \"seg_ex_table\", \"a\"\n"\
+    ".section seg_ex_table, \"a\"\n"\
     ".quad " #label "\n"\
-    ".previous\n"
+    ".section .text\n"
 #else
 #define SEG_EXCEPTION(label) \
-    ".section \"seg_ex_table\", \"a\"\n"\
+    ".section seg_ex_table, \"a\"\n"\
     ".long " #label "\n"\
-    ".previous\n"
+    ".section .text\n"
 #endif
 
 static inline unsigned long compute_eflags_user(struct kqemu_state *s, 
--- common/x86_64/monitor-win32.ld	Thu Jan  1 01:00:00 1970
+++ common/x86_64/monitor-win32.ld	Sat Sep  8 18:32:11 2007
@@ -0,0 +1,21 @@
+ENTRY(__start)
+SECTIONS
+{
+  . = 0xf0000000;
+  .text      : { *(.text) }
+  .rodata    : { *(.rodata) }
+  . = ALIGN(8);
+  ___start_seg_ex_table = . ;
+  seg_ex_table : { *(seg_ex_table) }
+  ___stop_seg_ex_table = . ;
+  .eh_frame   : { *(.eh_frame) }
+  .data    : { *(.data) }
+  .plt      : { *(.plt)	}
+  .got           : { *(.got.plt) *(.got) }
+  .bss       : {
+     *(.bss)
+      *(COMMON)
+  }   
+  . = ALIGN(4096);
+  _end = . ;
+}
--- common/x86_64/monitor_asm.S	Tue Feb  6 22:02:00 2007
+++ common/x86_64/monitor_asm.S	Sat Sep  8 18:21:50 2007
@@ -21,10 +21,10 @@
 #include "kqemu_int.h"
 
 #define SEG_EXCEPTION(label) \
-    .section "seg_ex_table", "a" ; \
+    .section seg_ex_table, "a" ; \
     .align 8 ; \
     .quad label ; \
-    .previous
+    .section .text
 
 /* unsigned long __exec_binary(unsigned long *eflags, int op, 
                                unsigned long a, unsigned long b) */
