2 * linux/arch/m68k/kernel/sys_m68k.c
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/m68k
9 #include <linux/capability.h>
10 #include <linux/errno.h>
11 #include <linux/sched.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.h>
15 #include <linux/sem.h>
16 #include <linux/msg.h>
17 #include <linux/shm.h>
18 #include <linux/stat.h>
19 #include <linux/syscalls.h>
20 #include <linux/mman.h>
21 #include <linux/file.h>
22 #include <linux/utsname.h>
24 #include <asm/setup.h>
25 #include <asm/uaccess.h>
26 #include <asm/cachectl.h>
27 #include <asm/traps.h>
30 #include <asm/unistd.h>
33 * sys_pipe() is the normal C calling standard for creating
34 * a pipe. It's not the way unix traditionally does this, though.
36 asmlinkage int sys_pipe(unsigned long __user * fildes)
43 if (copy_to_user(fildes, fd, 2*sizeof(int)))
49 /* common code for old and new mmaps */
50 static inline long do_mmap2(
51 unsigned long addr, unsigned long len,
52 unsigned long prot, unsigned long flags,
53 unsigned long fd, unsigned long pgoff)
56 struct file * file = NULL;
58 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
59 if (!(flags & MAP_ANONYMOUS)) {
65 down_write(¤t->mm->mmap_sem);
66 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
67 up_write(¤t->mm->mmap_sem);
75 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
76 unsigned long prot, unsigned long flags,
77 unsigned long fd, unsigned long pgoff)
79 return do_mmap2(addr, len, prot, flags, fd, pgoff);
83 * Perform the select(nd, in, out, ex, tv) and mmap() system
84 * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
85 * handle more than 4 system call parameters, so these system calls
86 * used a memory block for parameter passing..
89 struct mmap_arg_struct {
98 asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
100 struct mmap_arg_struct a;
103 if (copy_from_user(&a, arg, sizeof(a)))
107 if (a.offset & ~PAGE_MASK)
110 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
112 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
118 struct mmap_arg_struct64 {
123 __u64 offset; /* 64 bits */
127 asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
130 struct file * file = NULL;
131 struct mmap_arg_struct64 a;
134 if (copy_from_user(&a, arg, sizeof(a)))
137 if ((long)a.offset & ~PAGE_MASK)
140 pgoff = a.offset >> PAGE_SHIFT;
141 if ((a.offset >> PAGE_SHIFT) != pgoff)
144 if (!(a.flags & MAP_ANONYMOUS)) {
150 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
152 down_write(¤t->mm->mmap_sem);
153 error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
154 up_write(¤t->mm->mmap_sem);
162 struct sel_arg_struct {
164 fd_set __user *inp, *outp, *exp;
165 struct timeval __user *tvp;
168 asmlinkage int old_select(struct sel_arg_struct __user *arg)
170 struct sel_arg_struct a;
172 if (copy_from_user(&a, arg, sizeof(a)))
174 /* sys_select() does the appropriate kernel locking */
175 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
179 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
181 * This is really horribly ugly.
183 asmlinkage int sys_ipc (uint call, int first, int second,
184 int third, void __user *ptr, long fifth)
188 version = call >> 16; /* hack for backward compatibility */
194 return sys_semop (first, ptr, second);
196 return sys_semget (first, second, third);
201 if (get_user(fourth.__pad, (void __user *__user *) ptr))
203 return sys_semctl (first, second, third, fourth);
211 return sys_msgsnd (first, ptr, second, third);
215 struct ipc_kludge tmp;
218 if (copy_from_user (&tmp, ptr, sizeof (tmp)))
220 return sys_msgrcv (first, tmp.msgp, second,
224 return sys_msgrcv (first, ptr,
225 second, fifth, third);
228 return sys_msgget ((key_t) first, second);
230 return sys_msgctl (first, second, ptr);
240 ret = do_shmat (first, ptr, second, &raddr);
243 return put_user (raddr, (ulong __user *) third);
247 return sys_shmdt (ptr);
249 return sys_shmget (first, second, third);
251 return sys_shmctl (first, second, ptr);
259 /* Convert virtual (user) address VADDR to physical address PADDR */
260 #define virt_to_phys_040(vaddr) \
262 unsigned long _mmusr, _paddr; \
264 __asm__ __volatile__ (".chip 68040\n\t" \
266 "movec %%mmusr,%0\n\t" \
270 _paddr = (_mmusr & MMU_R_040) ? (_mmusr & PAGE_MASK) : 0; \
275 cache_flush_040 (unsigned long addr, int scope, int cache, unsigned long len)
277 unsigned long paddr, i;
281 case FLUSH_SCOPE_ALL:
284 case FLUSH_CACHE_DATA:
285 /* This nop is needed for some broken versions of the 68040. */
286 __asm__ __volatile__ ("nop\n\t"
291 case FLUSH_CACHE_INSN:
292 __asm__ __volatile__ ("nop\n\t"
298 case FLUSH_CACHE_BOTH:
299 __asm__ __volatile__ ("nop\n\t"
307 case FLUSH_SCOPE_LINE:
308 /* Find the physical address of the first mapped page in the
310 if ((paddr = virt_to_phys_040(addr))) {
311 paddr += addr & ~(PAGE_MASK | 15);
312 len = (len + (addr & 15) + 15) >> 4;
314 unsigned long tmp = PAGE_SIZE - (addr & ~PAGE_MASK);
323 if ((paddr = virt_to_phys_040(addr)))
330 len = (len + 15) >> 4;
332 i = (PAGE_SIZE - (paddr & ~PAGE_MASK)) >> 4;
337 case FLUSH_CACHE_DATA:
338 __asm__ __volatile__ ("nop\n\t"
340 "cpushl %%dc,(%0)\n\t"
344 case FLUSH_CACHE_INSN:
345 __asm__ __volatile__ ("nop\n\t"
347 "cpushl %%ic,(%0)\n\t"
352 case FLUSH_CACHE_BOTH:
353 __asm__ __volatile__ ("nop\n\t"
355 "cpushl %%bc,(%0)\n\t"
363 * No need to page align here since it is done by
364 * virt_to_phys_040().
368 /* Recompute physical address when crossing a page
372 if ((paddr = virt_to_phys_040(addr)))
386 case FLUSH_SCOPE_PAGE:
387 len += (addr & ~PAGE_MASK) + (PAGE_SIZE - 1);
388 for (len >>= PAGE_SHIFT; len--; addr += PAGE_SIZE)
390 if (!(paddr = virt_to_phys_040(addr)))
394 case FLUSH_CACHE_DATA:
395 __asm__ __volatile__ ("nop\n\t"
397 "cpushp %%dc,(%0)\n\t"
401 case FLUSH_CACHE_INSN:
402 __asm__ __volatile__ ("nop\n\t"
404 "cpushp %%ic,(%0)\n\t"
409 case FLUSH_CACHE_BOTH:
410 __asm__ __volatile__ ("nop\n\t"
412 "cpushp %%bc,(%0)\n\t"
423 #define virt_to_phys_060(vaddr) \
425 unsigned long paddr; \
426 __asm__ __volatile__ (".chip 68060\n\t" \
435 cache_flush_060 (unsigned long addr, int scope, int cache, unsigned long len)
437 unsigned long paddr, i;
441 * cpush %dc : flush DC, remains valid (with our %cacr setup)
442 * cpush %ic : invalidate IC
443 * cpush %bc : flush DC + invalidate IC
447 case FLUSH_SCOPE_ALL:
450 case FLUSH_CACHE_DATA:
451 __asm__ __volatile__ (".chip 68060\n\t"
455 case FLUSH_CACHE_INSN:
456 __asm__ __volatile__ (".chip 68060\n\t"
461 case FLUSH_CACHE_BOTH:
462 __asm__ __volatile__ (".chip 68060\n\t"
469 case FLUSH_SCOPE_LINE:
470 /* Find the physical address of the first mapped page in the
474 if (!(paddr = virt_to_phys_060(addr))) {
475 unsigned long tmp = PAGE_SIZE - (addr & ~PAGE_MASK);
484 if ((paddr = virt_to_phys_060(addr)))
492 len = (len + 15) >> 4;
493 i = (PAGE_SIZE - (paddr & ~PAGE_MASK)) >> 4;
498 case FLUSH_CACHE_DATA:
499 __asm__ __volatile__ (".chip 68060\n\t"
500 "cpushl %%dc,(%0)\n\t"
504 case FLUSH_CACHE_INSN:
505 __asm__ __volatile__ (".chip 68060\n\t"
506 "cpushl %%ic,(%0)\n\t"
511 case FLUSH_CACHE_BOTH:
512 __asm__ __volatile__ (".chip 68060\n\t"
513 "cpushl %%bc,(%0)\n\t"
522 * We just want to jump to the first cache line
529 /* Recompute physical address when crossing a page
533 if ((paddr = virt_to_phys_060(addr)))
547 case FLUSH_SCOPE_PAGE:
548 len += (addr & ~PAGE_MASK) + (PAGE_SIZE - 1);
549 addr &= PAGE_MASK; /* Workaround for bug in some
550 revisions of the 68060 */
551 for (len >>= PAGE_SHIFT; len--; addr += PAGE_SIZE)
553 if (!(paddr = virt_to_phys_060(addr)))
557 case FLUSH_CACHE_DATA:
558 __asm__ __volatile__ (".chip 68060\n\t"
559 "cpushp %%dc,(%0)\n\t"
563 case FLUSH_CACHE_INSN:
564 __asm__ __volatile__ (".chip 68060\n\t"
565 "cpushp %%ic,(%0)\n\t"
570 case FLUSH_CACHE_BOTH:
571 __asm__ __volatile__ (".chip 68060\n\t"
572 "cpushp %%bc,(%0)\n\t"
583 /* sys_cacheflush -- flush (part of) the processor cache. */
585 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
587 struct vm_area_struct *vma;
591 if (scope < FLUSH_SCOPE_LINE || scope > FLUSH_SCOPE_ALL ||
592 cache & ~FLUSH_CACHE_BOTH)
595 if (scope == FLUSH_SCOPE_ALL) {
596 /* Only the superuser may explicitly flush the whole cache. */
598 if (!capable(CAP_SYS_ADMIN))
602 * Verify that the specified address region actually belongs
605 vma = find_vma (current->mm, addr);
607 /* Check for overflow. */
608 if (addr + len < addr)
610 if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
614 if (CPU_IS_020_OR_030) {
615 if (scope == FLUSH_SCOPE_LINE && len < 256) {
617 __asm__ ("movec %%cacr, %0" : "=r" (cacr));
618 if (cache & FLUSH_CACHE_INSN)
620 if (cache & FLUSH_CACHE_DATA)
624 __asm__ __volatile__ ("movec %1, %%caar\n\t"
627 : "r" (cacr), "r" (addr));
631 /* Flush the whole cache, even if page granularity requested. */
633 __asm__ ("movec %%cacr, %0" : "=r" (cacr));
634 if (cache & FLUSH_CACHE_INSN)
636 if (cache & FLUSH_CACHE_DATA)
638 __asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
644 * 040 or 060: don't blindly trust 'scope', someone could
645 * try to flush a few megs of memory.
648 if (len>=3*PAGE_SIZE && scope<FLUSH_SCOPE_PAGE)
649 scope=FLUSH_SCOPE_PAGE;
650 if (len>=10*PAGE_SIZE && scope<FLUSH_SCOPE_ALL)
651 scope=FLUSH_SCOPE_ALL;
653 ret = cache_flush_040 (addr, scope, cache, len);
654 } else if (CPU_IS_060) {
655 ret = cache_flush_060 (addr, scope, cache, len);
663 asmlinkage int sys_getpagesize(void)
669 * Do a system call from kernel instead of calling sys_execve so we
670 * end up with proper pt_regs.
672 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
674 register long __res asm ("%d0") = __NR_execve;
675 register long __a asm ("%d1") = (long)(filename);
676 register long __b asm ("%d2") = (long)(argv);
677 register long __c asm ("%d3") = (long)(envp);
678 asm volatile ("trap #0" : "+d" (__res)
679 : "d" (__a), "d" (__b), "d" (__c));