Example #1
0
def pattern_generate(syn, insword):
    tmp = common.syntax_from_insword(insword)
    if syn != tmp:
        raise Exception('lookup says %08X: -%s- but we see -%s-' %
                        (insword, syn, tmp))

    always1 = insword
    always0 = ctypes.c_uint32(~insword).value

    # fuzz the insword, see what bits are always 1, always 0
    for fuzz in common.fuzz5():
        insword2 = insword ^ fuzz

        syn2 = common.syntax_from_insword(insword2)
        if syn == syn2:
            #print '%08X: %s' % (insword2, bin(insword2)[2:])
            always1 &= insword2
            always0 &= ctypes.c_uint32(~insword2).value
        else:
            pass

    constMaskStr = ''
    for i in range(31, -1, -1):
        assert not ((always1 & (1 << i)) and (always0 & (1 << i)))
        if always1 & (1 << i):
            constMaskStr += '1'
        elif always0 & (1 << i):
            constMaskStr += '0'
        else:
            constMaskStr += 'x'

    #print 'always1: %08X' % always1
    #print 'always0: %08X' % always0
    constbits = always1 | always0
    changebits = ctypes.c_uint32(~constbits).value
    qsynq = '"%s"' % syn
    qsynq = (48 - len(qsynq)) * ' ' + qsynq
    return "{%s,{0x%08X,0x%08X}}, // %s" % (qsynq, insword, changebits,
                                            constMaskStr)
Example #2
0
        syn2seed[m.group(1)] = int(m.group(2), 16)

###############
# go!
###############

fuzz = common.fuzz4()

targets = sorted(syn2seed)
if sys.argv[1:]:
    targets = [sys.argv[1]]

for syn in targets:
    seed = syn2seed[syn]

    syn2 = common.syntax_from_insword(seed)
    if syn != syn2:
        print 'ERROR: lookup says %08X: -%s- but we see -%s-' % \
         (seed, syn, syn2)
        sys.exit(-1)

    always1 = seed
    always0 = ctypes.c_uint32(~seed).value

    # for every <DEPTH> bit positions
    for mask in fuzz:
        seed2 = seed ^ mask
        syn2 = common.syntax_from_insword(seed2)
        if syn == syn2:
            always1 &= seed2
            always0 &= ctypes.c_uint32(~seed2).value
    if m:
        syn2example[m.group(1)] = int(m.group(2), 16)

###############
# go!
###############
DEPTH = 4

targets = sorted(syn2example)
if sys.argv[1:]:
    targets = [sys.argv[1]]

for syn in targets:
    example = syn2example[syn]

    syn2 = common.syntax_from_insword(example)
    if syn != syn2:
        print 'ERROR: lookup says %08X: -%s- but we see -%s-' % \
         (example, syn, syn2)
        sys.exit(-1)

    always1 = example
    always0 = ctypes.c_uint32(~example).value

    # for every <DEPTH> bit positions
    for positions in itertools.combinations(range(32), DEPTH):
        for bitvalues in itertools.product([0, 1], repeat=DEPTH):
            example_ = example

            for i in range(DEPTH):
                mask = 1 << positions[i]
###############
# go!
###############

targets = sorted(opc2example)
if sys.argv[1:]:
	targets = [sys.argv[1]]

syn2example = {}

DEPTH = 4 
for opc in targets:
	print "// on %s" % opc
	example = opc2example[opc]

	syn = common.syntax_from_insword(example)
	if not syn in syn2example:
		print "'%s': 0x%08X" % (syn, example)
		syn2example[syn] = example

	# for every <DEPTH> bit positions
	for positions in itertools.combinations(range(32), DEPTH):
		for bitvalues in itertools.product([0,1], repeat=DEPTH):
			example2 = example

			for i in range(DEPTH):
				mask = 1 << positions[i]

				if bitvalues[i]:
					#print 'setting bit %d' % positions[i]
					example2 |= mask