2 * linux/arch/ppc/kernel/sys_ppc.c
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Derived from "arch/i386/kernel/sys_i386.c"
8 * Adapted from the i386 version by Gary Thomas
9 * Modified by Cort Dougan (cort@cs.nmt.edu)
10 * and Paul Mackerras (paulus@cs.anu.edu.au).
12 * This file contains various random system calls that
13 * have a non-standard calling sequence on the Linux/PPC
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version
19 * 2 of the License, or (at your option) any later version.
23 #include <linux/errno.h>
24 #include <linux/sched.h>
26 #include <linux/smp.h>
27 #include <linux/smp_lock.h>
28 #include <linux/sem.h>
29 #include <linux/msg.h>
30 #include <linux/shm.h>
31 #include <linux/stat.h>
32 #include <linux/mman.h>
33 #include <linux/sys.h>
34 #include <linux/ipc.h>
35 #include <linux/utsname.h>
36 #include <linux/file.h>
37 #include <linux/init.h>
38 #include <linux/personality.h>
40 #include <asm/uaccess.h>
42 #include <asm/semaphore.h>
43 #include <asm/ppcdebug.h>
47 extern unsigned long wall_jiffies;
48 #define USEC_PER_SEC (1000000)
55 asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int on)
61 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
63 * This is really horribly ugly.
66 sys_ipc (uint call, int first, int second, long third, void *ptr, long fifth)
70 PPCDBG(PPCDBG_SYS64X, "sys_ipc - entered - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
72 version = call >> 16; /* hack for backward compatibility */
78 ret = sys_semop (first, (struct sembuf *)ptr, second);
81 ret = sys_semget (first, second, third);
88 if ((ret = verify_area (VERIFY_READ, ptr, sizeof(long)))
89 || (ret = get_user(fourth.__pad, (void **)ptr)))
91 ret = sys_semctl (first, second, third, fourth);
95 ret = sys_msgsnd (first, (struct msgbuf *) ptr, second, third);
100 struct ipc_kludge tmp;
104 if ((ret = verify_area (VERIFY_READ, ptr, sizeof(tmp)))
105 || (ret = copy_from_user(&tmp,
106 (struct ipc_kludge *) ptr,
109 ret = sys_msgrcv (first, (struct msgbuf *)tmp.msgp,
110 second, tmp.msgtyp, third);
114 ret = sys_msgrcv (first, (struct msgbuf *) ptr,
115 second, fifth, third);
120 ret = sys_msgget ((key_t) first, second);
123 ret = sys_msgctl (first, second, (struct msqid_ds *) ptr);
130 if ((ret = verify_area(VERIFY_WRITE, (ulong*) third,
133 ret = sys_shmat (first, (char *) ptr, second, &raddr);
136 ret = put_user (raddr, (ulong *) third);
139 case 1: /* iBCS2 emulator entry point */
140 if (!segment_eq(get_fs(), get_ds()))
142 ret = sys_shmat (first, (char *) ptr, second,
148 ret = sys_shmdt ((char *)ptr);
151 ret = sys_shmget (first, second, third);
154 ret = sys_shmctl (first, second, (struct shmid_ds *) ptr);
158 PPCDBG(PPCDBG_SYS64X, "sys_ipc - exited - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
163 * sys_pipe() is the normal C calling standard for creating
164 * a pipe. It's not the way unix traditionally does this, though.
166 asmlinkage int sys_pipe(int *fildes)
171 PPCDBG(PPCDBG_SYS64X, "sys_pipe - entered - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
175 if (copy_to_user(fildes, fd, 2*sizeof(int)))
179 PPCDBG(PPCDBG_SYS64X, "sys_pipe - exited - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
183 asmlinkage unsigned long sys_mmap(unsigned long addr, size_t len,
184 unsigned long prot, unsigned long flags,
185 unsigned long fd, off_t offset)
187 struct file * file = NULL;
188 unsigned long ret = -EBADF;
190 PPCDBG(PPCDBG_SYS64X, "sys_mmap - entered - addr=%lx, len=%lx - pid=%ld, comm=%s \n", addr, len, current->pid, current->comm);
192 if (!(flags & MAP_ANONYMOUS)) {
193 if (!(file = fget(fd)))
197 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
198 down_write(¤t->mm->mmap_sem);
199 ret = do_mmap(file, addr, len, prot, flags, offset);
200 up_write(¤t->mm->mmap_sem);
206 PPCDBG(PPCDBG_SYS64X, "sys_mmap - exited - ret=%x \n", ret);
211 asmlinkage int sys_pause(void)
214 PPCDBG(PPCDBG_SYS64X, "sys_pause - entered - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
215 current->state = TASK_INTERRUPTIBLE;
218 PPCDBG(PPCDBG_SYS64X, "sys_pause - exited - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
219 return -ERESTARTNOHAND;
222 static int __init set_fakeppc(char *str)
226 init_task.personality = PER_LINUX32;
229 __setup("fakeppc", set_fakeppc);
231 asmlinkage int sys_uname(struct old_utsname * name)
235 PPCDBG(PPCDBG_SYS64X, "sys_uname - entered - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
238 if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
242 PPCDBG(PPCDBG_SYS64X, "sys_uname - exited - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
246 asmlinkage int sys_olduname(struct oldold_utsname * name)
250 PPCDBG(PPCDBG_SYS64X, "sys_olduname - entered - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
254 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
258 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
259 error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
260 error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
261 error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
262 error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
263 error -= __put_user(0,name->release+__OLD_UTS_LEN);
264 error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
265 error -= __put_user(0,name->version+__OLD_UTS_LEN);
266 error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
267 error = __put_user(0,name->machine+__OLD_UTS_LEN);
270 error = error ? -EFAULT : 0;
272 PPCDBG(PPCDBG_SYS64X, "sys_olduname - exited - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
276 asmlinkage time_t sys64_time(time_t* tloc)
281 long tb_delta = tb_ticks_since(tb_last_stamp);
282 tb_delta += (jiffies - wall_jiffies) * tb_ticks_per_jiffy;
285 usecs = xtime.tv_usec + tb_delta / tb_ticks_per_usec;
286 while (usecs >= USEC_PER_SEC) {
288 usecs -= USEC_PER_SEC;
292 if (put_user(secs,tloc))