OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [or32/] [kernel/] [signal.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1624 jcastillo
/*
2
 *  linux/arch/ppc/kernel/signal.c
3
 *
4
 *  Copyright (C) 1991, 1992  Linus Torvalds
5
 *  Adapted for PowerPC by Gary Thomas
6
 */
7
 
8
#include <linux/config.h>
9
 
10
#include <linux/sched.h>
11
#include <linux/mm.h>
12
#include <linux/kernel.h>
13
#include <linux/signal.h>
14
#include <linux/errno.h>
15
#include <linux/wait.h>
16
#include <linux/ptrace.h>
17
#include <linux/unistd.h>
18
 
19
#include <asm/segment.h>
20
#include <asm/pgtable.h>
21
#include <asm/traps.h>
22
 
23
/*
24
#define DEBUG
25
*/
26
 
27
#define offsetof(type, member)  ((size_t)(&((type *)0)->member))
28
 
29
#define _S(nr) (1<<((nr)-1))
30
 
31
#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
32
 
33
asmlinkage int sys_waitpid(pid_t pid,unsigned long * stat_addr, int options);
34
asmlinkage int do_signal(unsigned long oldmask, struct pt_regs *regs);
35
 
36
/*
37
 * atomically swap in the new signal mask, and wait for a signal.
38
 */
39
asmlinkage int sys_sigsuspend(unsigned long set, int p2, int p3, int p4, int p6, int p7, struct pt_regs *regs)
40
{
41
        unsigned long mask;
42
 
43
        mask = current->blocked;
44
        current->blocked = set & _BLOCKABLE;
45
        regs->gprs[1] = -EINTR;
46
#if 0
47
printk("Task: %x[%d] - SIGSUSPEND at %x, Mask: %x\n", current, current->pid, regs->nip,
48
set);
49
#endif
50
        while (1) {
51
                current->state = TASK_INTERRUPTIBLE;
52
                schedule();
53
                if (do_signal(mask,regs))
54
                        return -EINTR;
55
        }
56
}
57
 
58
/*
59
 * This sets regs->esp even though we don't actually use sigstacks yet..
60
 */
61
asmlinkage int sys_sigreturn(struct pt_regs *regs)
62
{
63
        struct sigcontext_struct *sc;
64
        struct pt_regs *int_regs;
65
        int signo;
66
        sc = (struct sigcontext_struct *)regs->sp;
67
        current->blocked = sc->oldmask & _BLOCKABLE;
68
        int_regs = sc->regs;
69
        signo = sc->signal;
70
        sc++;  /* Pop signal 'context' */
71
        if (sc == (struct sigcontext_struct *)(int_regs))
72
        { /* Last stacked signal */
73
                int i;
74
#if 1
75
                memcpy(regs, int_regs, sizeof(*regs));
76
#else
77
                /* Don't mess up 'my' stack frame */
78
                for(i = 0; i < 30; i++)
79
                        if(i != 7)
80
                                regs->gprs[i] = int_regs->gprs[i];
81
                regs->sp = int_regs->sp;
82
#endif          
83
                if ((int)regs->orig_gpr3 >= 0 &&
84
                    ((int)regs->result == -ERESTARTNOHAND ||
85
                     (int)regs->result == -ERESTARTSYS ||
86
                     (int)regs->result == -ERESTARTNOINTR))
87
                {
88
                        regs->gprs[1] = regs->orig_gpr3;
89
                        regs->pc -= 8; /* Back up & retry system call */
90
                        regs->result = 0;
91
                }
92
                return (regs->result);
93
        } else
94
        { /* More signals to go */
95
                regs->sp = (unsigned long)sc;
96
                regs->gprs[1] = sc->signal;     /* r3 */
97
                regs->gprs[2] = (unsigned long)sc->regs;        /* r4 */
98
                regs->gprs[7] = (unsigned long)((sc->regs)+1);  /* r9 - link register */
99
                regs->pc = sc->handler;
100
                return (sc->signal);
101
        }
102
}
103
 
104
/*
105
 * Note that 'init' is a special process: it doesn't get signals it doesn't
106
 * want to handle. Thus you cannot kill init even with a SIGKILL even by
107
 * mistake.
108
 *
109
 * Note that we go through the signals twice: once to check the signals that
110
 * the kernel can handle, and then we build all the user-level signal handling
111
 * stack-frames in one go after that.
112
 */
113
asmlinkage int do_signal(unsigned long oldmask, struct pt_regs * regs)
114
{
115
        unsigned long mask = ~current->blocked;
116
        unsigned long handler_signal = 0;
117
        unsigned long *frame = NULL;
118
        unsigned long *trampoline;
119
        unsigned long *regs_ptr;
120
        unsigned long nip = 0;
121
        unsigned long signr;
122
        int bitno;
123
        struct sigcontext_struct *sc;
124
        struct sigaction * sa;
125
        unsigned long flags;
126
 
127
        save_flags(flags);
128
        cli();
129
 
130
        while ((signr = current->signal & mask)) {
131
#if 0
132
                signr = ffz(~signr);  /* Compute bit # */
133
#else
134
                for (bitno = 0;  bitno < 32;  bitno++)
135
                {
136
                        if (signr & (1<<bitno)) break;
137
                }
138
                signr = bitno;
139
#endif
140
                current->signal &= ~(1<<signr);  /* Clear bit */
141
                sa = current->sig->action + signr;
142
                signr++;
143
                if ((current->flags & PF_PTRACED) && signr != SIGKILL) {
144
                        current->exit_code = signr;
145
                        current->state = TASK_STOPPED;
146
                        notify_parent(current, SIGCHLD);
147
                        schedule();
148
                        if (!(signr = current->exit_code))
149
                                continue;
150
                        current->exit_code = 0;
151
                        if (signr == SIGSTOP)
152
                                continue;
153
                        if (_S(signr) & current->blocked) {
154
                                current->signal |= _S(signr);
155
                                continue;
156
                        }
157
                        sa = current->sig->action + signr - 1;
158
                }
159
                if (sa->sa_handler == SIG_IGN) {
160
                        if (signr != SIGCHLD)
161
                                continue;
162
                        /* check for SIGCHLD: it's special */
163
                        while (sys_waitpid(-1,NULL,WNOHANG) > 0)
164
                                /* nothing */;
165
                        continue;
166
                }
167
                if (sa->sa_handler == SIG_DFL) {
168
                        if (current->pid == 1)
169
                                continue;
170
                        switch (signr) {
171
                        case SIGCONT: case SIGCHLD: case SIGWINCH:
172
                                continue;
173
 
174
                        case SIGSTOP: case SIGTSTP: case SIGTTIN: case SIGTTOU:
175
                                if (current->flags & PF_PTRACED)
176
                                        continue;
177
                                current->state = TASK_STOPPED;
178
                                current->exit_code = signr;
179
                                if (!(current->p_pptr->sig->action[SIGCHLD-1].sa_flags &
180
                                                SA_NOCLDSTOP))
181
                                        notify_parent(current, SIGCHLD);
182
                                schedule();
183
                                continue;
184
 
185
                        case SIGQUIT: case SIGILL: case SIGTRAP:
186
                        case SIGIOT: case SIGFPE: case SIGSEGV:
187
                                if (current->binfmt && current->binfmt->core_dump) {
188
                                        if (current->binfmt->core_dump(signr, regs))
189
                                                signr |= 0x80;
190
                                }
191
                                /* fall through */
192
                        default:
193
                                current->signal |= _S(signr & 0x7f);
194
                                do_exit(signr);
195
                        }
196
                }
197
                /*
198
                 * OK, we're invoking a handler
199
                 */
200
                if ((int)regs->orig_gpr3 >= 0) {
201
                        if ((int)regs->result == -ERESTARTNOHAND ||
202
                           ((int)regs->result == -ERESTARTSYS && !(sa->sa_flags & SA_RESTART)))
203
                                (int)regs->result = -EINTR;
204
                }
205
                handler_signal |= 1 << (signr-1);
206
                mask &= ~sa->sa_mask;
207
        }
208
        if (!handler_signal)            /* no handler will be called - return 0 */
209
        {
210
                restore_flags(flags);
211
                return 0;
212
        }
213
        nip = regs->pc;
214
        frame = (unsigned long *) regs->sp;
215
        /* Build trampoline code on stack */
216
        frame -= 3;
217
        trampoline = frame;
218
        trampoline[0] = 0x9d607777;  /* l.addi r11,r0,0x7777 */
219
        trampoline[1] = 0x20000001;  /* l.sys  1 */
220
        trampoline[2] = 0x15000000;  /* l.nop  0 */
221
        frame -= sizeof(*regs) / sizeof(long);
222
        regs_ptr = frame;
223
        memcpy(regs_ptr, regs, sizeof(*regs));
224
        signr = 1;
225
        sa = current->sig->action;
226
        for (mask = 1 ; mask ; sa++,signr++,mask += mask) {
227
                if (mask > handler_signal)
228
                        break;
229
                if (!(mask & handler_signal))
230
                        continue;
231
                frame -= sizeof(struct sigcontext_struct) / sizeof(long);
232
                sc = (struct sigcontext_struct *)frame;
233
                nip = (unsigned long) sa->sa_handler;
234
#if 0 /* Old compiler */                
235
                nip = *(unsigned long *)nip;
236
#endif          
237
                if (sa->sa_flags & SA_ONESHOT)
238
                        sa->sa_handler = NULL;
239
                sc->handler = nip;
240
                sc->oldmask = current->blocked;
241
                sc->regs = (struct pt_regs *)regs_ptr;
242
                sc->signal = signr;
243
                current->blocked |= sa->sa_mask;
244
                regs->gprs[1] = signr; /* r3 = signr */
245
                regs->gprs[2] = (unsigned long)regs_ptr; /* r4 = regs_ptr */
246
        }
247
        regs->gprs[7] = (unsigned long)trampoline; /* r9 = trampoline (r9 is link register) */
248
        regs->pc = nip;
249
        regs->sp = (unsigned long)sc;
250
        /* The DATA cache must be flushed here to insure coherency */
251
        /* between the DATA & INSTRUCTION caches.  Since we just */
252
        /* created an instruction stream using the DATA [cache] space */
253
        /* and since the instruction cache will not look in the DATA */
254
        /* cache for new data, we have to force the data to go on to */
255
        /* memory and flush the instruction cache to force it to look */
256
        /* there.  The following function performs this magic */
257
#if ICACHE
258
        ic_invalidate();
259
#endif
260
        restore_flags(flags);
261
        return 1;
262
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.