From owner-freebsd-emulation@FreeBSD.ORG  Thu Feb 28 23:24:37 2008
Return-Path: <owner-freebsd-emulation@FreeBSD.ORG>
Delivered-To: freebsd-emulation@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 439E2106566B
	for <freebsd-emulation@freebsd.org>;
	Thu, 28 Feb 2008 23:24:37 +0000 (UTC)
	(envelope-from yuri.pankov@gmail.com)
Received: from mail.irbisnet.ru (mail.irbisnet.ru
	[IPv6:2001:470:1f09:aa:203:baff:fe18:f4c1])
	by mx1.freebsd.org (Postfix) with ESMTP id B7F648FC21
	for <freebsd-emulation@freebsd.org>;
	Thu, 28 Feb 2008 23:24:36 +0000 (UTC)
	(envelope-from yuri.pankov@gmail.com)
Received: from mail.irbisnet.ru (yuri@mail.irbisnet.ru [IPv6:::1])
	by mail.irbisnet.ru (8.14.2/8.14.2) with ESMTP id m1SNOZUs003619;
	Fri, 29 Feb 2008 02:24:35 +0300 (MSK)
	(envelope-from yuri.pankov@gmail.com)
Received: (from yuri@localhost)
	by mail.irbisnet.ru (8.14.2/8.14.2/Submit) id m1SNOZgD003618;
	Fri, 29 Feb 2008 02:24:35 +0300 (MSK)
	(envelope-from yuri.pankov@gmail.com)
X-Authentication-Warning: mail.irbisnet.ru: yuri set sender to
	yuri.pankov@gmail.com using -f
Date: Fri, 29 Feb 2008 02:24:35 +0300
From: Yuri Pankov <yuri.pankov@gmail.com>
To: freebsd-emulation@freebsd.org
Message-ID: <20080228232434.GA1562@mail.irbisnet.ru>
References: <20080216164331.GJ57756@deviant.kiev.zoral.com.ua>
	<20080216181850.GA35839@saturn.kn-bremen.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20080216181850.GA35839@saturn.kn-bremen.de>
User-Agent: Mutt/1.5.17 (2007-11-01)
Subject: Re: qemu-system-amd64 and freebsd guest
X-BeenThere: freebsd-emulation@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Development of Emulators of other operating systems
	<freebsd-emulation.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-emulation>, 
	<mailto:freebsd-emulation-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-emulation>
List-Post: <mailto:freebsd-emulation@freebsd.org>
List-Help: <mailto:freebsd-emulation-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-emulation>, 
	<mailto:freebsd-emulation-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 28 Feb 2008 23:24:37 -0000

On Sat, Feb 16, 2008 at 07:18:50PM +0100, Juergen Lock wrote:
> On Sat, Feb 16, 2008 at 06:43:31PM +0200, Kostik Belousov wrote:
> > My recent attempts to boot CURRENT amd64 on QEMU 0.9.1 resulted in the
> > consistent kernel panic in the first instruction of the root_bus_ocnfigure()
> > function. Looking around, I noted that this instruction is the second one
> > executed after "sti" in the amd64/amd64/autoconf.c:configure().
> > CPU executes
> > 	sti
> > 	call root_bus_configure
> > 	pushq %rbp <- General Protection Fault there
> > 
> > It makes me suspect that fault happen when hardware interrupt is delivered.
> > Indeed, looking around qemu source code and setting breakpoints in QEMU,
> > I noted that hw interrupt is delivered, with into = -1. Calculation of
> > the IDT index in the QEMU' target-i386/helper.c:do_interrupt64() as
> > intno*16 and comparision with unsigned limit looked as overflow and GPF
> > was delivered instead.
> > 
> > Then, it appears that -1 comes from cpu_get_pic_interrupt() when
> > apic_accept_pic_intr() returns false. This happen, in particular, when
> > corresponding lapic vector is masked. The situation is legitimate, and
> > I think that QEMU shall not deliver an interrupt in this case.
> > 
> > The following patch allows me to boot the amd64 freebsd on qemu 0.9.1
> > from ports.
> > 
> > --- cpu-exec.c.orig	2008-02-16 18:23:53.134009488 +0200
> > +++ cpu-exec.c	2008-02-16 18:24:47.127662872 +0200
> > @@ -452,13 +452,15 @@
> >                          svm_check_intercept(SVM_EXIT_INTR);
> >                          env->interrupt_request &= ~(CPU_INTERRUPT_HARD | CPU_INTERRUPT_VIRQ);
> >                          intno = cpu_get_pic_interrupt(env);
> > -                        if (loglevel & CPU_LOG_TB_IN_ASM) {
> > -                            fprintf(logfile, "Servicing hardware INT=0x%02x\n", intno);
> > -                        }
> > -                        do_interrupt(intno, 0, 0, 0, 1);
> > -                        /* ensure that no TB jump will be modified as
> > -                           the program flow was changed */
> > -                        BREAK_CHAIN;
> > +			if (intno != -1) {
> > +				if (loglevel & CPU_LOG_TB_IN_ASM) {
> > +				    fprintf(logfile, "Servicing hardware INT=0x%02x\n", intno);
> > +				}
> > +				do_interrupt(intno, 0, 0, 0, 1);
> > +				/* ensure that no TB jump will be modified as
> > +				   the program flow was changed */
> > +				BREAK_CHAIN;
> > +			}
> >  #if !defined(CONFIG_USER_ONLY)
> >                      } else if ((interrupt_request & CPU_INTERRUPT_VIRQ) &&
> >                          (env->eflags & IF_MASK) && !(env->hflags & HF_INHIBIT_IRQ_MASK)) {
> 
> Hey, thanks for looking at this one! :)  Maybe you should post the patch
> on the qemu list so the right ppl can look at it, and see if it is correct:
> 	http://lists.gnu.org/mailman/listinfo/qemu-devel
> 
>  Thanx,
> 	Juergen

Thanks from me too. I was finally able to boot 7.0-bootonly amd64 image
inside QEMU with this patch :-)


Yuri