From owner-freebsd-hackers Wed Dec 13 14:25:49 2000 From owner-freebsd-hackers@FreeBSD.ORG Wed Dec 13 14:25:46 2000 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id ACB3437B402; Wed, 13 Dec 2000 14:25:46 -0800 (PST) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id eBDMPeg05261; Wed, 13 Dec 2000 14:25:40 -0800 (PST) Date: Wed, 13 Dec 2000 14:25:40 -0800 From: Alfred Perlstein To: Drew Eckhardt Cc: Marc Tardif , freebsd-hackers@FreeBSD.ORG, obrien@FreeBSD.ORG Subject: Re: syscall assembly Message-ID: <20001213142539.R16205@fw.wintelcom.net> References: <20001213141023.O16205@fw.wintelcom.net> <200012132221.eBDMLdh28943@chopper.Poohsticks.ORG> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200012132221.eBDMLdh28943@chopper.Poohsticks.ORG>; from drew@PoohSticks.ORG on Wed, Dec 13, 2000 at 03:21:39PM -0700 Sender: bright@fw.wintelcom.net Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG David, can you look at this? #include int foo() { open("file", O_RDONLY); return 0; } int main() { int x; x = foo(); return 0; } results in: foo: pushl %ebp movl %esp,%ebp subl $8,%esp addl $-8,%esp pushl $0 pushl $.LC0 call open xorl %eax,%eax leave ret why the subl then addl? ~ % gcc -v Using builtin specs. gcc version 2.95.2 19991024 (release) ~ % uname -a 4.2-STABLE FreeBSD 4.2-STABLE #1: Wed Dec 6 02:49:24 PST 2000 * Drew Eckhardt [001213 14:21] wrote: > In message <20001213141023.O16205@fw.wintelcom.net>, bright@wintelcom.net write > s: > >> subl $8,%esp > >> addl $-8,%esp > > >> What is the purpose of the subl and addl > >> instructions? On Linux, they are simply > >> unexistent.. > > > >FreeBSD passes syscall args on the stack, Linux uses registers. > > The 'C' compiler doesn't know open is a syscall, and treats it like > any other code. > > The pushls put the arguments on the stack. > > The subl/addl are there because your version of GCC is broken. -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] "I have the heart of a child; I keep it in a jar on my desk." To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message