Module Assign NameStore ListLoad Str Str Str ImportFrom alias ImportFrom alias Import alias FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Str Expr Call NameLoad NameLoad NameLoad NameLoad Assign NameStore BinOpBitAnd BinOpAdd BinOpAdd NameLoad Call NameLoad NameLoad Num UnaryOpInvert Num Assign NameStore BinOpMod Str NameLoad Return Call NameLoad NameLoad NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call NameLoad NameLoad Call NameLoad Num BinOpMod Str Call NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults AttributeLoad NameLoad attr NameLoad NameLoad NameLoad body Expr Str Assign NameStore Call NameLoad Num NameLoad keyword NameLoad Assign NameStore Call NameLoad NameLoad Assign NameStore BinOpAdd NameLoad BinOpMult Num Call NameLoad NameLoad Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad keyword Call NameLoad NameLoad keyword NameLoad keyword Call NameLoad NameLoad keyword NameLoad keyword AttributeLoad NameLoad attr AugAssignAdd NameStore Call NameLoad NameLoad Expr Call NameLoad NameLoad NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad If NameLoad body Print BinOpMod Str TupleLoad Call NameLoad NameLoad NameLoad Print BinOpMod Str TupleLoad Call NameLoad NameLoad NameLoad If NameLoad body Expr Call AttributeLoad NameLoad attr If NameLoad body Print Str Return NameLoad decorator_list Assign NameStore Str Assign NameStore Str Assign NameStore Call NameLoad keyword Str keyword Str keyword Str keyword Str keyword Str keyword Str keyword Str keyword Str ClassDef bases body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Raise Call NameLoad BinOpAdd Str Str decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad AttributeLoad NameLoad attr Index NameLoad NameLoad If CompareNotEq BinOpBitAnd NameLoad Num NameLoad body Expr Call AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad AttributeLoad NameLoad attr Index Str Num If CompareNotEq NameLoad Num body Raise Call NameLoad BinOpMod Str NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad AttributeLoad NameLoad attr Index Str Num decorator_list FunctionDef arguments args NameParam defaults body Return SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad AttributeLoad NameLoad attr Index Str Num Index Num decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call AttributeLoad NameLoad attr Str NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call AttributeLoad NameLoad attr Str BinOpBitOr BinOpBitAnd NameLoad Num BinOpLShift BinOpBitAnd NameLoad Num Num decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call AttributeLoad NameLoad attr Str BinOpBitAnd NameLoad Num decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call AttributeLoad NameLoad attr Str BinOpBitOr BinOpBitAnd NameLoad Num BinOpLShift BinOpBitAnd NameLoad Num Num decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body For TupleStore NameStore NameStore Call NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body Assert CompareLtE NameLoad AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad AttributeLoad NameLoad attr Index Str BinOpBitOr BinOpBitAnd NameLoad Num BinOpLShift NameLoad Num If CompareEq NameLoad Num body Expr Call AttributeLoad NameLoad attr Return Call NameLoad AttributeLoad NameLoad attr NameLoad NameLoad decorator_list decorator_list
N/A N/A __all__ N/A cpu8051_boot cpu8051_evalasm cpu8051_backdoor code * dump * N/A target_memory cpu8051_boot N/A N/A d firmware address N/A pad N/A N/A Transmit a firmware image to the 8051 and boot it.
    Returns the status code, or 0 if booting timed out.
     N/A N/A poke_words_from_string d address firmware N/A code_address N/A N/A N/A address N/A len firmware 7 N/A 7 N/A code N/A MT1939::CPU8051::start((uint8_t*) 0x%08x address N/A N/A evalc d code address code_address N/A cpu8051_evalasm N/A N/A d code N/A N/A N/A Run a snippet of assembly code on the 8051
    Returns the value of 'a'
     N/A N/A cpu8051_boot d N/A assemble51_string 0 N/A         %(code)s
        mov     dptr, #0x4d91
        movx    @dptr, a
        sjmp    .
     N/A locals N/A cpu8051_backdoor N/A N/A d address verbose show_listing start_cpu N/A N/A target_memory cpu8051_backdoor True False True N/A N/A Run a backdoor stub on the 8051 so we can control it remotely.

    Returns a library of ARM C++ functions for interacting with the stub.
    If start_cpu is True, we restart the 8051 running the debug stub firmware.
    If it's false, we leave the 8051 as-is.
     N/A bd51string N/A compile51_string 0 backdoor_8051 show_listing show_listing N/A words N/A words_from_string bd51string N/A code_address N/A address N/A 4 N/A len words N/A N/A libstring lib N/A compile_library_string code_address backdoor_arm_funcs includes N/A dict includes backdoor backdoor_arm_lib defines N/A dict defines backdoor_firmware address bounce_buffer_address N/A target_memory bounce_buffer N/A words N/A words_from_string libstring N/A N/A poke_words d address words N/A bd N/A BackdoorDevice d lib N/A verbose N/A N/A N/A * 8051 backdoor is 0x%x bytes, loaded at 0x%x N/A N/A len bd51string address N/A N/A * ARM library is 0x%x bytes, loaded at 0x%x N/A N/A len libstring code_address N/A start_cpu N/A N/A N/A N/A bd start N/A verbose N/A N/A * 8051 backdoor running N/A bd N/A N/A backdoor_8051     typedef unsigned char uint8_t;
    #define XADDR ((__xdata unsigned char *)( addr_low | (addr_high << 8) ))
    __sbit __at (0xaf) irq_enable;
    __xdata __at (0x4d91) volatile uint8_t status;

    void start()
    {
        uint8_t addr_low;
        uint8_t addr_high;
        uint8_t data;
        uint8_t s;

        irq_enable = 0;
        status = 1;

        while (1) {
            s = status;

            if (s & 0x80) {
                // Store data
                data = s & 0x7f;
                status = 1;
                continue;
            }

            switch (s) {

            case 2:  addr_low  = data;         status = 1; break;
            case 3:  addr_low  = data | 0x80;  status = 1; break;
            case 4:  addr_high = data;         status = 1; break;
            case 5:  addr_high = data | 0x80;  status = 1; break;
            case 6:  *XADDR = data;            status = 1; break;
            case 7:  *XADDR = data | 0x80;     status = 1; break;

            case 0x40:
                data = *XADDR;                      // Peek
                status = 0x70 | (data >> 7);        // High bit
                while (status != 1);                //   wait for ARM to ack
                status = 0x80 | data;               // Low 7 bits
                while (status != 1);                //   wait for ARM to ack
                break;

            }
        }
    }
 N/A backdoor_arm_lib     namespace backdoor {
    using namespace MT1939::CPU8051;
    auto bounce_buffer = (uint8_t*) bounce_buffer_address;

    bool set_status(uint8_t s, SysTime deadline)
    {
        return cr_write(0x41f4d91, s, deadline) >= 0;
    }

    bool get_status(uint8_t &s, SysTime deadline)
    {
        int r = cr_read(0x41f4d91, deadline);
        s = r;
        return r >= 0;
    }

    bool wait_idle(SysTime deadline)
    {
        uint8_t s;
        while (get_status(s, deadline)) {
            if (s == 1) {
                return true;
            }
        }
        return false;
    }

    bool wait_response(uint8_t exclude, uint8_t &result, SysTime deadline)
    {
        while (get_status(result, deadline)) {
            if (result != exclude) {
                return true;
            }
        }
        return false;
    }

    bool set_address(uint16_t addr, SysTime deadline)
    {
        return
            set_status(0x80 | (0x7f & (addr >> 8)), deadline) &&
            wait_idle(deadline) &&
            set_status(0x04 | (0x01 & (addr >> 15)), deadline) &&
            wait_idle(deadline) &&
            set_status(0x80 | (0x7f & addr), deadline) &&
            wait_idle(deadline) &&
            set_status(0x02 | (0x01 & (addr >> 7)), deadline) &&
            wait_idle(deadline);
    }

    bool xpoke(uint16_t addr, uint8_t data)
    {
        SysTime deadline = SysTime::future(0.25);
        return
            set_address(addr, deadline) &&
            set_status(0x80 | (0x7f & data), deadline) &&
            wait_idle(deadline) &&
            set_status(0x06 | (0x01 & (data >> 7)), deadline) &&
            wait_idle(deadline);
    }

    int xpeek(uint16_t addr)
    {
        SysTime deadline = SysTime::future(0.25);
        uint8_t r1, r2;
        return (
            set_address(addr, deadline) &&
            set_status(0x40, deadline) &&
            wait_response(0x40, r1, deadline) &&
            set_status(1, deadline) &&
            wait_response(1, r2, deadline) &&
            set_status(1, deadline)
        ) ? ( ((r1 << 7) & 0x80) | (r2 & 0x7F) ) : -1;
    }

    uint8_t *xpeek_block(uint16_t addr, unsigned length)
    {
        for (unsigned i = 0; i != length; i++) {
            int v = xpeek(addr + i);
            if (v < 0) {
                return 0;
            }
            bounce_buffer[i] = v;
        }
        return bounce_buffer;
    }
} N/A backdoor_arm_funcs N/A dict start CPU8051::start( (uint8_t*) backdoor_firmware ) stop CPU8051::stop(), 0 status CPU8051::status() cr_read CPU8051::cr_read(0x041f0000 | (arg & 0xffff)) cr_write CPU8051::cr_write(0x041f0000 | (arg & 0xffff), arg >> 16) xpeek backdoor::xpeek(arg) xpoke backdoor::xpoke(arg, arg >> 16) ? 0 : -1 xpeek_block (uint32_t) backdoor::xpeek_block(arg, arg >> 16) BackdoorDevice N/A N/A N/A Python interface to the 8051 CPU backdoor.
    Communicates via an ARM function library 'lib', assumed to already be installed.
     __init__ N/A N/A self d lib N/A N/A N/A N/A self d d N/A N/A self lib lib N/A _timeout N/A N/A self N/A N/A N/A N/A IOError N/A Timeout waiting on 8051 backdoor

 --> You can (re)start the backdoor firmware with d8.start() N/A _call_with_timeout N/A N/A self name arg N/A N/A N/A N/A v _ N/A N/A N/A self d blx N/A N/A self lib N/A name arg N/A N/A N/A v 255 v N/A N/A N/A N/A self _timeout N/A v N/A start N/A N/A self N/A N/A N/A N/A status _ N/A N/A N/A self d blx N/A N/A self lib N/A start 0 N/A N/A status 1 N/A N/A N/A IOError N/A Failed to boot 8051 processor, status 0x%02x status N/A stop N/A N/A self N/A N/A N/A N/A N/A N/A self d blx N/A N/A self lib N/A stop 0 N/A status N/A N/A self N/A N/A N/A N/A N/A N/A N/A self d blx N/A N/A self lib N/A status 0 N/A 0 N/A cr_read N/A N/A self addr N/A N/A N/A N/A N/A self _call_with_timeout cr_read addr N/A cr_write N/A N/A self addr data N/A N/A N/A N/A N/A self _call_with_timeout cr_write N/A N/A addr 65535 N/A N/A data 255 16 N/A xpeek N/A N/A self addr N/A N/A N/A N/A N/A self _call_with_timeout xpeek N/A addr 65535 N/A xpoke N/A N/A self addr data N/A N/A N/A N/A N/A self _call_with_timeout xpoke N/A N/A addr 65535 N/A N/A data 255 16 N/A xpoke_bytes N/A N/A self addr bytes N/A N/A N/A N/A i b N/A enumerate bytes N/A N/A N/A N/A self xpoke N/A addr i b N/A xpeek_block N/A N/A self addr length N/A 256 N/A N/A N/A length N/A target_memory bounce_buffer_size N/A N/A addr _ N/A N/A N/A self d blx N/A N/A self lib N/A xpeek_block N/A N/A addr 65535 N/A length 16 N/A N/A addr 0 N/A N/A N/A N/A self _timeout N/A N/A read_block N/A self d addr length N/A N/A