2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * arch/sh64/kernel/sys_sh64.c
8 * Copyright (C) 2000, 2001 Paolo Alberelli
10 * This file contains various random system calls that
11 * have a non-standard calling sequence on the Linux/SH5
14 * Mostly taken from i386 version.
18 #include <linux/errno.h>
19 #include <linux/rwsem.h>
20 #include <linux/sched.h>
22 #include <linux/smp.h>
23 #include <linux/sem.h>
24 #include <linux/msg.h>
25 #include <linux/shm.h>
26 #include <linux/stat.h>
27 #include <linux/mman.h>
28 #include <linux/file.h>
29 #include <linux/utsname.h>
30 #include <linux/syscalls.h>
31 #include <asm/uaccess.h>
33 #include <asm/ptrace.h>
34 #include <asm/unistd.h>
39 * sys_pipe() is the normal C calling standard for creating
40 * a pipe. It's not the way Unix traditionally does this, though.
42 #ifdef NEW_PIPE_IMPLEMENTATION
43 asmlinkage int sys_pipe(unsigned long * fildes,
44 unsigned long dummy_r3,
45 unsigned long dummy_r4,
46 unsigned long dummy_r5,
47 unsigned long dummy_r6,
48 unsigned long dummy_r7,
49 struct pt_regs * regs) /* r8 = pt_regs forced by entry.S */
57 ***********************************************************************
58 * To avoid the copy_to_user we prefer to break the ABIs convention, *
59 * packing the valid pair of file IDs into a single register (r3); *
60 * while r2 is the return code as defined by the sh5-ABIs. *
61 * BE CAREFUL: pipe stub, into glibc, must be aware of this solution *
62 ***********************************************************************
64 #ifdef __LITTLE_ENDIAN__
65 regs->regs[REG_3] = (((unsigned long long) fd[1]) << 32) | ((unsigned long long) fd[0]);
67 regs->regs[REG_3] = (((unsigned long long) fd[0]) << 32) | ((unsigned long long) fd[1]);
71 /* although not very clever this is endianess independent */
72 regs->regs[REG_3] = (unsigned long long) *((unsigned long long *) fd);
78 asmlinkage int sys_pipe(unsigned long * fildes)
85 if (copy_to_user(fildes, fd, 2*sizeof(int)))
94 * To avoid cache alias, we map the shard page with same color.
96 #define COLOUR_ALIGN(addr) (((addr)+SHMLBA-1)&~(SHMLBA-1))
98 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
99 unsigned long len, unsigned long pgoff, unsigned long flags)
101 struct vm_area_struct *vma;
103 if (flags & MAP_FIXED) {
104 /* We do not accept a shared mapping if it would violate
105 * cache aliasing constraints.
107 if ((flags & MAP_SHARED) && (addr & (SHMLBA - 1)))
115 addr = TASK_UNMAPPED_BASE;
117 if (flags & MAP_PRIVATE)
118 addr = PAGE_ALIGN(addr);
120 addr = COLOUR_ALIGN(addr);
122 for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
123 /* At this point: (!vma || addr < vma->vm_end). */
124 if (TASK_SIZE - len < addr)
126 if (!vma || addr + len <= vma->vm_start)
129 if (!(flags & MAP_PRIVATE))
130 addr = COLOUR_ALIGN(addr);
134 /* common code for old and new mmaps */
135 static inline long do_mmap2(
136 unsigned long addr, unsigned long len,
137 unsigned long prot, unsigned long flags,
138 unsigned long fd, unsigned long pgoff)
141 struct file * file = NULL;
143 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
144 if (!(flags & MAP_ANONYMOUS)) {
150 down_write(¤t->mm->mmap_sem);
151 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
152 up_write(¤t->mm->mmap_sem);
160 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
161 unsigned long prot, unsigned long flags,
162 unsigned long fd, unsigned long pgoff)
164 return do_mmap2(addr, len, prot, flags, fd, pgoff);
167 asmlinkage int old_mmap(unsigned long addr, unsigned long len,
168 unsigned long prot, unsigned long flags,
169 int fd, unsigned long off)
171 if (off & ~PAGE_MASK)
173 return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
177 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
179 * This is really horribly ugly.
181 asmlinkage int sys_ipc(uint call, int first, int second,
182 int third, void __user *ptr, long fifth)
186 version = call >> 16; /* hack for backward compatibility */
192 return sys_semtimedop(first, (struct sembuf __user *)ptr,
195 return sys_semtimedop(first, (struct sembuf __user *)ptr,
197 (const struct timespec __user *)fifth);
199 return sys_semget (first, second, third);
204 if (get_user(fourth.__pad, (void * __user *) ptr))
206 return sys_semctl (first, second, third, fourth);
215 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
220 struct ipc_kludge tmp;
224 if (copy_from_user(&tmp,
225 (struct ipc_kludge __user *) ptr,
228 return sys_msgrcv (first, tmp.msgp, second,
232 return sys_msgrcv (first,
233 (struct msgbuf __user *) ptr,
234 second, fifth, third);
237 return sys_msgget ((key_t) first, second);
239 return sys_msgctl (first, second,
240 (struct msqid_ds __user *) ptr);
250 ret = do_shmat (first, (char __user *) ptr,
254 return put_user (raddr, (ulong __user *) third);
256 case 1: /* iBCS2 emulator entry point */
257 if (!segment_eq(get_fs(), get_ds()))
259 return do_shmat (first, (char __user *) ptr,
260 second, (ulong *) third);
263 return sys_shmdt ((char __user *)ptr);
265 return sys_shmget (first, second, third);
267 return sys_shmctl (first, second,
268 (struct shmid_ds __user *) ptr);
276 asmlinkage int sys_uname(struct old_utsname * name)
282 err = copy_to_user(name, utsname(), sizeof (*name));
284 return err?-EFAULT:0;
288 * Do a system call from kernel instead of calling sys_execve so we
289 * end up with proper pt_regs.
291 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
293 register unsigned long __sc0 __asm__ ("r9") = ((0x13 << 16) | __NR_execve);
294 register unsigned long __sc2 __asm__ ("r2") = (unsigned long) filename;
295 register unsigned long __sc3 __asm__ ("r3") = (unsigned long) argv;
296 register unsigned long __sc4 __asm__ ("r4") = (unsigned long) envp;
297 __asm__ __volatile__ ("trapa %1 !\t\t\t execve(%2,%3,%4)"
299 : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4) );
300 __asm__ __volatile__ ("!dummy %0 %1 %2 %3"
301 : : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4) : "memory");