Skip to contentSkip to conversation

Don't set FD bit in user mode emulation

Qemu-devel Lionel Landwerlin 3 participants 3 messages Dec 13, 2008

lore
Share & tools
lore
#0 lore raw
Quoted 1 line

From 1823395215d00c436f91b218f15797e918659f20 Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Fri, 12 Dec 2008 09:55:32 +0100
Subject: [PATCH] [sh] Don't set FD bit in user mode emulation

This causes qemu to exist very early (before libc initialization)

---
 target-sh4/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-sh4/translate.c +1 -1
index d6cfb7c..287b4a3 100644
@@ -184,7 +184,7 @@ void cpu_dump_state(CPUState * env, FILE * f,
 static void cpu_sh4_reset(CPUSH4State * env)
 {
 #if defined(CONFIG_USER_ONLY)
-    env->sr = SR_FD;            /* FD - kernel does lazy fpu context switch */
+    /* env->sr = SR_FD; */            /* FD - kernel does lazy fpu context switch */
 #else
     env->sr = 0x700000F0;	/* MD, RB, BL, I3-I0 */
 #endif
Signature · 1 line
1.5.6.5
#1 lore raw

target-sh4/translate.c void cpu_dump_state(CPUState * env, FILE * f, · line 187

Quoted 5 lines · Lionel Landwerlin

static void cpu_sh4_reset(CPUSH4State * env)
{
#if defined(CONFIG_USER_ONLY)

target-sh4/translate.c +1 -1
-    env->sr = SR_FD;            /* FD - kernel does lazy fpu context switch */
+    /* env->sr = SR_FD; */            /* FD - kernel does lazy fpu context switch */

I think it's better when commenting out code to say why it's commented out.

However in that particular case, I would simply remove the
code: unless there's something I don't understand, I can't see why FPU disable should be set (unless, as I said previously, if the ELF header contains a flag stating the program needs FPU instructions in which case this should be handled differently).

Laurent

#2 lore raw
In reply to Lionel Landwerlin

Hi,

target-sh4/translate.c void cpu_dump_state(CPUState * env, FILE * f, · line 188

Quoted 4 lines

#if defined(CONFIG_USER_ONLY)

target-sh4/translate.c +1 -1
-    env->sr = SR_FD;            /* FD - kernel does lazy fpu context switch */
+    /* env->sr = SR_FD; */            /* FD - kernel does lazy fpu context switch */
 #else

I think this CPP conditional here itself is wrong.
This is where we do CPU reset. CPU reset should be done as datasheet says.

Initialization dedicated for linux_user emulation corresponds to user process
initialization in linux kernel, which(for ELF) is in <linux_kernel>/fs/binfmt_elf.c:load_elf_binary()
that initializes registers using ELF_PLAT_INIT, which is in
<linux_kernel>/arch/sh/include/asm/elf.h:ELF_PLAT_INIT
that is

  do { _r->regs[0]=0; _r->regs[1]=0; _r->regs[2]=0; _r->regs[3]=0; \
       _r->regs[4]=0; _r->regs[5]=0; _r->regs[6]=0; _r->regs[7]=0; \
       _r->regs[8]=0; _r->regs[9]=0; _r->regs[10]=0; _r->regs[11]=0; \
       _r->regs[12]=0; _r->regs[13]=0; _r->regs[14]=0; \
       _r->sr = SR_FD; } while (0)

.
I guess "env->sr = SR_FD" comes from this.

In qemu, the corresponding place is linux-user/elfload.c, though qemu
doesn't have such an arch depend initialization there.
But the initializations are in linux-user/main.c after loader_exec(). for sh4, this is as follows.

        for(i = 0; i < 16; i++) {
            env->gregs[i] = regs->regs[i];
        }
        env->pc = regs->pc;

I think this is good place to add env->sr = 0;
Fortunately, this works so far, because both ELF and bFLT use same initial
register value on SuperH :). We can change it when ELF-FDPIC is suppoted.

BTW, the value is 0, but SR_FD.
Actually, Linux kernel do set FD when initialization as shown above. This is a trap to know if the process use FPU, to do FPU context switching. But, we don't need it in qemu user emulation, because we always have all
FP context stored in env in qemu user emulation.
/yoshii