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_FILLED_NEW_ARRAY.S
1822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
1922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Code: Constructs and fills an array with the given data. Provides
2022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * For: float-to-int
2222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Description: Construct an array of the given type and size,
2422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              filling it with the supplied contents. The type
2522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              must be an array type. The array's contents
2622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              must be single-word. The constructed instance
2722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              is stored as a result in the same way that the
2822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              method invocation instructions store their results,
2922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              so the constructed instance must be moved to a
3022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              register with a subsequent move-result-object
3122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              instruction.
3222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
3322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Format: B|A|op CCCC G|F|E|D (35c)
3422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         AA|op BBBB CCCC (3rc) (range)
3522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
3622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Syntax: [B=5] op {vD, vE, vF, vG, vA}, vtaboff@CCCC
3722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=4] op {vD, vE, vF, vG}, vtaboff@CCCC
3822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=3] op {vD, vE, vF}, vtaboff@CCCC
3922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=2] op {vD, vE}, vtaboff@CCCC
4022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         [B=1] op {vD}, vtaboff@CCCC
4122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
4222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         op {vCCCC .. vNNNN}, meth@BBBB
4322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *         op {vCCCC .. vNNNN}, type@BBBB
4422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
4522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
4622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch%default { "isrange":"0" }
4722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
4822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        rGLUE, %edx             # %edx<- MterpGlue pointer
4922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offGlue_methodClassDex(%edx), %edx # %edx<- glue->methodClassDex
5022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offDvmDex_pResClasses(%edx), %edx # %edx<- glue->methodClassDex->pResClasses
5122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FETCH       1, %ecx                 # %ecx<- BBBB
5222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    EXPORT_PC
5322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl (%edx, %ecx, 4), %eax # %eax<- possibly resolved class
5422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    cmp         $$0, %eax               # %eax<- check if already resolved
5522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jne         .L${opcode}_continue
5622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jmp         .L${opcode}_break
5722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch%break
5822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
5922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_break:
6022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        $$0, -8(%esp)           # push parameter false
6122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %ecx, -12(%esp)         # push parameter BBBB
6222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        rGLUE, %edx             # %edx<- MterpGlue pointer
6322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offGlue_method(%edx), %edx # %edx<- glue->method
6422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offMethod_clazz(%edx), %edx # %edx<- glue->method->clazz
6522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %edx, -16(%esp)         # push parameter glue->method->clazz
6622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         -16(%esp), %esp
6722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    call        dvmResolveClass         # call: (const ClassObject* referrer, u4 classIdx,
6822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch                                        #        bool fromUnverifiedConstant)
6922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch                                        # return: ClassObject*
7022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         16(%esp), %esp
7122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    cmp         $$0, %eax               # check for null return
7222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    je          common_exceptionThrown  # handle exception
7322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
7422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /*
7522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * On entry:
7622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *  %eax holds array class
7722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *  rINST holds BA or AA
7822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
7922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
8022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_continue:
8122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        offClassObject_descriptor(%eax), %eax # %eax<- arrayClass->descriptor
8222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movzbl      1(%eax), %eax           # %eax<- descriptor[1]
83f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    cmpb        $$'I', %al             # check if array of ints
84f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    je          1f
85f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    cmpb        $$'L', %al
86f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    je          1f
87f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    cmpb        $$'[', %al
8822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jne         .L${opcode}_notimpl     # jump to not implemented
89f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch1:
90f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    movl        %eax, sReg0             # save type
9122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        rINST, -12(%esp)        # push parameter length
9222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %eax, -16(%esp)         # push parameter descriptor[1]
9322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        $$ALLOC_DONT_TRACK, -8(%esp) # push parameter to allocate flags
9422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    .if         (!$isrange)
9522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    shrl        $$4, -12(%esp)          # parameter length is B
9622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    .endif
9722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         -16(%esp), %esp
9822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    call        dvmAllocPrimitiveArray  # call: (char type, size_t length, int allocFlags)
9922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch                                        # return: ArrayObject*
10022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         16(%esp), %esp
10122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    cmp         $$0, %eax               # check for null return
10222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    je          common_exceptionThrown  # handle exception
10322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
10422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FETCH       2, %edx                 # %edx<- FEDC or CCCC
10522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        rGLUE, %ecx             # %ecx<- MterpGlue pointer
10622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %eax, offGlue_retval(%ecx) # retval<- new array
10722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         offArrayObject_contents(%eax), %eax # %eax<- newArray->contents
10822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    subl        $$1, -12(%esp)          # length--; check for negative
10922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    js          2f                      # if length was zero, finish
11022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
11122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /*
11222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * copy values from registers into the array
11322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * %eax=array, %edx=CCCC/FEDC, -12(%esp)=length (from AA or B), rINST=AA/BA
11422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
11522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
11622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    .if         $isrange
11722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         (rFP, %edx, 4), %ecx    # %ecx<- &fpp[CCCC]
11822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch1:
11922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        (%ecx), %edx            # %edx<- %ecx++
12022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         4(%ecx), %ecx           # %ecx++
12122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %edx, (%eax)            # *contents<- vX
12222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         4(%eax), %eax           # %eax++; contents++
12322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    subl        $$1, -12(%esp)          # length--
12422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jns         1b                      # or continue at 2
12522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    .else
12622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    cmp         $$4, -12(%esp)          # check length
12722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jne         1f                      # has four args
12822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    and         $$15, rINST             # rINST<- A
12922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    GET_VREG    rINST                   # rINST<- vA
13022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    subl        $$1, -12(%esp)          # count--
13122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        rINST, 16(%eax)         # contents[4]<- vA
13222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch1:
13322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %edx, %ecx              # %ecx<- %edx; ecx for temp
13422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    andl        $$15, %ecx              # %ecx<- G/F/E/D
13522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    GET_VREG    %ecx                    # %ecx<- vG/vF/vE/vD
13622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    shr         $$4, %edx               # %edx<- put next reg in low 4
13722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    subl        $$1, -12(%esp)          # count--
13822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        %ecx, (%eax)            # *contents<- vX
13922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         4(%eax), %eax           # %eax++; contents++
14022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jns         1b                      # or continue at 2
14122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    .endif
14222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch2:
143f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    cmpb        $$'I', sReg0            # check for int array
144f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    je          3f
145f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    movl        rGLUE, %ecx             # %ecx<- MterpGlue pointer
146f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    movl        offGlue_retval(%ecx), %eax # Object head
147f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    movl        offGlue_cardTable(%ecx), %ecx # card table base
148f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    shrl        $$GC_CARD_SHIFT, %eax   # convert to card num
149f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch    movb        %cl,(%ecx, %eax)        # mark card based on object head
150f8f23d402dc1eef107995b29ad4d91ee5b4e1c34Johnnie Birch3:
15122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FINISH      3                       # jump to next instruction
15222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
15322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /*
15422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Throw an exception to indicate this mode of filled-new-array
15522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * has not been implemented.
15622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
15722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
15822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_notimpl:
15922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        $$.LstrInternalError, -8(%esp)
16022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        $$.LstrFilledNewArrayNotImpl, -4(%esp)
16122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         -8(%esp), %esp
16222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    call        dvmThrowException # call: (const char* exceptionDescriptor,
16322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch                                  #        const char* msg)
16422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch                                  # return: void
16522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    lea         8(%esp), %esp
16622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jmp         common_exceptionThrown
16722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
16822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.if         (!$isrange)                 # define in one or the other, not both
16922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.LstrFilledNewArrayNotImpl:
17022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.asciz      "filled-new-array only implemented for 'int'"
17122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.LstrInternalError:
17222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.asciz  "Ljava/lang/InternalError;"
17322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.endif
174