Package org.jnode.assembler.x86

Examples of org.jnode.assembler.x86.X86Assembler


    /**
     * @see org.jnode.vm.x86.compiler.l1a.Item#clone()
     */
    protected Item clone(EmitterContext ec) {
        final WordItem res;
        final X86Assembler os = ec.getStream();

        switch (getKind()) {
            case Kind.GPR:
                res = L1AHelper.requestWordRegister(ec, getType(), false);
                final GPR r = res.getRegister();
                os.writeMOV(gpr.getSize(), r, gpr);
                break;

            case Kind.LOCAL:
                res = (WordItem) factory.createLocal(getType(), getOffsetToFP(ec));
                break;

            case Kind.CONSTANT:
                res = cloneConstant(ec);
                break;

            case Kind.FPUSTACK:
                // TODO
                notImplemented();
                res = null;
                break;

            case Kind.STACK:
                os.writePUSH(X86Register.ESP, 0);
                res = (WordItem) factory.createStack(getType());
                if (VirtualStack.checkOperandStack) {
                    final ItemStack operandStack = ec.getVStack().operandStack;
                    operandStack.pop(this);
                    operandStack.push(this);
View Full Code Here


     * @param reg register to load the item to
     */
    final void loadTo(EmitterContext ec, X86Register.GPR reg) {
        if (VmUtils.verifyAssertions())
            VmUtils._assert(reg != null, "Reg != null");
        final X86Assembler os = ec.getStream();
        final X86RegisterPool pool = ec.getGPRPool();
        final VirtualStack stack = ec.getVStack();
        final X86CompilerHelper helper = ec.getHelper();
        if (VmUtils.verifyAssertions()) {
            VmUtils._assert(!pool.isFree(reg), "reg not free");
        }

        switch (getKind()) {
            case Kind.GPR:
                if (this.gpr != reg) {
                    os.writeMOV(reg.getSize(), reg, this.gpr);
                    cleanup(ec);
                }
                break;

            case Kind.LOCAL:
                os.writeMOV(reg.getSize(), reg, helper.BP, getOffsetToFP(ec));
                break;

            case Kind.CONSTANT:
                loadToConstant(ec, os, reg);
                break;

            case Kind.FPUSTACK:
                // Make sure this item is on top of the FPU stack
                FPUHelper.fxch(os, stack.fpuStack, this);
                stack.fpuStack.pop(this);
                // Convert & move to new space on normal stack
                os.writeLEA(helper.SP, helper.SP, -helper.SLOTSIZE);
                popFromFPU(os, helper.SP, 0);
                os.writePOP(reg);
                break;

            case Kind.STACK:
                // TODO: make sure 'this' is on top of stack
                // TODO: implemen it for 64 bits
                if (!stack.operandStack.isTos(this)) {

                    int stack_loc = stack.operandStack.stackLocation(this);
                    if (stack_loc < 0)
                        throw new StackException("Item not found on stack");

                    stack.operandStack.makeTop(stack_loc);

                    //todo test it
                    os.writeMOV(org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32, reg, helper.SP, helper.SLOTSIZE);
                    os.writeXCHG(helper.SP, org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32 * stack_loc, reg);
                    os.writeMOV(org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32, helper.SP, helper.SLOTSIZE, reg);
                }

                if (VirtualStack.checkOperandStack) {
                    stack.operandStack.pop(this);
                }
                os.writePOP(reg);
                break;

            default:
                throw new IllegalArgumentException("Invalid item kind");
        }
View Full Code Here

    /**
     * @see org.jnode.vm.x86.compiler.l1a.Item#push(EmitterContext)
     */
    final void push(EmitterContext ec) {
        final X86Assembler os = ec.getStream();
        final VirtualStack stack = ec.getVStack();
        final X86CompilerHelper helper = ec.getHelper();

        switch (getKind()) {
            case Kind.GPR:
                os.writePUSH(gpr);
                break;

            case Kind.LOCAL:
                os.writePUSH(helper.BP, getOffsetToFP(ec));
                break;

            case Kind.CONSTANT:
                pushConstant(ec, os);
                break;

            case Kind.FPUSTACK:
                // Make sure this item is on top of the FPU stack
                final FPUStack fpuStack = stack.fpuStack;
                FPUHelper.fxch(os, fpuStack, this);
                stack.fpuStack.pop(this);
                // Convert & move to new space on normal stack
                os.writeLEA(helper.SP, helper.SP, -helper.SLOTSIZE);
                popFromFPU(os, helper.SP, 0);
                break;

            case Kind.STACK:
                // nothing to do
View Full Code Here

    /**
     * @see org.jnode.vm.x86.compiler.l1a.Item#pushToFPU(EmitterContext)
     */
    final void pushToFPU(EmitterContext ec) {
        final X86Assembler os = ec.getStream();
        final VirtualStack stack = ec.getVStack();
        final X86CompilerHelper helper = ec.getHelper();

        switch (getKind()) {
            case Kind.GPR:
                os.writePUSH(gpr);
                pushToFPU(os, helper.SP, 0);
                os.writeLEA(helper.SP, helper.SP, helper.SLOTSIZE);
                break;

            case Kind.LOCAL:
                pushToFPU(os, helper.BP, getOffsetToFP(ec));
                break;

            case Kind.CONSTANT:
                pushConstant(ec, os);
                pushToFPU(os, helper.SP, 0);
                os.writeLEA(helper.SP, helper.SP, helper.SLOTSIZE);
                break;

            case Kind.FPUSTACK:
                // Assert this item is at the top of the stack
                stack.fpuStack.pop(this);
                stack.fpuStack.push(this);
                return;
            // break;

            case Kind.STACK:
                if (VirtualStack.checkOperandStack) {
                    stack.operandStack.pop(this);
                }
                pushToFPU(os, helper.SP, 0);
                os.writeLEA(helper.SP, helper.SP, helper.SLOTSIZE);
                break;

            default:
                throw new IllegalArgumentException("Invalid item kind");
        }
View Full Code Here

        final CompiledMethod cm = new CompiledMethod(level);
        if (method.isNative()) {
            Object label = new Label(method.getMangledName());
            cm.setCodeStart(nos.getObjectRef(label));
        } else {
            final X86Assembler os = (X86Assembler) nos;
            final EntryPoints context = getEntryPoints();
            // Create the helper
            final X86CompilerHelper ih = new X86CompilerHelper(os, null, context, isBootstrap);
            // Start an "object"
            final NativeStream.ObjectInfo objectInfo = os.startObject(context.getVmMethodCodeClass());
            // Start the code creation
            cm.setCodeStart(os.setObjectRef(new Label(method.getMangledName() + "$$start")));

            // Setup call to {@link VmMethod#recompileMethod(int, int)}
            final VmType<?> declClass = method.getDeclaringClass();
            os.writePUSH(declClass.getSharedStaticsIndex());
            os.writePUSH(declClass.indexOf(method));
            final int recompileStatOfs = ih.getSharedStaticsOffset(context.getRecompileMethod());
            os.writeCALL(ih.STATICS, recompileStatOfs);

            // Emit jump to the newly compiled code.
            final int methodStatOfs = ih.getSharedStaticsOffset(method);
            os.writeJMP(ih.STATICS, methodStatOfs);

            // Close the "object"
            objectInfo.markEnd();
            // The end
            cm.setCodeEnd(os.setObjectRef(new Label(method.getMangledName() + "$$end")));

            // Test for unresolved objectrefs
            if (!isBootstrap && os.hasUnresolvedObjectRefs()) {
                throw new Error("There are unresolved objectrefs " + os.getUnresolvedObjectRefs());
            }
        }

        return cm;
    }
View Full Code Here

    protected final CompiledMethod doCompileAbstract(VmMethod method,
                                                     NativeStream nos, int level, boolean isBootstrap) {
        if (isBootstrap) {
            // System.out.println("Abstract method " + method);
            final CompiledMethod cm = new CompiledMethod(level);
            final X86Assembler os = (X86Assembler) nos;
            // Create the helper
            final X86CompilerHelper helper = new X86CompilerHelper(os, null,
                context, isBootstrap);
            // Start an "object"
            final NativeStream.ObjectInfo objectInfo = os.startObject(context
                .getVmMethodCodeClass());
            // Start the code creation
            cm.setCodeStart(os.setObjectRef(new Label(method.getMangledName()
                + "$$abstract-start")));
            // Call abstract method error method
            helper.writeJumpTableJMP(X86JumpTable.VM_INVOKE_ABSTRACT_IDX);
            // Close the "object"
            objectInfo.markEnd();
            // The end
            cm.setCodeEnd(os.setObjectRef(new Label(method.getMangledName()
                + "$$abstract-end")));

            return cm;
        } else {
            // Set the address of the abstract method code
View Full Code Here

     * @return
     */
    static DoubleWordItem requestDoubleWordRegisters(
        EmitterContext eContext, int jvmType) {
        final X86RegisterPool pool = eContext.getGPRPool();
        final X86Assembler os = eContext.getStream();
        final ItemFactory ifac = eContext.getItemFactory();
        final DoubleWordItem result;
        if (os.isCode32()) {
            final X86Register.GPR lsb = (X86Register.GPR) requestRegister(eContext, JvmType.INT, false);
            final X86Register.GPR msb = (X86Register.GPR) requestRegister(eContext, JvmType.INT, false);
            result = ifac.createReg(eContext, jvmType, lsb,
                msb);
            pool.transferOwnerTo(lsb, result);
View Full Code Here

     * Request two register for a 8-byte item.
     */
    static final DoubleWordItem requestDoubleWordRegisters(
        EmitterContext eContext, int jvmType) {
        final X86RegisterPool pool = eContext.getGPRPool();
        final X86Assembler os = eContext.getStream();
        final ItemFactory ifac = eContext.getItemFactory();
        final DoubleWordItem result;
        if (os.isCode32()) {
            final X86Register.GPR lsb = (X86Register.GPR) requestRegister(eContext, JvmType.INT, false);
            final X86Register.GPR msb = (X86Register.GPR) requestRegister(eContext, JvmType.INT, false);
            result = ifac.createReg(eContext, jvmType, lsb,
                msb);
            pool.transferOwnerTo(lsb, result);
View Full Code Here

     *
     * @param ec
     * @param reg
     */
    final void loadTo64(EmitterContext ec, X86Register.GPR64 reg) {
        final X86Assembler os = ec.getStream();
//      final X86RegisterPool pool = ec.getGPRPool();
        final VirtualStack stack = ec.getVStack();
        if (!os.isCode64()) {
            throw new RuntimeException("Can only be used in 64-bit mode.");
        }

        if (VmUtils.verifyAssertions()) {
            VmUtils._assert(reg != null, "reg != null");
        }

        switch (getKind()) {
            case Kind.GPR:
                if (this.reg != reg) {
                    os.writeMOV(BITS64, reg, this.reg);
                    cleanup(ec);
                }
                break;

            case Kind.LOCAL:
                os.writeMOV(BITS64, reg, X86Register.RBP, getOffsetToFP(ec));
                break;

            case Kind.CONSTANT:
                loadToConstant64(ec, os, reg);
                break;

            case Kind.FPUSTACK:
                // Make sure this item is on top of the FPU stack
                stack.fpuStack.pop(this);
                // Convert & move to new space on normal stack
                os.writeLEA(X86Register.RSP, X86Register.RSP, -8);
                popFromFPU(os, X86Register.RSP, 0);
                os.writePOP(reg);
                break;

            case Kind.STACK:
                if (VirtualStack.checkOperandStack) {
                    stack.operandStack.pop(this);
                }
                os.writePOP(reg);
                os.writeLEA(X86Register.RSP, X86Register.RSP, 8); // garbage
                break;

        }
        setKind(Kind.GPR);
        this.reg = reg;
View Full Code Here

     *
     * @param ec
     */
    final void loadToGPR(EmitterContext ec) {
        if (!isGPR()) {
            final X86Assembler os = ec.getStream();

            if (os.isCode32()) {
                X86Register.GPR lsb = (X86Register.GPR) ec.getGPRPool()
                    .request(JvmType.INT);
                if (lsb == null) {
                    ec.getVStack().push(ec);
                    lsb = (X86Register.GPR) ec.getGPRPool()
View Full Code Here

TOP

Related Classes of org.jnode.assembler.x86.X86Assembler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.