Calling syscalls through int 0x80 documentation?

Yuri yuri at
Thu Oct 18 12:28:49 PDT 2007

> I guess I'd ask why you want to use syscall at all to just open a file?  I 
> thought you wanted to access some hardware and had no other way to do that.


Opening a file is just an example. I want to be able to make any system call
this way since my program for whatever reasons has to be compiled with such gcc
options that prevent being linked to system calls in the traditional way. No
hardware issues for me.

Btw I submitted the wrong assembly code with my previous message.
The right one (still not working) is below.

Lack of documentation causes me to ask this kind of question here.


---- code ---
#include <fcntl.h>

extern int mysyscall (
          int syscall_no,
          int a1, int a2, int a3,
          int a4, int a5, int a6);
"       movl    %esp,%ebx\n"
"       push    28(%ebx)\n"
"       push    24(%ebx)\n"
"       push    20(%ebx)\n"
"       push    16(%ebx)\n"
"       push    12(%ebx)\n"
"       push    8(%ebx)\n"
"       push    4(%ebx)\n"
"       int     $0x80\n"
"       pop     %ecx\n"
"       pop     %ecx\n"
"       pop     %ecx\n"
"       pop     %ecx\n"
"       pop     %ecx\n"
"       pop     %ecx\n"
"       pop     %ecx\n"
"       ret\n"

main() {
  char *fname = "myxxxfile";
  //int fd = open(fname, O_WRONLY|O_CREAT);
  int fd = mysyscall(5, (int)fname,O_WRONLY|O_CREAT,0,0,0,0); // open

More information about the freebsd-questions mailing list