portable_entrypoints_x86.S revision bd136a29f08486525d6abc7d0a0006ce5b4011c1
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "asm_support_x86.S" 18 19 /* 20 * Portable invocation stub. 21 * On entry: 22 * [sp] = return address 23 * [sp + 4] = method pointer 24 * [sp + 8] = argument array or NULL for no argument methods 25 * [sp + 12] = size of argument array in bytes 26 * [sp + 16] = (managed) thread pointer 27 * [sp + 20] = JValue* result 28 * [sp + 24] = result type char 29 */ 30DEFINE_FUNCTION art_portable_invoke_stub 31 PUSH ebp // save ebp 32 PUSH ebx // save ebx 33 mov %esp, %ebp // copy value of stack pointer into base pointer 34 .cfi_def_cfa_register ebp 35 mov 20(%ebp), %ebx // get arg array size 36 addl LITERAL(28), %ebx // reserve space for return addr, method*, ebx, and ebp in frame 37 andl LITERAL(0xFFFFFFF0), %ebx // align frame size to 16 bytes 38 subl LITERAL(12), %ebx // remove space for return address, ebx, and ebp 39 subl %ebx, %esp // reserve stack space for argument array 40 lea 4(%esp), %eax // use stack pointer + method ptr as dest for memcpy 41 pushl 20(%ebp) // push size of region to memcpy 42 pushl 16(%ebp) // push arg array as source of memcpy 43 pushl %eax // push stack pointer as destination of memcpy 44 call SYMBOL(memcpy) // (void*, const void*, size_t) 45 addl LITERAL(12), %esp // pop arguments to memcpy 46 mov 12(%ebp), %eax // move method pointer into eax 47 mov %eax, (%esp) // push method pointer onto stack 48 call *METHOD_CODE_OFFSET(%eax) // call the method 49 mov %ebp, %esp // restore stack pointer 50 POP ebx // pop ebx 51 POP ebp // pop ebp 52 mov 20(%esp), %ecx // get result pointer 53 cmpl LITERAL(68), 24(%esp) // test if result type char == 'D' 54 je return_double_portable 55 cmpl LITERAL(70), 24(%esp) // test if result type char == 'F' 56 je return_float_portable 57 mov %eax, (%ecx) // store the result 58 mov %edx, 4(%ecx) // store the other half of the result 59 ret 60return_double_portable: 61 fstpl (%ecx) // store the floating point result as double 62 ret 63return_float_portable: 64 fstps (%ecx) // store the floating point result as float 65 ret 66END_FUNCTION art_portable_invoke_stub 67 68DEFINE_FUNCTION art_portable_proxy_invoke_handler 69 // Fake callee save ref and args frame set up, note portable doesn't use callee save frames. 70 // TODO: just save the registers that are needed in artPortableProxyInvokeHandler. 71 PUSH edi // Save callee saves 72 PUSH esi 73 PUSH ebp 74 PUSH ebx // Save args 75 PUSH edx 76 PUSH ecx 77 PUSH eax // Align stack, eax will be clobbered by Method* 78 // Begin argument set up. 79 PUSH esp // pass SP 80 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 81 .cfi_adjust_cfa_offset 4 82 PUSH ecx // pass receiver 83 PUSH eax // pass proxy method 84 call SYMBOL(artPortableProxyInvokeHandler) // (proxy method, receiver, Thread*, SP) 85 movd %eax, %xmm0 // place return value also into floating point return value 86 movd %edx, %xmm1 87 punpckldq %xmm1, %xmm0 88 addl LITERAL(44), %esp // pop arguments 89 .cfi_adjust_cfa_offset -44 90 ret 91END_FUNCTION art_portable_proxy_invoke_handler 92 93DEFINE_FUNCTION art_portable_resolution_trampoline 94 pushl %ebp 95 movl %esp, %ebp // save ESP 96 subl LITERAL(8), %esp // Align stack 97 movl 8(%ebp), %eax // Method* called 98 leal 8(%ebp), %edx // Method** called_addr 99 pushl %edx // pass called_addr 100 pushl %fs:THREAD_SELF_OFFSET // pass thread 101 pushl %ecx // pass receiver 102 pushl %eax // pass called 103 call SYMBOL(artPortableResolutionTrampoline) 104 leave 105 cmpl LITERAL(0), %eax 106 je resolve_fail 107 jmp * %eax 108resolve_fail: 109 ret 110END_FUNCTION art_portable_resolution_trampoline 111 112DEFINE_FUNCTION art_portable_to_interpreter_bridge 113 pushl %ebp 114 movl %esp, %ebp // save ESP 115 subl LITERAL(12), %esp // Align stack 116 movl 8(%ebp), %eax // Method* called 117 leal 8(%ebp), %edx // Method** called_addr 118 pushl %edx // pass called_addr 119 pushl %fs:THREAD_SELF_OFFSET // pass thread 120 pushl %eax // pass called 121 call SYMBOL(artPortableToInterpreterBridge) 122 leave 123 ret 124END_FUNCTION art_quick_to_interpreter_bridge 125