'setting unicorn registers'

def set_regs(self):

    uc = self.uc
    if (self.state.arch.qemu_name == 'x86_64'):
        fs = self.state.se.any_int(self.state.regs.fs)
        gs = self.state.se.any_int(self.state.regs.gs)
        self.write_msr(fs, 3221225728)
        self.write_msr(gs, 3221225729)
        flags = self._process_value(ccall._get_flags(self.state)[0], 'reg')
        if (flags is None):
            raise SimValueError('symbolic    eflags')
        uc.reg_write(self._uc_const.UC_X86_REG_EFLAGS, self.state.se.any_int(flags))
    elif (self.state.arch.qemu_name == 'i386'):
        flags = self._process_value(ccall._get_flags(self.state)[0], 'reg')
        if (flags is None):
            raise SimValueError('symbolic    eflags')
        uc.reg_write(self._uc_const.UC_X86_REG_EFLAGS, self.state.se.any_int(flags))
        fs = (self.state.se.any_int(self.state.regs.fs) << 16)
        gs = (self.state.se.any_int(self.state.regs.gs) << 16)
        self.setup_gdt(fs, gs)
    for (r, c) in self._uc_regs.iteritems():
        if (r in self.reg_blacklist):
            continue
        v = self._process_value(getattr(self.state.regs, r), 'reg')
        if (v is None):
            raise SimValueError('setting    a    symbolic    register')
        uc.reg_write(c, self.state.se.any_int(v))
    if (self.state.arch.name in ('X86', 'AMD64')):
        c3210 = self.state.se.any_int(self.state.regs.fc3210)
        top = self.state.se.any_int(self.state.regs.ftop[2:0])
        rm = self.state.se.any_int(self.state.regs.fpround[1:0])
        control = (895 | (rm << 10))
        status = ((top << 11) | c3210)
        uc.reg_write(unicorn.x86_const.UC_X86_REG_FPCW, control)
        uc.reg_write(unicorn.x86_const.UC_X86_REG_FPSW, status)
        uc_offset = unicorn.x86_const.UC_X86_REG_FP0
        vex_offset = self.state.arch.registers['fpu_regs'][0]
        vex_tag_offset = self.state.arch.registers['fpu_tags'][0]
        tag_word = 0
        for _ in xrange(8):
            tag = self.state.se.any_int(self.state.registers.load(vex_tag_offset, size=1))
            tag_word <<= 2
            if (tag == 0):
                tag_word |= 3
            else:
                val = self._process_value(self.state.registers.load(vex_offset, size=8), 'reg')
                if (val is None):
                    raise SimValueError('setting    a    symbolic    fp    register')
                val = self.state.se.any_int(val)
                sign = bool((val & 9223372036854775808L))
                exponent = ((val & 9218868437227405312) >> 52)
                mantissa = (val & 4503599627370495)
                if (exponent not in (0, 2047)):
                    exponent = ((exponent - 1023) + 16383)
                    mantissa <<= 11
                    mantissa |= 9223372036854775808L
                elif (exponent == 0):
                    mantissa = 0
                elif (exponent == 2047):
                    exponent = 32767
                    if (mantissa != 0):
                        mantissa = 9223372036854775808L
                    else:
                        mantissa = 18446744073709551615L
                if sign:
                    exponent |= 32768
                uc.reg_write(uc_offset, (exponent, mantissa))
            uc_offset += 1
            vex_offset += 8
            vex_tag_offset += 1
        uc.reg_write(unicorn.x86_const.UC_X86_REG_FPTAG, tag_word)
