Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/utsname.h> |
Yoshinori Sato | 0cd82ef | 2007-08-22 14:01:24 -0700 | [diff] [blame] | 21 | #include <linux/fs.h> |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 22 | #include <linux/ipc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include <asm/setup.h> |
| 25 | #include <asm/uaccess.h> |
| 26 | #include <asm/cachectl.h> |
| 27 | #include <asm/traps.h> |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 28 | #include <asm/unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * sys_pipe() is the normal C calling standard for creating |
| 32 | * a pipe. It's not the way unix traditionally does this, though. |
| 33 | */ |
| 34 | asmlinkage int sys_pipe(unsigned long * fildes) |
| 35 | { |
| 36 | int fd[2]; |
| 37 | int error; |
| 38 | |
| 39 | error = do_pipe(fd); |
| 40 | if (!error) { |
| 41 | if (copy_to_user(fildes, fd, 2*sizeof(int))) |
| 42 | error = -EFAULT; |
| 43 | } |
| 44 | return error; |
| 45 | } |
| 46 | |
| 47 | /* common code for old and new mmaps */ |
| 48 | static inline long do_mmap2( |
| 49 | unsigned long addr, unsigned long len, |
| 50 | unsigned long prot, unsigned long flags, |
| 51 | unsigned long fd, unsigned long pgoff) |
| 52 | { |
| 53 | int error = -EBADF; |
| 54 | struct file * file = NULL; |
| 55 | |
| 56 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 57 | if (!(flags & MAP_ANONYMOUS)) { |
| 58 | file = fget(fd); |
| 59 | if (!file) |
| 60 | goto out; |
| 61 | } |
| 62 | |
| 63 | down_write(¤t->mm->mmap_sem); |
| 64 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
| 65 | up_write(¤t->mm->mmap_sem); |
| 66 | |
| 67 | if (file) |
| 68 | fput(file); |
| 69 | out: |
| 70 | return error; |
| 71 | } |
| 72 | |
| 73 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, |
| 74 | unsigned long prot, unsigned long flags, |
| 75 | unsigned long fd, unsigned long pgoff) |
| 76 | { |
| 77 | return do_mmap2(addr, len, prot, flags, fd, pgoff); |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Perform the select(nd, in, out, ex, tv) and mmap() system |
| 82 | * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to |
| 83 | * handle more than 4 system call parameters, so these system calls |
| 84 | * used a memory block for parameter passing.. |
| 85 | */ |
| 86 | |
| 87 | struct mmap_arg_struct { |
| 88 | unsigned long addr; |
| 89 | unsigned long len; |
| 90 | unsigned long prot; |
| 91 | unsigned long flags; |
| 92 | unsigned long fd; |
| 93 | unsigned long offset; |
| 94 | }; |
| 95 | |
| 96 | asmlinkage int old_mmap(struct mmap_arg_struct *arg) |
| 97 | { |
| 98 | struct mmap_arg_struct a; |
| 99 | int error = -EFAULT; |
| 100 | |
| 101 | if (copy_from_user(&a, arg, sizeof(a))) |
| 102 | goto out; |
| 103 | |
| 104 | error = -EINVAL; |
| 105 | if (a.offset & ~PAGE_MASK) |
| 106 | goto out; |
| 107 | |
| 108 | a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 109 | |
| 110 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); |
| 111 | out: |
| 112 | return error; |
| 113 | } |
| 114 | |
| 115 | #if 0 /* DAVIDM - do we want this */ |
| 116 | struct mmap_arg_struct64 { |
| 117 | __u32 addr; |
| 118 | __u32 len; |
| 119 | __u32 prot; |
| 120 | __u32 flags; |
| 121 | __u64 offset; /* 64 bits */ |
| 122 | __u32 fd; |
| 123 | }; |
| 124 | |
| 125 | asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg) |
| 126 | { |
| 127 | int error = -EFAULT; |
| 128 | struct file * file = NULL; |
| 129 | struct mmap_arg_struct64 a; |
| 130 | unsigned long pgoff; |
| 131 | |
| 132 | if (copy_from_user(&a, arg, sizeof(a))) |
| 133 | return -EFAULT; |
| 134 | |
| 135 | if ((long)a.offset & ~PAGE_MASK) |
| 136 | return -EINVAL; |
| 137 | |
| 138 | pgoff = a.offset >> PAGE_SHIFT; |
| 139 | if ((a.offset >> PAGE_SHIFT) != pgoff) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | if (!(a.flags & MAP_ANONYMOUS)) { |
| 143 | error = -EBADF; |
| 144 | file = fget(a.fd); |
| 145 | if (!file) |
| 146 | goto out; |
| 147 | } |
| 148 | a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 149 | |
| 150 | down_write(¤t->mm->mmap_sem); |
| 151 | error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff); |
| 152 | up_write(¤t->mm->mmap_sem); |
| 153 | if (file) |
| 154 | fput(file); |
| 155 | out: |
| 156 | return error; |
| 157 | } |
| 158 | #endif |
| 159 | |
| 160 | struct sel_arg_struct { |
| 161 | unsigned long n; |
| 162 | fd_set *inp, *outp, *exp; |
| 163 | struct timeval *tvp; |
| 164 | }; |
| 165 | |
| 166 | asmlinkage int old_select(struct sel_arg_struct *arg) |
| 167 | { |
| 168 | struct sel_arg_struct a; |
| 169 | |
| 170 | if (copy_from_user(&a, arg, sizeof(a))) |
| 171 | return -EFAULT; |
| 172 | /* sys_select() does the appropriate kernel locking */ |
| 173 | return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp); |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
| 178 | * |
| 179 | * This is really horribly ugly. |
| 180 | */ |
| 181 | asmlinkage int sys_ipc (uint call, int first, int second, |
| 182 | int third, void *ptr, long fifth) |
| 183 | { |
| 184 | int version, ret; |
| 185 | |
| 186 | version = call >> 16; /* hack for backward compatibility */ |
| 187 | call &= 0xffff; |
| 188 | |
| 189 | if (call <= SEMCTL) |
| 190 | switch (call) { |
| 191 | case SEMOP: |
| 192 | return sys_semop (first, (struct sembuf *)ptr, second); |
| 193 | case SEMGET: |
| 194 | return sys_semget (first, second, third); |
| 195 | case SEMCTL: { |
| 196 | union semun fourth; |
| 197 | if (!ptr) |
| 198 | return -EINVAL; |
| 199 | if (get_user(fourth.__pad, (void **) ptr)) |
| 200 | return -EFAULT; |
| 201 | return sys_semctl (first, second, third, fourth); |
| 202 | } |
| 203 | default: |
| 204 | return -EINVAL; |
| 205 | } |
| 206 | if (call <= MSGCTL) |
| 207 | switch (call) { |
| 208 | case MSGSND: |
| 209 | return sys_msgsnd (first, (struct msgbuf *) ptr, |
| 210 | second, third); |
| 211 | case MSGRCV: |
| 212 | switch (version) { |
| 213 | case 0: { |
| 214 | struct ipc_kludge tmp; |
| 215 | if (!ptr) |
| 216 | return -EINVAL; |
| 217 | if (copy_from_user (&tmp, |
| 218 | (struct ipc_kludge *)ptr, |
| 219 | sizeof (tmp))) |
| 220 | return -EFAULT; |
| 221 | return sys_msgrcv (first, tmp.msgp, second, |
| 222 | tmp.msgtyp, third); |
| 223 | } |
| 224 | default: |
| 225 | return sys_msgrcv (first, |
| 226 | (struct msgbuf *) ptr, |
| 227 | second, fifth, third); |
| 228 | } |
| 229 | case MSGGET: |
| 230 | return sys_msgget ((key_t) first, second); |
| 231 | case MSGCTL: |
| 232 | return sys_msgctl (first, second, |
| 233 | (struct msqid_ds *) ptr); |
| 234 | default: |
| 235 | return -EINVAL; |
| 236 | } |
| 237 | if (call <= SHMCTL) |
| 238 | switch (call) { |
| 239 | case SHMAT: |
| 240 | switch (version) { |
| 241 | default: { |
| 242 | ulong raddr; |
| 243 | ret = do_shmat (first, (char *) ptr, |
| 244 | second, &raddr); |
| 245 | if (ret) |
| 246 | return ret; |
| 247 | return put_user (raddr, (ulong *) third); |
| 248 | } |
| 249 | } |
| 250 | case SHMDT: |
| 251 | return sys_shmdt ((char *)ptr); |
| 252 | case SHMGET: |
| 253 | return sys_shmget (first, second, third); |
| 254 | case SHMCTL: |
| 255 | return sys_shmctl (first, second, |
| 256 | (struct shmid_ds *) ptr); |
| 257 | default: |
| 258 | return -EINVAL; |
| 259 | } |
| 260 | |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
| 264 | /* sys_cacheflush -- no support. */ |
| 265 | asmlinkage int |
| 266 | sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len) |
| 267 | { |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | asmlinkage int sys_getpagesize(void) |
| 272 | { |
| 273 | return PAGE_SIZE; |
| 274 | } |
| 275 | |
| 276 | #if defined(CONFIG_SYSCALL_PRINT) |
| 277 | asmlinkage void syscall_print(void *dummy,...) |
| 278 | { |
| 279 | struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4); |
| 280 | printk("call %06lx:%ld 1:%08lx,2:%08lx,3:%08lx,ret:%08lx\n", |
| 281 | ((regs->pc)&0xffffff)-2,regs->orig_er0,regs->er1,regs->er2,regs->er3,regs->er0); |
| 282 | } |
| 283 | #endif |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * Do a system call from kernel instead of calling sys_execve so we |
| 287 | * end up with proper pt_regs. |
| 288 | */ |
| 289 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) |
| 290 | { |
| 291 | register long res __asm__("er0"); |
Yoshinori Sato | 8778beb | 2007-06-01 00:47:01 -0700 | [diff] [blame] | 292 | register char *const *_c __asm__("er3") = envp; |
| 293 | register char *const *_b __asm__("er2") = argv; |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 294 | register const char * _a __asm__("er1") = filename; |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 295 | __asm__ __volatile__ ("mov.l %1,er0\n\t" |
| 296 | "trapa #0\n\t" |
| 297 | : "=r" (res) |
| 298 | : "g" (__NR_execve), |
| 299 | "g" (_a), |
| 300 | "g" (_b), |
| 301 | "g" (_c) |
| 302 | : "cc", "memory"); |
| 303 | return res; |
| 304 | } |
| 305 | |
| 306 | |