<s> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> from code import * <EOL> from dump import * <EOL> import target_memory <EOL> def cpu8051_boot ( d , firmware , address = pad ) : <EOL> """<STR_LIT>""" <EOL> poke_words_from_string ( d , address , firmware ) <EOL> code_address = ( address + len ( firmware ) + <NUM_LIT:7> ) & ~ <NUM_LIT:7> <EOL> code = '<STR_LIT>' % address <EOL> return evalc ( d , code , address = code_address ) <EOL> def cpu8051_evalasm ( d , code ) : <EOL> """<STR_LIT>""" <EOL> return cpu8051_boot ( d , assemble51_string ( <NUM_LIT:0> , '''<STR_LIT>''' % locals ( ) ) ) <EOL> def cpu8051_backdoor ( d , <EOL> address = target_memory . cpu8051_backdoor , <EOL> verbose = True , show_listing = False , start_cpu = True ) : <EOL> """<STR_LIT>""" <EOL> bd51string = compile51_string ( <NUM_LIT:0> , backdoor_8051 , show_listing = show_listing ) <EOL> words = words_from_string ( bd51string ) <EOL> code_address = address + <NUM_LIT:4> * len ( words ) <EOL> libstring , lib = compile_library_string ( code_address , <EOL> backdoor_arm_funcs , <EOL> includes = dict ( includes , <EOL> backdoor = backdoor_arm_lib <EOL> ) , <EOL> defines = dict ( defines , <EOL> backdoor_firmware = address , <EOL> bounce_buffer_address = target_memory . bounce_buffer <EOL> ) ) <EOL> words += words_from_string ( libstring ) <EOL> poke_words ( d , address , words ) <EOL> bd = BackdoorDevice ( d , lib ) <EOL> if verbose : <EOL> print "<STR_LIT>" % ( len ( bd51string ) , address ) <EOL> print "<STR_LIT>" % ( len ( libstring ) , code_address ) <EOL> if start_cpu : <EOL> bd . start ( ) <EOL> if verbose : <EOL> print "<STR_LIT>" <EOL> return bd <EOL> backdoor_8051 = '''<STR_LIT>''' <EOL> backdoor_arm_lib = '''<STR_LIT>''' <EOL> backdoor_arm_funcs = dict ( <EOL> start = '<STR_LIT>' , <EOL> stop = '<STR_LIT>' , <EOL> status = '<STR_LIT>' , <EOL> cr_read = '<STR_LIT>' , <EOL> cr_write = '<STR_LIT>' , <EOL> xpeek = '<STR_LIT>' , <EOL> xpoke = '<STR_LIT>' , <EOL> xpeek_block = '<STR_LIT>' <EOL> ) <EOL> class BackdoorDevice : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , d , lib ) : <EOL> self . d = d <EOL> self . lib = lib <EOL> def _timeout ( self ) : <EOL> raise IOError ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> def _call_with_timeout ( self , name , arg ) : <EOL> v , _ = self . d . blx ( self . lib [ name ] , arg ) <EOL> if ( v & <NUM_LIT> ) != v : <EOL> self . _timeout ( ) <EOL> return v <EOL> def start ( self ) : <EOL> status , _ = self . d . blx ( self . lib [ '<STR_LIT:start>' ] , <NUM_LIT:0> ) <EOL> if status != <NUM_LIT:1> : <EOL> raise IOError ( "<STR_LIT>" % status ) <EOL> def stop ( self ) : <EOL> self . d . blx ( self . lib [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> def status ( self ) : <EOL> return self . d . blx ( self . lib [ '<STR_LIT:status>' ] , <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> def cr_read ( self , addr ) : <EOL> return self . _call_with_timeout ( '<STR_LIT>' , addr ) <EOL> def cr_write ( self , addr , data ) : <EOL> self . _call_with_timeout ( '<STR_LIT>' , ( addr & <NUM_LIT> ) | ( ( data & <NUM_LIT> ) << <NUM_LIT:16> ) ) <EOL> def xpeek ( self , addr ) : <EOL> return self . _call_with_timeout ( '<STR_LIT>' , addr & <NUM_LIT> ) <EOL> def xpoke ( self , addr , data ) : <EOL> self . _call_with_timeout ( '<STR_LIT>' , ( addr & <NUM_LIT> ) | ( ( data & <NUM_LIT> ) << <NUM_LIT:16> ) ) <EOL> def xpoke_bytes ( self , addr , bytes ) : <EOL> for i , b in enumerate ( bytes ) : <EOL> self . xpoke ( addr + i , b ) <EOL> def xpeek_block ( self , addr , length = <NUM_LIT> ) : <EOL> assert length <= target_memory . bounce_buffer_size <EOL> addr , _ = self . d . blx ( self . lib [ '<STR_LIT>' ] , ( addr & <NUM_LIT> ) | ( length << <NUM_LIT:16> ) ) <EOL> if addr == <NUM_LIT:0> : <EOL> self . _timeout ( ) <EOL> return read_block ( self . d , addr , length ) </s>
