Commit 5fdd8390 authored by Jean-Claude Beaudoin's avatar Jean-Claude Beaudoin
Browse files

Rework callback trampoline machine code.

parent bf157a01
.arch armv7-a .arch armv7-a
.file "arm_callback_trampoline.s" .file "arm_callback_trampoline.s"
.text .text
.align 1 .align 1
.p2align 2,,3 .p2align 2,,3
...@@ -12,20 +10,19 @@ ...@@ -12,20 +10,19 @@
.fpu vfpv3-d16 .fpu vfpv3-d16
.type trampoline, %function .type trampoline, %function
trampoline: trampoline:
mov r3, pc
add r3, #24
push {r4, lr} push {r4, lr}
ldr r2, [r3] mov r4, sp
ldr r0, [r3, #4] push {r4} @ push stack_marker
mov r1, sp ldr r4, =0xdeadbeef @ get cbk_info
blx r2 push {r4} @ push cbk_info
ldr r4, =0xbeefdead @ get pointer to mkcl_XXX_dynamic_callback_execute
blx r4 @ call through r4
add sp, sp, #8 @ remove pushed args
pop {r4, pc} pop {r4, pc}
nop
nop
.align 2 .align 2
.Lptr: .Lptr:
.word -1 @ mkcl_dynamic_callback_execute @ .word -1 @ mkcl_dynamic_callback_execute
.word -2 @ cbk_info @ .word -2 @ cbk_info
.size trampoline, .-trampoline .size trampoline, .-trampoline
.align 2 .align 2
......
...@@ -456,19 +456,19 @@ mkcl_dynamic_callback_make(MKCL, mkcl_object data, enum mkcl_ffi_calling_convent ...@@ -456,19 +456,19 @@ mkcl_dynamic_callback_make(MKCL, mkcl_object data, enum mkcl_ffi_calling_convent
mkcl_FEerror(env, "Invalid C function callback return type", 0); mkcl_FEerror(env, "Invalid C function callback return type", 0);
} }
i(0x7B); i(0x46); /* mov r3, pc */ i(0x10); i(0xB5); /* push {r4, lr} */
i(0x03); i(0xF1); i(0x18); i(0x03); /* add r3, #24 */ i(0x6C); i(0x46); /* mov r4, sp */
i(0x10); i(0xB5); /* push {r4, lr} */ i(0x10); i(0xB4); /* push {r4} @ push stack_marker */
i(0x1A); i(0x68); /* ldr r2, [r3] */ /* pointer to trampoline */ i(0x03); i(0x4C); /* ldr r4, =0xdeadbeef @ get cbk_info */
i(0x58); i(0x68); /* ldr r0, [r3, #4] */ /* arg0 */ i(0x10); i(0xB4); /* push {r4} @ push cbk_info */
i(0x69); i(0x46); /* mov r1, sp */ /* arg1 */ i(0x03); i(0x4C); /* ldr r4, =0xbeefdead @ get pointer to callback frame provider */
i(0x90); i(0x47); /* blx r2 */ /* call the callback trampoline */ i(0xA0); i(0x47); /* blx r4 @ call through r4 */
i(0x10); i(0xBD); /* pop {r4, pc} */ /* return to caller. */ i(0x02); i(0xB0); /* add sp, sp, #8 @ remove pushed args */
i(0x00); i(0xBF); /* nop */ i(0x10); i(0xBD); /* pop {r4, pc} */
i(0x00); i(0xBF); /* nop */ i(0x00); i(0xBF); /* .align 2 */
i(0x00); i(0xBF); /* .align 2 */ immed_ptr(data);
immed_ptr(fptr); /* The code here above expect this pointer to be 24 bytes (0x18) after the first opcode. */ immed_ptr(fptr);
immed_ptr(data); /* The code here above expect this pointer to be 4 bytes after the previous one. */
{ {
int rc = mprotect(buf, mkcl_core.pagesize, PROT_READ | /* PROT_WRITE | */ PROT_EXEC); int rc = mprotect(buf, mkcl_core.pagesize, PROT_READ | /* PROT_WRITE | */ PROT_EXEC);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment