Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[pandora-kernel.git] / arch / h8300 / kernel / sys_h8300.c
1 /*
2  * linux/arch/h8300/kernel/sys_h8300.c
3  *
4  * This file contains various random system calls that
5  * have a non-standard calling sequence on the H8/300
6  * platform.
7  */
8
9 #include <linux/errno.h>
10 #include <linux/sched.h>
11 #include <linux/mm.h>
12 #include <linux/smp.h>
13 #include <linux/sem.h>
14 #include <linux/msg.h>
15 #include <linux/shm.h>
16 #include <linux/stat.h>
17 #include <linux/syscalls.h>
18 #include <linux/mman.h>
19 #include <linux/file.h>
20 #include <linux/fs.h>
21 #include <linux/ipc.h>
22
23 #include <asm/setup.h>
24 #include <asm/uaccess.h>
25 #include <asm/cachectl.h>
26 #include <asm/traps.h>
27 #include <asm/unistd.h>
28
29 /*
30  * Perform the select(nd, in, out, ex, tv) and mmap() system
31  * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
32  * handle more than 4 system call parameters, so these system calls
33  * used a memory block for parameter passing..
34  */
35
36 struct mmap_arg_struct {
37         unsigned long addr;
38         unsigned long len;
39         unsigned long prot;
40         unsigned long flags;
41         unsigned long fd;
42         unsigned long offset;
43 };
44
45 asmlinkage int old_mmap(struct mmap_arg_struct *arg)
46 {
47         struct mmap_arg_struct a;
48         int error = -EFAULT;
49
50         if (copy_from_user(&a, arg, sizeof(a)))
51                 goto out;
52
53         error = -EINVAL;
54         if (a.offset & ~PAGE_MASK)
55                 goto out;
56
57         error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
58                                a.offset >> PAGE_SHIFT);
59 out:
60         return error;
61 }
62
63 struct sel_arg_struct {
64         unsigned long n;
65         fd_set *inp, *outp, *exp;
66         struct timeval *tvp;
67 };
68
69 asmlinkage int old_select(struct sel_arg_struct *arg)
70 {
71         struct sel_arg_struct a;
72
73         if (copy_from_user(&a, arg, sizeof(a)))
74                 return -EFAULT;
75         /* sys_select() does the appropriate kernel locking */
76         return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
77 }
78
79 /*
80  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
81  *
82  * This is really horribly ugly.
83  */
84 asmlinkage int sys_ipc (uint call, int first, int second,
85                         int third, void *ptr, long fifth)
86 {
87         int version, ret;
88
89         version = call >> 16; /* hack for backward compatibility */
90         call &= 0xffff;
91
92         if (call <= SEMCTL)
93                 switch (call) {
94                 case SEMOP:
95                         return sys_semop (first, (struct sembuf *)ptr, second);
96                 case SEMGET:
97                         return sys_semget (first, second, third);
98                 case SEMCTL: {
99                         union semun fourth;
100                         if (!ptr)
101                                 return -EINVAL;
102                         if (get_user(fourth.__pad, (void **) ptr))
103                                 return -EFAULT;
104                         return sys_semctl (first, second, third, fourth);
105                         }
106                 default:
107                         return -EINVAL;
108                 }
109         if (call <= MSGCTL) 
110                 switch (call) {
111                 case MSGSND:
112                         return sys_msgsnd (first, (struct msgbuf *) ptr, 
113                                           second, third);
114                 case MSGRCV:
115                         switch (version) {
116                         case 0: {
117                                 struct ipc_kludge tmp;
118                                 if (!ptr)
119                                         return -EINVAL;
120                                 if (copy_from_user (&tmp,
121                                                     (struct ipc_kludge *)ptr,
122                                                     sizeof (tmp)))
123                                         return -EFAULT;
124                                 return sys_msgrcv (first, tmp.msgp, second,
125                                                    tmp.msgtyp, third);
126                                 }
127                         default:
128                                 return sys_msgrcv (first,
129                                                    (struct msgbuf *) ptr,
130                                                    second, fifth, third);
131                         }
132                 case MSGGET:
133                         return sys_msgget ((key_t) first, second);
134                 case MSGCTL:
135                         return sys_msgctl (first, second,
136                                            (struct msqid_ds *) ptr);
137                 default:
138                         return -EINVAL;
139                 }
140         if (call <= SHMCTL) 
141                 switch (call) {
142                 case SHMAT:
143                         switch (version) {
144                         default: {
145                                 ulong raddr;
146                                 ret = do_shmat (first, (char *) ptr,
147                                                  second, &raddr);
148                                 if (ret)
149                                         return ret;
150                                 return put_user (raddr, (ulong *) third);
151                         }
152                         }
153                 case SHMDT: 
154                         return sys_shmdt ((char *)ptr);
155                 case SHMGET:
156                         return sys_shmget (first, second, third);
157                 case SHMCTL:
158                         return sys_shmctl (first, second,
159                                            (struct shmid_ds *) ptr);
160                 default:
161                         return -EINVAL;
162                 }
163
164         return -EINVAL;
165 }
166
167 /* sys_cacheflush -- no support.  */
168 asmlinkage int
169 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
170 {
171         return -EINVAL;
172 }
173
174 asmlinkage int sys_getpagesize(void)
175 {
176         return PAGE_SIZE;
177 }
178
179 #if defined(CONFIG_SYSCALL_PRINT)
180 asmlinkage void syscall_print(void *dummy,...)
181 {
182         struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
183         printk("call %06lx:%ld 1:%08lx,2:%08lx,3:%08lx,ret:%08lx\n",
184                ((regs->pc)&0xffffff)-2,regs->orig_er0,regs->er1,regs->er2,regs->er3,regs->er0);
185 }
186 #endif
187
188 /*
189  * Do a system call from kernel instead of calling sys_execve so we
190  * end up with proper pt_regs.
191  */
192 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
193 {
194         register long res __asm__("er0");
195         register char *const *_c __asm__("er3") = envp;
196         register char *const *_b __asm__("er2") = argv;
197         register const char * _a __asm__("er1") = filename;
198         __asm__ __volatile__ ("mov.l %1,er0\n\t"
199                         "trapa  #0\n\t"
200                         : "=r" (res)
201                         : "g" (__NR_execve),
202                           "g" (_a),
203                           "g" (_b),
204                           "g" (_c)
205                         : "cc", "memory");
206         return res;
207 }
208
209