All pastes #808137 Raw Edit

Anonymous

public python v1 · immutable
·published 2007-12-07 09:35 UTC
rendered paste body
class DecoderException(Exception):	passclass Decoder(object):	D = (		14, 12, 13, 15,		28, 29, 11, 10,		34, 35, 50, 51,		48, 49, 42, 43,		40, 41, 46, 32,		33,  7, 24, 25,		38, 39, 54, 55,		52, 53, 44, 45,		47, 36, 37,  8,		 3, 26, 27	)	X = (		 28, 60,  0, 32,		 26,758, 86,470,		 54,278,246,1014,		310,438,854,284,		954,922,264, 32,		982,119, 87,631,		599,567,535,375,		343,790,311,279,		597,533, 20,534,		 55, 23, 64,512,		 19, 83,595,316,		146,210,242,476,		124,444,412, 24,		792,824,536,247,		215,759,727,983,		695,663,918,439,		407,725,661,662,		150,183,151,598,		370,306,566,  4,		264, 32,  0, 14,		 15, 72,136, 40,		 12, 64,583, 70,		 38,134,659	)		def decode(self, inst):		opcd = inst & 0x3F				if opcd == 18: # bx -- I form			return (				opcd, # OPCD				(inst & 0x3fffffc0) >>  6, # LI				(inst & 0x40000000) >> 30, # AA				 inst               >> 31  # LK			)		elif opcd == 16: # bcx -- B form			return (				opcd, # OPCD				(inst & 0x000007c0) >>  6, # BO				(inst & 0x0000f800) >> 11, # BI				(inst & 0x3fff0000) >> 16, # BD				(inst & 0x40000000) >> 30, # AA				 inst               >> 31  # LK			)		elif opcd == 17 and ((inst & 0x40000000) >> 30) == 1: # sc -- SC form			return (				opcd, # OPCD			)		elif opcd in self.D: # D form			return (				opcd, # OPCD				(inst & 0x000007c0) >>  6, # D/S/(crfD|0|L)/TO				(inst & 0x0000f800) >> 11, # A				 inst               >> 16  # SIMM/UIMM/d			)		elif opcd in self.X: # X form			opcd |= (inst & 0x7fe00000) >> 15			return (				opcd, # OPCD				(inst & 0x000007c0) >>  6, # D/S/(crfD|0|L)/TO				(inst & 0x0000f800) >> 11, # A				(inst & 0x001f0000) >> 16, # B/NB/SH/IMM				 inst               >> 31  # Rc/0/1			)		else:			raise DecoderException('Bad instruction %08x' % inst)