Re: Calling syscalls through int 0x80 documentation?

2007-10-19 Thread Yuri

 Yuri,
 
 Sorry I wasn't more help.  I'm an old assembler programmer, but have not 
 done much of that under FreeBSD.
 
 Glad you got it solved.
 
  -Derek

This no problem at all Derek. Thank you for answering me anyway.
Now I solved my problem and moved on.

Have a good weekend!
Yuri
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Calling syscalls through int 0x80 documentation?

2007-10-18 Thread Yuri
Hi,

Is there a documentation on how to call system calls via 'int 0x80'?
Which registers should contain which values.
BTW I am well aware of system call 'syscall' but still need to use 'int 0x80' 
:-)

Thanks,
Yuri
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Calling syscalls through int 0x80 documentation?

2007-10-18 Thread Derek Ragona

At 01:12 PM 10/18/2007, Yuri wrote:

Hi,

Is there a documentation on how to call system calls via 'int 0x80'?
Which registers should contain which values.
BTW I am well aware of system call 'syscall' but still need to use 'int 
0x80' :-)


Thanks,
Yuri


You can try here:
http://www.ctyme.com/intr/int-80.htm

-Derek

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Calling syscalls through int 0x80 documentation?

2007-10-18 Thread Yuri
 You can try here:
 http://www.ctyme.com/intr/int-80.htm
 
Thanks Derek.
This site just says: parameters on stack.

So when following this I write the function 'mysyscall' (below) it doesn't work.
It should return 3 but returns 14.
And I am on i386.

So something is missing.

Yuri

--- code
#include fcntl.h

extern int mysyscall (
  int syscall_no,
  int a1, int a2, int a3,
  int a4, int a5, int a6);

asm(
.text\n
mysyscall:\n
   push28(%esp)\n
   push24(%esp)\n
   push20(%esp)\n
   push16(%esp)\n
   push12(%esp)\n
   push8(%esp)\n
   push4(%esp)\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
.previous\n
);

main() {
  char *fname = myxxxfile;
  //int fd = open(fname, O_WRONLY|O_CREAT);
  int fd = mysyscall(5/*open*/, (int)fname,O_WRONLY|O_CREAT,0,0,0,0); // open
  printf(fd=%i\n,fd);
}
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Calling syscalls through int 0x80 documentation?

2007-10-18 Thread Derek Ragona

At 01:47 PM 10/18/2007, Yuri wrote:

 You can try here:
 http://www.ctyme.com/intr/int-80.htm

Thanks Derek.
This site just says: parameters on stack.

So when following this I write the function 'mysyscall' (below) it doesn't 
work.

It should return 3 but returns 14.
And I am on i386.

So something is missing.

Yuri

--- code
#include fcntl.h

extern int mysyscall (
  int syscall_no,
  int a1, int a2, int a3,
  int a4, int a5, int a6);

asm(
.text\n
mysyscall:\n
   push28(%esp)\n
   push24(%esp)\n
   push20(%esp)\n
   push16(%esp)\n
   push12(%esp)\n
   push8(%esp)\n
   push4(%esp)\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
.previous\n
);

main() {
  char *fname = myxxxfile;
  //int fd = open(fname, O_WRONLY|O_CREAT);
  int fd = mysyscall(5/*open*/, (int)fname,O_WRONLY|O_CREAT,0,0,0,0); // open
  printf(fd=%i\n,fd);
}


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.


-Derek

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Calling syscalls through int 0x80 documentation?

2007-10-18 Thread Yuri

 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.

Derek,

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.

Yuri

 code ---
#include fcntl.h

extern int mysyscall (
  int syscall_no,
  int a1, int a2, int a3,
  int a4, int a5, int a6);
asm(
.text\n
mysyscall:\n
   movl%esp,%ebx\n
   push28(%ebx)\n
   push24(%ebx)\n
   push20(%ebx)\n
   push16(%ebx)\n
   push12(%ebx)\n
   push8(%ebx)\n
   push4(%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
.previous\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
  printf(fd=%i\n,fd);
}
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Calling syscalls through int 0x80 documentation?

2007-10-18 Thread Yuri
By experimenting I found the working version now.
I still don't understand why first element on stack while going into 'int 0x80'
should be stack pointer.

asm(
.text\n
mysyscall:\n
   movl%esp,%eax\n
   push28(%eax)\n
   push24(%eax)\n
   push20(%eax)\n
   push16(%eax)\n
   push12(%eax)\n
   push8(%eax)\n
   push%eax\n
   movl4(%eax), %eax\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
.previous\n
);
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Calling syscalls through int 0x80 documentation?

2007-10-18 Thread icantthinkofone

Yuri wrote:
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.



Derek,

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.

Yuri

 code ---
#include fcntl.h

extern int mysyscall (
  int syscall_no,
  int a1, int a2, int a3,
  int a4, int a5, int a6);
asm(
.text\n
mysyscall:\n
   movl%esp,%ebx\n
   push28(%ebx)\n
   push24(%ebx)\n
   push20(%ebx)\n
   push16(%ebx)\n
   push12(%ebx)\n
   push8(%ebx)\n
   push4(%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
.previous\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
  printf(fd=%i\n,fd);
}
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]

  
I think the problem may relate to how FreeBSD handles the stack.  Try 
pushing an extra word, anything will do, before making the int 80.  Let 
us know if that makes it work and I'll point to a link that explains it.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Calling syscalls through int 0x80 documentation?

2007-10-18 Thread Mak Kolybabi

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

http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86.html

Have you looked at the documentation there?
Has a section on system calls and return values.


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Calling syscalls through int 0x80 documentation?

2007-10-18 Thread Yuri

 
 http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86.html
 
 Have you looked at the documentation there?
 Has a section on system calls and return values.

Thank you Mak!

This is what I was looking for.
Somehow I have oversaw it myself.

Yuri
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]