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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [arch/] [ppc/] [kernel/] [signal.c] - Blame information for rev 199

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

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

powered by: WebSVN 2.1.0

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