Beispiel #1
0
primitiveResetCPU(void)
{
	void *cpu;
	sqInt cpuAlien;
	sqInt maybeErr;

	cpuAlien = stackValue(0);
	if (failed()) {
		return null;
	}
	if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0
		? (cpuAlien + BaseHeaderSize) + BytesPerOop
		: longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) {
		primitiveFailFor(PrimErrBadReceiver);
		return null;
	}
	maybeErr = resetCPU(cpu);
	if (maybeErr != 0) {
		primitiveFailFor(PrimErrInappropriate);
		return null;
	}
	if (failed()) {
		return null;
	}
	popthenPush(1, cpuAlien);
	return null;
}
Beispiel #2
0
primitiveErrorAndLog(void)
{
	char *log;
	sqInt logLen;
	sqInt logObj;
	char *logObjData;
	sqInt resultObj;

	logLen = 0;
	log = getlog((&logLen));
	resultObj = instantiateClassindexableSize(classArray(), 2);
	if (resultObj == 0) {
		primitiveFailFor(PrimErrNoMemory);
		return null;
	}
	storePointerofObjectwithValue(0, resultObj, integerObjectOf(errorAcorn()));
	if (logLen > 0) {
		pushRemappableOop(resultObj);
		logObj = instantiateClassindexableSize(classString(), logLen);
		if (failed()) {
			popRemappableOop();
			primitiveFailFor(PrimErrNoMemory);
			return null;
		}
		resultObj = popRemappableOop();
		logObjData = arrayValueOf(logObj);
		memcpy(logObjData, log, logLen);
		storePointerofObjectwithValue(1, resultObj, logObj);
	}
	popthenPush(1, resultObj);
	if (failed()) {
		return null;
	}
	return null;
}
Beispiel #3
0
primitiveNormalize(void)
{
    sqInt i;
    double len;
    sqInt length;
    sqInt rcvr;
    float *rcvrPtr;

	rcvr = stackValue(0);
	if (!(isWords(rcvr))) {
		primitiveFailFor(PrimErrBadReceiver);
	}
	length = stSizeOf(rcvr);
	rcvrPtr = ((float *) (firstIndexableField(rcvr)));
	len = 0.0;
	for (i = 0; i < length; i += 1) {
		len += (((double) (rcvrPtr[i]))) * (((double) (rcvrPtr[i])));
	}
	if (!(len > 0.0)) {
		primitiveFailFor(PrimErrBadReceiver);
	}
	len = sqrt(len);
	for (i = 0; i < length; i += 1) {
		rcvrPtr[i] = ((((double) (rcvrPtr[i]))) / len);
	}
	return 0;
}
Beispiel #4
0
primitiveDisassembleAtInMemory(void)
{
	usqIntptr_t address;
	void *cpu;
	sqInt cpuAlien;
	sqInt instrLenOrErr;
	sqInt log;
	sqInt logLen;
	sqInt logObj;
	sqInt logObjData;
	char *memory;
	sqInt resultObj;

	logLen = 0;
	address = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(1))
		: positive64BitValueOf(stackValue(1)));
	success(isWordsOrBytes(stackValue(0)));
	memory = ((char *) (firstIndexableField(stackValue(0))));
	cpuAlien = stackValue(2);
	if (failed()) {
		return null;
	}
	if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0
		? (cpuAlien + BaseHeaderSize) + BytesPerOop
		: longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) {
		primitiveFailFor(PrimErrBadReceiver);
		return null;
	}
	instrLenOrErr = disassembleForAtInSize(cpu, address, memory, byteSizeOf(((sqInt)(sqIntptr_t)(memory) - BaseHeaderSize)));
	if (instrLenOrErr < 0) {
		primitiveFailFor(PrimErrInappropriate);
		return null;
	}
	log = getlog((&logLen));
	resultObj = instantiateClassindexableSize(classArray(), 2);
	if (resultObj == 0) {
		primitiveFailFor(PrimErrNoMemory);
		return null;
	}
	pushRemappableOop(resultObj);
	logObj = instantiateClassindexableSize(classString(), logLen);
	if (failed()) {
		popRemappableOop();
		primitiveFailFor(PrimErrNoMemory);
		return null;
	}
	logObjData = arrayValueOf(logObj);
	memcpy(logObjData, log, logLen);
	resultObj = popRemappableOop();
	storePointerofObjectwithValue(0, resultObj, integerObjectOf(instrLenOrErr));
	storePointerofObjectwithValue(1, resultObj, logObj);
	if (failed()) {
		return null;
	}
	popthenPush(3, resultObj);
	return null;
}
Beispiel #5
0
primitiveSingleStepInMemoryMinAddressMaxAddressReadWrite(void)
{
	void *cpu;
	sqInt cpuAlien;
	usqIntptr_t maxAddress;
	sqInt maybeErr;
	char *memory;
	sqInt memorySize;
	usqIntptr_t minAddress;
	usqIntptr_t minWriteMaxExecAddress;

	success(isWordsOrBytes(stackValue(3)));
	memory = ((char *) (firstIndexableField(stackValue(3))));
	minAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(2))
		: positive64BitValueOf(stackValue(2)));
	maxAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(1))
		: positive64BitValueOf(stackValue(1)));
	minWriteMaxExecAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(0))
		: positive64BitValueOf(stackValue(0)));
	cpuAlien = stackValue(4);
	if (failed()) {
		return null;
	}
	if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0
		? (cpuAlien + BaseHeaderSize) + BytesPerOop
		: longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) {
		primitiveFailFor(PrimErrBadReceiver);
		return null;
	}
	prevInterruptCheckChain = setInterruptCheckChain(forceStopOnInterrupt);
	if (prevInterruptCheckChain == (forceStopOnInterrupt)) {
		prevInterruptCheckChain == 0;
	}
	memorySize = byteSizeOf(((sqInt)(sqIntptr_t)(memory) - BaseHeaderSize));
	maybeErr = singleStepCPUInSizeMinAddressReadWrite(cpu, memory, ((memorySize < maxAddress) ? memorySize : maxAddress), minAddress, minWriteMaxExecAddress);
	setInterruptCheckChain(prevInterruptCheckChain);
	if (maybeErr != 0) {
		primitiveFailFor(PrimErrInappropriate);
		return null;
	}
	if (failed()) {
		return null;
	}
	popthenPush(5, cpuAlien);
	return null;
}
primitiveFileRead(void)
{
	// FilePlugin>>#primitiveFileRead
    sqInt array;
    sqInt bytesRead;
    size_t count;
    size_t elementSize;
    SQFile *file;
    sqInt objectPointer;
    sqInt retryCount;
    size_t startIndex;

	retryCount = 0;
	count = positive32BitValueOf(stackValue(0));
	startIndex = positive32BitValueOf(stackValue(1));
	while (1) {
array = stackValue(2);
		/* begin fileValueOf: */
		objectPointer = stackValue(3);
		if (!((isBytes(objectPointer))
			 && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) {
			primitiveFail();
			file = null;
			goto l1;
		}
		file = firstIndexableField(objectPointer);
	l1:	/* end fileValueOf: */;
		if ((failed())
		 || (!(isWordsOrBytes(array)))) {
			return primitiveFailFor(PrimErrBadArgument);
		}
		elementSize = (isWords(array)
			? 4
			: 1);
		if (!((startIndex >= 1)
			 && (((startIndex + count) - 1) <= (slotSizeOf(array))))) {
			return primitiveFailFor(PrimErrBadIndex);
		}
		bytesRead = sqFileReadIntoAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize);
		if (!(((primitiveFailureCode()) == PrimErrObjectMayMove)
		 && (((retryCount += 1)) <= 2))) break;
		tenuringIncrementalGC();
		primitiveFailFor(PrimNoErr);
	}
	if (!(failed())) {
		popthenPush(5, integerObjectOf(bytesRead / elementSize));
	}
}
Beispiel #7
0
primitiveFlushICacheFromTo(void)
{
	void *cpu;
	sqInt cpuAlien;
	usqIntptr_t endAddress;
	usqIntptr_t startAddress;

	startAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(1))
		: positive64BitValueOf(stackValue(1)));
	endAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(0))
		: positive64BitValueOf(stackValue(0)));
	cpuAlien = stackValue(2);
	if (failed()) {
		return null;
	}
	if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0
		? (cpuAlien + BaseHeaderSize) + BytesPerOop
		: longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) {
		primitiveFailFor(PrimErrBadReceiver);
		return null;
	}
	flushICacheFromTo(cpu, startAddress, endAddress);
	if (failed()) {
		return null;
	}
	pop(2);
	return null;
}
primitiveDLSym(void)
{
    void *addr;
    sqInt i;
    char *name;
    sqInt nameObj;
    char *namePtr;
    sqInt sz;

	nameObj = stackValue(0);
	if (!(isBytes(nameObj))) {
		return primitiveFailFor(PrimErrBadArgument);
	}
	sz = byteSizeOf(nameObj);
	name = malloc(sz + 1);
	namePtr = firstIndexableField(nameObj);
	for (i = 0; i < sz; i += 1) {
		name[i] = (namePtr[i]);
	}
	name[sz] = 0;
	addr = dlsym(RTLD_SELF,name);
	free(name);
	return methodReturnValue((addr == 0
		? nilObject()
		: (/* begin positiveMachineIntegerFor: */
			(BytesPerWord == 8
					? positive64BitIntegerFor(((usqIntptr_t)addr))
					: positive32BitIntegerFor(((usqIntptr_t)addr))))));
}
primitiveFileStdioHandles(void)
{
	// FilePlugin>>#primitiveFileStdioHandles
    SQFile fileRecords[3];
    sqInt index;
    sqInt result;
    sqInt validMask;

	if (sHFAfn != 0) {
		if (!( ((sqInt (*)(void))sHFAfn)())) {
			return primitiveFailFor(PrimErrUnsupported);
		}
	}
	
validMask = sqFileStdioHandlesInto(fileRecords);
	if (validMask == 0) {
return primitiveFailFor(PrimErrUnsupported);
	}
	result = instantiateClassindexableSize(classArray(), 3);
	if (result == null) {
return primitiveFailFor(PrimErrNoMemory);
	}
	pushRemappableOop(result);
	for (index = 0; index <= 2; index += 1) {
if ((validMask & (1 << index)) != 0) {
			result = instantiateClassindexableSize(classByteArray(), sizeof(SQFile));
			if (result == null) {
popRemappableOop();
				return primitiveFailFor(PrimErrNoMemory);
			}
			storePointerofObjectwithValue(index, topRemappableOop(), result);
			memcpy(firstIndexableField(result), (&(fileRecords[index])), sizeof(SQFile));
		}
	}
	
#  if COGMTVM
	fullGC();

#  endif /* COGMTVM */

	result = popRemappableOop();
	popthenPush(1, result);
}
primitiveFileWrite(void)
{
	// FilePlugin>>#primitiveFileWrite
    sqInt array;
    sqInt bytesWritten;
    size_t count;
    size_t elementSize;
    SQFile *file;
    sqInt objectPointer;
    size_t startIndex;

	count = positive32BitValueOf(stackValue(0));
	startIndex = positive32BitValueOf(stackValue(1));
	array = stackValue(2);
	/* begin fileValueOf: */
	objectPointer = stackValue(3);
	if (!((isBytes(objectPointer))
		 && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) {
		primitiveFail();
		file = null;
		goto l1;
	}
	file = firstIndexableField(objectPointer);
l1:	/* end fileValueOf: */;
	if ((failed())
	 || (!(isWordsOrBytes(array)))) {
		return primitiveFailFor(PrimErrBadArgument);
	}
	elementSize = (isWords(array)
		? 4
		: 1);
	if (!((startIndex >= 1)
		 && (((startIndex + count) - 1) <= (slotSizeOf(array))))) {
		return primitiveFailFor(PrimErrBadIndex);
	}
	bytesWritten = sqFileWriteFromAt(file, count * elementSize, ((char *) (firstIndexableField(array))), (startIndex - 1) * elementSize);
	if (!(failed())) {
		popthenPush(5, integerObjectOf(bytesWritten / elementSize));
	}
}
Beispiel #11
0
primitiveSingleStepInMemoryMinimumAddressReadWrite(void)
{
	void *cpu;
	sqInt cpuAlien;
	sqInt maybeErr;
	char *memory;
	usqIntptr_t minAddress;
	usqIntptr_t minWriteMaxExecAddress;

	success(isWordsOrBytes(stackValue(2)));
	memory = ((char *) (firstIndexableField(stackValue(2))));
	minAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(1))
		: positive64BitValueOf(stackValue(1)));
	minWriteMaxExecAddress = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(0))
		: positive64BitValueOf(stackValue(0)));
	cpuAlien = stackValue(3);
	if (failed()) {
		return null;
	}
	if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0
		? (cpuAlien + BaseHeaderSize) + BytesPerOop
		: longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) {
		primitiveFailFor(PrimErrBadReceiver);
		return null;
	}
	maybeErr = singleStepCPUInSizeMinAddressReadWrite(cpu, memory, byteSizeOf(((sqInt)(sqIntptr_t)(memory) - BaseHeaderSize)), minAddress, minWriteMaxExecAddress);
	if (maybeErr != 0) {
		primitiveFailFor(PrimErrInappropriate);
		return null;
	}
	if (failed()) {
		return null;
	}
	popthenPush(4, cpuAlien);
	return null;
}