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 [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to