duke@435: /* trims@1907: * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: duke@435: #include duke@435: #include duke@435: duke@435: static const int R_O0_num = 1000; duke@435: static const int R_I0_num = 2000; duke@435: static const int R_F0_num = 3000; duke@435: static const int R_F1_num = R_F0_num + 1; duke@435: static const int R_F2_num = R_F0_num + 2; duke@435: static const int STACK_num= 4000; duke@435: duke@435: static bool LP64 = false; duke@435: static bool LONGS_IN_ONE_ENTRY = false; duke@435: duke@435: static const int Op_RegI = 'I'; duke@435: static const int Op_RegP = 'P'; duke@435: static const int Op_RegF = 'F'; duke@435: static const int Op_RegD = 'D'; duke@435: static const int Op_RegL = 'L'; duke@435: static const int SPARC_ARGS_IN_REGS_NUM=6; duke@435: duke@435: static void print_reg( int reg ) { duke@435: if( reg == 0 ) duke@435: printf("__"); // halve's duke@435: else if( reg >= STACK_num && reg < STACK_num+100 ) duke@435: printf("S%d_",reg - STACK_num); duke@435: else if( reg >= R_F0_num && reg < R_F0_num+100 ) duke@435: printf("F%d_",reg - R_F0_num); duke@435: else if( reg >= R_O0_num && reg < R_O0_num+100 ) { duke@435: if( LONGS_IN_ONE_ENTRY ) { duke@435: reg -= R_O0_num; duke@435: printf("O%d",reg>>1); duke@435: printf(reg&1 ? "H" : "L"); duke@435: } else duke@435: printf("O%d_",reg - R_O0_num); duke@435: } else duke@435: printf("Wretched: %d\n", reg); duke@435: } duke@435: duke@435: static void print_convention( int *sig, const char *s, int length ) { duke@435: // Print it out duke@435: for( int i = 0; i < length; i++) { duke@435: if( sig[i] == 0 ) continue; // do not print 'halves' duke@435: print_reg( sig[i] & 0xFFFF ); duke@435: int reg = sig[i] >> 16; duke@435: if( reg ) { duke@435: printf(":"); duke@435: print_reg( reg ); duke@435: } else { duke@435: printf(" "); duke@435: } duke@435: printf(" "); duke@435: } duke@435: printf("\n"); duke@435: } duke@435: duke@435: static int INT_SCALE( int x ) { duke@435: return LONGS_IN_ONE_ENTRY ? (x<<1) : x; duke@435: } duke@435: duke@435: static void java_convention( int *sig, const char *s, int length ) { duke@435: if( LP64 && !LONGS_IN_ONE_ENTRY ) { duke@435: printf("LP64 and 2-reg longs not supported\n"); duke@435: return; duke@435: } duke@435: for( int i = 0; i < length; i++ ) duke@435: sig[i] = s[i]; // Reset sig array duke@435: bool is_outgoing = true; duke@435: duke@435: int int_base = (is_outgoing ? R_O0_num : R_I0_num); duke@435: duke@435: // Convention is to pack the first 6 int/oop args into the first 6 duke@435: // registers (I0-I5), extras spill to the stack. Then pack the first duke@435: // 32 float args into F0-F31, extras spill to the stack. Then pad duke@435: // all register sets to align. Then put longs and doubles into the duke@435: // same registers as they fit, else spill to the stack. duke@435: int int_reg_max = SPARC_ARGS_IN_REGS_NUM; duke@435: int flt_reg_max = 32; duke@435: duke@435: // Count int/oop and float args. See how many stack slots we'll need duke@435: // and where the longs & doubles will go. duke@435: int int_reg_cnt = 0; duke@435: int flt_reg_cnt = 0; duke@435: int stk_reg_pairs = 0; duke@435: for( int i = 0; i < length; i++) { duke@435: switch( sig[i] ) { duke@435: case Op_RegL: // Longs-in-1-reg compete with int args duke@435: if( LONGS_IN_ONE_ENTRY ) { duke@435: if( int_reg_cnt < int_reg_max ) int_reg_cnt++; duke@435: } duke@435: break; duke@435: case Op_RegP: duke@435: if( int_reg_cnt < int_reg_max ) int_reg_cnt++; duke@435: else if( !LP64 ) stk_reg_pairs++; duke@435: break; duke@435: case Op_RegI: duke@435: if( int_reg_cnt < int_reg_max ) int_reg_cnt++; duke@435: else stk_reg_pairs++; duke@435: break; duke@435: case Op_RegF: duke@435: if( flt_reg_cnt < flt_reg_max ) flt_reg_cnt++; duke@435: else stk_reg_pairs++; duke@435: break; duke@435: } duke@435: } duke@435: duke@435: // This is where the longs/doubles start on the stack. duke@435: stk_reg_pairs = (stk_reg_pairs+1) & ~1; // Round duke@435: duke@435: int int_reg_pairs = (int_reg_cnt+1) & ~1; // 32-bit 2-reg longs only duke@435: int flt_reg_pairs = (flt_reg_cnt+1) & ~1; duke@435: duke@435: int stk_reg = 0; duke@435: int int_reg = 0; duke@435: int flt_reg = 0; duke@435: duke@435: // Now do the signature layout duke@435: for( int i = 0; i < length; i++) { duke@435: int tmp = sig[i]; duke@435: if( tmp == Op_RegP ) duke@435: tmp = LP64 ? Op_RegL : Op_RegI; // Treat ptrs and ints or long accordingly duke@435: switch( tmp ) { duke@435: case Op_RegI: duke@435: // case Op_RegP: duke@435: if( int_reg < int_reg_max) tmp = INT_SCALE(int_reg++) + int_base; duke@435: else tmp = STACK_num + stk_reg++; duke@435: sig[i] = tmp; duke@435: break; duke@435: duke@435: case Op_RegL: duke@435: if( sig[i] != Op_RegP && sig[i+1] != 'h' ) { printf("expecting (h)alf, found %c\n", sig[i+1]); return; } duke@435: // case Op_RegP: duke@435: if( LONGS_IN_ONE_ENTRY ) { duke@435: if( int_reg < int_reg_max ) { duke@435: tmp = INT_SCALE(int_reg++) + int_base; duke@435: } else { duke@435: tmp = STACK_num + stk_reg_pairs; duke@435: stk_reg_pairs += 2; duke@435: } duke@435: } else { duke@435: if( int_reg_pairs < int_reg_max ) { duke@435: tmp = int_reg_pairs + int_base; duke@435: int_reg_pairs += 2; duke@435: } else { duke@435: tmp = STACK_num + stk_reg_pairs; duke@435: stk_reg_pairs += 2; duke@435: } duke@435: } duke@435: sig[i] = tmp | (tmp+1)<<16; // Smear to pair duke@435: break; duke@435: duke@435: case Op_RegF: duke@435: sig[i] = (flt_reg < flt_reg_max) ? (R_F0_num + flt_reg++) : STACK_num + stk_reg++; duke@435: break; duke@435: case Op_RegD: duke@435: if( sig[i+1] != 'h' ) { printf("expecting (h)alf, found %c\n", sig[i+1]); return; } duke@435: if( flt_reg_pairs < flt_reg_max ) { duke@435: tmp = R_F0_num + flt_reg_pairs; duke@435: flt_reg_pairs += 2; duke@435: } else { duke@435: tmp = STACK_num + stk_reg_pairs; duke@435: stk_reg_pairs += 2; duke@435: } duke@435: sig[i] = tmp | (tmp+1)<<16; // Smear to pair duke@435: break; duke@435: case 'h': sig[i] = 0; break; duke@435: default: duke@435: printf("Bad character: %c\n", sig[i] ); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: printf("java "); duke@435: printf(LP64 ? "LP64 " : "LP32 "); duke@435: printf(LONGS_IN_ONE_ENTRY ? "long1: " : "long2: "); duke@435: print_convention(sig,s,length); duke@435: } duke@435: duke@435: static int int_stk_helper( int i ) { duke@435: if( i < 6 ) return R_O0_num + (LONGS_IN_ONE_ENTRY ? i<<1 : i); duke@435: else return STACK_num + (LP64 ? i<<1 : i); duke@435: } duke@435: duke@435: static void native_convention( int *sig, const char *s, int length ) { duke@435: if( LP64 && !LONGS_IN_ONE_ENTRY ) { duke@435: printf("LP64 and 2-reg longs not supported\n"); duke@435: return; duke@435: } duke@435: for( int i = 0; i < length; i++ ) duke@435: sig[i] = s[i]; // Reset sig array duke@435: duke@435: // The native convention is V8 if !LP64, which means the V8 convention is duke@435: // used both with and without LONGS_IN_ONE_ENTRY, an unfortunate split. The duke@435: // same actual machine registers are used, but they are named differently in duke@435: // the LONGS_IN_ONE_ENTRY mode. The LP64 convention is the V9 convention duke@435: // which is slightly more sane. duke@435: duke@435: if( LP64 ) { duke@435: // V9 convention: All things "as-if" on double-wide stack slots. duke@435: // Hoist any int/ptr/long's in the first 6 to int regs. duke@435: // Hoist any flt/dbl's in the first 16 dbl regs. duke@435: int j = 0; // Count of actual args, not HALVES duke@435: for( int i=0; i