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