122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /* Copyright (C) 2008 The Android Open Source Project
222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Licensed under the Apache License, Version 2.0 (the "License");
422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * you may not use this file except in compliance with the License.
522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * You may obtain a copy of the License at
622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * http://www.apache.org/licenses/LICENSE-2.0
822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Unless required by applicable law or agreed to in writing, software
1022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * distributed under the License is distributed on an "AS IS" BASIS,
1122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * See the License for the specific language governing permissions and
1322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * limitations under the License.
1422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
1522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
1622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /*
1722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * File: OP_INVOKE_VIRTUAL.S
1822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
1922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Code: Call a virtual method. Provides an "isrange" variable and
2022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *       a "routine" variable to specify this is the "range" version of
2122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *       invoke_direct that allows up to 255 arguments.
2222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * For: invoke-virtual, invoke-virtual/range
2422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Description: invoke-virtual is used to invoke a normal virtual method;
2622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              a method that is not static or final, and is not a constructor.
2722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Format: B|A|op CCCC G|F|E|D (35c)
2922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         AA|op BBBB CCCC (3rc)
3022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
3122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Syntax: [B=5] op {vD, vE, vF, vG, vA}, meth@CCCC (35c)
3222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=5] op {vD, vE, vF, vG, vA}, type@CCCC (35c)
3322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=4] op {vD, vE, vF, vG}, kind@CCCC (35c)
3422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=3] op {vD, vE, vF}, kind@CCCC (35c)
3522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=2] op {vD, vE}, kind@CCCC (35c)
3622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=1] op {vD}, kind@CCCC (35c)
3722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=0] op {}, kind@CCCC (35c)
3822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
3922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         op {vCCCC .. vNNNN}, meth@BBBB (3rc) (where NNNN = CCCC+AA-1, that
4022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         op {vCCCC .. vNNNN}, type@BBBB (3rc) is A determines the count 0..255,
4122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *                                              and C determines the first register)
4222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
4322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
4422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch%default { "isrange":"0", "routine":"NoRange" }
4522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
4622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        rGLUE, %eax             # %eax<- pMterpGlue
4722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    EXPORT_PC                           # must export pc for invoke
4822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offGlue_methodClassDex(%eax), %eax # %eax<- pDvmDex
4922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FETCH       1, %ecx                 # %ecx<- method index
5022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offDvmDex_pResMethods(%eax), %eax # %eax<- pDvmDex->pResMethods
5122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FETCH       2, %edx                 # %edx<- GFED or CCCC
5222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    .if         (!$isrange)
5322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    and         $$15, %edx              # %edx<- D if not range
5422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    .endif
5522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    cmp         $$0, (%eax, %ecx, 4)    # check if already resolved
5622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    je          .L${opcode}_break
5722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        (%eax, %ecx, 4), %eax   # %eax<- resolved base method
5822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jmp         .L${opcode}_continue
5922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch%break
6022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
6122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_break:
6222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        rGLUE, %eax             # %eax<- pMterpGlue
6322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %edx, -4(%esp)          # save "this" pointer register
6422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offGlue_method(%eax), %eax # %eax<- glue->method
6522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        $$METHOD_VIRTUAL, -8(%esp) # push parameter method type
6622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %ecx, -12(%esp)         # push paramter method index
6722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offMethod_clazz(%eax), %eax # %eax<- glue->method->clazz
6822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         -16(%esp), %esp
6922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %eax, (%esp)            # push parameter clazz
7022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    call        dvmResolveMethod        # call: (const ClassObject* referrer,
7122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch                                        #       u4 methodIdx, MethodType methodType)
7222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch                                        # return: Method*
7322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         16(%esp), %esp
7422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    cmp         $$0, %eax               # check for null method return
7522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        -4(%esp), %edx          # get "this" pointer register
7622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jne         .L${opcode}_continue
7722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jmp         common_exceptionThrown  # null pointer; handle exception
7822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
7922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /*
8022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * At this point:
8122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *  %eax = resolved base method
8222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *  %edx = D or CCCC (index of first arg, which is the "this" ptr)
8322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
8422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
8522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_continue:
8622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    GET_VREG    %edx                    # %edx<- "this" ptr
8722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movzwl      offMethod_methodIndex(%eax), %eax # %eax<- baseMethod->methodIndex
8822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    cmp         $$0, %edx               # %edx<- check for null "this"
8922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    je          common_errNullObject    # handle null object
9022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offObject_clazz(%edx), %edx # %edx<- thisPtr->clazz
9122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offClassObject_vtable(%edx), %edx # %edx<- thisPtr->clazz->vtable
9222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        (%edx, %eax, 4), %ecx   # %ecx<- vtable[methodIndex]
9322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jmp         common_invokeMethod${routine} # invoke method common code
9422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
95