List of usage examples for org.objectweb.asm Opcodes GETSTATIC
int GETSTATIC
To view the source code for org.objectweb.asm Opcodes GETSTATIC.
Click Source Link
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
@Override public void loadVprInt() { mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextInternalName, "vprInt", "[I"); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void loadInstruction(Instruction insn) { String classInternalName = instructionsInternalName; if (insn == Common.UNK) { // UNK instruction is in Common class, not Instructions classInternalName = Type.getInternalName(Common.class); }/*from w ww.j a v a 2 s. c om*/ mv.visitFieldInsn(Opcodes.GETSTATIC, classInternalName, insn.name().replace('.', '_').replace(' ', '_'), instructionDescriptor); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void loadModuleLoggger(HLEModuleFunction func) { mv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(func.getHLEModuleMethod().getDeclaringClass()), "log", Type.getDescriptor(Logger.class)); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
/** * Generate the required Java code to call a syscall function. * The code generated must match the Java behavior implemented in * jpcsp.HLE.modules.HLEModuleFunctionReflection * * The following code is generated:/*from w w w . j a v a2s . c om*/ * if (func.getFirmwareVersion() <= RuntimeContext.firmwareVersion) { * if (!fastSyscall) { * RuntimeContext.preSyscall(); * } * if (func.checkInsideInterrupt()) { * if (IntrManager.getInstance.isInsideInterrupt()) { * cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT; * goto afterSyscall; * } * } * if (func.checkDispatchThreadEnabled()) { * if (!Modules.ThreadManForUserModule.isDispatchThreadEnabled()) { * cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT; * goto afterSyscall; * } * } * if (func.isUnimplemented()) { * Modules.getLogger(func.getModuleName()).warn("Unimplemented <function name> parameterName1=parameterValue1, parameterName2=parameterValue2, ..."); * } * foreach parameter { * loadParameter(parameter); * } * try { * returnValue = <module name>.<function name>(...parameters...); * storeReturnValue(); * if (parameterReader.hasErrorPointer()) { * errorPointer.setValue(0); * } * } catch (SceKernelErrorException e) { * errorCode = e.errorCode; * if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) { * Modules.getLogger(func.getModuleName()).debug(String.format("<function name> return errorCode 0x%08X", errorCode)); * } * if (parameterReader.hasErrorPointer()) { * errorPointer.setValue(errorCode); * cpu.gpr[_v0] = 0; * } else { * cpu.gpr[_v0] = errorCode; * } * reload cpu.gpr[_ra]; // an exception is always clearing the whole stack * } * afterSyscall: * if (fastSyscall) { * RuntimeContext.postSyscallFast(); * } else { * RuntimeContext.postSyscall(); * } * } else { * Modules.getLogger(func.getModuleName()).warn("<function name> is not supported in firmware version <firmwareVersion>, it requires at least firmware version <function firmwareVersion>"); * cpu.gpr[_v0] = -1; * } * * @param func the syscall function * @param fastSyscall true if this is a fast syscall (i.e. without context switching) * false if not (i.e. a syscall where context switching could happen) */ private void visitSyscall(HLEModuleFunction func, boolean fastSyscall) { // The compilation of a syscall requires more stack size than usual maxStackSize = SYSCALL_MAX_STACK_SIZE; boolean needFirmwareVersionCheck = true; if (func.getFirmwareVersion() >= 999) { // Dummy version number meaning valid for all versions needFirmwareVersionCheck = false; } else if (isCodeInstructionInKernelMemory()) { // When compiling code in the kernel memory space, do not perform any version check. // This is used by overwritten HLE functions. needFirmwareVersionCheck = false; } else { // When compiling code loaded from flash0, do not perform any version check. // This is used by overwritten HLE functions. SceModule module = Managers.modules.getModuleByAddress(codeInstruction.getAddress()); if (module != null && module.pspfilename != null && module.pspfilename.startsWith("flash0:")) { if (log.isDebugEnabled()) { log.debug(String.format("syscall from a flash0 module(%s, '%s'), no firmware version check", module, module.pspfilename)); } needFirmwareVersionCheck = false; } } Label unsupportedVersionLabel = null; if (needFirmwareVersionCheck) { unsupportedVersionLabel = new Label(); loadImm(func.getFirmwareVersion()); mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextInternalName, "firmwareVersion", "I"); mv.visitJumpInsn(Opcodes.IF_ICMPGT, unsupportedVersionLabel); } // Save the syscall parameter to locals for debugging if (!fastSyscall) { saveParametersToLocals(); } if (!fastSyscall) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "preSyscall", "()V"); } Label afterSyscallLabel = new Label(); if (func.checkInsideInterrupt()) { // if (IntrManager.getInstance().isInsideInterrupt()) { // if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) { // Modules.getLogger(func.getModuleName()).debug("<function name> return errorCode 0x80020064 (ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT)"); // } // cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT; // goto afterSyscall // } mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(IntrManager.class), "getInstance", "()" + Type.getDescriptor(IntrManager.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(IntrManager.class), "isInsideInterrupt", "()Z"); Label notInsideInterrupt = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, notInsideInterrupt); loadModuleLoggger(func); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "isDebugEnabled", "()Z"); Label notDebug = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, notDebug); loadModuleLoggger(func); mv.visitLdcInsn( String.format("%s returning errorCode 0x%08X (ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT)", func.getFunctionName(), SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "debug", "(" + Type.getDescriptor(Object.class) + ")V"); mv.visitLabel(notDebug); storeRegister(_v0, SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT); mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel); mv.visitLabel(notInsideInterrupt); } if (func.checkDispatchThreadEnabled()) { // if (!Modules.ThreadManForUserModule.isDispatchThreadEnabled() || !Interrupts.isInterruptsEnabled()) { // if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) { // Modules.getLogger(func.getModuleName()).debug("<function name> return errorCode 0x800201A7 (ERROR_KERNEL_WAIT_CAN_NOT_WAIT)"); // } // cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT; // goto afterSyscall // } loadModule("ThreadManForUser"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ThreadManForUser.class), "isDispatchThreadEnabled", "()Z"); Label returnError = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, returnError); loadProcessor(); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Processor.class), "isInterruptsEnabled", "()Z"); Label noError = new Label(); mv.visitJumpInsn(Opcodes.IFNE, noError); mv.visitLabel(returnError); loadModuleLoggger(func); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "isDebugEnabled", "()Z"); Label notDebug = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, notDebug); loadModuleLoggger(func); mv.visitLdcInsn(String.format("%s returning errorCode 0x%08X (ERROR_KERNEL_WAIT_CAN_NOT_WAIT)", func.getFunctionName(), SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "debug", "(" + Type.getDescriptor(Object.class) + ")V"); mv.visitLabel(notDebug); storeRegister(_v0, SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT); mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel); mv.visitLabel(noError); } logSyscallStart(func); if (func.hasStackUsage()) { loadMemory(); loadRegister(_sp); loadImm(func.getStackUsage()); mv.visitInsn(Opcodes.ISUB); loadImm(0); loadImm(func.getStackUsage()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "memset", "(IBI)V"); } // Collecting the parameters and calling the module function... CompilerParameterReader parameterReader = new CompilerParameterReader(this); loadModule(func.getModuleName()); parameterReader.incrementCurrentStackSize(); Label tryStart = new Label(); Label tryEnd = new Label(); Label catchSceKernelErrorException = new Label(); mv.visitTryCatchBlock(tryStart, tryEnd, catchSceKernelErrorException, Type.getInternalName(SceKernelErrorException.class)); Class<?>[] parameterTypes = func.getHLEModuleMethod().getParameterTypes(); Class<?> returnType = func.getHLEModuleMethod().getReturnType(); StringBuilder methodDescriptor = new StringBuilder(); methodDescriptor.append("("); Annotation[][] paramsAnotations = func.getHLEModuleMethod().getParameterAnnotations(); int paramIndex = 0; for (Class<?> parameterType : parameterTypes) { methodDescriptor.append(Type.getDescriptor(parameterType)); loadParameter(parameterReader, func, parameterType, paramsAnotations[paramIndex], afterSyscallLabel, catchSceKernelErrorException); paramIndex++; } methodDescriptor.append(")"); methodDescriptor.append(Type.getDescriptor(returnType)); mv.visitLabel(tryStart); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(func.getHLEModuleMethod().getDeclaringClass()), func.getFunctionName(), methodDescriptor.toString()); storeReturnValue(func, returnType); if (parameterReader.hasErrorPointer()) { // errorPointer.setValue(0); mv.visitVarInsn(Opcodes.ALOAD, LOCAL_ERROR_POINTER); loadImm(0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(TErrorPointer32.class), "setValue", "(I)V"); } loadRegister(_v0); logSyscallEnd(func, false); mv.visitInsn(Opcodes.POP); mv.visitLabel(tryEnd); mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel); // catch (SceKernelErrorException e) { // errorCode = e.errorCode; // if (Modules.log.isDebugEnabled()) { // Modules.log.debug(String.format("<function name> return errorCode 0x%08X", errorCode)); // } // if (hasErrorPointer()) { // errorPointer.setValue(errorCode); // cpu.gpr[_v0] = 0; // } else { // cpu.gpr[_v0] = errorCode; // } // } mv.visitLabel(catchSceKernelErrorException); mv.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(SceKernelErrorException.class), "errorCode", "I"); logSyscallEnd(func, true); if (parameterReader.hasErrorPointer()) { // errorPointer.setValue(errorCode); // cpu.gpr[_v0] = 0; mv.visitVarInsn(Opcodes.ALOAD, LOCAL_ERROR_POINTER); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(TErrorPointer32.class), "setValue", "(I)V"); storeRegister(_v0, 0); } else { // cpu.gpr[_v0] = errorCode; storeRegister(_v0); } // Reload the $ra register, the stack is lost after an exception CodeInstruction previousInstruction = codeBlock.getCodeInstruction(codeInstruction.getAddress() - 4); if (previousInstruction != null && previousInstruction.getInsn() == Instructions.JR) { int jumpRegister = (previousInstruction.getOpcode() >> 21) & 0x1F; loadRegister(jumpRegister); } mv.visitLabel(afterSyscallLabel); if (fastSyscall) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "postSyscallFast", "()V"); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "postSyscall", "()V"); } if (needFirmwareVersionCheck) { Label afterVersionCheckLabel = new Label(); mv.visitJumpInsn(Opcodes.GOTO, afterVersionCheckLabel); mv.visitLabel(unsupportedVersionLabel); loadModuleLoggger(func); mv.visitLdcInsn(String.format( "%s is not supported in firmware version %d, it requires at least firmware version %d", func.getFunctionName(), RuntimeContext.firmwareVersion, func.getFirmwareVersion())); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "warn", "(" + Type.getDescriptor(Object.class) + ")V"); storeRegister(_v0, -1); mv.visitLabel(afterVersionCheckLabel); } }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
public void startSequenceMethod() { if (storeCpuLocal) { mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextInternalName, "cpu", cpuDescriptor); mv.visitVarInsn(Opcodes.ASTORE, LOCAL_CPU); }//ww w.java2s . c o m if (storeMemoryIntLocal) { mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextInternalName, "memoryInt", "[I"); mv.visitVarInsn(Opcodes.ASTORE, LOCAL_MEMORY_INT); } if (enableIntructionCounting) { currentInstructionCount = 0; mv.visitInsn(Opcodes.ICONST_0); storeLocalVar(LOCAL_INSTRUCTION_COUNT); } startNonBranchingCodeSequence(); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
public void checkSync() { if (RuntimeContext.enableDaemonThreadSync) { Label doNotWantSync = new Label(); mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextInternalName, "wantSync", "Z"); mv.visitJumpInsn(Opcodes.IFEQ, doNotWantSync); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, RuntimeContext.syncName, "()V"); mv.visitLabel(doNotWantSync);//from w ww.j a v a 2 s.c om } }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void startInternalMethod() { // if (e != null) Label notReplacedLabel = new Label(); mv.visitFieldInsn(Opcodes.GETSTATIC, codeBlock.getClassName(), getReplaceFieldName(), executableDescriptor); mv.visitJumpInsn(Opcodes.IFNULL, notReplacedLabel); {/*from www. j a v a2s . c o m*/ // return e.exec(returnAddress, alternativeReturnAddress, isJump); mv.visitFieldInsn(Opcodes.GETSTATIC, codeBlock.getClassName(), getReplaceFieldName(), executableDescriptor); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, executableInternalName, getExecMethodName(), getExecMethodDesc()); mv.visitInsn(Opcodes.IRETURN); } mv.visitLabel(notReplacedLabel); if (Profiler.isProfilerEnabled()) { loadImm(getCodeBlock().getStartAddress()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, profilerInternalName, "addCall", "(I)V"); } if (RuntimeContext.debugCodeBlockCalls) { loadImm(getCodeBlock().getStartAddress()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, RuntimeContext.debugCodeBlockStart, "(I)V"); } }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void flushInstructionCount(boolean local, boolean last) { if (enableIntructionCounting) { if (local) { if (currentInstructionCount > 0) { mv.visitIincInsn(LOCAL_INSTRUCTION_COUNT, currentInstructionCount); }/*from w w w . j a v a2 s . co m*/ } else { mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextInternalName, "currentThread", sceKernalThreadInfoDescriptor); mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(Opcodes.GETFIELD, sceKernalThreadInfoInternalName, "runClocks", "J"); loadLocalVar(LOCAL_INSTRUCTION_COUNT); if (currentInstructionCount > 0) { loadImm(currentInstructionCount); mv.visitInsn(Opcodes.IADD); } if (Profiler.isProfilerEnabled()) { mv.visitInsn(Opcodes.DUP); loadImm(getCodeBlock().getStartAddress()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, profilerInternalName, "addInstructionCount", "(II)V"); } mv.visitInsn(Opcodes.I2L); mv.visitInsn(Opcodes.LADD); mv.visitFieldInsn(Opcodes.PUTFIELD, sceKernalThreadInfoInternalName, "runClocks", "J"); if (!last) { mv.visitInsn(Opcodes.ICONST_0); storeLocalVar(LOCAL_INSTRUCTION_COUNT); } } currentInstructionCount = 0; } }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void startInstructionLLE(CodeInstruction codeInstruction) { // Check for a pending interrupt only for instructions not being in a delay slot if (codeInstruction.isDelaySlot()) { return;//from w ww . j a v a2 s .c o m } // TO avoid checking too often for a pending interrupt, check // only for instructions being the target of the branch or for those marked // as potentially modifying the interrupt state. if (!codeInstruction.isBranchTarget() && !previousInstructionModifiesInterruptState(codeInstruction)) { return; } Label noPendingInterrupt = new Label(); mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextLLEInternalName, "pendingInterruptIPbits", "I"); mv.visitJumpInsn(Opcodes.IFEQ, noPendingInterrupt); int returnAddress = codeInstruction.getAddress(); loadImm(returnAddress); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextLLEInternalName, "checkPendingInterruptException", "(I)I"); visitContinueToAddress(returnAddress, false); mv.visitLabel(noPendingInterrupt); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
public void loadPspNaNInt() { mv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(VfpuState.class), "pspNaNint", "I"); }