Brian Fundakowski Feldman wrote:
> 
> 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.  

I couldn't find any documentation for FreeBSD, so used what I found for
Linux as a first approximation. At least it assembled and ran, even if
it didn't work. 

> Even if you
> really needed to write in assembly, you shouldn't call the syscalls
> directly.  

I'm doing this as a learning exercise, so I wanted to do it the hard way
first. 

> 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. 

Using write, and making the other appropriate changes to the code,
works. write() uses
        leal 4, %eax
instead of
        movl $4, %eax
before the int $0x80 call. But doing this myself still does not work. At
first glance, it doesn't seem that the C startup stuff does anything
that would affect syscalls, so I don't see why calling write() would
make a difference.

> 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.

It looks like syscall() in trap.c is where int $0x80 is handled. I'll
have to do some more digging. Thanks for the help.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to