qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

linux-user/sparc: Fix cpu_clone_regs_*

We failed to set the secondary return value in %o1
we failed to advance the PC past the syscall,
we failed to adjust regwptr into the new structure,
we stored the stack pointer into the wrong register.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20191106113318.10226-12-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>

authored by

Richard Henderson and committed by
Laurent Vivier
2ad983e0 07a6ecf4

+36 -7
+36 -7
linux-user/sparc/target_cpu.h
··· 23 23 static inline void cpu_clone_regs_child(CPUSPARCState *env, target_ulong newsp, 24 24 unsigned flags) 25 25 { 26 + /* 27 + * After cpu_copy, env->regwptr is pointing into the old env. 28 + * Update the new cpu to use its own register window. 29 + */ 30 + env->regwptr = env->regbase + (env->cwp * 16); 31 + 26 32 if (newsp) { 27 - env->regwptr[22] = newsp; 33 + /* When changing stacks, do it with clean register windows. */ 34 + #ifdef TARGET_SPARC64 35 + env->cansave = env->nwindows - 2; 36 + env->cleanwin = env->nwindows - 2; 37 + env->canrestore = 0; 38 + #else 39 + env->wim = 1 << env->cwp; 40 + #endif 41 + /* ??? The kernel appears to copy one stack frame to the new stack. */ 42 + /* ??? The kernel force aligns the new stack. */ 43 + env->regwptr[WREG_SP] = newsp; 28 44 } 29 - /* syscall return for clone child: 0, and clear CF since 30 - * this counts as a success return value. 31 - */ 32 - env->regwptr[0] = 0; 45 + 46 + if (flags & CLONE_VM) { 47 + /* 48 + * Syscall return for clone child: %o0 = 0 and clear CF since this 49 + * counts as a success return value. Advance the PC past the syscall. 50 + * For fork child, all of this happens in cpu_loop, and we must not 51 + * do the pc advance twice. 52 + */ 53 + env->regwptr[WREG_O0] = 0; 33 54 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) 34 - env->xcc &= ~PSR_CARRY; 55 + env->xcc &= ~PSR_CARRY; 35 56 #else 36 - env->psr &= ~PSR_CARRY; 57 + env->psr &= ~PSR_CARRY; 37 58 #endif 59 + env->pc = env->npc; 60 + env->npc = env->npc + 4; 61 + } 62 + 63 + /* Set the second return value for the child: %o1 = 1. */ 64 + env->regwptr[WREG_O1] = 1; 38 65 } 39 66 40 67 static inline void cpu_clone_regs_parent(CPUSPARCState *env, unsigned flags) 41 68 { 69 + /* Set the second return value for the parent: %o1 = 0. */ 70 + env->regwptr[WREG_O1] = 0; 42 71 } 43 72 44 73 static inline void cpu_set_tls(CPUSPARCState *env, target_ulong newtls)