1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_mips.S Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* -*- Mode: asm; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * Version: MPL 1.1 1.6 + * 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +/* This code is for MIPS using the O32 ABI. */ 1.12 + 1.13 +#ifdef ANDROID 1.14 +#include <asm/regdef.h> 1.15 +#include <asm/asm.h> 1.16 +#include <machine/asm.h> 1.17 +#else 1.18 +#include <sys/regdef.h> 1.19 +#include <sys/asm.h> 1.20 +#endif 1.21 + 1.22 +# NARGSAVE is the argument space in the callers frame, including extra 1.23 +# 'shadowed' space for the argument registers. The minimum of 4 1.24 +# argument slots is sometimes predefined in the header files. 1.25 +#ifndef NARGSAVE 1.26 +#define NARGSAVE 4 1.27 +#endif 1.28 + 1.29 +#define LOCALSZ 3 /* gp, fp, ra */ 1.30 +#define FRAMESZ ((((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK) 1.31 + 1.32 +#define RAOFF (FRAMESZ - (1*SZREG)) 1.33 +#define FPOFF (FRAMESZ - (2*SZREG)) 1.34 +#define GPOFF (FRAMESZ - (3*SZREG)) 1.35 + 1.36 +#define A0OFF (FRAMESZ + (0*SZREG)) 1.37 +#define A1OFF (FRAMESZ + (1*SZREG)) 1.38 +#define A2OFF (FRAMESZ + (2*SZREG)) 1.39 +#define A3OFF (FRAMESZ + (3*SZREG)) 1.40 + 1.41 + .text 1.42 + 1.43 +# 1.44 +# _NS_InvokeByIndex(that, methodIndex, paramCount, params) 1.45 +# a0 a1 a2 a3 1.46 + 1.47 + .globl _NS_InvokeByIndex 1.48 + .align 2 1.49 + .type _NS_InvokeByIndex,@function 1.50 + .ent _NS_InvokeByIndex,0 1.51 + .frame fp, FRAMESZ, ra 1.52 +_NS_InvokeByIndex: 1.53 + SETUP_GP 1.54 + subu sp, FRAMESZ 1.55 + 1.56 + # specify the save register mask for gp, fp, ra, a3 - a0 1.57 + .mask 0xD00000F0, RAOFF-FRAMESZ 1.58 + 1.59 + sw ra, RAOFF(sp) 1.60 + sw fp, FPOFF(sp) 1.61 + 1.62 + # we can't use .cprestore in a variable stack frame 1.63 + sw gp, GPOFF(sp) 1.64 + 1.65 + sw a0, A0OFF(sp) 1.66 + sw a1, A1OFF(sp) 1.67 + sw a2, A2OFF(sp) 1.68 + sw a3, A3OFF(sp) 1.69 + 1.70 + # save bottom of fixed frame 1.71 + move fp, sp 1.72 + 1.73 + # extern "C" uint32 1.74 + # invoke_count_words(uint32_t paramCount, nsXPTCVariant* s); 1.75 + la t9, invoke_count_words 1.76 + move a0, a2 1.77 + move a1, a3 1.78 + jalr t9 1.79 + lw gp, GPOFF(fp) 1.80 + 1.81 + # allocate variable stack, with a size of: 1.82 + # wordsize (of 4 bytes) * result (already aligned to dword) 1.83 + # but a minimum of 16 byte 1.84 + sll v0, 2 1.85 + slt t0, v0, 16 1.86 + beqz t0, 1f 1.87 + li v0, 16 1.88 +1: subu sp, v0 1.89 + 1.90 + # let a0 point to the bottom of the variable stack, allocate 1.91 + # another fixed stack for: 1.92 + # extern "C" void 1.93 + # invoke_copy_to_stack(uint32_t* d, uint32_t paramCount, 1.94 + # nsXPTCVariant* s); 1.95 + la t9, invoke_copy_to_stack 1.96 + move a0, sp 1.97 + lw a1, A2OFF(fp) 1.98 + lw a2, A3OFF(fp) 1.99 + subu sp, 16 1.100 + jalr t9 1.101 + lw gp, GPOFF(fp) 1.102 + 1.103 + # back to the variable stack frame 1.104 + addu sp, 16 1.105 + 1.106 + # calculate the function we need to jump to, which must then be 1.107 + # stored in t9 1.108 + lw a0, A0OFF(fp) # a0 = set "that" to be "this" 1.109 + lw t0, A1OFF(fp) # a1 = methodIndex 1.110 + lw t9, 0(a0) 1.111 + # t0 = methodIndex << PTRLOG 1.112 + sll t0, t0, PTRLOG 1.113 + addu t9, t0 1.114 + lw t9, (t9) 1.115 + 1.116 + # Set a1-a3 to what invoke_copy_to_stack told us. a0 is already 1.117 + # the "this" pointer. We don't have to care about floating 1.118 + # point arguments, the non-FP "this" pointer as first argument 1.119 + # means they'll never be used. 1.120 + lw a1, 1*SZREG(sp) 1.121 + lw a2, 2*SZREG(sp) 1.122 + lw a3, 3*SZREG(sp) 1.123 + 1.124 + jalr t9 1.125 + # Micro-optimization: There's no gp usage below this point, so 1.126 + # we don't reload. 1.127 + # lw gp, GPOFF(fp) 1.128 + 1.129 + # leave variable stack frame 1.130 + move sp, fp 1.131 + 1.132 + lw ra, RAOFF(sp) 1.133 + lw fp, FPOFF(sp) 1.134 + 1.135 + addiu sp, FRAMESZ 1.136 + j ra 1.137 +END(_NS_InvokeByIndex)