upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / arch / mips / kernel / irixsig.c
1 /*
2  * irixsig.c: WHEEE, IRIX signals!  YOW, am I compatible or what?!?!
3  *
4  * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5  * Copyright (C) 1997 - 2000 Ralf Baechle (ralf@gnu.org)
6  * Copyright (C) 2000 Silicon Graphics, Inc.
7  */
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/mm.h>
11 #include <linux/errno.h>
12 #include <linux/smp.h>
13 #include <linux/smp_lock.h>
14 #include <linux/time.h>
15 #include <linux/ptrace.h>
16 #include <linux/suspend.h>
17
18 #include <asm/ptrace.h>
19 #include <asm/uaccess.h>
20
21 #undef DEBUG_SIG
22
23 #define _S(nr) (1<<((nr)-1))
24
25 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
26
27 typedef struct {
28         unsigned long sig[4];
29 } irix_sigset_t;
30
31 struct sigctx_irix5 {
32         u32 rmask, cp0_status;
33         u64 pc;
34         u64 regs[32];
35         u64 fpregs[32];
36         u32 usedfp, fpcsr, fpeir, sstk_flags;
37         u64 hi, lo;
38         u64 cp0_cause, cp0_badvaddr, _unused0;
39         irix_sigset_t sigset;
40         u64 weird_fpu_thing;
41         u64 _unused1[31];
42 };
43
44 #ifdef DEBUG_SIG
45 /* Debugging */
46 static inline void dump_irix5_sigctx(struct sigctx_irix5 *c)
47 {
48         int i;
49
50         printk("misc: rmask[%08lx] status[%08lx] pc[%08lx]\n",
51                (unsigned long) c->rmask,
52                (unsigned long) c->cp0_status,
53                (unsigned long) c->pc);
54         printk("regs: ");
55         for(i = 0; i < 16; i++)
56                 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
57         printk("\nregs: ");
58         for(i = 16; i < 32; i++)
59                 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
60         printk("\nfpregs: ");
61         for(i = 0; i < 16; i++)
62                 printk("[%d]<%08lx> ", i, (unsigned long) c->fpregs[i]);
63         printk("\nfpregs: ");
64         for(i = 16; i < 32; i++)
65                 printk("[%d]<%08lx> ", i, (unsigned long) c->fpregs[i]);
66         printk("misc: usedfp[%d] fpcsr[%08lx] fpeir[%08lx] stk_flgs[%08lx]\n",
67                (int) c->usedfp, (unsigned long) c->fpcsr,
68                (unsigned long) c->fpeir, (unsigned long) c->sstk_flags);
69         printk("misc: hi[%08lx] lo[%08lx] cause[%08lx] badvaddr[%08lx]\n",
70                (unsigned long) c->hi, (unsigned long) c->lo,
71                (unsigned long) c->cp0_cause, (unsigned long) c->cp0_badvaddr);
72         printk("misc: sigset<0>[%08lx] sigset<1>[%08lx] sigset<2>[%08lx] "
73                "sigset<3>[%08lx]\n", (unsigned long) c->sigset.sig[0],
74                (unsigned long) c->sigset.sig[1],
75                (unsigned long) c->sigset.sig[2],
76                (unsigned long) c->sigset.sig[3]);
77 }
78 #endif
79
80 static void setup_irix_frame(struct k_sigaction *ka, struct pt_regs *regs,
81                              int signr, sigset_t *oldmask)
82 {
83         unsigned long sp;
84         struct sigctx_irix5 *ctx;
85         int i;
86
87         sp = regs->regs[29];
88         sp -= sizeof(struct sigctx_irix5);
89         sp &= ~(0xf);
90         ctx = (struct sigctx_irix5 *) sp;
91         if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
92                 goto segv_and_exit;
93
94         __put_user(0, &ctx->weird_fpu_thing);
95         __put_user(~(0x00000001), &ctx->rmask);
96         __put_user(0, &ctx->regs[0]);
97         for(i = 1; i < 32; i++)
98                 __put_user((u64) regs->regs[i], &ctx->regs[i]);
99
100         __put_user((u64) regs->hi, &ctx->hi);
101         __put_user((u64) regs->lo, &ctx->lo);
102         __put_user((u64) regs->cp0_epc, &ctx->pc);
103         __put_user(current->used_math, &ctx->usedfp);
104         __put_user((u64) regs->cp0_cause, &ctx->cp0_cause);
105         __put_user((u64) regs->cp0_badvaddr, &ctx->cp0_badvaddr);
106
107         __put_user(0, &ctx->sstk_flags); /* XXX sigstack unimp... todo... */
108
109         __copy_to_user(&ctx->sigset, oldmask, sizeof(irix_sigset_t));
110
111 #ifdef DEBUG_SIG
112         dump_irix5_sigctx(ctx);
113 #endif
114
115         regs->regs[4] = (unsigned long) signr;
116         regs->regs[5] = 0; /* XXX sigcode XXX */
117         regs->regs[6] = regs->regs[29] = sp;
118         regs->regs[7] = (unsigned long) ka->sa.sa_handler;
119         regs->regs[25] = regs->cp0_epc = (unsigned long) ka->sa_restorer;
120
121         return;
122
123 segv_and_exit:
124         force_sigsegv(signr, current);
125 }
126
127 static void inline
128 setup_irix_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
129                int signr, sigset_t *oldmask, siginfo_t *info)
130 {
131         printk("Aiee: setup_tr_frame wants to be written");
132         do_exit(SIGSEGV);
133 }
134
135 static inline void handle_signal(unsigned long sig, siginfo_t *info,
136         struct k_sigaction *ka, sigset_t *oldset, struct pt_regs * regs)
137 {
138         switch(regs->regs[0]) {
139         case ERESTARTNOHAND:
140                 regs->regs[2] = EINTR;
141                 break;
142         case ERESTARTSYS:
143                 if(!(ka->sa.sa_flags & SA_RESTART)) {
144                         regs->regs[2] = EINTR;
145                         break;
146                 }
147         /* fallthrough */
148         case ERESTARTNOINTR:            /* Userland will reload $v0.  */
149                 regs->cp0_epc -= 8;
150         }
151
152         regs->regs[0] = 0;              /* Don't deal with this again.  */
153
154         if (ka->sa.sa_flags & SA_SIGINFO)
155                 setup_irix_rt_frame(ka, regs, sig, oldset, info);
156         else
157                 setup_irix_frame(ka, regs, sig, oldset);
158
159         if (!(ka->sa.sa_flags & SA_NODEFER)) {
160                 spin_lock_irq(&current->sighand->siglock);
161                 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
162                 sigaddset(&current->blocked,sig);
163                 recalc_sigpending();
164                 spin_unlock_irq(&current->sighand->siglock);
165         }
166 }
167
168 asmlinkage int do_irix_signal(sigset_t *oldset, struct pt_regs *regs)
169 {
170         struct k_sigaction ka;
171         siginfo_t info;
172         int signr;
173
174         /*
175          * We want the common case to go fast, which is why we may in certain
176          * cases get here from kernel mode. Just return without doing anything
177          * if so.
178          */
179         if (!user_mode(regs))
180                 return 1;
181
182         if (current->flags & PF_FREEZE) {
183                 refrigerator(0);
184                 goto no_signal;
185         }
186
187         if (!oldset)
188                 oldset = &current->blocked;
189
190         signr = get_signal_to_deliver(&info, &ka, regs, NULL);
191         if (signr > 0) {
192                 handle_signal(signr, &info, &ka, oldset, regs);
193                 return 1;
194         }
195
196 no_signal:
197         /*
198          * Who's code doesn't conform to the restartable syscall convention
199          * dies here!!!  The li instruction, a single machine instruction,
200          * must directly be followed by the syscall instruction.
201          */
202         if (regs->regs[0]) {
203                 if (regs->regs[2] == ERESTARTNOHAND ||
204                     regs->regs[2] == ERESTARTSYS ||
205                     regs->regs[2] == ERESTARTNOINTR) {
206                         regs->cp0_epc -= 8;
207                 }
208         }
209         return 0;
210 }
211
212 asmlinkage void
213 irix_sigreturn(struct pt_regs *regs)
214 {
215         struct sigctx_irix5 *context, *magic;
216         unsigned long umask, mask;
217         u64 *fregs;
218         int sig, i, base = 0;
219         sigset_t blocked;
220
221         /* Always make any pending restarted system calls return -EINTR */
222         current_thread_info()->restart_block.fn = do_no_restart_syscall;
223
224         if (regs->regs[2] == 1000)
225                 base = 1;
226
227         context = (struct sigctx_irix5 *) regs->regs[base + 4];
228         magic = (struct sigctx_irix5 *) regs->regs[base + 5];
229         sig = (int) regs->regs[base + 6];
230 #ifdef DEBUG_SIG
231         printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
232                current->comm, current->pid, context, magic, sig);
233 #endif
234         if (!context)
235                 context = magic;
236         if (!access_ok(VERIFY_READ, context, sizeof(struct sigctx_irix5)))
237                 goto badframe;
238
239 #ifdef DEBUG_SIG
240         dump_irix5_sigctx(context);
241 #endif
242
243         __get_user(regs->cp0_epc, &context->pc);
244         umask = context->rmask; mask = 2;
245         for (i = 1; i < 32; i++, mask <<= 1) {
246                 if(umask & mask)
247                         __get_user(regs->regs[i], &context->regs[i]);
248         }
249         __get_user(regs->hi, &context->hi);
250         __get_user(regs->lo, &context->lo);
251
252         if ((umask & 1) && context->usedfp) {
253                 fregs = (u64 *) &current->thread.fpu;
254                 for(i = 0; i < 32; i++)
255                         fregs[i] = (u64) context->fpregs[i];
256                 __get_user(current->thread.fpu.hard.fcr31, &context->fpcsr);
257         }
258
259         /* XXX do sigstack crapola here... XXX */
260
261         if (__copy_from_user(&blocked, &context->sigset, sizeof(blocked)))
262                 goto badframe;
263
264         sigdelsetmask(&blocked, ~_BLOCKABLE);
265         spin_lock_irq(&current->sighand->siglock);
266         current->blocked = blocked;
267         recalc_sigpending();
268         spin_unlock_irq(&current->sighand->siglock);
269
270         /*
271          * Don't let your children do this ...
272          */
273         if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
274                 do_syscall_trace(regs, 1);
275         __asm__ __volatile__(
276                 "move\t$29,%0\n\t"
277                 "j\tsyscall_exit"
278                 :/* no outputs */
279                 :"r" (&regs));
280                 /* Unreached */
281
282 badframe:
283         force_sig(SIGSEGV, current);
284 }
285
286 struct sigact_irix5 {
287         int flags;
288         void (*handler)(int);
289         u32 sigset[4];
290         int _unused0[2];
291 };
292
293 #ifdef DEBUG_SIG
294 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
295 {
296         printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
297                (unsigned long) p->handler,
298                (unsigned long) p->sigset[0]);
299 }
300 #endif
301
302 asmlinkage int
303 irix_sigaction(int sig, const struct sigaction *act,
304               struct sigaction *oact, void *trampoline)
305 {
306         struct k_sigaction new_ka, old_ka;
307         int ret;
308
309 #ifdef DEBUG_SIG
310         printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
311                (!old ? "0" : "OLD"), trampoline);
312         if(new) {
313                 dump_sigact_irix5(new); printk(" ");
314         }
315 #endif
316         if (act) {
317                 sigset_t mask;
318                 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
319                     __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
320                     __get_user(new_ka.sa.sa_flags, &act->sa_flags))
321                         return -EFAULT;
322
323                 __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t));
324
325                 /*
326                  * Hmmm... methinks IRIX libc always passes a valid trampoline
327                  * value for all invocations of sigaction.  Will have to
328                  * investigate.  POSIX POSIX, die die die...
329                  */
330                 new_ka.sa_restorer = trampoline;
331         }
332
333 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
334         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
335
336         if (!ret && oact) {
337                 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
338                     __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
339                     __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
340                         return -EFAULT;
341                 __copy_to_user(&old_ka.sa.sa_mask, &oact->sa_mask,
342                                sizeof(sigset_t));
343         }
344
345         return ret;
346 }
347
348 asmlinkage int irix_sigpending(irix_sigset_t *set)
349 {
350         return do_sigpending(set, sizeof(*set));
351 }
352
353 asmlinkage int irix_sigprocmask(int how, irix_sigset_t *new, irix_sigset_t *old)
354 {
355         sigset_t oldbits, newbits;
356         int error;
357
358         if (new) {
359                 error = verify_area(VERIFY_READ, new, sizeof(*new));
360                 if (error)
361                         return error;
362                 __copy_from_user(&newbits, new, sizeof(unsigned long)*4);
363                 sigdelsetmask(&newbits, ~_BLOCKABLE);
364
365                 spin_lock_irq(&current->sighand->siglock);
366                 oldbits = current->blocked;
367
368                 switch(how) {
369                 case 1:
370                         sigorsets(&newbits, &oldbits, &newbits);
371                         break;
372
373                 case 2:
374                         sigandsets(&newbits, &oldbits, &newbits);
375                         break;
376
377                 case 3:
378                         break;
379
380                 case 256:
381                         siginitset(&newbits, newbits.sig[0]);
382                         break;
383
384                 default:
385                         return -EINVAL;
386                 }
387                 recalc_sigpending();
388                 spin_unlock_irq(&current->sighand->siglock);
389         }
390         if(old) {
391                 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
392                 if(error)
393                         return error;
394                 __copy_to_user(old, &current->blocked, sizeof(unsigned long)*4);
395         }
396
397         return 0;
398 }
399
400 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
401 {
402         sigset_t *uset, saveset, newset;
403
404         uset = (sigset_t *) regs->regs[4];
405         if (copy_from_user(&newset, uset, sizeof(sigset_t)))
406                 return -EFAULT;
407         sigdelsetmask(&newset, ~_BLOCKABLE);
408
409         spin_lock_irq(&current->sighand->siglock);
410         saveset = current->blocked;
411         current->blocked = newset;
412         recalc_sigpending();
413         spin_unlock_irq(&current->sighand->siglock);
414
415         regs->regs[2] = -EINTR;
416         while (1) {
417                 current->state = TASK_INTERRUPTIBLE;
418                 schedule();
419                 if (do_irix_signal(&saveset, regs))
420                         return -EINTR;
421         }
422 }
423
424 /* hate hate hate... */
425 struct irix5_siginfo {
426         int sig, code, error;
427         union {
428                 char unused[128 - (3 * 4)]; /* Safety net. */
429                 struct {
430                         int pid;
431                         union {
432                                 int uid;
433                                 struct {
434                                         int utime, status, stime;
435                                 } child;
436                         } procdata;
437                 } procinfo;
438
439                 unsigned long fault_addr;
440
441                 struct {
442                         int fd;
443                         long band;
444                 } fileinfo;
445
446                 unsigned long sigval;
447         } stuff;
448 };
449
450 static inline unsigned long timespectojiffies(struct timespec *value)
451 {
452         unsigned long sec = (unsigned) value->tv_sec;
453         long nsec = value->tv_nsec;
454
455         if (sec > (LONG_MAX / HZ))
456                 return LONG_MAX;
457         nsec += 1000000000L / HZ - 1;
458         nsec /= 1000000000L / HZ;
459         return HZ * sec + nsec;
460 }
461
462 asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
463                                 struct timespec *tp)
464 {
465         long expire = MAX_SCHEDULE_TIMEOUT;
466         sigset_t kset;
467         int i, sig, error, timeo = 0;
468
469 #ifdef DEBUG_SIG
470         printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
471                current->comm, current->pid, set, info, tp);
472 #endif
473
474         /* Must always specify the signal set. */
475         if(!set)
476                 return -EINVAL;
477
478         error = verify_area(VERIFY_READ, set, sizeof(kset));
479         if (error)
480                 goto out;
481
482         __copy_from_user(&kset, set, sizeof(set));
483         if (error)
484                 goto out;
485
486         if (info && clear_user(info, sizeof(*info))) {
487                 error = -EFAULT;
488                 goto out;
489         }
490
491         if(tp) {
492                 error = verify_area(VERIFY_READ, tp, sizeof(*tp));
493                 if(error)
494                         return error;
495                 if(!tp->tv_sec && !tp->tv_nsec) {
496                         error = -EINVAL;
497                         goto out;
498                 }
499                 expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec);
500         }
501
502         while(1) {
503                 long tmp = 0;
504
505                 current->state = TASK_INTERRUPTIBLE;
506                 expire = schedule_timeout(expire);
507
508                 for (i=0; i<=4; i++)
509                         tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
510
511                 if (tmp)
512                         break;
513                 if (!expire) {
514                         timeo = 1;
515                         break;
516                 }
517                 if (signal_pending(current))
518                         return -EINTR;
519         }
520         if (timeo)
521                 return -EAGAIN;
522
523         for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
524                 if (sigismember (&kset, sig))
525                         continue;
526                 if (sigismember (&current->pending.signal, sig)) {
527                         /* XXX need more than this... */
528                         if (info)
529                                 info->sig = sig;
530                         error = 0;
531                         goto out;
532                 }
533         }
534
535         /* Should not get here, but do something sane if we do. */
536         error = -EINTR;
537
538 out:
539         return error;
540 }
541
542 /* This is here because of irix5_siginfo definition. */
543 #define IRIX_P_PID    0
544 #define IRIX_P_PGID   2
545 #define IRIX_P_ALL    7
546
547 extern int getrusage(struct task_struct *, int, struct rusage __user *);
548
549 #define W_EXITED     1
550 #define W_TRAPPED    2
551 #define W_STOPPED    4
552 #define W_CONT       8
553 #define W_NOHANG    64
554
555 #define W_MASK      (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
556
557 asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
558                             int options, struct rusage *ru)
559 {
560         int flag, retval;
561         DECLARE_WAITQUEUE(wait, current);
562         struct task_struct *tsk;
563         struct task_struct *p;
564         struct list_head *_p;
565
566         if (!info) {
567                 retval = -EINVAL;
568                 goto out;
569         }
570         retval = verify_area(VERIFY_WRITE, info, sizeof(*info));
571         if(retval)
572                 goto out;
573         if (ru) {
574                 retval = verify_area(VERIFY_WRITE, ru, sizeof(*ru));
575                 if(retval)
576                         goto out;
577         }
578         if (options & ~(W_MASK)) {
579                 retval = -EINVAL;
580                 goto out;
581         }
582         if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL) {
583                 retval = -EINVAL;
584                 goto out;
585         }
586         add_wait_queue(&current->wait_chldexit, &wait);
587 repeat:
588         flag = 0;
589         current->state = TASK_INTERRUPTIBLE;
590         read_lock(&tasklist_lock);
591         tsk = current;
592         list_for_each(_p,&tsk->children) {
593                 p = list_entry(_p,struct task_struct,sibling);
594                 if ((type == IRIX_P_PID) && p->pid != pid)
595                         continue;
596                 if ((type == IRIX_P_PGID) && process_group(p) != pid)
597                         continue;
598                 if ((p->exit_signal != SIGCHLD))
599                         continue;
600                 flag = 1;
601                 switch (p->state) {
602                 case TASK_STOPPED:
603                         if (!p->exit_code)
604                                 continue;
605                         if (!(options & (W_TRAPPED|W_STOPPED)) &&
606                             !(p->ptrace & PT_PTRACED))
607                                 continue;
608                         read_unlock(&tasklist_lock);
609
610                         /* move to end of parent's list to avoid starvation */
611                         write_lock_irq(&tasklist_lock);
612                         remove_parent(p);
613                         add_parent(p, p->parent);
614                         write_unlock_irq(&tasklist_lock);
615                         retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
616                         if (!retval && ru) {
617                                 retval |= __put_user(SIGCHLD, &info->sig);
618                                 retval |= __put_user(0, &info->code);
619                                 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
620                                 retval |= __put_user((p->exit_code >> 8) & 0xff,
621                                            &info->stuff.procinfo.procdata.child.status);
622                                 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
623                                 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
624                         }
625                         if (!retval) {
626                                 p->exit_code = 0;
627                         }
628                         goto end_waitsys;
629
630                 case TASK_ZOMBIE:
631                         current->signal->cutime += p->utime + p->signal->cutime;
632                         current->signal->cstime += p->stime + p->signal->cstime;
633                         if (ru != NULL)
634                                 getrusage(p, RUSAGE_BOTH, ru);
635                         __put_user(SIGCHLD, &info->sig);
636                         __put_user(1, &info->code);      /* CLD_EXITED */
637                         __put_user(p->pid, &info->stuff.procinfo.pid);
638                         __put_user((p->exit_code >> 8) & 0xff,
639                                    &info->stuff.procinfo.procdata.child.status);
640                         __put_user(p->utime,
641                                    &info->stuff.procinfo.procdata.child.utime);
642                         __put_user(p->stime,
643                                    &info->stuff.procinfo.procdata.child.stime);
644                         retval = 0;
645                         if (p->real_parent != p->parent) {
646                                 write_lock_irq(&tasklist_lock);
647                                 remove_parent(p);
648                                 p->parent = p->real_parent;
649                                 add_parent(p, p->parent);
650                                 do_notify_parent(p, SIGCHLD);
651                                 write_unlock_irq(&tasklist_lock);
652                         } else
653                                 release_task(p);
654                         goto end_waitsys;
655                 default:
656                         continue;
657                 }
658                 tsk = next_thread(tsk);
659         }
660         read_unlock(&tasklist_lock);
661         if (flag) {
662                 retval = 0;
663                 if (options & W_NOHANG)
664                         goto end_waitsys;
665                 retval = -ERESTARTSYS;
666                 if (signal_pending(current))
667                         goto end_waitsys;
668                 current->state = TASK_INTERRUPTIBLE;
669                 schedule();
670                 goto repeat;
671         }
672         retval = -ECHILD;
673 end_waitsys:
674         current->state = TASK_RUNNING;
675         remove_wait_queue(&current->wait_chldexit, &wait);
676
677 out:
678         return retval;
679 }
680
681 struct irix5_context {
682         u32 flags;
683         u32 link;
684         u32 sigmask[4];
685         struct { u32 sp, size, flags; } stack;
686         int regs[36];
687         u32 fpregs[32];
688         u32 fpcsr;
689         u32 _unused0;
690         u32 _unused1[47];
691         u32 weird_graphics_thing;
692 };
693
694 asmlinkage int irix_getcontext(struct pt_regs *regs)
695 {
696         int error, i, base = 0;
697         struct irix5_context *ctx;
698         unsigned long flags;
699
700         if (regs->regs[2] == 1000)
701                 base = 1;
702         ctx = (struct irix5_context *) regs->regs[base + 4];
703
704 #ifdef DEBUG_SIG
705         printk("[%s:%d] irix_getcontext(%p)\n",
706                current->comm, current->pid, ctx);
707 #endif
708
709         error = verify_area(VERIFY_WRITE, ctx, sizeof(*ctx));
710         if(error)
711                 goto out;
712         __put_user(current->thread.irix_oldctx, &ctx->link);
713
714         __copy_to_user(&ctx->sigmask, &current->blocked, sizeof(irix_sigset_t));
715
716         /* XXX Do sigstack stuff someday... */
717         __put_user(0, &ctx->stack.sp);
718         __put_user(0, &ctx->stack.size);
719         __put_user(0, &ctx->stack.flags);
720
721         __put_user(0, &ctx->weird_graphics_thing);
722         __put_user(0, &ctx->regs[0]);
723         for (i = 1; i < 32; i++)
724                 __put_user(regs->regs[i], &ctx->regs[i]);
725         __put_user(regs->lo, &ctx->regs[32]);
726         __put_user(regs->hi, &ctx->regs[33]);
727         __put_user(regs->cp0_cause, &ctx->regs[34]);
728         __put_user(regs->cp0_epc, &ctx->regs[35]);
729
730         flags = 0x0f;
731         if(!current->used_math) {
732                 flags &= ~(0x08);
733         } else {
734                 /* XXX wheee... */
735                 printk("Wheee, no code for saving IRIX FPU context yet.\n");
736         }
737         __put_user(flags, &ctx->flags);
738         error = 0;
739
740 out:
741         return error;
742 }
743
744 asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
745 {
746         int error, base = 0;
747         struct irix5_context *ctx;
748
749         if(regs->regs[2] == 1000)
750                 base = 1;
751         ctx = (struct irix5_context *) regs->regs[base + 4];
752
753 #ifdef DEBUG_SIG
754         printk("[%s:%d] irix_setcontext(%p)\n",
755                current->comm, current->pid, ctx);
756 #endif
757
758         error = verify_area(VERIFY_READ, ctx, sizeof(*ctx));
759         if (error)
760                 goto out;
761
762         if (ctx->flags & 0x02) {
763                 /* XXX sigstack garbage, todo... */
764                 printk("Wheee, cannot do sigstack stuff in setcontext\n");
765         }
766
767         if (ctx->flags & 0x04) {
768                 int i;
769
770                 /* XXX extra control block stuff... todo... */
771                 for(i = 1; i < 32; i++)
772                         regs->regs[i] = ctx->regs[i];
773                 regs->lo = ctx->regs[32];
774                 regs->hi = ctx->regs[33];
775                 regs->cp0_epc = ctx->regs[35];
776         }
777
778         if (ctx->flags & 0x08) {
779                 /* XXX fpu context, blah... */
780                 printk("Wheee, cannot restore FPU context yet...\n");
781         }
782         current->thread.irix_oldctx = ctx->link;
783         error = regs->regs[2];
784
785 out:
786         return error;
787 }
788
789 struct irix_sigstack { unsigned long sp; int status; };
790
791 asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
792 {
793         int error;
794
795 #ifdef DEBUG_SIG
796         printk("[%s:%d] irix_sigstack(%p,%p)\n",
797                current->comm, current->pid, new, old);
798 #endif
799         if(new) {
800                 error = verify_area(VERIFY_READ, new, sizeof(*new));
801                 if(error)
802                         goto out;
803         }
804
805         if(old) {
806                 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
807                 if(error)
808                         goto out;
809         }
810         error = 0;
811
812 out:
813         return error;
814 }
815
816 struct irix_sigaltstack { unsigned long sp; int size; int status; };
817
818 asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
819                                 struct irix_sigaltstack *old)
820 {
821         int error;
822
823 #ifdef DEBUG_SIG
824         printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
825                current->comm, current->pid, new, old);
826 #endif
827         if (new) {
828                 error = verify_area(VERIFY_READ, new, sizeof(*new));
829                 if(error)
830                         goto out;
831         }
832
833         if (old) {
834                 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
835                 if(error)
836                         goto out;
837         }
838         error = 0;
839
840 out:
841         error = 0;
842
843         return error;
844 }
845
846 struct irix_procset {
847         int cmd, ltype, lid, rtype, rid;
848 };
849
850 asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
851 {
852         int error;
853
854         error = verify_area(VERIFY_READ, pset, sizeof(*pset));
855         if(error)
856                 goto out;
857 #ifdef DEBUG_SIG
858         printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
859                current->comm, current->pid,
860                pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,
861                sig);
862 #endif
863         error = -EINVAL;
864
865 out:
866         return error;
867 }