diff options
author | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-09-30 22:04:13 +0000 |
---|---|---|
committer | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-09-30 22:04:13 +0000 |
commit | 6d5e216de979afdc0a26410580ad31376f7107f7 (patch) | |
tree | 699b7a6fa6b1a7493ecf844f66ae5184742f07d2 /linux-user | |
parent | e8af50a30e89e5cfdc1b2a2fa8fab3ce463a4790 (diff) |
SPARC fixes (Blue Swirl)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1084 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'linux-user')
-rw-r--r-- | linux-user/signal.c | 340 | ||||
-rw-r--r-- | linux-user/syscall_defs.h | 96 |
2 files changed, 436 insertions, 0 deletions
diff --git a/linux-user/signal.c b/linux-user/signal.c index bde492237b..50f2ba10a0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -1271,6 +1271,346 @@ badframe: return 0; } +#elif defined(TARGET_SPARC) +#define __SUNOS_MAXWIN 31 + +/* This is what SunOS does, so shall I. */ +struct target_sigcontext { + target_ulong sigc_onstack; /* state to restore */ + + target_ulong sigc_mask; /* sigmask to restore */ + target_ulong sigc_sp; /* stack pointer */ + target_ulong sigc_pc; /* program counter */ + target_ulong sigc_npc; /* next program counter */ + target_ulong sigc_psr; /* for condition codes etc */ + target_ulong sigc_g1; /* User uses these two registers */ + target_ulong sigc_o0; /* within the trampoline code. */ + + /* Now comes information regarding the users window set + * at the time of the signal. + */ + target_ulong sigc_oswins; /* outstanding windows */ + + /* stack ptrs for each regwin buf */ + char *sigc_spbuf[__SUNOS_MAXWIN]; + + /* Windows to restore after signal */ + struct { + target_ulong locals[8]; + target_ulong ins[8]; + } sigc_wbuf[__SUNOS_MAXWIN]; +}; +/* A Sparc stack frame */ +struct sparc_stackf { + target_ulong locals[8]; + target_ulong ins[6]; + struct sparc_stackf *fp; + target_ulong callers_pc; + char *structptr; + target_ulong xargs[6]; + target_ulong xxargs[1]; +}; + +typedef struct { + struct { + target_ulong psr; + target_ulong pc; + target_ulong npc; + target_ulong y; + target_ulong u_regs[16]; /* globals and ins */ + } si_regs; + int si_mask; +} __siginfo_t; + +typedef struct { + unsigned long si_float_regs [32]; + unsigned long si_fsr; + unsigned long si_fpqdepth; + struct { + unsigned long *insn_addr; + unsigned long insn; + } si_fpqueue [16]; +} __siginfo_fpu_t; + + +struct target_signal_frame { + struct sparc_stackf ss; + __siginfo_t info; + __siginfo_fpu_t *fpu_save; + target_ulong insns[2] __attribute__ ((aligned (8))); + target_ulong extramask[TARGET_NSIG_WORDS - 1]; + target_ulong extra_size; /* Should be 0 */ + __siginfo_fpu_t fpu_state; +}; +struct target_rt_signal_frame { + struct sparc_stackf ss; + siginfo_t info; + target_ulong regs[20]; + sigset_t mask; + __siginfo_fpu_t *fpu_save; + unsigned int insns[2]; + stack_t stack; + unsigned int extra_size; /* Should be 0 */ + __siginfo_fpu_t fpu_state; +}; + +#define UREG_O0 0 +#define UREG_O6 6 +#define UREG_I0 16 +#define UREG_I1 17 +#define UREG_I2 18 +#define UREG_I6 22 +#define UREG_I7 23 +#define UREG_FP UREG_I6 +#define UREG_SP UREG_O6 + +static inline void *get_sigframe(struct emulated_sigaction *sa, CPUState *env, unsigned long framesize) +{ + unsigned long sp; + + sp = env->regwptr[UREG_FP]; +#if 0 + + /* This is the X/Open sanctioned signal stack switching. */ + if (sa->sa_flags & TARGET_SA_ONSTACK) { + if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7)) + sp = current->sas_ss_sp + current->sas_ss_size; + } +#endif + return (void *)(sp - framesize); +} + +static int +setup___siginfo(__siginfo_t *si, CPUState *env, target_ulong mask) +{ + int err = 0, i; + + fprintf(stderr, "2.a %lx psr: %lx regs: %lx\n", si, env->psr, si->si_regs.psr); + err |= __put_user(env->psr, &si->si_regs.psr); + fprintf(stderr, "2.a1 pc:%lx\n", si->si_regs.pc); + err |= __put_user(env->pc, &si->si_regs.pc); + err |= __put_user(env->npc, &si->si_regs.npc); + err |= __put_user(env->y, &si->si_regs.y); + fprintf(stderr, "2.b\n"); + for (i=0; i < 7; i++) { + err |= __put_user(env->gregs[i], &si->si_regs.u_regs[i]); + } + for (i=0; i < 7; i++) { + err |= __put_user(env->regwptr[i+16], &si->si_regs.u_regs[i+8]); + } + fprintf(stderr, "2.c\n"); + err |= __put_user(mask, &si->si_mask); + return err; +} +static int +setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/ + CPUState *env, unsigned long mask) +{ + int err = 0; + + err |= __put_user(mask, &sc->sigc_mask); + err |= __put_user(env->regwptr[UREG_SP], &sc->sigc_sp); + err |= __put_user(env->pc, &sc->sigc_pc); + err |= __put_user(env->npc, &sc->sigc_npc); + err |= __put_user(env->psr, &sc->sigc_psr); + err |= __put_user(env->gregs[1], &sc->sigc_g1); + err |= __put_user(env->regwptr[UREG_O0], &sc->sigc_o0); + + return err; +} +#define NF_ALIGNEDSZ (((sizeof(struct target_signal_frame) + 7) & (~7))) + +static void setup_frame(int sig, struct emulated_sigaction *ka, + target_sigset_t *set, CPUState *env) +{ + struct target_signal_frame *sf; + int sigframe_size, err, i; + + /* 1. Make sure everything is clean */ + //synchronize_user_stack(); + + sigframe_size = NF_ALIGNEDSZ; + + sf = (struct target_signal_frame *) + get_sigframe(ka, env, sigframe_size); + +#if 0 + if (invalid_frame_pointer(sf, sigframe_size)) + goto sigill_and_return; +#endif + /* 2. Save the current process state */ + err = setup___siginfo(&sf->info, env, set->sig[0]); + err |= __put_user(0, &sf->extra_size); + + //err |= save_fpu_state(regs, &sf->fpu_state); + //err |= __put_user(&sf->fpu_state, &sf->fpu_save); + + err |= __put_user(set->sig[0], &sf->info.si_mask); + for (i = 0; i < TARGET_NSIG_WORDS - 1; i++) { + err |= __put_user(set->sig[i + 1], &sf->extramask[i]); + } + + for (i = 0; i < 7; i++) { + err |= __put_user(env->regwptr[i + 8], &sf->ss.locals[i]); + } + for (i = 0; i < 7; i++) { + err |= __put_user(env->regwptr[i + 16], &sf->ss.ins[i]); + } + //err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP], + // sizeof(struct reg_window)); + if (err) + goto sigsegv; + + /* 3. signal handler back-trampoline and parameters */ + env->regwptr[UREG_FP] = (target_ulong) sf; + env->regwptr[UREG_I0] = sig; + env->regwptr[UREG_I1] = (target_ulong) &sf->info; + env->regwptr[UREG_I2] = (target_ulong) &sf->info; + + /* 4. signal handler */ + env->pc = (unsigned long) ka->sa._sa_handler; + env->npc = (env->pc + 4); + /* 5. return to kernel instructions */ + if (ka->sa.sa_restorer) + env->regwptr[UREG_I7] = (unsigned long)ka->sa.sa_restorer; + else { + env->regwptr[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2); + + /* mov __NR_sigreturn, %g1 */ + err |= __put_user(0x821020d8, &sf->insns[0]); + + /* t 0x10 */ + err |= __put_user(0x91d02010, &sf->insns[1]); + if (err) + goto sigsegv; + + /* Flush instruction space. */ + //flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0])); + //tb_flush(env); + } + return; + +sigill_and_return: + force_sig(TARGET_SIGILL); +sigsegv: + force_sig(TARGET_SIGSEGV); +} +static inline int +restore_fpu_state(CPUState *env, __siginfo_fpu_t *fpu) +{ + int err; +#if 0 +#ifdef CONFIG_SMP + if (current->flags & PF_USEDFPU) + regs->psr &= ~PSR_EF; +#else + if (current == last_task_used_math) { + last_task_used_math = 0; + regs->psr &= ~PSR_EF; + } +#endif + current->used_math = 1; + current->flags &= ~PF_USEDFPU; +#endif +#if 0 + if (verify_area (VERIFY_READ, fpu, sizeof(*fpu))) + return -EFAULT; +#endif + + err = __copy_from_user(&env->fpr[0], &fpu->si_float_regs[0], + (sizeof(unsigned long) * 32)); + err |= __get_user(env->fsr, &fpu->si_fsr); +#if 0 + err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth); + if (current->thread.fpqdepth != 0) + err |= __copy_from_user(¤t->thread.fpqueue[0], + &fpu->si_fpqueue[0], + ((sizeof(unsigned long) + + (sizeof(unsigned long *)))*16)); +#endif + return err; +} + + +static void setup_rt_frame(int sig, struct emulated_sigaction *ka, + target_siginfo_t *info, + target_sigset_t *set, CPUState *env) +{ + fprintf(stderr, "setup_rt_frame: not implemented\n"); +} + +long do_sigreturn(CPUState *env) +{ + struct target_signal_frame *sf; + unsigned long up_psr, pc, npc; + target_sigset_t set; + __siginfo_fpu_t *fpu_save; + int err; + + sf = (struct new_signal_frame *) env->regwptr[UREG_FP]; + fprintf(stderr, "sigreturn sf: %lx\n", &sf); + + /* 1. Make sure we are not getting garbage from the user */ +#if 0 + if (verify_area (VERIFY_READ, sf, sizeof (*sf))) + goto segv_and_exit; +#endif + + if (((uint) sf) & 3) + goto segv_and_exit; + + err = __get_user(pc, &sf->info.si_regs.pc); + err |= __get_user(npc, &sf->info.si_regs.npc); + + fprintf(stderr, "pc: %lx npc %lx\n", pc, npc); + if ((pc | npc) & 3) + goto segv_and_exit; + + /* 2. Restore the state */ + up_psr = env->psr; + //err |= __copy_from_user(regs, &sf->info.si_regs, sizeof (struct pt_regs) + //); + /* User can only change condition codes and FPU enabling in %psr. */ + env->psr = (up_psr & ~(PSR_ICC /* | PSR_EF */)) + | (env->psr & (PSR_ICC /* | PSR_EF */)); + fprintf(stderr, "psr: %lx\n", env->psr); + + err |= __get_user(fpu_save, &sf->fpu_save); + + if (fpu_save) + err |= restore_fpu_state(env, fpu_save); + + /* This is pretty much atomic, no amount locking would prevent + * the races which exist anyways. + */ + err |= __get_user(set.sig[0], &sf->info.si_mask); + //err |= __copy_from_user(&set.sig[1], &sf->extramask, + // (_NSIG_WORDS-1) * sizeof(unsigned int)); + + if (err) + goto segv_and_exit; + +#if 0 + sigdelsetmask(&set, ~_BLOCKABLE); + spin_lock_irq(¤t->sigmask_lock); + current->blocked = set; + recalc_sigpending(current); + spin_unlock_irq(¤t->sigmask_lock); +#endif + fprintf(stderr, "returning %lx\n", env->regwptr[0]); + return env->regwptr[0]; + +segv_and_exit: + force_sig(TARGET_SIGSEGV); +} + +long do_rt_sigreturn(CPUState *env) +{ + fprintf(stderr, "do_rt_sigreturn: not implemented\n"); + return -ENOSYS; +} + + #else static void setup_frame(int sig, struct emulated_sigaction *ka, diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 91e1fe5385..ae212ec32c 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -294,6 +294,7 @@ int do_sigaction(int sig, const struct target_sigaction *act, #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_PPC) +#if !defined(TARGET_SPARC) #define TARGET_SA_NOCLDSTOP 0x00000001 #define TARGET_SA_NOCLDWAIT 0x00000002 /* not supported yet */ #define TARGET_SA_SIGINFO 0x00000004 @@ -302,6 +303,57 @@ int do_sigaction(int sig, const struct target_sigaction *act, #define TARGET_SA_NODEFER 0x40000000 #define TARGET_SA_RESETHAND 0x80000000 #define TARGET_SA_RESTORER 0x04000000 +#else /* TARGET_SPARC */ +#define TARGET_SA_NOCLDSTOP 8u +#define TARGET_SA_NOCLDWAIT 0x100u +#define TARGET_SA_SIGINFO 0x200u +#define TARGET_SA_ONSTACK 1u +#define TARGET_SA_RESTART 2u +#define TARGET_SA_NODEFER 0x20u +#define TARGET_SA_RESETHAND 4u +#endif + +#if defined(TARGET_SPARC) + +#define TARGET_SIGHUP 1 +#define TARGET_SIGINT 2 +#define TARGET_SIGQUIT 3 +#define TARGET_SIGILL 4 +#define TARGET_SIGTRAP 5 +#define TARGET_SIGABRT 6 +#define TARGET_SIGIOT 6 +#define TARGET_SIGSTKFLT 7 /* actually EMT */ +#define TARGET_SIGFPE 8 +#define TARGET_SIGKILL 9 +#define TARGET_SIGBUS 10 +#define TARGET_SIGSEGV 11 +#define TARGET_SIGSYS 12 +#define TARGET_SIGPIPE 13 +#define TARGET_SIGALRM 14 +#define TARGET_SIGTERM 15 +#define TARGET_SIGURG 16 +#define TARGET_SIGSTOP 17 +#define TARGET_SIGTSTP 18 +#define TARGET_SIGCONT 19 +#define TARGET_SIGCHLD 20 +#define TARGET_SIGTTIN 21 +#define TARGET_SIGTTOU 22 +#define TARGET_SIGIO 23 +#define TARGET_SIGXCPU 24 +#define TARGET_SIGXFSZ 25 +#define TARGET_SIGVTALRM 26 +#define TARGET_SIGPROF 27 +#define TARGET_SIGWINCH 28 +#define TARGET_SIGPWR 29 +#define TARGET_SIGUSR1 30 +#define TARGET_SIGUSR2 31 +#define TARGET_SIGRTMIN 32 + +#define TARGET_SIG_BLOCK 0x01 /* for blocking signals */ +#define TARGET_SIG_UNBLOCK 0x02 /* for unblocking signals */ +#define TARGET_SIG_SETMASK 0x04 /* for setting the signal mask */ + +#else #define TARGET_SIGHUP 1 #define TARGET_SIGINT 2 @@ -341,6 +393,8 @@ int do_sigaction(int sig, const struct target_sigaction *act, #define TARGET_SIG_UNBLOCK 1 /* for unblocking signals */ #define TARGET_SIG_SETMASK 2 /* for setting the signal mask */ +#endif + struct target_old_sigaction { target_ulong _sa_handler; target_ulong sa_mask; @@ -359,6 +413,30 @@ typedef union target_sigval { int sival_int; target_ulong sival_ptr; } target_sigval_t; +#if 0 +#if defined (TARGET_SPARC) +typedef struct { + struct { + target_ulong psr; + target_ulong pc; + target_ulong npc; + target_ulong y; + target_ulong u_regs[16]; /* globals and ins */ + } si_regs; + int si_mask; +} __siginfo_t; + +typedef struct { + unsigned long si_float_regs [32]; + unsigned long si_fsr; + unsigned long si_fpqdepth; + struct { + unsigned long *insn_addr; + unsigned long insn; + } si_fpqueue [16]; +} __siginfo_fpu_t; +#endif +#endif #define TARGET_SI_MAX_SIZE 128 #define TARGET_SI_PAD_SIZE ((TARGET_SI_MAX_SIZE/sizeof(int)) - 3) @@ -954,6 +1032,24 @@ struct target_stat64 { #define TARGET_O_NOFOLLOW 0100000 /* don't follow links */ #define TARGET_O_LARGEFILE 0200000 #define TARGET_O_DIRECT 0400000 /* direct disk access hint */ +#elif defined (TARGET_SPARC) +#define TARGET_O_RDONLY 0x0000 +#define TARGET_O_WRONLY 0x0001 +#define TARGET_O_RDWR 0x0002 +#define TARGET_O_ACCMODE 0x0003 +#define TARGET_O_APPEND 0x0008 +#define TARGET_FASYNC 0x0040 /* fcntl, for BSD compatibility */ +#define TARGET_O_CREAT 0x0200 /* not fcntl */ +#define TARGET_O_TRUNC 0x0400 /* not fcntl */ +#define TARGET_O_EXCL 0x0800 /* not fcntl */ +#define TARGET_O_SYNC 0x2000 +#define TARGET_O_NONBLOCK 0x4000 +#define TARGET_O_NDELAY (0x0004 | O_NONBLOCK) +#define TARGET_O_NOCTTY 0x8000 /* not fcntl */ +#define TARGET_O_DIRECTORY 0x10000 /* must be a directory */ +#define TARGET_O_NOFOLLOW 0x20000 /* don't follow links */ +#define TARGET_O_LARGEFILE 0x40000 +#define TARGET_O_DIRECT 0x100000 /* direct disk access hint */ #else #define TARGET_O_ACCMODE 0003 #define TARGET_O_RDONLY 00 |