Exemple #1
0
static orl_sec_offset   calcLIDataLength( int is32, omf_bytes *input, omf_rec_size *len )
{
    omf_rec_size    size;
    omf_bytes       buffer;
    int             wordsize;
    long            tmp;
    uint_32         repeat;
    long            block;
    long            result = 0;

    assert( input );
    assert( *input );
    assert( len );

    buffer = *input;
    size = *len;
    wordsize = OmfGetWordSize( is32 );
    tmp = wordsize + 2;

    if( size < tmp ) return( 0 );
    repeat = getUWord( buffer, wordsize );
    buffer += wordsize;
    block = getUWord( buffer, 2 );
    buffer += 2;
    size -= tmp;

    if( block ) {
        while( block ) {
            tmp = calcLIDataLength( is32, &buffer, &size );
            if( !tmp ) return( 0 );
            result += tmp;
            block--;
        }
    } else {
        result = buffer[0];
        size -= ( result + 1 );
        if( size < 0 ) return( 0 );
        buffer += result + 1;
    }

    result *= repeat;
    *input = buffer;
    *len = size;

    return( result );
}
Exemple #2
0
void db_send_data_result(int db_opcode, ByteAddress actual_ip, UWordAddress actual_fp) {
    UWordAddress return_fp;
    UWordAddress p;
    UWordAddress sp0;
    int nlocals;
    ByteAddress mid;
    if (db_opcode == OPC_EXTEND) {
        mid = actual_ip - 1;
    } else if (db_opcode == OPC_EXTEND0) {
        mid = actual_ip - 1;
    } else {
        mid = (ByteAddress)getObject(actual_fp, FP_method);
    }
    nlocals = getLocalCount(mid);

    db_printf0("*DEBUG*:D:R:S:");

    p = actual_fp;
    return_fp = (UWordAddress)getUWord(p, FP_returnFP);
    p = p + FP_parm0; // move to first parameter
    db_printf0("P:");
    while (p < (actual_fp + FP_parm0 + db_get_parameter_count(mid) - 1)) {
		db_printf1("%i,", getUWord(p, 0));
		p++;
    }
	db_printf1("%i", getUWord(p, 0));
    db_printf0(":L:");
    p = actual_fp;
    --p; // skip the method id
    sp0 = actual_fp - (nlocals - 1);
    while (p >= sp0) {
        UWord value = getUWord(p, 0);
        if (value == DEADBEEF) {
            db_printf0("X");
        } else {
            db_printf1("%i", value);
            }
        if (p != sp0) {
            db_printf0(",");
        }
        --p;
    }
    db_printf0("\n");
}
Exemple #3
0
UWord loadBootstrapSuiteFromFlash(
		char *bootstrapSuiteFile,
		Address *romStart,
		Address *suite,
		int *hash) {
	// ROM starts at the flash address set on command line
	Address javabytecodesbase = (Address) atoi(bootstrapSuiteFile);
	*suite = (void *)(getUWord(javabytecodesbase, 0) + javabytecodesbase);
	*hash = (int)getUWord(javabytecodesbase, 1);
	UWord size=getUWord(javabytecodesbase, 2);
	*romStart=(void *)(javabytecodesbase + NUMBER_OF_BYTES_IN_BYTECODE_HEADER);

	diagnosticWithValue("javabytecodesbase: ", (int) javabytecodesbase);
	diagnosticWithValue("rootOffset: ", (int) *suite);
	diagnosticWithValue("hash: ", getUWord(javabytecodesbase, 0));
	diagnosticWithValue("suite size: ", size);
	diagnosticWithValue("romStart: ", (int) *romStart);
	return size;
}
Exemple #4
0
static orl_return   writeAndFixupLIData( omf_file_handle ofh, omf_sec_handle sh, omf_bytes buffer )
{
    int                 wordsize;
    long                tmp;
    uint_32             repeat;
    long                block;
    int                 size;
    int                 used;
    int                 hi;
    int                 lo;
    omf_bytes           ptr;
    orl_return          err = ORL_OKAY;
    omf_tmp_fixup       ftr;
    omf_tmp_fixup       ntr;
    int                 x;

    assert( ofh );
    assert( ofh->lidata );
    assert( sh );
    assert( sh->contents );
    assert( buffer );

    if( ofh->status & OMF_STATUS_EASY_OMF ) {
        wordsize = OmfGetWordSize( 0 );
    } else {
        wordsize = OmfGetWordSize( ofh->lidata->is32 );
    }
    tmp = wordsize + 2;

    if( ofh->lidata->size < tmp )
        return( ORL_ERROR );
    used = ofh->lidata->used;
    size = ofh->lidata->size;
    ptr = buffer + used;

    repeat = getUWord( ptr, wordsize );
    ptr += wordsize;
    block = getUWord( ptr, 2 );
    ptr += 2;

    lo = used;
    hi = lo + tmp;
    size -= tmp;
    used += tmp;

    if( findMatchingFixup( ofh->lidata->first_fixup, lo, hi ) ) {
        return( ORL_ERROR );
    } else if( block ) {
        while( repeat ) {
            repeat--;
            ofh->lidata->used = used;
            ofh->lidata->size = size;
            for( x = 0; x < block; x++ ) {
                err = writeAndFixupLIData( ofh, sh, buffer );
                if( err != ORL_OKAY ) {
                    break;
                }
            }
        }
    } else {
        tmp = *ptr;
        ptr++;
        used++;
        size--;

        lo = used;
        hi = used + tmp - 1;

        while( repeat ) {
            buffer = sh->contents + sh->assoc.seg.cur_offset;
            memcpy( buffer, ptr, tmp );

            /* create appropriate fixup records
             */
            ftr = findMatchingFixup( ofh->lidata->first_fixup, lo, hi );
            while( ftr ) {
                ntr = _ClientAlloc( ofh, sizeof( omf_tmp_fixup_struct ) );
                if( !ntr )
                    return( ORL_OUT_OF_MEMORY );
                memcpy( ntr, ftr, sizeof( omf_tmp_fixup_struct ) );

                /* determine new offset as if this was an LEData we were
                 * doing a fixup for
                 */
                ntr->offset = ofh->lidata->offset - used + ftr->offset;

                /* insert into new fixup queue
                 */
                if( ofh->lidata->new_fixup ) {
                    ofh->lidata->last_fixup->next = ntr;
                } else {
                    ofh->lidata->new_fixup = ntr;
                }
                ofh->lidata->last_fixup = ntr;

                ftr = findMatchingFixup( ftr->next, lo, hi );
            }

            ofh->lidata->offset += tmp;
            sh->assoc.seg.cur_offset += tmp;
            repeat--;
        }

        ofh->lidata->size = size - tmp;
        ofh->lidata->used = used + tmp;
        err = ORL_OKAY;
    }

    return( err );
}
Exemple #5
0
/**
 * Loads the bootstrap suite from a file into a given buffer.
 *
 * @param file    the name of the file to load from
 * @param buffer  the buffer into which the object memory is to be loaded
 * @param size    the size of the buffer. This must at least equal to the size of the file
 * @param suite   OUT: the pointer to the suite
 * @param hash    OUT: the hash of the object memory in canonical form
 * @return the size of the object memory
 */
