From owner-freebsd-questions@freebsd.org Tue Aug 1 21:11:58 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 15431DBD789 for ; Tue, 1 Aug 2017 21:11:58 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay11.qsc.de (mailrelay11.qsc.de [212.99.187.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.antispameurope.com", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7D5C46974B for ; Tue, 1 Aug 2017 21:11:56 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay11.qsc.de; Tue, 01 Aug 2017 23:11:47 +0200 Received: from r56.edvax.de (port-92-195-203-176.dynamic.qsc.de [92.195.203.176]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id D79803CBF9; Tue, 1 Aug 2017 23:11:46 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id v71LBjlq004920; Tue, 1 Aug 2017 23:11:45 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Tue, 1 Aug 2017 23:11:45 +0200 From: Polytropon To: Makketron Cc: freebsd-questions@freebsd.org Subject: Re: FreeBSD System Calls in Assembly Message-Id: <20170801231145.b6972dc2.freebsd@edvax.de> In-Reply-To: <92ddcdcb-5033-73ec-0551-3bc26e5680f2@cordula.ws> References: <92ddcdcb-5033-73ec-0551-3bc26e5680f2@cordula.ws> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-cloud-security-sender: freebsd@edvax.de X-cloud-security-recipient: freebsd-questions@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay11.qsc.de with 2EFA56A35EB X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.1655 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Aug 2017 21:11:58 -0000 On Tue, 1 Aug 2017 03:00:42 +0200, cpghost wrote: > On 07/31/17 21:59, Makketron wrote: > > Hello, > > It seems that the documentation here doesn't apply for 64-bits. > > > > https://www.freebsd.org/doc/en/books/developers-handbook/x86.html > > > > I asked a question on stackoverflow. I thought I should ask it here too > > https://stackoverflow.com/questions/45423987/freebsd-64bits-convention-call-documentation > > > > I am running FreeBSD 11.0. > > > > The following from the FreeBSD manual does NOT print the "Hello, World!" > > message: > > [snip] > > https://farid.hajji.org/en/blog/29-hello-world-in-freebsd-assembly > https://farid.hajji.org/en/blog/32-return-values-of-freebsd-syscalls-in-assembly > > Basically, in i386, you pass function values on the stack, > and on amd64 via registers. > > The amd64 ABI calling convention, shared by common Unices: > > https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI > > Just remember that the list of syscalls and therefore the > syscall ID differs across the various Unix variants... Addition: The 64 bit ABI specifies that the registers to be used for parameters are rdi, rsi, rdx, r10, r8, r9. Compare with this table, but as it has been mentioned, the syscall numbers of FreeBSD are different than the ones of Linux: http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/ You can find the correct numbers in /usr/src/sys/kern/syscalls.c (and in different places on the system, as they are generated from a master table into different formats for the various purposes). However, FreeBSD manual pages are a good place for reference for the parameters, and you just have to use the registers in the same order as the parameters. For example, from "man 2 write": ssize_t write(int d, const void *buf, size_t nbytes); ^ ^ ^ rdi rsi rdx The syscalls usually don't have hundreds of parameters. :-) Further documentation: https://en.wikibooks.org/wiki/X86_Assembly/Interfacing_with_Linux#syscall_2 -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...