@magic.line_magic
    @magic_arguments()
    @argument('serial_port', type=str, nargs='?', help='Serial port filename to use for reaching the bitbang port')
    @argument('-q', '--quiet', action='store_true', help="Just install the hook, don't talk about it")
    @argument('-e', '--exit', action='store_true', help='Exit an existing bitbang debug session')
    @argument('-a', '--attach', action='store_true', help='Assume bitbang_backdoor() is already running, attach to it')
    @argument('-R', '--reset', action='store_true', help="Reset the ARM before starting")
    @argument('-8', '--cpu8051',action='store_true', help='Install the 8051 backdoor interface ("d8" in the shell)')
    @argument('--address', type=hexint_aligned, default=target_memory.bitbang_backdoor, help='Where to load the bitbang backdoor code. By default this goes just below the console buffer.')
    def bitbang(self, line):
        args = parse_argstring(self.bitbang, line)
        d = self.shell.user_ns['d']
        d_remote = self.shell.user_ns.get('d_remote')
        d_bitbang = self.shell.user_ns.get('d_bitbang')

        if args.exit:
            if not d_bitbang:
                raise UsageError("No bitbang shell to exit")

            self.shell.write('* Asking bitbang backdoor to exit\n')
            d_bitbang.exit()
            self.shell.user_ns['d_bitbang'] = None
            self.shell.user_ns['d'] = d_remote
            d_remote.reset()

        else:
            if not args.attach and not d_remote:
                raise UsageError("No way in; if the target is already in bitbang mode, try -a")
            if not args.serial_port:
                raise UsageError("Need a hardware serial port; see 'bitbang?' for more info")

            if args.reset:
                print '* Trying to reset... (cycle power if target does not respond)'
                reset_arm(d_remote)

            if not args.attach:
                bitbang_backdoor(d_remote, args.address, verbose=not args.quiet)

            self.shell.write('* Connecting to bitbang backdoor via %s\n' % args.serial_port)
            d_bitbang = BitbangDevice(args.serial_port)

            self.shell.user_ns['d_bitbang'] = d_bitbang
            self.shell.user_ns['d'] = d_bitbang

        d = self.shell.user_ns['d']
        self.shell.write('* Debug interface switched to %r\n' % d)

        if args.cpu8051:
            self.shell.user_ns['d8'] = cpu8051_backdoor(d)
Raises OverflowError if the address is illegal
dataset/ETHPy150Open scanlime/coastermelt/backdoor/shell_magics.py/ShellMagics.bitbang--crossover with--dataset/ETHPy150Open mnaberez/py65/py65/utils/addressing.py/AddressParser._constrain