Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxTI7-0003Lh-4S for qemu-devel@nongnu.org; Mon, 12 Oct 2009 18:22:55 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxTI5-0003LS-Jm for qemu-devel@nongnu.org; Mon, 12 Oct 2009 18:22:53 -0400 Received: from [199.232.76.173] (port=46337 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxTI5-0003LK-G9 for qemu-devel@nongnu.org; Mon, 12 Oct 2009 18:22:53 -0400 Received: from gelbbaer.kn-bremen.de ([78.46.108.116]:34439 helo=smtp.kn-bremen.de) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MxTI4-0007pZ-TP for qemu-devel@nongnu.org; Mon, 12 Oct 2009 18:22:53 -0400 From: Juergen Lock Date: Tue, 13 Oct 2009 00:20:58 +0200 Subject: Re: [Qemu-devel] Re: playing with qemu usermode emulation on FreeBSD... Message-ID: <20091012222058.GA43121@triton8.kn-bremen.de> References: <20091007220549.GA65997@triton8.kn-bremen.de> <20091011221840.GA55502@triton8.kn-bremen.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: freebsd-emulation@freebsd.org, Toni , Juergen Lock , Aleksej Saushev , qemu-devel@nongnu.org On Mon, Oct 12, 2009 at 10:55:24PM +0300, Blue Swirl wrote: > On Mon, Oct 12, 2009 at 1:18 AM, Juergen Lock = wrote: > > On Thu, Oct 08, 2009 at 12:05:49AM +0200, Juergen Lock wrote: > >> I recently noticed there are x86 bsd-user targets now (yeah I totall= y > >> missed those commits...) and now got it working a tiny little bit: > >> I can run > >> =A0 =A0 =A0 qemu-x86_64 -bsd freebsd /rescue/echo foo bar > >> here on FreeBSD 8/amd64 and it echoes foo bar as expected, but > >> segfaults afterwards. :) =A0(in pthread_setcancelstate() invoked fro= m > >> a guest write() syscall, in case anyone is wondering.) =A0Other thin= gs > >> I tried either exit with errors or segfault as well, and i386 hosts > >> probably still don't work at all yet. =A0(qemu-i386 here on amd64 do= es > >> at least something, but probably needs lock_user() treatment for all > >> kinds of syscalls, I only tried adding that for sysctl so far.) > >> > >> =A0Anyway, here is an emulators/qemu-devel git head snapshot port > >> update with my current patches (files/patch-bsd-user), feel free to > >> test/debug/improve: > >> =A0 =A0 =A0 http://people.freebsd.org/~nox/qemu/qemu-devel-20091007.= patch > >> (For the folks reading this on the qemu list: =A0I shall start doing > >> `proper' patch submissions later, this is more for the FreeBSD folks > >> and because I was asked to send what I have...) > > > > New version at the same place, which now runs FreeBSD/{i386,sparc64} > > /rescue/echo on FreeBSD/amd64, the FreeBSD/amd64 target now segfaults > > in pthread_setcancelstate() invoked from the final writev() tho. > > Oh and I also uploaded the snapshot tarball so others can now actuall= y > > build the port too... :) =A0And I have switched to the cpu-exec.c pat= ch > > posted by Aleksej Saushev on the qemu list and added back amd64 > > code there. > > > > =A0Here is the bsd-user patch again: >=20 > Please add Signed-off-by: line and use 'diff -u' (or preferably git dif= f). >=20 Well I wasn't expecting this diff to be committed just yet anyway, it's still more a wip version... > > + =A0 =A0if (1 /* bsd_type =3D=3D target_freebsd */) > > + =A0 =A0 =A0 =A0regs->rdi =3D infop->start_stack; >=20 > Why the if and comment? >=20 > > + =A0 =A0 =A0 =A0if (1 /* bsd_type =3D=3D target_freebsd */) { > > + =A0 =A0 =A0 =A0 =A0 =A0regs->u_regs[8] =3D infop->start_stack; > > + =A0 =A0 =A0 =A0 =A0 =A0regs->u_regs[11] =3D infop->start_stack; >=20 > Same here. >=20 Because bsd_type isn't available at these places in the code but probably should be checked, I still wanted to fix that. (Maybe make it global?) > > =A0 =A0 =A0 =A0 case 0x100: > > + =A0 =A0 =A0 =A0/* FreeBSD uses 0x141 for syscalls too */ > > + =A0 =A0 =A0 =A0case 0x141: > > + =A0 =A0 =A0 =A0 =A0 =A0if (bsd_type !=3D target_freebsd) > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto badtrap; >=20 > You are now also trapping on case 0x100 if bsd_type !=3D target_freebsd= , > which probably breaks other BSDs. >=20 Right, thats broken, the 0x141 case should come before the 0x100 here of course. > > +/* XXX this needs to be emulated on non-FreeBSD hosts... */ > > +static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, = abi_ulong oldp, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0abi_ulong oldlen= p, abi_ulong newp, abi_ulong newlen) >=20 > What kind of call is this, is it possible to emulate on other BSDs? Is > it important? Its used mostly for things that on linux is done by manipulating /proc or /sys, like getting the kernel version, number of cpus, pagesize, etc. - and there are also sysctls that can be written to, like to enable ip forwarding or change sysV ipc settings. Although changes are usually restriced to root so `regular' executables rarely do them and I'm not really handling those yet. See here: http://www.freebsd.org/cgi/man.cgi?query=3Dsysctl&apropos=3D0&sektion=3D= 3&manpath=3DFreeBSD+7.2-RELEASE&format=3Dhtml > I'm just wondering if the cross-BSD emulation makes > sense after all. It would make the emulator much simpler if we could > assume that host_bsdness =3D=3D target_bsdness. Yeah I was wondering about that too... Cheers, Juergen