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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [i960/] [kernel/] [syscall.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1623 jcastillo
/*
2
 *   FILE: syscall.c
3
 * AUTHOR: kma
4
 *  DESCR: High-level system call path.
5
 */
6
 
7
#ident "$Id: syscall.c,v 1.1 2005-12-20 09:42:38 jcastillo Exp $"
8
#include <linux/sched.h>
9
#include <linux/mm.h>
10
#include <linux/sem.h>
11
#include <linux/msg.h>
12
#include <linux/shm.h>
13
 
14
#include <asm/unistd.h>
15
#include <asm/cachectl.h>
16
#include <asm/dprintk.h>
17
#include <asm/mman.h>
18
 
19
#ifdef DEBUG
20
#define CHECK_STACK() \
21
do { \
22
        unsigned long sp;       \
23
        \
24
        __asm__ __volatile__("mov sp, %0" : "=r"(sp));  \
25
        if (current->pid        \
26
            && (!(sp > current->kernel_stack_page       \
27
             && sp < (current->kernel_stack_page + PAGE_SIZE))))        \
28
                panic("bad ksp: 0x%8x\ncurrent ksp: 0x%8x", sp, \
29
                      current->kernel_stack_page);      \
30
} while(0)
31
#else
32
#define CHECK_STACK() \
33
do { } while (0)
34
#endif
35
 
36
extern void system_break(void);
37
extern int (*syscall_tab[])(int, int, int, int, int);
38
static int sys_mmap(struct pt_regs* regs);
39
 
40
asmlinkage void
41
csyscall(struct pt_regs* regs)
42
{
43
        unsigned long   num = regs->gregs[13];
44
        extern void stack_trace(void);
45
        extern void leave_kernel(struct pt_regs* regs);
46
 
47
        CHECK_STACK();
48
#if 0
49
        if (user_mode(regs)) {
50
                printk("syscall %d; pc == 0x%8x\n", num, get_pc());
51
                stack_trace();
52
        }
53
#endif
54
        if (num >= 0 && num < __NR_nocall) {
55
                switch(num) {
56
                        /*
57
                         * system calls that need the regs
58
                         */
59
                        case __NR_fork:
60
                        case __NR_clone:
61
                        case __NR_execve:
62
                        case __NR_sigsuspend:
63
                                regs->gregs[0] = ((int (*)(int))(syscall_tab[num]))((int)regs);
64
                                break;
65
 
66
#ifdef DEBUG    /* help debug user applications */
67
                        case __NR_dbg_break:
68
                                printk("break: %s\n", regs->gregs[0]);
69
                                system_break();
70
                                break;
71
 
72
                        case __NR_dbg_hexprint:
73
                                printk("value: %x\n", regs->gregs[0]);
74
                                break;
75
#endif
76
                        case __NR_mmap:
77
                                regs->gregs[0] = sys_mmap(regs);
78
#if 0
79
                                dprintk("mmap: returning 0x%8x\n",
80
                                        regs->gregs[0]);
81
#endif
82
                                break;
83
 
84
                        default:
85
                                regs->gregs[0] =
86
                                        syscall_tab[num](regs->gregs[0],
87
                                                         regs->gregs[1],
88
                                                         regs->gregs[2],
89
                                                         regs->gregs[3],
90
                                                         regs->gregs[4]);
91
                                break;
92
                }
93
        } else {
94
                regs->gregs[0] = -ENOSYS;
95
        }
96
#if 0   
97
        printk("csyscall: returning %p\n", regs->gregs[0]);
98
        stack_trace();
99
#endif
100
 
101
        leave_kernel(regs);
102
}
103
 
104
static int
105
sys_mmap(struct pt_regs* regs)
106
{
107
        struct file* file = 0;
108
        unsigned long flags = regs->gregs[3];
109
 
110
        if (!(flags & MAP_ANON)) {
111
                unsigned long fd = regs->gregs[4];
112
                if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
113
                        return -EBADF;
114
        }
115
 
116
        flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
117
        return do_mmap(file, regs->gregs[0], regs->gregs[1], regs->gregs[2],
118
                       flags, regs->gregs[5]);
119
}
120
 
121
asmlinkage int
122
sys_fork(struct pt_regs* regs)
123
{
124
        return do_fork(SIGCHLD|CLONE_WAIT, regs->lregs[PT_SP], regs);
125
}
126
 
127
asmlinkage int
128
sys_clone(struct pt_regs* regs)
129
{
130
        dprintk("in sys_clone\n");
131
        return do_fork(regs->gregs[0], regs->gregs[1], regs);
132
}
133
 
134
asmlinkage int
135
sys_execve(struct pt_regs* regs)
136
{
137
        dprintk("sys_execve: %s, %p, %p\n",
138
                regs->gregs[0], regs->gregs[1], regs->gregs[2]);
139
        return do_execve((void*)regs->gregs[0], (void*)regs->gregs[1],
140
                         (void*)regs->gregs[2], regs);
141
}
142
 
143
asmlinkage int
144
sys_ioperm(unsigned long from, unsigned long num, int turn_on)
145
{
146
        return -EINVAL;
147
}
148
 
149
asmlinkage int
150
sys_ipc (uint call, int first, int second, int third, void* ptr, long fifth)
151
{
152
        int version;
153
 
154
        version = call >> 16;
155
        call &= 0xffff;
156
 
157
        if (call <= SEMCTL)
158
                switch (call) {
159
                case SEMOP:
160
                        return sys_semop (first, (struct sembuf *)ptr, second);
161
                case SEMGET:
162
                        return sys_semget (first, second, third);
163
                case SEMCTL: {
164
                        union semun fourth;
165
                        int err;
166
                        if (!ptr)
167
                                return -EINVAL;
168
                        if ((err = verify_area (VERIFY_READ, ptr, sizeof(long))))
169
                                return err;
170
                        fourth.__pad = (void *) get_fs_long(ptr);
171
                        return sys_semctl (first, second, third, fourth);
172
                        }
173
                default:
174
                        return -EINVAL;
175
                }
176
        if (call <= MSGCTL)
177
                switch (call) {
178
                case MSGSND:
179
                        return sys_msgsnd (first, (struct msgbuf *) ptr,
180
                                           second, third);
181
                case MSGRCV:
182
                        switch (version) {
183
                        case 0: {
184
                                struct ipc_kludge tmp;
185
                                int err;
186
                                if (!ptr)
187
                                        return -EINVAL;
188
                                if ((err = verify_area (VERIFY_READ, ptr, sizeof(tmp))))
189
                                        return err;
190
                                memcpy_fromfs (&tmp,(struct ipc_kludge *) ptr,
191
                                               sizeof (tmp));
192
                                return sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third);
193
                                }
194
                        case 1: default:
195
                                return sys_msgrcv (first, (struct msgbuf *) ptr, second, fifth, third);
196
                        }
197
                case MSGGET:
198
                        return sys_msgget ((key_t) first, second);
199
                case MSGCTL:
200
                        return sys_msgctl (first, second, (struct msqid_ds *) ptr);
201
                default:
202
                        return -EINVAL;
203
                }
204
        if (call <= SHMCTL)
205
                switch (call) {
206
                case SHMAT:
207
                        switch (version) {
208
                        case 0: default: {
209
                                ulong raddr;
210
                                int err;
211
                                if ((err = verify_area(VERIFY_WRITE, (ulong*) third, sizeof(ulong))))
212
                                        return err;
213
                                err = sys_shmat (first, (char *) ptr, second, &raddr);
214
                                if (err)
215
                                        return err;
216
                                put_fs_long (raddr, (ulong *) third);
217
                                return 0;
218
                                }
219
                        case 1: /* iBCS2 emulator entry point */
220
                                if (get_fs() != get_ds())
221
                                        return -EINVAL;
222
                                return sys_shmat (first, (char *) ptr, second, (ulong *) third);
223
                        }
224
                case SHMDT:
225
                        return sys_shmdt ((char *)ptr);
226
                case SHMGET:
227
                        return sys_shmget (first, second, third);
228
                case SHMCTL:
229
                        return sys_shmctl (first, second, (struct shmid_ds *) ptr);
230
                default:
231
                        return -EINVAL;
232
                }
233
        return -EINVAL;
234
 
235
}
236
 
237
asmlinkage int
238
sys_cacheflush(char* addr, int nbytes, int cache)
239
{
240
        if (cache & ICACHE)
241
                __asm__ __volatile__ ("icctl    2, g0, g0");
242
 
243
        if (cache & DCACHE)
244
                __asm__ __volatile__ ("dcctl    2, g0, g0");
245
 
246
        return 0;
247
}
248
 
249
void
250
kthread_start(void (*func)(void*), void* arg)
251
{
252
        extern long _etext, _stext;
253
 
254
        CHECK_STACK();
255
        if ( ((unsigned long)func > (unsigned long)&_etext)
256
             || ((unsigned long)func < (unsigned long)&_stext) ) {
257
                panic("XXX: bad kthread addr: %p\n", func);
258
        }
259
        func(arg);
260
}

powered by: WebSVN 2.1.0

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