static void tss_load_seg(CPUX86State *env, int seg_reg, int selector)

{

    uint32_t e1, e2;

    int rpl, dpl, cpl;



    if ((selector & 0xfffc) != 0) {

        if (load_segment(env, &e1, &e2, selector) != 0) {

            raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

        }

        if (!(e2 & DESC_S_MASK)) {

            raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

        }

        rpl = selector & 3;

        dpl = (e2 >> DESC_DPL_SHIFT) & 3;

        cpl = env->hflags & HF_CPL_MASK;

        if (seg_reg == R_CS) {

            if (!(e2 & DESC_CS_MASK)) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

            /* XXX: is it correct? */

            if (dpl != rpl) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

            if ((e2 & DESC_C_MASK) && dpl > rpl) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

        } else if (seg_reg == R_SS) {

            /* SS must be writable data */

            if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK)) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

            if (dpl != cpl || dpl != rpl) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

        } else {

            /* not readable code */

            if ((e2 & DESC_CS_MASK) && !(e2 & DESC_R_MASK)) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

            /* if data or non conforming code, checks the rights */

            if (((e2 >> DESC_TYPE_SHIFT) & 0xf) < 12) {

                if (dpl < cpl || dpl < rpl) {

                    raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

                }

            }

        }

        if (!(e2 & DESC_P_MASK)) {

            raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc);

        }

        cpu_x86_load_seg_cache(env, seg_reg, selector,

                               get_seg_base(e1, e2),

                               get_seg_limit(e1, e2),

                               e2);

    } else {

        if (seg_reg == R_SS || seg_reg == R_CS) {

            raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

        }

    }

}

static void tss_load_seg(CPUX86State *env, int seg_reg, int selector)

{

    uint32_t e1, e2;

    int rpl, dpl, cpl;



    if ((selector & 0xfffc) != 0) {

        if (load_segment(env, &e1, &e2, selector) != 0) {

            raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

        }

        if (!(e2 & DESC_S_MASK)) {

            raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

        }

        rpl = selector & 3;

        dpl = (e2 >> DESC_DPL_SHIFT) & 3;

        cpl = env->hflags & HF_CPL_MASK;

        if (seg_reg == R_CS) {

            if (!(e2 & DESC_CS_MASK)) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

            

            if (dpl != rpl) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

            if ((e2 & DESC_C_MASK) && dpl > rpl) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

        } else if (seg_reg == R_SS) {

            

            if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK)) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

            if (dpl != cpl || dpl != rpl) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

        } else {

            

            if ((e2 & DESC_CS_MASK) && !(e2 & DESC_R_MASK)) {

                raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

            }

            

            if (((e2 >> DESC_TYPE_SHIFT) & 0xf) < 12) {

                if (dpl < cpl || dpl < rpl) {

                    raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

                }

            }

        }

        if (!(e2 & DESC_P_MASK)) {

            raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc);

        }

        cpu_x86_load_seg_cache(env, seg_reg, selector,

                               get_seg_base(e1, e2),

                               get_seg_limit(e1, e2),

                               e2);

    } else {

        if (seg_reg == R_SS || seg_reg == R_CS) {

            raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc);

        }

    }

}

static void FUNC_0(CPUX86State *VAR_0, int VAR_1, int VAR_2)

{

    uint32_t e1, e2;

    int VAR_3, VAR_4, VAR_5;



    if ((VAR_2 & 0xfffc) != 0) {

        if (load_segment(VAR_0, &e1, &e2, VAR_2) != 0) {

            raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

        }

        if (!(e2 & DESC_S_MASK)) {

            raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

        }

        VAR_3 = VAR_2 & 3;

        VAR_4 = (e2 >> DESC_DPL_SHIFT) & 3;

        VAR_5 = VAR_0->hflags & HF_CPL_MASK;

        if (VAR_1 == R_CS) {

            if (!(e2 & DESC_CS_MASK)) {

                raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

            }

            

            if (VAR_4 != VAR_3) {

                raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

            }

            if ((e2 & DESC_C_MASK) && VAR_4 > VAR_3) {

                raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

            }

        } else if (VAR_1 == R_SS) {

            

            if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK)) {

                raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

            }

            if (VAR_4 != VAR_5 || VAR_4 != VAR_3) {

                raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

            }

        } else {

            

            if ((e2 & DESC_CS_MASK) && !(e2 & DESC_R_MASK)) {

                raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

            }

            

            if (((e2 >> DESC_TYPE_SHIFT) & 0xf) < 12) {

                if (VAR_4 < VAR_5 || VAR_4 < VAR_3) {

                    raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

                }

            }

        }

        if (!(e2 & DESC_P_MASK)) {

            raise_exception_err(VAR_0, EXCP0B_NOSEG, VAR_2 & 0xfffc);

        }

        cpu_x86_load_seg_cache(VAR_0, VAR_1, VAR_2,

                               get_seg_base(e1, e2),

                               get_seg_limit(e1, e2),

                               e2);

    } else {

        if (VAR_1 == R_SS || VAR_1 == R_CS) {

            raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc);

        }

    }

}

static void FUNC_0(CPUX86State *VAR_0, int VAR_1, int VAR_2)
{ uint32_t e1, e2; int VAR_3, VAR_4, VAR_5; if ((VAR_2 & 0xfffc) != 0) { if (load_segment(VAR_0, &e1, &e2, VAR_2) != 0) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } if (!(e2 & DESC_S_MASK)) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } VAR_3 = VAR_2 & 3; VAR_4 = (e2 >> DESC_DPL_SHIFT) & 3; VAR_5 = VAR_0->hflags & HF_CPL_MASK; if (VAR_1 == R_CS) { if (!(e2 & DESC_CS_MASK)) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } if (VAR_4 != VAR_3) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } if ((e2 & DESC_C_MASK) && VAR_4 > VAR_3) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } } else if (VAR_1 == R_SS) { if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK)) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } if (VAR_4 != VAR_5 || VAR_4 != VAR_3) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } } else { if ((e2 & DESC_CS_MASK) && !(e2 & DESC_R_MASK)) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } if (((e2 >> DESC_TYPE_SHIFT) & 0xf) < 12) { if (VAR_4 < VAR_5 || VAR_4 < VAR_3) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } } } if (!(e2 & DESC_P_MASK)) { raise_exception_err(VAR_0, EXCP0B_NOSEG, VAR_2 & 0xfffc); } cpu_x86_load_seg_cache(VAR_0, VAR_1, VAR_2,
get_seg_base(e1, e2),
get_seg_limit(e1, e2),
e2); } else { if (VAR_1 == R_SS || VAR_1 == R_CS) { raise_exception_err(VAR_0, EXCP0A_TSS, VAR_2 & 0xfffc); } } }