From owner-freebsd-hackers@FreeBSD.ORG Mon Oct 18 11:32:56 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 715371065696 for ; Mon, 18 Oct 2010 11:32:56 +0000 (UTC) (envelope-from eugen@grosbein.pp.ru) Received: from eg.sd.rdtc.ru (eg.sd.rdtc.ru [62.231.161.221]) by mx1.freebsd.org (Postfix) with ESMTP id B44F98FC18 for ; Mon, 18 Oct 2010 11:32:54 +0000 (UTC) Received: from eg.sd.rdtc.ru (localhost [127.0.0.1]) by eg.sd.rdtc.ru (8.14.4/8.14.4) with ESMTP id o9IBWpMm078560; Mon, 18 Oct 2010 18:32:52 +0700 (NOVST) (envelope-from eugen@grosbein.pp.ru) Message-ID: <4CBC3063.7000407@grosbein.pp.ru> Date: Mon, 18 Oct 2010 18:32:51 +0700 From: Eugene Grosbein User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; ru-RU; rv:1.9.1.10) Gecko/20100712 Thunderbird/3.0.5 MIME-Version: 1.0 To: Kostik Belousov References: <4CBC2109.4030303@grosbein.pp.ru> <20101018111131.GE2392@deviant.kiev.zoral.com.ua> In-Reply-To: <20101018111131.GE2392@deviant.kiev.zoral.com.ua> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: 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 11:32:56 -0000 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 "Hello, world!\n" #define MESG_SZ sizeof(MESG)-1 int syscall(const int n, ...); #define _exit(a) syscall(SYS_exit, a) #define write(a, b, c) syscall(SYS_write, a, b, c) int errno; int main() { write(1,MESG,MESG_SZ); _exit(0); return 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. Eugene Grosbein