site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com User-agent: Mutt/1.5.12-2006-07-14 On Sun, Mar 18, 2007 at 11:02:55AM +0000, Filipe Cabecinhas wrote:
Thank you very much, now it runs :D
I have now another problem.
As far as I could see (by going through the source of Darwin, when I want to call a system call directly (I can't link the output of my compiler with the libc, I have to link it with my run-time library) I should do the following:
push the arguments to the stack(for example (write): push nbytes, push str, push fd) set eax to the system call number (4) call __sysenter_trap
sysenter_trap: put the esp in ecx sysenter
I think I should call the trap so the system call has an address to return to, right?
No, you missed something: sysenter_trap looks like this: __sysenter_trap: 90110ac0 popl %edx 90110ac1 movl %esp,%ecx 90110ac3 sysenter So, %ecx contains the saved stack pointer and %edx contains the return address. By the way, I am not quite sure if doing things directly is such a good idea ... can you not go through libc? - gl
But my problem is, when I return from sysenter, it goes to a weird position instead of going to the address after the call __sysenter_trap.
Am I doing anything wrong?
Thanks for the help
Filipe Cabecinhas
On 18 Mar, 2007, at 07:50, Geoffrey Lee wrote:
The question is: how does darwin know where is the entry point of the binary and how can I choose it?
Use -e flag in ld(1). It is actually stored in the thread state, the kernel loads this thread state when the binary is loaded, you can see for yourself with otool -l, srr0 on ppc and eip on 32bit x86.
- gl
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com