From owner-freebsd-hackers Sat Mar 4 21:20:33 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.ptd.net (mail1.ha-net.ptd.net [207.44.96.65]) by hub.freebsd.org (Postfix) with SMTP id AE88537B972 for ; Sat, 4 Mar 2000 21:20:28 -0800 (PST) (envelope-from tms2@mail.ptd.net) Received: (qmail 2598 invoked from network); 5 Mar 2000 05:20:34 -0000 Received: from du39.cli.ptd.net (HELO mail.ptd.net) (204.186.33.39) by mail.ptd.net with SMTP; 5 Mar 2000 05:20:34 -0000 Message-ID: <38C1EE72.B72F520D@mail.ptd.net> Date: Sun, 05 Mar 2000 00:19:46 -0500 From: "Thomas M. Sommers" X-Mailer: Mozilla 4.51 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: freebsd-Hackers@freebsd.org Subject: Re: Can't write to stdout in assembly References: <20000304194140.48F3D2E803@hermes.tue.nl> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Marco van de Voort wrote: > > > >From what I understand, the following should print "Hello, world." on > > stdout. I stole the code from the Linux HOWTO, but I think it should > > work on FreeBSD as well. Instead, the call to write returns 9 (EBADF). > > I disassembled FreeBSD programs (create a small C prog, compile, and use > objdump), and it looks more like this: (I haven't tested this yet, but it is definitely > stack based, not register based, the part which I haven't tested is if the placing > the int $0x80 behind a call is required) > It turns out that placing the int $0x80 behind a call is required. I infer that the kernel does not look for the arguments at the top of the stack, but farther down. When you think about it, that makes some sense, since any sane person would call the kernel through libc, and not directly. Thanks for the help. In the remote chance that anyone is interested, here is the code that works: .data msg: .string "Hello, world.\n" len = . - msg - 1 .text .global _start _start: pushl $len pushl $msg pushl $1 movl $4, %eax call make_syscall addl $12, %esp movl $1, %eax pushl $0 call make_syscall make_syscall: int $0x80 ret To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message