Skip to content

I can't see a way for MIPS to change the current ISA in unicorn. #2086

Description

@ZakDanger

MIPS supports various 16bit or variable sized instructions formats in addition to the normal 32bit instructions.

This is pretty much the same deal as ARM supporting THUMB instructions.
For MIPS the lowest address bit of PC is even used for change between modes, just like between ARM and THUMB.

I cannot however find any way to perform this change when using unicorn with MIPS.
Perhaps I am missing something?

In "qemu/target/mips/cpu.c" lin 28 you can see how setting the PC is used to set the M16 (mips16 bit mode) flag.

static void mips_cpu_set_pc(CPUState *cs, vaddr value)
{
    MIPSCPU *cpu = MIPS_CPU(cs);
    CPUMIPSState *env = &cpu->env;

    env->active_tc.PC = value & ~(target_ulong)1;
    if (value & 1) {
        env->hflags |= MIPS_HFLAG_M16;
    } else {
        env->hflags &= ~(MIPS_HFLAG_M16);
    }
}

However the code in "qemu/target/mips/unicorn.c" only does this:

static void mips_set_pc(struct uc_struct *uc, uint64_t address)
{
    ((CPUMIPSState *)uc->cpu->env_ptr)->active_tc.PC = address;
}

I propose to change it to:

static void mips_set_pc(struct uc_struct *uc, uint64_t address)
{
    ((CPUMIPSState *)uc->cpu->env_ptr)->active_tc.PC = address & ~(uint64_t )1ULL;
    if (address & 1) {
        ((CPUMIPSState *)uc->cpu->env_ptr)->hflags |= MIPS_HFLAG_M16;
    } else {
        ((CPUMIPSState *)uc->cpu->env_ptr)->hflags &= ~(MIPS_HFLAG_M16);
    }
}

This would make it similar to unicorns "set pc" function for arm which is:

static void arm_set_pc(struct uc_struct *uc, uint64_t address)
{
    ((CPUARMState *)uc->cpu->env_ptr)->pc = address;
    ((CPUARMState *)uc->cpu->env_ptr)->regs[15] = address & ~1;
    ((CPUARMState *)uc->cpu->env_ptr)->thumb = address & 1;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions