linux-user/mips: Create init_main_thread

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Note that init_thread had set cp0_status in target_pt_regs, but
target_cpu_copy_regs did not copy to env.  This turns out to be
ok because mips_cpu_reset_hold initializes CP0_Status properly.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2025-07-28 13:33:18 -10:00
parent a2c83f5156
commit e17cc00f71
2 changed files with 7 additions and 17 deletions

View file

@ -581,13 +581,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
#define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
#endif
static inline void init_thread(struct target_pt_regs *regs,
struct image_info *infop)
{
regs->cp0_status = 2 << CP0St_KSU;
regs->cp0_epc = infop->entry;
regs->regs[29] = infop->start_stack;
}
#define HAVE_INIT_MAIN_THREAD
/* See linux kernel: arch/mips/include/asm/elf.h. */
#define ELF_NREG 45

View file

@ -211,12 +211,9 @@ done_syscall:
}
}
void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
void init_main_thread(CPUState *cs, struct image_info *info)
{
CPUState *cpu = env_cpu(env);
TaskState *ts = get_task_state(cpu);
struct image_info *info = ts->info;
int i;
CPUArchState *env = cpu_env(cs);
struct mode_req {
bool single;
@ -245,12 +242,11 @@ void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
struct mode_req prog_req;
struct mode_req interp_req;
target_ulong entry = info->entry;
for(i = 0; i < 32; i++) {
env->active_tc.gpr[i] = regs->regs[i];
}
env->active_tc.PC = regs->cp0_epc & ~(target_ulong)1;
if (regs->cp0_epc & 1) {
env->active_tc.gpr[29] = info->start_stack;
env->active_tc.PC = entry & ~(target_ulong)1;
if (entry & 1) {
env->hflags |= MIPS_HFLAG_M16;
}