KQEMU build on MinGW patch
Attached patch allows KQEMU to build on pure MinGW installation without the need for ELF tools or compilation on Linux. I'm not sure if it breaks the Linux compilation, so it should be carefully tested. Hope it's usefull at least for someone.
Best regards,
Filip Navara
Makefile +8 -5
@@ -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
genmon.c +6 -0
@@ -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 (;;) {
i386/monitor-win32.ld +20 -0
@@ -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 = . ; +}
i386/monitor_asm.S +2 -2
@@ -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,
i386/nexus_asm.S +8 -8
@@ -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:
kqemu_int.h +8 -8
@@ -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,
x86_64/monitor-win32.ld +21 -0
@@ -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 = . ; +}
x86_64/monitor_asm.S +2 -2
@@ -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) */
Attached patch allows KQEMU to build on pure MinGW installation without the need for ELF tools or compilation on Linux. I'm not sure if it breaks the Linux compilation, so it should be carefully tested. Hope it's usefull at least for someone.
Best regards,
Filip Navara
Makefile +8 -5
@@ -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
genmon.c +6 -0
@@ -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 (;;) {
i386/monitor-win32.ld +20 -0
@@ -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 = . ; +}
i386/monitor_asm.S +2 -2
@@ -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,
i386/nexus_asm.S +8 -8
@@ -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:
kqemu_int.h +8 -8
@@ -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,
x86_64/monitor-win32.ld +21 -0
@@ -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 = . ; +}
x86_64/monitor_asm.S +2 -2
@@ -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) */
Quoted 4 lines · Filip Navara
Attached patch allows KQEMU to build on pure MinGW installation without the need for ELF tools or compilation on Linux. I'm not sure if it breaks the Linux compilation, so it should be carefully tested. Hope it's usefull at least for someone.
at long last!... I thought it was my setup that was wrong, so I've always used the supplied kqemu.sys. Now only I realize we're supposed to cross compile.
yes, it's very useful ! and it works :)
Thanks!
Signature · 3 lines
Christian -- http://detaolb.sourceforge.net/, a linux distribution for Qemu