e9a3ecf90c9c83247a28ec6988c3009f5ac80b17
[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 /*
64  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
65  *
66  * This is really horribly ugly.
67  */
68 asmlinkage int sys_ipc (uint call, int first, int second,
69                         int third, void *ptr, long fifth)
70 {
71         int version, ret;
72
73         version = call >> 16; /* hack for backward compatibility */
74         call &= 0xffff;
75
76         if (call <= SEMCTL)
77                 switch (call) {
78                 case SEMOP:
79                         return sys_semop (first, (struct sembuf *)ptr, second);
80                 case SEMGET:
81                         return sys_semget (first, second, third);
82                 case SEMCTL: {
83                         union semun fourth;
84                         if (!ptr)
85                                 return -EINVAL;
86                         if (get_user(fourth.__pad, (void **) ptr))
87                                 return -EFAULT;
88                         return sys_semctl (first, second, third, fourth);
89                         }
90                 default:
91                         return -EINVAL;
92                 }
93         if (call <= MSGCTL) 
94                 switch (call) {
95                 case MSGSND:
96                         return sys_msgsnd (first, (struct msgbuf *) ptr, 
97                                           second, third);
98                 case MSGRCV:
99                         switch (version) {
100                         case 0: {
101                                 struct ipc_kludge tmp;
102                                 if (!ptr)
103                                         return -EINVAL;
104                                 if (copy_from_user (&tmp,
105                                                     (struct ipc_kludge *)ptr,
106                                                     sizeof (tmp)))
107                                         return -EFAULT;
108                                 return sys_msgrcv (first, tmp.msgp, second,
109                                                    tmp.msgtyp, third);
110                                 }
111                         default:
112                                 return sys_msgrcv (first,
113                                                    (struct msgbuf *) ptr,
114                                                    second, fifth, third);
115                         }
116                 case MSGGET:
117                         return sys_msgget ((key_t) first, second);
118                 case MSGCTL:
119                         return sys_msgctl (first, second,
120                                            (struct msqid_ds *) ptr);
121                 default:
122                         return -EINVAL;
123                 }
124         if (call <= SHMCTL) 
125                 switch (call) {
126                 case SHMAT:
127                         switch (version) {
128                         default: {
129                                 ulong raddr;
130                                 ret = do_shmat (first, (char *) ptr,
131                                                  second, &raddr);
132                                 if (ret)
133                                         return ret;
134                                 return put_user (raddr, (ulong *) third);
135                         }
136                         }
137                 case SHMDT: 
138                         return sys_shmdt ((char *)ptr);
139                 case SHMGET:
140                         return sys_shmget (first, second, third);
141                 case SHMCTL:
142                         return sys_shmctl (first, second,
143                                            (struct shmid_ds *) ptr);
144                 default:
145                         return -EINVAL;
146                 }
147
148         return -EINVAL;
149 }
150
151 /* sys_cacheflush -- no support.  */
152 asmlinkage int
153 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
154 {
155         return -EINVAL;
156 }
157
158 asmlinkage int sys_getpagesize(void)
159 {
160         return PAGE_SIZE;
161 }
162
163 #if defined(CONFIG_SYSCALL_PRINT)
164 asmlinkage void syscall_print(void *dummy,...)
165 {
166         struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
167         printk("call %06lx:%ld 1:%08lx,2:%08lx,3:%08lx,ret:%08lx\n",
168                ((regs->pc)&0xffffff)-2,regs->orig_er0,regs->er1,regs->er2,regs->er3,regs->er0);
169 }
170 #endif
171
172 /*
173  * Do a system call from kernel instead of calling sys_execve so we
174  * end up with proper pt_regs.
175  */
176 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
177 {
178         register long res __asm__("er0");
179         register char *const *_c __asm__("er3") = envp;
180         register char *const *_b __asm__("er2") = argv;
181         register const char * _a __asm__("er1") = filename;
182         __asm__ __volatile__ ("mov.l %1,er0\n\t"
183                         "trapa  #0\n\t"
184                         : "=r" (res)
185                         : "g" (__NR_execve),
186                           "g" (_a),
187                           "g" (_b),
188                           "g" (_c)
189                         : "cc", "memory");
190         return res;
191 }
192
193