001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.tools.header_gen;
014    
015    import org.jikesrvm.VM;
016    import org.jikesrvm.ppc.BaselineConstants;
017    import org.jikesrvm.ppc.RegisterConstants;
018    import org.jikesrvm.ppc.StackframeLayoutConstants;
019    import org.jikesrvm.ppc.TrapConstants;
020    import org.jikesrvm.runtime.ArchEntrypoints;
021    import org.vmmagic.unboxed.Offset;
022    
023    /**
024     * Emit the architecture-specific part of a header file containing declarations
025     * required to access VM data structures from C++.
026     * Posix version: AIX PPC, Linux PPC, Linux IA32
027     */
028    final class GenArch_ppc extends GenArch {
029      @Override
030      public void emitArchVirtualMachineDeclarations() {
031        Offset offset;
032        offset = ArchEntrypoints.registersLRField.getOffset();
033        pln("Registers_lr_offset = ", offset);
034    
035        p("static const int Constants_JTOC_POINTER               = " + RegisterConstants.JTOC_POINTER + ";\n");
036        p("static const int Constants_FRAME_POINTER              = " + RegisterConstants.FRAME_POINTER + ";\n");
037        p("static const int Constants_THREAD_REGISTER            = " + RegisterConstants.THREAD_REGISTER + ";\n");
038        p("static const int Constants_FIRST_VOLATILE_GPR         = " + RegisterConstants.FIRST_VOLATILE_GPR + ";\n");
039        p("static const int Constants_DIVIDE_BY_ZERO_MASK        = " + TrapConstants.DIVIDE_BY_ZERO_MASK + ";\n");
040        p("static const int Constants_DIVIDE_BY_ZERO_TRAP        = " + TrapConstants.DIVIDE_BY_ZERO_TRAP + ";\n");
041        p("static const int Constants_MUST_IMPLEMENT_MASK        = " + TrapConstants.MUST_IMPLEMENT_MASK + ";\n");
042        p("static const int Constants_MUST_IMPLEMENT_TRAP        = " + TrapConstants.MUST_IMPLEMENT_TRAP + ";\n");
043        p("static const int Constants_STORE_CHECK_MASK           = " + TrapConstants.STORE_CHECK_MASK + ";\n");
044        p("static const int Constants_STORE_CHECK_TRAP           = " + TrapConstants.STORE_CHECK_TRAP + ";\n");
045        p("static const int Constants_ARRAY_INDEX_MASK           = " + TrapConstants.ARRAY_INDEX_MASK + ";\n");
046        p("static const int Constants_ARRAY_INDEX_TRAP           = " + TrapConstants.ARRAY_INDEX_TRAP + ";\n");
047        p("static const int Constants_ARRAY_INDEX_REG_MASK       = " + TrapConstants.ARRAY_INDEX_REG_MASK + ";\n");
048        p("static const int Constants_ARRAY_INDEX_REG_SHIFT      = " + TrapConstants.ARRAY_INDEX_REG_SHIFT + ";\n");
049        p("static const int Constants_CONSTANT_ARRAY_INDEX_MASK  = " +
050          TrapConstants.CONSTANT_ARRAY_INDEX_MASK + ";\n");
051        p("static const int Constants_CONSTANT_ARRAY_INDEX_TRAP  = " +
052          TrapConstants.CONSTANT_ARRAY_INDEX_TRAP + ";\n");
053        p("static const int Constants_CONSTANT_ARRAY_INDEX_INFO  = " +
054          TrapConstants.CONSTANT_ARRAY_INDEX_INFO + ";\n");
055        p("static const int Constants_WRITE_BUFFER_OVERFLOW_MASK = " +
056          TrapConstants.WRITE_BUFFER_OVERFLOW_MASK + ";\n");
057        p("static const int Constants_WRITE_BUFFER_OVERFLOW_TRAP = " +
058          TrapConstants.WRITE_BUFFER_OVERFLOW_TRAP + ";\n");
059        p("static const int Constants_STACK_OVERFLOW_MASK        = " + TrapConstants.STACK_OVERFLOW_MASK + ";\n");
060        p("static const int Constants_STACK_OVERFLOW_HAVE_FRAME_TRAP = " +
061          TrapConstants.STACK_OVERFLOW_HAVE_FRAME_TRAP + ";\n");
062        p("static const int Constants_STACK_OVERFLOW_TRAP        = " + TrapConstants.STACK_OVERFLOW_TRAP + ";\n");
063        p("static const int Constants_CHECKCAST_MASK             = " + TrapConstants.CHECKCAST_MASK + ";\n");
064        p("static const int Constants_CHECKCAST_TRAP             = " + TrapConstants.CHECKCAST_TRAP + ";\n");
065        p("static const int Constants_REGENERATE_MASK            = " + TrapConstants.REGENERATE_MASK + ";\n");
066        p("static const int Constants_REGENERATE_TRAP            = " + TrapConstants.REGENERATE_TRAP + ";\n");
067        p("static const int Constants_NULLCHECK_MASK             = " + TrapConstants.NULLCHECK_MASK + ";\n");
068        p("static const int Constants_NULLCHECK_TRAP             = " + TrapConstants.NULLCHECK_TRAP + ";\n");
069        p("static const int Constants_JNI_STACK_TRAP_MASK             = " +
070          TrapConstants.JNI_STACK_TRAP_MASK + ";\n");
071        p("static const int Constants_JNI_STACK_TRAP             = " + TrapConstants.JNI_STACK_TRAP + ";\n");
072        p("static const int Constants_STACKFRAME_RETURN_ADDRESS_OFFSET = " +
073          StackframeLayoutConstants.STACKFRAME_RETURN_ADDRESS_OFFSET + ";\n");
074        p("static const int Constants_STACKFRAME_ALIGNMENT = " +
075          StackframeLayoutConstants.STACKFRAME_ALIGNMENT + " ;\n");
076      }
077    
078      @Override
079      public void emitArchAssemblerDeclarations() {
080        if (VM.BuildForOsx) {
081          pln("#define FP r" + BaselineConstants.FP);
082          pln("#define JTOC r" + BaselineConstants.JTOC);
083          pln("#define THREAD_REGISTER r" + BaselineConstants.THREAD_REGISTER);
084          pln("#define S0 r" + BaselineConstants.S0);
085          pln("#define T0 r" + BaselineConstants.T0);
086          pln("#define T1 r" + BaselineConstants.T1);
087          pln("#define T2 r" + BaselineConstants.T2);
088          pln("#define T3 r" + BaselineConstants.T3);
089          pln("#define STACKFRAME_RETURN_ADDRESS_OFFSET " +
090              StackframeLayoutConstants.STACKFRAME_RETURN_ADDRESS_OFFSET);
091        } else {
092          pln(".set FP," + BaselineConstants.FP);
093          pln(".set JTOC," + BaselineConstants.JTOC);
094          pln(".set THREAD_REGISTER," + BaselineConstants.THREAD_REGISTER);
095          pln(".set S0," + BaselineConstants.S0);
096          pln(".set T0," + BaselineConstants.T0);
097          pln(".set T1," + BaselineConstants.T1);
098          pln(".set T2," + BaselineConstants.T2);
099          pln(".set T3," + BaselineConstants.T3);
100          pln(".set STACKFRAME_RETURN_ADDRESS_OFFSET," + StackframeLayoutConstants.STACKFRAME_RETURN_ADDRESS_OFFSET);
101          if (!VM.BuildForAix) {
102            pln(".set T4," + (BaselineConstants.T3 + 1));
103          }
104        }
105      }
106    }