From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KwzjF-0004sO-FU for qemu-devel@nongnu.org; Mon, 03 Nov 2008 08:44:25 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KwzjE-0004qQ-1H for qemu-devel@nongnu.org; Mon, 03 Nov 2008 08:44:24 -0500 Received: from [199.232.76.173] (port=45885 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KwzjD-0004q7-Ls for qemu-devel@nongnu.org; Mon, 03 Nov 2008 08:44:23 -0500 Received: from lizzard.sbs.de ([194.138.37.39]:16620) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KwzjC-0003kr-Rp for qemu-devel@nongnu.org; Mon, 03 Nov 2008 08:44:23 -0500 Message-ID: <490F0031.9000807@siemens.com> Date: Mon, 03 Nov 2008 14:44:17 +0100 From: Jan Kiszka MIME-Version: 1.0 References: <20081029171942.GA19158@raleigh.neotoma.org> In-Reply-To: <20081029171942.GA19158@raleigh.neotoma.org> Content-Type: multipart/mixed; boundary="------------090308030103040000030209" Subject: [Qemu-devel] Re: kqemu does not build on hybrid x86_64/i386 system Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Daniel Baumann This is a multi-part message in MIME format. --------------090308030103040000030209 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Chris Dukes wrote: > Hi, > I'm attempting to build kqemu 1.4.0~pre1 on a debian sid i386 system running > debian's 2.6.26-1-amd64 kernel. > > It fails attemping to assemble nexus_asm.S with a combination of > x86_64/nexus_asm.S:63: Error: bad register name `%rax' > type errors > and > x86_64/nexus_asm.S:84: Error: `movzwq' is only supported in 64-bit mode > > I believe this is happening because the kqemu script makes > extensive use of uname -m to determine the architecture for > build and incorrectly assumes that just because it's x86_64ish > that gcc will emit 64bit code. > > After much kludging (And it's incorrect for anything except Linux), > I was able to have common/Makefile apply -m32 or -m64 as I thought was > appropriate. Now the .S files assemble fine, but link fails with > x86_64/monitor_asm.o: In function `__monitor_exception': > (.text+0x68d): undefined reference to `KQEMU_STATE_monitor_ss_null_sel' > x86_64/monitor_asm.o: In function `exception_return': > (.text+0x6d3): undefined reference to `KQEMU_STATE_monitor_ss_null_sel' > x86_64/monitor_asm.o: In function `exception_return16': > (.text+0x776): undefined reference to `KQEMU_STATE_monitor_cs32_sel' > x86_64/monitor_asm.o: In function `__monitor_interrupt': > (.text+0x81c): undefined reference to `KQEMU_STATE_monitor_ss_null_sel' > > It's somewhat confusing as it builds fine for an x86_64 kernel with > x86_64 userspace and 686 kernel with i386 userspace. I recently hacked the kqemu's build system for such cross-compilation scenarios. Find my patches attached. The magic configure command I invoked was this: ./configure --kernel-path=... --cpu=i386 --cc="gcc -m32" \ --extra-ldflags=-melf_i386 Please note that those patches are no real solutions, maybe even cause problems to other OSes. The build system is desperately looking for a rework, specifically for Linux platforms. I think it should be switched completely to kbuild (with included tools, to build the monitor image), and then checked if the other target OSes can be cleanly folded into that or better kept separately. Jan -- Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux --------------090308030103040000030209 Content-Type: text/x-patch; name="0001-Cleanup-build-system-for-Linux.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-Cleanup-build-system-for-Linux.patch" >>From aaa820fa9ec6ff5a8e9dd07abf70f6becc249cd9 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Fri, 24 Oct 2008 12:45:44 +0200 Subject: [PATCH] Cleanup build system for Linux Cleanup root makefile /wrt Linux module building. Add a distclean rule. Signed-off-by: Jan Kiszka --- Makefile | 20 +++++++++++--------- common/Makefile | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 51e0a02..5a2607a 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,8 @@ else ifdef CONFIG_KBUILD26 # 2.6 build -all: kqemu.ko - -kqemu.ko: - make -C common all +all: + make -C common monitor-image.h make -C $(KERNEL_PATH) M=`pwd` modules else @@ -38,7 +36,11 @@ endif # !CONFIG_WIN32 clean: $(MAKE) -C common clean - rm -f kqemu.ko *.o *~ + rm -rf kqemu.ko *.o *~ .kqemu* Module.* modules.order kqemu.mod.c .tmp_versions \ + common/.kernel* common/*/.kernel* + +distclean: clean + rm -rf config-host.mak FILES=configure Makefile README Changelog LICENSE COPYING \ install.sh kqemu-linux.c kqemu.h \ @@ -89,10 +91,10 @@ kqemu.o: $(kqemu-objs) else # called from 2.6 kernel kbuild -obj-m:= kqemu.o -kqemu-objs:= kqemu-linux.o kqemu-mod.o +EXTRA_AFLAGS := -I $(M)/common +EXTRA_CFLAGS := -I $(M) -$(obj)/kqemu-mod.o: $(src)/kqemu-mod-$(ARCH).o - cp $< $@ +obj-m := kqemu.o +kqemu-objs := kqemu-linux.o common/kernel.o common/$(ARCH)/kernel_asm.o endif endif # PATCHLEVEL diff --git a/common/Makefile b/common/Makefile index 181c777..9d109ab 100644 --- a/common/Makefile +++ b/common/Makefile @@ -16,7 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -include ../config-host.mak +-include ../config-host.mak #CONFIG_WIN32=y #ARCH=i386 #ARCH=x86_64 -- 1.5.6 --------------090308030103040000030209 Content-Type: text/x-patch; name="0002-Improve-cross-compilation.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0002-Improve-cross-compilation.patch" >>From 1a62dc7d129714f2bae483e4f68affafecfcaaf8 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 28 Oct 2008 17:14:14 +0100 Subject: [PATCH] Improve cross-compilation Improve cross-compilation support of the build system. Signed-off-by: Jan Kiszka --- Makefile | 2 +- common/Makefile | 7 ++++--- configure | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 5a2607a..b09636c 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ ifdef CONFIG_KBUILD26 all: make -C common monitor-image.h - make -C $(KERNEL_PATH) M=`pwd` modules + make -C $(KERNEL_PATH) ARCH=$(ARCH) M=`pwd` modules else # 2.4 build diff --git a/common/Makefile b/common/Makefile index 9d109ab..80b8d84 100644 --- a/common/Makefile +++ b/common/Makefile @@ -28,7 +28,7 @@ cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \ /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;) HOST_CC=gcc -MON_CC=gcc +MON_CC:=$(CC) MON_LD=ld ifdef CONFIG_WIN32 TARGET=../kqemu-mod-$(ARCH)-win32.o @@ -50,6 +50,7 @@ endif CFLAGS=$(COMMON_CFLAGS) MON_CFLAGS=$(COMMON_CFLAGS) KERNEL_CFLAGS=$(COMMON_CFLAGS) +MON_LDFLAGS=$(LDFLAGS) # Disable SSP if GCC supports it MON_CFLAGS+=$(call cc-option,$(MON_CC),-fno-stack-protector,) @@ -75,7 +76,7 @@ kqemu_global_init kqemu_global_delete all: $(TARGET) $(TARGET): kernel.o $(ARCH)/kernel_asm.o - $(LD) -r -o $@ kernel.o $(ARCH)/kernel_asm.o + $(LD) $(LDFLAGS) -r -o $@ kernel.o $(ARCH)/kernel_asm.o monitor-image.h: monitor-image.bin genmon ./genmon < $< > $@ @@ -84,7 +85,7 @@ monitor-image.bin: monitor-image.out 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) $(MON_LDFLAGS) -T $(ARCH)/monitor.ld -o $@ $^ $(ARCH)/nexus_asm.o: $(ARCH)/nexus_asm.S monitor_def.h diff --git a/configure b/configure index a4a0585..106d301 100755 --- a/configure +++ b/configure @@ -248,6 +248,7 @@ echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" echo " --cc=CC use C compiler CC [$cc]" echo " --host-cc=CC use C compiler CC [$host_cc]" echo " --make=MAKE use specified make [$make]" +echo " --cpu=CPU specify target CPU [host CPU]" echo "" exit 1 fi -- 1.5.6 --------------090308030103040000030209 Content-Type: text/x-patch; name="0003-Add-missing-CDECLs.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0003-Add-missing-CDECLs.patch" >>From 1fe5e27bd3bd772369b23e3c6f9ec30742d4f864 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 28 Oct 2008 17:18:27 +0100 Subject: [PATCH] Add missing CDECLs Add CDECL to function definitions that are declared with CDECL. Signed-off-by: Jan Kiszka --- common/kernel.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/common/kernel.c b/common/kernel.c index 6a88452..ab441d4 100644 --- a/common/kernel.c +++ b/common/kernel.c @@ -341,7 +341,7 @@ static void kqemu_del_state(struct kqemu_state *s) } } -struct kqemu_global_state *kqemu_global_init(int max_locked_pages) +struct kqemu_global_state * CDECL kqemu_global_init(int max_locked_pages) { struct kqemu_global_state *g; @@ -354,14 +354,14 @@ struct kqemu_global_state *kqemu_global_init(int max_locked_pages) return g; } -void kqemu_global_delete(struct kqemu_global_state *g) +void CDECL kqemu_global_delete(struct kqemu_global_state *g) { /* XXX: free all existing states ? */ kqemu_vfree(g); } -struct kqemu_state *kqemu_init(struct kqemu_init *d, - struct kqemu_global_state *g) +struct kqemu_state *CDECL kqemu_init(struct kqemu_init *d, + struct kqemu_global_state *g) { struct kqemu_state *s; const struct monitor_code_header *m = (void *)monitor_code; @@ -756,8 +756,8 @@ struct kqemu_state *kqemu_init(struct kqemu_init *d, return NULL; } -int kqemu_set_phys_mem(struct kqemu_state *s, - const struct kqemu_phys_mem *kphys_mem) +int CDECL kqemu_set_phys_mem(struct kqemu_state *s, + const struct kqemu_phys_mem *kphys_mem) { uint64_t start, size, end, addr; uint32_t ram_addr, ram_end, *ptr, pd, io_index; @@ -951,7 +951,7 @@ static void profile_dump(struct kqemu_state *s) } #endif -void kqemu_delete(struct kqemu_state *s) +void CDECL kqemu_delete(struct kqemu_state *s) { uint8_t *s1; struct kqemu_ram_page *rp; @@ -990,7 +990,7 @@ void kqemu_delete(struct kqemu_state *s) kqemu_vfree(s1); } -struct kqemu_cpu_state *kqemu_get_cpu_state(struct kqemu_state *s) +struct kqemu_cpu_state * CDECL kqemu_get_cpu_state(struct kqemu_state *s) { return &s->cpu_state; } @@ -1063,7 +1063,7 @@ static void apic_restore_nmi(struct kqemu_state *s, int lvt_mask) }\ } -long kqemu_exec(struct kqemu_state *s) +long CDECL kqemu_exec(struct kqemu_state *s) { const struct monitor_code_header *m = (void *)monitor_code; void (*kernel2monitor)(struct kqemu_state *s) = -- 1.5.6 --------------090308030103040000030209--