From owner-freebsd-hackers@FreeBSD.ORG Mon Oct 18 12:08:39 2010 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 817EC1065670 for ; Mon, 18 Oct 2010 12:08:39 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-iw0-f182.google.com (mail-iw0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 2B4D48FC18 for ; Mon, 18 Oct 2010 12:08:38 +0000 (UTC) Received: by iwn36 with SMTP id 36so663iwn.13 for ; Mon, 18 Oct 2010 05:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=Fp5adbO3NHx7xw6w13phtMycMTkahho4Zc9A2m/yExk=; b=WmbcDc2YVZkwSVBP0hYR3+EZjgOAMvYptcksYdKCYxP3Nw799lgWqfR9D9YgrgE9VB CoGa1EpGR0fNGJMGslfr1xq1uK2EFN6v+zDNYjbTBzFYuBaDw1Q4YBUznGPg2Ujlo8Lm mZJ56iYVnpC+0LDcEomFoCSU+GeSEc26R7T6E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=D6W9cUKsttIRtG5MAhHi47hh8Gu/sjTVw2arTV80o6YETbzxp7gLaNZUStDCe1PXqw G3iC2b+r8hStlqFKnOnpgoOiD/v3VoZIcGsYx5/krZYhVcR1Xbp3EUrDzP7N7Yeq8rs1 roeY0I3OrLWyUev5s/QFrjwnM/dt8XAol52bY= MIME-Version: 1.0 Received: by 10.231.35.66 with SMTP id o2mr3144391ibd.30.1287402108931; Mon, 18 Oct 2010 04:41:48 -0700 (PDT) Sender: yanegomi@gmail.com Received: by 10.231.184.3 with HTTP; Mon, 18 Oct 2010 04:41:48 -0700 (PDT) In-Reply-To: <4CBC3063.7000407@grosbein.pp.ru> References: <4CBC2109.4030303@grosbein.pp.ru> <20101018111131.GE2392@deviant.kiev.zoral.com.ua> <4CBC3063.7000407@grosbein.pp.ru> Date: Mon, 18 Oct 2010 04:41:48 -0700 X-Google-Sender-Auth: 4K-56E7RE4SWB3wbtZ08xipFhpw Message-ID: From: Garrett Cooper To: Eugene Grosbein Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Kostik Belousov , hackers@freebsd.org Subject: Re: syscall X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2010 12:08:39 -0000 On Mon, Oct 18, 2010 at 4:32 AM, Eugene Grosbein wro= te: > On 18.10.2010 18:11, Kostik Belousov wrote: >> On Mon, Oct 18, 2010 at 05:27:21PM +0700, Eugene Grosbein wrote: >>> Hi! >>> >>> I've written an utility in C that does not link libc normally, >>> instead it includes and calls syscall(). >>> It works nice for FreeBSD8/i386. >>> >>> Now I'm porting it to FreeBSD8/amd64 and just cannot find >>> how to call syscall() directly from C code. >> Show what you tried to do. Syscall() at the C-level works the same >> (well, almost, but the differences are too subtle for this discussion) >> for all architectures. > > I'm prepearing a binary that would start before /sbin/init > to make just a couple of ioctl(MDIOCATTACH)/nmount system calls > then execve(/sbin/init). It has to be small in size for NanoBSD build. > Detailed explanation (in russian) and source code are available here: > http://dadv.livejournal.com/105161.html > > In short: > > #include > > #define MESG =A0 =A0"Hello, world!\n" > #define MESG_SZ sizeof(MESG)-1 > > int syscall(const int n, ...); > > #define _exit(a) =A0 =A0 =A0 syscall(SYS_exit, a) > #define write(a, b, c) syscall(SYS_write, a, b, c) > > int errno; > > int main() { > =A0write(1,MESG,MESG_SZ); > =A0_exit(0); > =A0return 0; /* make compiler happy */ > } > >>> For arm, i386 and mips there are: >>> >>> lib/libc/arm/sys/syscall.S >>> lib/libc/i386/sys/syscall.S >>> lib/libc/mips/sys/syscall.S >> amd64 syscall() wrapper code is autogenerated. >> >>> >>> What about amd64? >> Indeed, what is your issue with amd64 ? > > I cannot find a module to link with > to resolve syscall() symbol when I do not want to link with libc. Official work similar to this was just committed yesterday at SVN r2140= 06. Cheers, -Garrett