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>
32 * sys_pipe() is the normal C calling standard for creating
33 * a pipe. It's not the way unix traditionally does this, though.
35 asmlinkage int sys_pipe(unsigned long __user * fildes)
42 if (copy_to_user(fildes, fd, 2*sizeof(int)))
48 /* common code for old and new mmaps */
49 static inline long do_mmap2(
50 unsigned long addr, unsigned long len,
51 unsigned long prot, unsigned long flags,
52 unsigned long fd, unsigned long pgoff)
55 struct file * file = NULL;
57 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
58 if (!(flags & MAP_ANONYMOUS)) {
64 down_write(¤t->mm->mmap_sem);
65 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
66 up_write(¤t->mm->mmap_sem);
74 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
75 unsigned long prot, unsigned long flags,
76 unsigned long fd, unsigned long pgoff)
78 return do_mmap2(addr, len, prot, flags, fd, pgoff);
82 * Perform the select(nd, in, out, ex, tv) and mmap() system
83 * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
84 * handle more than 4 system call parameters, so these system calls
85 * used a memory block for parameter passing..
88 struct mmap_arg_struct {
97 asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
99 struct mmap_arg_struct a;
102 if (copy_from_user(&a, arg, sizeof(a)))
106 if (a.offset & ~PAGE_MASK)
109 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
111 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
117 struct mmap_arg_struct64 {
122 __u64 offset; /* 64 bits */
126 asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
129 struct file * file = NULL;
130 struct mmap_arg_struct64 a;
133 if (copy_from_user(&a, arg, sizeof(a)))
136 if ((long)a.offset & ~PAGE_MASK)
139 pgoff = a.offset >> PAGE_SHIFT;
140 if ((a.offset >> PAGE_SHIFT) != pgoff)
143 if (!(a.flags & MAP_ANONYMOUS)) {
149 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
151 down_write(¤t->mm->mmap_sem);
152 error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
153 up_write(¤t->mm->mmap_sem);
161 struct sel_arg_struct {
163 fd_set __user *inp, *outp, *exp;
164 struct timeval __user *tvp;
167 asmlinkage int old_select(struct sel_arg_struct __user *arg)
169 struct sel_arg_struct a;
171 if (copy_from_user(&a, arg, sizeof(a)))
173 /* sys_select() does the appropriate kernel locking */
174 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
178 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
180 * This is really horribly ugly.
182 asmlinkage int sys_ipc (uint call, int first, int second,
183 int third, void __user *ptr, long fifth)
187 version = call >> 16; /* hack for backward compatibility */
193 return sys_semop (first, ptr, second);
195 return sys_semget (first, second, third);
200 if (get_user(fourth.__pad, (void __user *__user *) ptr))
202 return sys_semctl (first, second, third, fourth);
210 return sys_msgsnd (first, ptr, second, third);
214 struct ipc_kludge tmp;
217 if (copy_from_user (&tmp, ptr, sizeof (tmp)))
219 return sys_msgrcv (first, tmp.msgp, second,
223 return sys_msgrcv (first, ptr,
224 second, fifth, third);
227 return sys_msgget ((key_t) first, second);
229 return sys_msgctl (first, second, ptr);
239 ret = do_shmat (first, ptr, second, &raddr);
242 return put_user (raddr, (ulong __user *) third);
246 return sys_shmdt (ptr);
248 return sys_shmget (first, second, third);
250 return sys_shmctl (first, second, ptr);
258 /* Convert virtual (user) address VADDR to physical address PADDR */
259 #define virt_to_phys_040(vaddr) \
261 unsigned long _mmusr, _paddr; \
263 __asm__ __volatile__ (".chip 68040\n\t" \
265 "movec %%mmusr,%0\n\t" \
269 _paddr = (_mmusr & MMU_R_040) ? (_mmusr & PAGE_MASK) : 0; \
274 cache_flush_040 (unsigned long addr, int scope, int cache, unsigned long len)
276 unsigned long paddr, i;
280 case FLUSH_SCOPE_ALL:
283 case FLUSH_CACHE_DATA:
284 /* This nop is needed for some broken versions of the 68040. */
285 __asm__ __volatile__ ("nop\n\t"
290 case FLUSH_CACHE_INSN:
291 __asm__ __volatile__ ("nop\n\t"
297 case FLUSH_CACHE_BOTH:
298 __asm__ __volatile__ ("nop\n\t"
306 case FLUSH_SCOPE_LINE:
307 /* Find the physical address of the first mapped page in the
309 if ((paddr = virt_to_phys_040(addr))) {
310 paddr += addr & ~(PAGE_MASK | 15);
311 len = (len + (addr & 15) + 15) >> 4;
313 unsigned long tmp = PAGE_SIZE - (addr & ~PAGE_MASK);
322 if ((paddr = virt_to_phys_040(addr)))
329 len = (len + 15) >> 4;
331 i = (PAGE_SIZE - (paddr & ~PAGE_MASK)) >> 4;
336 case FLUSH_CACHE_DATA:
337 __asm__ __volatile__ ("nop\n\t"
339 "cpushl %%dc,(%0)\n\t"
343 case FLUSH_CACHE_INSN:
344 __asm__ __volatile__ ("nop\n\t"
346 "cpushl %%ic,(%0)\n\t"
351 case FLUSH_CACHE_BOTH:
352 __asm__ __volatile__ ("nop\n\t"
354 "cpushl %%bc,(%0)\n\t"
362 * No need to page align here since it is done by
363 * virt_to_phys_040().
367 /* Recompute physical address when crossing a page
371 if ((paddr = virt_to_phys_040(addr)))
385 case FLUSH_SCOPE_PAGE:
386 len += (addr & ~PAGE_MASK) + (PAGE_SIZE - 1);
387 for (len >>= PAGE_SHIFT; len--; addr += PAGE_SIZE)
389 if (!(paddr = virt_to_phys_040(addr)))
393 case FLUSH_CACHE_DATA:
394 __asm__ __volatile__ ("nop\n\t"
396 "cpushp %%dc,(%0)\n\t"
400 case FLUSH_CACHE_INSN:
401 __asm__ __volatile__ ("nop\n\t"
403 "cpushp %%ic,(%0)\n\t"
408 case FLUSH_CACHE_BOTH:
409 __asm__ __volatile__ ("nop\n\t"
411 "cpushp %%bc,(%0)\n\t"
422 #define virt_to_phys_060(vaddr) \
424 unsigned long paddr; \
425 __asm__ __volatile__ (".chip 68060\n\t" \
434 cache_flush_060 (unsigned long addr, int scope, int cache, unsigned long len)
436 unsigned long paddr, i;
440 * cpush %dc : flush DC, remains valid (with our %cacr setup)
441 * cpush %ic : invalidate IC
442 * cpush %bc : flush DC + invalidate IC
446 case FLUSH_SCOPE_ALL:
449 case FLUSH_CACHE_DATA:
450 __asm__ __volatile__ (".chip 68060\n\t"
454 case FLUSH_CACHE_INSN:
455 __asm__ __volatile__ (".chip 68060\n\t"
460 case FLUSH_CACHE_BOTH:
461 __asm__ __volatile__ (".chip 68060\n\t"
468 case FLUSH_SCOPE_LINE:
469 /* Find the physical address of the first mapped page in the
473 if (!(paddr = virt_to_phys_060(addr))) {
474 unsigned long tmp = PAGE_SIZE - (addr & ~PAGE_MASK);
483 if ((paddr = virt_to_phys_060(addr)))
491 len = (len + 15) >> 4;
492 i = (PAGE_SIZE - (paddr & ~PAGE_MASK)) >> 4;
497 case FLUSH_CACHE_DATA:
498 __asm__ __volatile__ (".chip 68060\n\t"
499 "cpushl %%dc,(%0)\n\t"
503 case FLUSH_CACHE_INSN:
504 __asm__ __volatile__ (".chip 68060\n\t"
505 "cpushl %%ic,(%0)\n\t"
510 case FLUSH_CACHE_BOTH:
511 __asm__ __volatile__ (".chip 68060\n\t"
512 "cpushl %%bc,(%0)\n\t"
521 * We just want to jump to the first cache line
528 /* Recompute physical address when crossing a page
532 if ((paddr = virt_to_phys_060(addr)))
546 case FLUSH_SCOPE_PAGE:
547 len += (addr & ~PAGE_MASK) + (PAGE_SIZE - 1);
548 addr &= PAGE_MASK; /* Workaround for bug in some
549 revisions of the 68060 */
550 for (len >>= PAGE_SHIFT; len--; addr += PAGE_SIZE)
552 if (!(paddr = virt_to_phys_060(addr)))
556 case FLUSH_CACHE_DATA:
557 __asm__ __volatile__ (".chip 68060\n\t"
558 "cpushp %%dc,(%0)\n\t"
562 case FLUSH_CACHE_INSN:
563 __asm__ __volatile__ (".chip 68060\n\t"
564 "cpushp %%ic,(%0)\n\t"
569 case FLUSH_CACHE_BOTH:
570 __asm__ __volatile__ (".chip 68060\n\t"
571 "cpushp %%bc,(%0)\n\t"
582 /* sys_cacheflush -- flush (part of) the processor cache. */
584 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
586 struct vm_area_struct *vma;
590 if (scope < FLUSH_SCOPE_LINE || scope > FLUSH_SCOPE_ALL ||
591 cache & ~FLUSH_CACHE_BOTH)
594 if (scope == FLUSH_SCOPE_ALL) {
595 /* Only the superuser may explicitly flush the whole cache. */
597 if (!capable(CAP_SYS_ADMIN))
601 * Verify that the specified address region actually belongs
604 vma = find_vma (current->mm, addr);
606 /* Check for overflow. */
607 if (addr + len < addr)
609 if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
613 if (CPU_IS_020_OR_030) {
614 if (scope == FLUSH_SCOPE_LINE && len < 256) {
616 __asm__ ("movec %%cacr, %0" : "=r" (cacr));
617 if (cache & FLUSH_CACHE_INSN)
619 if (cache & FLUSH_CACHE_DATA)
623 __asm__ __volatile__ ("movec %1, %%caar\n\t"
626 : "r" (cacr), "r" (addr));
630 /* Flush the whole cache, even if page granularity requested. */
632 __asm__ ("movec %%cacr, %0" : "=r" (cacr));
633 if (cache & FLUSH_CACHE_INSN)
635 if (cache & FLUSH_CACHE_DATA)
637 __asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
643 * 040 or 060: don't blindly trust 'scope', someone could
644 * try to flush a few megs of memory.
647 if (len>=3*PAGE_SIZE && scope<FLUSH_SCOPE_PAGE)
648 scope=FLUSH_SCOPE_PAGE;
649 if (len>=10*PAGE_SIZE && scope<FLUSH_SCOPE_ALL)
650 scope=FLUSH_SCOPE_ALL;
652 ret = cache_flush_040 (addr, scope, cache, len);
653 } else if (CPU_IS_060) {
654 ret = cache_flush_060 (addr, scope, cache, len);
662 asmlinkage int sys_getpagesize(void)