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 */
013package org.jikesrvm.tools.header_gen;
014
015import static org.jikesrvm.ia32.ArchConstants.SSE2_BASE;
016import static org.jikesrvm.ia32.BaselineConstants.TR;
017import static org.jikesrvm.ia32.RegisterConstants.EAX;
018import static org.jikesrvm.ia32.RegisterConstants.EBP;
019import static org.jikesrvm.ia32.RegisterConstants.EBX;
020import static org.jikesrvm.ia32.RegisterConstants.ECX;
021import static org.jikesrvm.ia32.RegisterConstants.EDI;
022import static org.jikesrvm.ia32.RegisterConstants.EDX;
023import static org.jikesrvm.ia32.RegisterConstants.ESI;
024import static org.jikesrvm.ia32.RegisterConstants.ESP;
025import static org.jikesrvm.ia32.RegisterConstants.R10;
026import static org.jikesrvm.ia32.RegisterConstants.R11;
027import static org.jikesrvm.ia32.RegisterConstants.R12;
028import static org.jikesrvm.ia32.RegisterConstants.R13;
029import static org.jikesrvm.ia32.RegisterConstants.R14;
030import static org.jikesrvm.ia32.RegisterConstants.R15;
031import static org.jikesrvm.ia32.RegisterConstants.R8;
032import static org.jikesrvm.ia32.RegisterConstants.R9;
033import static org.jikesrvm.ia32.StackframeLayoutConstants.STACKFRAME_BODY_OFFSET;
034import static org.jikesrvm.ia32.StackframeLayoutConstants.STACKFRAME_RETURN_ADDRESS_OFFSET;
035import static org.jikesrvm.ia32.TrapConstants.RVM_TRAP_BASE;
036
037import org.jikesrvm.VM;
038import org.jikesrvm.runtime.ArchEntrypoints;
039import org.vmmagic.unboxed.Offset;
040
041/**
042 * Emit the architecture-specific part of a header file containing declarations
043 * required to access VM data structures from C.
044 */
045final class GenArch_ia32 extends GenArch {
046  @Override
047  public void emitArchVirtualMachineDeclarations() {
048    Offset offset;
049
050    offset = ArchEntrypoints.registersFPField.getOffset();
051    pln("Registers_fp_offset", offset);
052
053    pln("Constants_EAX", EAX.value());
054    pln("Constants_ECX", ECX.value());
055    pln("Constants_EDX", EDX.value());
056    pln("Constants_EBX", EBX.value());
057    pln("Constants_ESP", ESP.value());
058    pln("Constants_EBP", EBP.value());
059    pln("Constants_ESI", ESI.value());
060    pln("Constants_EDI", EDI.value());
061    if (VM.BuildFor64Addr) {
062      pln("Constants_R8", R8.value());
063      pln("Constants_R9", R9.value());
064      pln("Constants_R10", R10.value());
065      pln("Constants_R11", R11.value());
066      pln("Constants_R12", R12.value());
067      pln("Constants_R13", R13.value());
068      pln("Constants_R14", R14.value());
069      pln("Constants_R15", R15.value());
070    }
071    pln("Constants_STACKFRAME_BODY_OFFSET", STACKFRAME_BODY_OFFSET);
072    pln("Constants_STACKFRAME_RETURN_ADDRESS_OFFSET", STACKFRAME_RETURN_ADDRESS_OFFSET);
073    pln("Constants_RVM_TRAP_BASE", RVM_TRAP_BASE);
074
075    offset = ArchEntrypoints.framePointerField.getOffset();
076    pln("Thread_framePointer_offset", offset);
077    offset = ArchEntrypoints.arrayIndexTrapParamField.getOffset();
078    pln("Thread_arrayIndexTrapParam_offset", offset);
079
080    pln("ArchConstants_SSE2", (SSE2_BASE ? 1 : 0));
081  }
082
083  @Override
084  public void emitArchAssemblerDeclarations() {
085    if (TR != ESI) {
086      throw new Error("Unexpected TR value");
087    }
088    p("#define TR %ESI\n");
089  }
090}