List of usage examples for org.objectweb.asm Opcodes SWAP
int SWAP
To view the source code for org.objectweb.asm Opcodes SWAP.
Click Source Link
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void logSyscall(HLEModuleFunction func, String logPrefix, String logCheckFunction, String logFunction) { // Modules.getLogger(func.getModuleName()).warn("Unimplemented..."); loadModuleLoggger(func);/*from w ww. j av a2s . c o m*/ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logCheckFunction, "()Z"); Label loggingDisabled = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, loggingDisabled); loadModuleLoggger(func); StringBuilder formatString = new StringBuilder(); if (logPrefix != null) { formatString.append(logPrefix); } formatString.append(func.getFunctionName()); ParameterInfo[] parameters = new ClassAnalyzer().getParameters(func.getFunctionName(), func.getHLEModuleMethod().getDeclaringClass()); if (parameters != null) { // Log message: // String.format( // "Unimplemented <function name> // <parameterIntegerName>=0x%X, // <parameterBooleanName>=%b, // <parameterLongName>=0x%X, // <parameterFloatName>=%f, // <parameterOtherTypeName>=%s", // new Object[] { // new Integer(parameterValueInteger), // new Boolean(parameterValueBoolean), // new Long(parameterValueLong), // new Float(parameterValueFloat), // parameterValueOtherTypes // }) loadImm(parameters.length); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); CompilerParameterReader parameterReader = new CompilerParameterReader(this); Annotation[][] paramsAnotations = func.getHLEModuleMethod().getParameterAnnotations(); int objectArrayIndex = 0; for (int paramIndex = 0; paramIndex < parameters.length; paramIndex++) { ParameterInfo parameter = parameters[paramIndex]; Class<?> parameterType = parameter.type; CompilerTypeInformation typeInformation = compilerTypeManager .getCompilerTypeInformation(parameterType); mv.visitInsn(Opcodes.DUP); loadImm(objectArrayIndex); formatString.append(paramIndex > 0 ? ", " : " "); formatString.append(parameter.name); formatString.append("="); formatString.append(typeInformation.formatString); if (typeInformation.boxingTypeInternalName != null) { mv.visitTypeInsn(Opcodes.NEW, typeInformation.boxingTypeInternalName); mv.visitInsn(Opcodes.DUP); } loadParameter(parameterReader, func, parameterType, paramsAnotations[paramIndex], null, null); if (typeInformation.boxingTypeInternalName != null) { mv.visitMethodInsn(Opcodes.INVOKESPECIAL, typeInformation.boxingTypeInternalName, "<init>", typeInformation.boxingMethodDescriptor); } mv.visitInsn(Opcodes.AASTORE); objectArrayIndex++; } mv.visitLdcInsn(formatString.toString()); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "format", "(" + Type.getDescriptor(String.class) + "[" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(String.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logFunction, "(" + Type.getDescriptor(Object.class) + ")V"); parameterReader = new CompilerParameterReader(this); for (int paramIndex = 0; paramIndex < parameters.length; paramIndex++) { ParameterInfo parameter = parameters[paramIndex]; Class<?> parameterType = parameter.type; LengthInfo lengthInfo = BufferInfo.defaultLengthInfo; int length = BufferInfo.defaultLength; Usage usage = BufferInfo.defaultUsage; for (Annotation parameterAnnotation : paramsAnotations[paramIndex]) { if (parameterAnnotation instanceof BufferInfo) { BufferInfo bufferInfo = (BufferInfo) parameterAnnotation; lengthInfo = bufferInfo.lengthInfo(); length = bufferInfo.length(); usage = bufferInfo.usage(); } } boolean parameterRead = false; if ((usage == Usage.in || usage == Usage.inout) && (lengthInfo != LengthInfo.unknown || parameterType == TPointer16.class || parameterType == TPointer32.class || parameterType == TPointer64.class)) { loadModuleLoggger(func); loadImm(1); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); mv.visitInsn(Opcodes.DUP); loadImm(0); Label done = new Label(); Label addressNull = new Label(); parameterReader.loadNextInt(); parameterRead = true; mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFEQ, addressNull); String format = String.format("%s[%s]:%%s", parameter.name, usage); boolean useMemoryDump = true; switch (lengthInfo) { case fixedLength: loadImm(length); break; case nextNextParameter: parameterReader.skipNextInt(); paramIndex++; parameterReader.loadNextInt(); paramIndex++; break; case nextParameter: parameterReader.loadNextInt(); paramIndex++; break; case previousParameter: // Go back to the address parameter parameterReader.rewindPreviousInt(); // Go back to the previous parameter parameterReader.rewindPreviousInt(); // Load the length from the previous parameter parameterReader.loadNextInt(); // Skip again the address parameter // to come back to the above situation parameterReader.skipNextInt(); break; case variableLength: mv.visitInsn(Opcodes.DUP); loadMemory(); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I"); break; case unknown: useMemoryDump = false; format = String.format("%s[%s]: 0x%%X", parameter.name, usage); loadMemory(); mv.visitInsn(Opcodes.SWAP); if (parameterType == TPointer64.class) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read64", "(I)J"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Long.class)); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.POP2); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Long.class), "<init>", "(J)V"); } else if (parameterType == TPointer16.class) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read16", "(I)I"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); } else { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); } break; default: log.error(String.format("Unimplemented lengthInfo=%s", lengthInfo)); break; } if (useMemoryDump) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Utilities.class), "getMemoryDump", "(II)" + Type.getDescriptor(String.class)); } mv.visitInsn(Opcodes.AASTORE); mv.visitLdcInsn(format); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "format", "(" + Type.getDescriptor(String.class) + "[" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(String.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logFunction, "(" + Type.getDescriptor(Object.class) + ")V"); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(addressNull); mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.POP2); mv.visitInsn(Opcodes.POP2); mv.visitLabel(done); } if (!parameterRead) { if (parameterType == long.class) { parameterReader.skipNextLong(); } else if (parameterType == float.class) { parameterReader.skipNextFloat(); } else { parameterReader.skipNextInt(); } } } } else { mv.visitLdcInsn(formatString.toString()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logFunction, "(" + Type.getDescriptor(Object.class) + ")V"); } mv.visitLabel(loggingDisabled); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void logSyscallEnd(HLEModuleFunction func, boolean isErrorCode) { String loggingLevel = getLoggingLevel(func); if (loggingLevel == null) { return;/*from w w w . j av a 2s . c om*/ } String logCheckFunction = getLogCheckFunction(loggingLevel); // if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) { // Modules.getLogger(func.getModuleName()).debug(String.format("<function name> returning 0x%X", new Object[1] { new Integer(returnValue) })); // } loadModuleLoggger(func); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logCheckFunction, "()Z"); Label notDebug = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, notDebug); boolean isReturningVoid = func.getHLEModuleMethod().getReturnType() == void.class; mv.visitInsn(Opcodes.DUP); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); loadImm(1); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); loadImm(0); mv.visitInsn(Opcodes.SWAP); mv.visitInsn(Opcodes.AASTORE); String prefix = func.isUnimplemented() && !codeBlock.isHLEFunction() ? "Unimplemented " : ""; mv.visitLdcInsn(String.format("%s%s returning %s%s", prefix, func.getFunctionName(), isErrorCode ? "errorCode " : "", isReturningVoid ? "void" : "0x%X")); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "format", "(" + Type.getDescriptor(String.class) + "[" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(String.class)); loadModuleLoggger(func); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), loggingLevel, "(" + Type.getDescriptor(Object.class) + ")V"); if (!isErrorCode) { ParameterInfo[] parameters = new ClassAnalyzer().getParameters(func.getFunctionName(), func.getHLEModuleMethod().getDeclaringClass()); if (parameters != null) { CompilerParameterReader parameterReader; if (parametersSavedToLocals) { parameterReader = new CompilerLocalVarParameterReader(this, LOCAL_FIRST_SAVED_PARAMETER); } else { parameterReader = new CompilerParameterReader(this); } Annotation[][] paramsAnotations = func.getHLEModuleMethod().getParameterAnnotations(); for (int paramIndex = 0; paramIndex < parameters.length; paramIndex++) { ParameterInfo parameter = parameters[paramIndex]; Class<?> parameterType = parameter.type; LengthInfo lengthInfo = BufferInfo.defaultLengthInfo; int length = BufferInfo.defaultLength; Usage usage = BufferInfo.defaultUsage; boolean debugMemory = false; for (Annotation parameterAnnotation : paramsAnotations[paramIndex]) { if (parameterAnnotation instanceof BufferInfo) { BufferInfo bufferInfo = (BufferInfo) parameterAnnotation; lengthInfo = bufferInfo.lengthInfo(); length = bufferInfo.length(); usage = bufferInfo.usage(); } else if (parameterAnnotation instanceof DebugMemory) { debugMemory = true; } } boolean parameterRead = false; if ((usage == Usage.out || usage == Usage.inout) && (lengthInfo != LengthInfo.unknown || parameterType == TPointer16.class || parameterType == TPointer32.class || parameterType == TPointer64.class)) { loadModuleLoggger(func); loadImm(1); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); mv.visitInsn(Opcodes.DUP); loadImm(0); Label done = new Label(); Label addressNull = new Label(); parameterReader.loadNextInt(); parameterRead = true; mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFEQ, addressNull); String format = String.format("%s[%s]:%%s", parameter.name, usage); boolean useMemoryDump = true; switch (lengthInfo) { case fixedLength: loadImm(length); break; case nextNextParameter: parameterReader.skipNextInt(); paramIndex++; parameterReader.loadNextInt(); paramIndex++; break; case nextParameter: parameterReader.loadNextInt(); paramIndex++; break; case previousParameter: // Go back to the address parameter parameterReader.rewindPreviousInt(); // Go back to the previous parameter parameterReader.rewindPreviousInt(); // Load the length from the previous parameter parameterReader.loadNextInt(); // Skip again the address parameter // to come back to the above situation parameterReader.skipNextInt(); break; case variableLength: mv.visitInsn(Opcodes.DUP); loadMemory(); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I"); break; case returnValue: loadRegister(_v0); break; case unknown: useMemoryDump = false; format = String.format("%s[%s]: 0x%%X", parameter.name, usage); loadMemory(); mv.visitInsn(Opcodes.SWAP); if (parameterType == TPointer64.class) { if (debugMemory) { mv.visitInsn(Opcodes.DUP); loadImm(8); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemory", "(II)V"); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read64", "(I)J"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Long.class)); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.POP2); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Long.class), "<init>", "(J)V"); } else if (parameterType == TPointer16.class) { if (debugMemory) { mv.visitInsn(Opcodes.DUP); loadImm(2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemory", "(II)V"); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read16", "(I)I"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); } else { if (debugMemory) { mv.visitInsn(Opcodes.DUP); loadImm(4); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemory", "(II)V"); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); } break; default: log.error(String.format("Unimplemented lengthInfo=%s", lengthInfo)); break; } if (useMemoryDump) { if (debugMemory) { mv.visitInsn(Opcodes.DUP2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemory", "(II)V"); } mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Utilities.class), "getMemoryDump", "(II)" + Type.getDescriptor(String.class)); } mv.visitInsn(Opcodes.AASTORE); mv.visitLdcInsn(format); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "format", "(" + Type.getDescriptor(String.class) + "[" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(String.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), loggingLevel, "(" + Type.getDescriptor(Object.class) + ")V"); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(addressNull); mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.POP2); mv.visitInsn(Opcodes.POP2); mv.visitLabel(done); } if (!parameterRead) { if (parameterType == long.class) { parameterReader.skipNextLong(); } else if (parameterType == float.class) { parameterReader.skipNextFloat(); } else { parameterReader.skipNextInt(); } } } } } mv.visitLabel(notDebug); }
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 ww . j av a2 s .c o m * 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
private void endInternalMethod() { if (RuntimeContext.debugCodeBlockCalls) { mv.visitInsn(Opcodes.DUP);//from w w w.java 2 s . c o m loadImm(getCodeBlock().getStartAddress()); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, RuntimeContext.debugCodeBlockEnd, "(II)V"); } }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
@Override public void memWrite32(int registerIndex, int offset) { if (!memWritePrepared) { if (useMMIO()) { loadMMIO();// w ww . jav a2 s . co m } else if (!RuntimeContext.hasMemoryInt()) { loadMemory(); } else { loadMemoryInt(); } mv.visitInsn(Opcodes.SWAP); loadRegister(registerIndex); if (offset != 0) { loadImm(offset); mv.visitInsn(Opcodes.IADD); } if (checkMemoryAccess()) { loadImm(codeInstruction.getAddress()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryWrite32", "(II)I"); } mv.visitInsn(Opcodes.SWAP); } if (RuntimeContext.debugMemoryWrite) { if (!RuntimeContext.debugMemoryReadWriteNoSP || registerIndex != _sp) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.SWAP); loadImm(2); mv.visitInsn(Opcodes.ISHL); mv.visitInsn(Opcodes.SWAP); loadImm(codeInstruction.getAddress()); loadImm(0); loadImm(32); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemoryReadWrite", "(IIIZI)V"); } } if (useMMIO() || !RuntimeContext.hasMemoryInt()) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "write32", "(II)V"); } else { mv.visitInsn(Opcodes.IASTORE); } memWritePrepared = false; }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
@Override public void memWrite16(int registerIndex, int offset) { if (!memWritePrepared) { if (useMMIO()) { loadMMIO();/*from w w w. j a v a2 s .c o m*/ } else if (!RuntimeContext.hasMemoryInt()) { loadMemory(); } else { loadMemoryInt(); } mv.visitInsn(Opcodes.SWAP); loadRegister(registerIndex); if (offset != 0) { loadImm(offset); mv.visitInsn(Opcodes.IADD); } if (RuntimeContext.hasMemoryInt()) { if (checkMemoryAccess()) { loadImm(codeInstruction.getAddress()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryWrite16", "(II)I"); } } mv.visitInsn(Opcodes.SWAP); } if (useMMIO() || !RuntimeContext.hasMemoryInt()) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "write16", "(IS)V"); } else { // tmp2 = value & 0xFFFF; // tmp1 = (address & 2) << 3; // memoryInt[address >> 2] = (memoryInt[address >> 2] & ((0xFFFF << tmp1) ^ 0xFFFFFFFF)) | (tmp2 << tmp1); loadImm(0xFFFF); mv.visitInsn(Opcodes.IAND); storeTmp2(); mv.visitInsn(Opcodes.DUP); loadImm(2); mv.visitInsn(Opcodes.IAND); loadImm(3); mv.visitInsn(Opcodes.ISHL); storeTmp1(); if (checkMemoryAccess()) { loadImm(2); mv.visitInsn(Opcodes.ISHR); } else { loadImm(3); mv.visitInsn(Opcodes.ISHL); loadImm(5); mv.visitInsn(Opcodes.IUSHR); } mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.IALOAD); loadImm(0xFFFF); loadTmp1(); mv.visitInsn(Opcodes.ISHL); loadImm(-1); mv.visitInsn(Opcodes.IXOR); mv.visitInsn(Opcodes.IAND); loadTmp2(); loadTmp1(); mv.visitInsn(Opcodes.ISHL); mv.visitInsn(Opcodes.IOR); mv.visitInsn(Opcodes.IASTORE); } memWritePrepared = false; }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
@Override public void memWrite8(int registerIndex, int offset) { if (!memWritePrepared) { if (useMMIO()) { loadMMIO();//from w w w . j av a2 s. c o m } else if (!RuntimeContext.hasMemoryInt()) { loadMemory(); } else { loadMemoryInt(); } mv.visitInsn(Opcodes.SWAP); loadRegister(registerIndex); if (offset != 0) { loadImm(offset); mv.visitInsn(Opcodes.IADD); } if (RuntimeContext.hasMemoryInt()) { if (checkMemoryAccess()) { loadImm(codeInstruction.getAddress()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryWrite8", "(II)I"); } } mv.visitInsn(Opcodes.SWAP); } if (useMMIO() || !RuntimeContext.hasMemoryInt()) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "write8", "(IB)V"); } else { // tmp2 = value & 0xFF; // tmp1 = (address & 3) << 3; // memoryInt[address >> 2] = (memoryInt[address >> 2] & ((0xFF << tmp1) ^ 0xFFFFFFFF)) | (tmp2 << tmp1); loadImm(0xFF); mv.visitInsn(Opcodes.IAND); storeTmp2(); mv.visitInsn(Opcodes.DUP); loadImm(3); mv.visitInsn(Opcodes.IAND); loadImm(3); mv.visitInsn(Opcodes.ISHL); storeTmp1(); if (checkMemoryAccess()) { loadImm(2); mv.visitInsn(Opcodes.ISHR); } else { loadImm(3); mv.visitInsn(Opcodes.ISHL); loadImm(5); mv.visitInsn(Opcodes.IUSHR); } mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.IALOAD); loadImm(0xFF); loadTmp1(); mv.visitInsn(Opcodes.ISHL); loadImm(-1); mv.visitInsn(Opcodes.IXOR); mv.visitInsn(Opcodes.IAND); loadTmp2(); loadTmp1(); mv.visitInsn(Opcodes.ISHL); mv.visitInsn(Opcodes.IOR); mv.visitInsn(Opcodes.IASTORE); } memWritePrepared = false; }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
@Override public void storeVcrCc(int cc) { if (preparedRegisterForStore == cc) { mv.visitInsn(Opcodes.BASTORE);// w ww. j a v a 2s.co m preparedRegisterForStore = -1; } else { loadVcr(); mv.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(Vcr.class), "cc", "[Z"); mv.visitInsn(Opcodes.SWAP); loadImm(cc); mv.visitInsn(Opcodes.SWAP); mv.visitInsn(Opcodes.BASTORE); } }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
@Override public void compileVFPUInstr(Object cstBefore, int opcode, String mathFunction) { int vsize = getVsize(); boolean useVt = getCodeInstruction().hasFlags(Instruction.FLAG_USES_VFPU_PFXT); if (mathFunction == null && opcode == Opcodes.NOP && !useVt && cstBefore == null && canUseVFPUInt(vsize)) { // VMOV should use int instead of float startPfxCompiled(false);//from w ww. j a va 2 s .co m for (int n = 0; n < vsize; n++) { prepareVdForStoreInt(n); loadVsInt(n); storeVdInt(n); } endPfxCompiled(vsize, false); } else { startPfxCompiled(true); for (int n = 0; n < vsize; n++) { prepareVdForStore(n); if (cstBefore != null) { mv.visitLdcInsn(cstBefore); } loadVs(n); if (useVt) { loadVt(n); } if (mathFunction != null) { if ("abs".equals(mathFunction)) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction, "(F)F"); } else if ("max".equals(mathFunction) || "min".equals(mathFunction)) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction, "(FF)F"); } else { mv.visitInsn(Opcodes.F2D); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction, "(D)D"); mv.visitInsn(Opcodes.D2F); } } Label doneStore = null; if (opcode != Opcodes.NOP) { Label doneOpcode = null; if (opcode == Opcodes.FDIV && cstBefore == null) { // if (value1 == 0f && value2 == 0f) { // result = PSP-NaN | (sign(value1) ^ sign(value2)); // } else { // result = value1 / value2; // } doneOpcode = new Label(); doneStore = new Label(); Label notZeroByZero = new Label(); Label notZeroByZeroPop = new Label(); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.FCONST_0); mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFNE, notZeroByZeroPop); mv.visitInsn(Opcodes.FCONST_0); mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFNE, notZeroByZero); convertVFloatToInt(); loadImm(0x80000000); mv.visitInsn(Opcodes.IAND); mv.visitInsn(Opcodes.SWAP); convertVFloatToInt(); loadImm(0x80000000); mv.visitInsn(Opcodes.IAND); mv.visitInsn(Opcodes.IXOR); storeTmp1(); // Store the NaN value as an "int" to not loose any bit. // Storing as float results in 0x7FC00001 instead of 0x7F800001. mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.POP2); loadPspNaNInt(); loadTmp1(); mv.visitInsn(Opcodes.IOR); int preparedRegister = preparedRegisterForStore; storeVdInt(n); preparedRegisterForStore = preparedRegister; mv.visitJumpInsn(Opcodes.GOTO, doneStore); mv.visitLabel(notZeroByZeroPop); mv.visitInsn(Opcodes.POP); mv.visitLabel(notZeroByZero); } mv.visitInsn(opcode); if (doneOpcode != null) { mv.visitLabel(doneOpcode); } } storeVd(n); if (doneStore != null) { mv.visitLabel(doneStore); } } endPfxCompiled(vsize, true); } }
From source file:ldapbeans.bean.LdapBeanClassManager.java
License:LGPL
/** * Generate code for printing the object on the top of the stack * /*from w w w. ja va 2s .c om*/ * @param p_MethodVisitor * The {@link MethodVisitor} of the generated method * @deprecated Use this method only for debug. */ @SuppressWarnings("unused") @Deprecated private void generatePrintTopStack(MethodVisitor p_MethodVisitor) { MethodVisitor mv = p_MethodVisitor; mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V"); }