UWord loadBootstrapSuite(const char *file, Address buffer, UWord size,
		Address *suite, int *hash) {
	DataInputStream dis;
	UWord suiteOffset;
	ByteAddress oopMap;
	UWord oopMapLength;
	unsigned int i;
	int attributes;
	boolean hasTypemap;
	int pad, fileSize;

	fileSize = getFileSize(file);
	if (fileSize == -1) {
		fprintf(stderr, "Bootstrap suite file '%s' not found\n", file);
		fatalVMError("");
	} else if (size < fileSize) {
		fatalVMError("buffer size is too small for bootstrap suite");
	}
	/*
	 * Try to open the suite file.
	 */
	DataInputStream_open(&dis, file);

	/*
	 * Read 'magic'
	 */
	if (DataInputStream_readInt(&dis, "magic") != 0xdeadbeef) {
		fatalVMError("bad magic in bootstrap suite");
	}

	/*
	 * Read (and ignore for now) version identifiers
	 */
	DataInputStream_readUnsignedShort(&dis, "minor_version");
	DataInputStream_readUnsignedShort(&dis, "major_version");

	/*
	 * Read 'attributes'
	 */
	attributes = DataInputStream_readInt(&dis, "attributes");
	hasTypemap = ((attributes
			& com_sun_squawk_ObjectMemoryFile_ATTRIBUTE_TYPEMAP) != 0);
	if (((attributes & com_sun_squawk_ObjectMemoryFile_ATTRIBUTE_32BIT) != 0)
			== SQUAWK_64) {
		fatalVMError("word size in bootstrap suite is incorrect");
	}
	if (((attributes & com_sun_squawk_ObjectMemoryFile_ATTRIBUTE_BIGENDIAN) != 0)
			!= PLATFORM_BIG_ENDIAN) {
		fatalVMError("endianess in bootstrap suite is incorrect");
	}
	/*
	 * Read and ignore 'parent_hash'
	 */
	DataInputStream_readInt(&dis, "parent_hash");
	/*
	 * Read the length of 'parent_url' and verify that it is 0
	 */
	if (DataInputStream_readUnsignedShort(&dis, "parent_url") != 0) {
		fatalVMError("bootstrap suite should have no parent");
	}
	/*
	 * Read 'root'
	 */
	suiteOffset = DataInputStream_readInt(&dis, "root");
	/*
	 * Read 'size'
	 */
	size = DataInputStream_readInt(&dis, "size");
	/*
	 * Read 'oopmap'
	 */
	oopMapLength = ((size / HDR_BYTES_PER_WORD) + 7) / 8;
	oopMap = (ByteAddress) buffer + size;

	DataInputStream_readFully(&dis, oopMap, oopMapLength, "oopmap");
	/*
	 * Skip the padding for 'memory' to be word aligned
	 */
	pad = roundUpToWord(DataInputStream_readSoFar(&dis))
			- DataInputStream_readSoFar(&dis);
	DataInputStream_skip(&dis, pad, "padding");
	/*
	 * Read 'memory'
	 */
	DataInputStream_readFully(&dis, buffer, size, "memory");
	/*
	 * Calculate the hash of the object memory while it is still in canonical form.
	 */
	*hash = size;
	for (i = 0; i != size; ++i) {
		setType((ByteAddress) buffer + i, AddressType_BYTE, 1);
		*hash += getByte(buffer, i);
	}

	/*
	 * Relocate all the pointers in the object memory.
	 */
#if TRACE_SUITE
	{
		FILE *pointers = fopen("squawk.suite.pointers", "w");
		int cardinality = 0;
#endif /* TRACE_SUITE */

	for (i = 0; i != oopMapLength; ++i) {
		int oopMapByte = oopMap[i];
		int bit;

		for (bit = 0; bit != 8; ++bit) {
			if ((oopMapByte & (1 << bit)) != 0) {
				int offset = (i * 8) + bit;
				UWord pointer;
				setType((UWordAddress) buffer + offset, AddressType_UWORD,
						HDR_BYTES_PER_WORD);
				pointer = getUWord(buffer, offset);
				if (pointer != 0) {
					setUWord(buffer, offset, pointer + (UWord) buffer);
				}
#if TRACE_SUITE
				++cardinality;
				fprintf(pointers, format("%A: %A -> %A\n"), offset*HDR_BYTES_PER_WORD, pointer, pointer + (UWord)buffer);
#endif /* TRACE_SUITE */
			}
		}
	}

#if TRACE_SUITE
	fprintf(stderr, "oopmap:{cardinality = %d}\n", cardinality);
	fclose(pointers);
}
#endif /* TRACE_SUITE */

	/*
	 * Initialize the suite pointer.
	 */
	*suite = (ByteAddress) buffer + suiteOffset;

#if TYPEMAP
	if (hasTypemap) {
		ByteAddress p = buffer;
		int i;

		for (i = 0; i != size; ++i) {
			char type = DataInputStream_readUnsignedByte(&dis, "type");
			setType(p, type, 1);
			p++;
		}
	}
#endif /* TYPEMAP */
	/*
	 * Close the data input stream.
	 */
	DataInputStream_close(&dis);
	return size;
}