Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 4 Mar 2000 08:21:50 -0500 (EST)
From:      Brian Fundakowski Feldman <green@FreeBSD.org>
To:        "Thomas M. Sommers" <tms2@mail.ptd.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Can't write to stdout in assembly
Message-ID:  <Pine.BSF.4.21.0003040815450.6016-100000@green.dyndns.org>
In-Reply-To: <38C0EA12.A4252C20@mail.ptd.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 4 Mar 2000, Thomas M. Sommers 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).
> 
[ Linux-specific asm elided ... ]
> 
> Can anyone explain what I've done wrong?
> 
> As a related question, can anyone point me to the source for the int
> 0x80 handler? I've looked all over but can't find it.

You're trying to run Linux assembly on FreeBSD.  The calling conventions
are not the same at all, and cannot be treated as such.  Even if you
really needed to write in assembly, you shouldn't call the syscalls
directly.  Note that the library stubs are just that, stubs to call
the system calls.  Try doing something more along the lines of:

pushl $stringlen
pushl stringaddr
pushl $0x1
call write

which would result in %eax containing the return value.

For what it's worth, you can find all of the syscall calling conventions
in src/lib/libc, and you can find where the calling conventions are
"defined" by looking at src/sys/i386/i386/trap.c.

> Thanks.

-- 
 Brian Fundakowski Feldman           \  FreeBSD: The Power to Serve!  /
 green@FreeBSD.org                    `------------------------------'



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0003040815450.6016-100000>