docs/ikteam: Delete most files.
[haiku.git] / src / bin / debug / ltrace / arch / x86 / arch_ltrace_stub.S
blob740c5c6234dde64f54c7aeca4acf75da6d68464a
1 /*
2  * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
6 #include <asm_defs.h>
9 call_stub:
10         // push a pointer to arguments and a pointer to ourselves on the stack
11         lea             4(%esp), %eax
12         push    %eax
13         call    1f
15         pop             %eax
16         subl    $(1b - call_stub), %eax
17         push    %eax
19         // call the wrapper function
20         movl    (call_stub_callback_address - call_stub)(%eax), %eax
21         call    *%eax
22                                 // returns a pointer to the actual function
23         lea             8(%esp), %esp
25         jmp             *%eax
27 .align 4
28 call_stub_callback_address:
29         .long   0
30 call_stub_end:
33 // size_t arch_call_stub_size();
34 FUNCTION(arch_call_stub_size):
35         movl    $(call_stub_end - call_stub), %eax
36         ret
37 FUNCTION_END(arch_call_stub_size)
41 // void arch_init_call_stub(void* stub,
42 //              void* (*callback)(const void* stub, const void* args),
43 //              void* function);
44 FUNCTION(arch_init_call_stub):
45         push    %ebp
46         movl    %esp, %ebp
48         // stub address to %edi
49         push    %edi
50         movl    8(%ebp), %edi
52         // copy the stub
53         movl    $(call_stub_end - call_stub), %eax
54         push    %eax
55         movl    $call_stub, %eax
56         push    %eax
57         push    %edi
58         call    memcpy
59         lea             12(%esp), %esp
61         // set the callback address in the stub
62         movl    12(%ebp), %eax
63         movl    %eax, (call_stub_callback_address - call_stub)(%edi)
65         // restore %edi
66         pop             %edi
68         movl    %ebp, %esp
69         pop             %ebp
70         ret
71 FUNCTION_END(arch_init_call_stub)