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>
14 #include <linux/smp.h>
15 #include <linux/smp_lock.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/syscalls.h>
21 #include <linux/mman.h>
22 #include <linux/file.h>
23 #include <linux/ipc.h>
25 #include <asm/setup.h>
26 #include <asm/uaccess.h>
27 #include <asm/cachectl.h>
28 #include <asm/traps.h>
30 #include <asm/unistd.h>
32 asmlinkage
long sys_mmap2(unsigned long addr
, unsigned long len
,
33 unsigned long prot
, unsigned long flags
,
34 unsigned long fd
, unsigned long pgoff
)
37 * This is wrong for sun3 - there PAGE_SIZE is 8Kb,
38 * so we need to shift the argument down by 1; m68k mmap64(3)
39 * (in libc) expects the last argument of mmap2 in 4Kb units.
41 return sys_mmap_pgoff(addr
, len
, prot
, flags
, fd
, pgoff
);
45 * Perform the select(nd, in, out, ex, tv) and mmap() system
46 * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
47 * handle more than 4 system call parameters, so these system calls
48 * used a memory block for parameter passing..
51 struct mmap_arg_struct
{
60 asmlinkage
int old_mmap(struct mmap_arg_struct __user
*arg
)
62 struct mmap_arg_struct a
;
65 if (copy_from_user(&a
, arg
, sizeof(a
)))
69 if (a
.offset
& ~PAGE_MASK
)
72 error
= sys_mmap_pgoff(a
.addr
, a
.len
, a
.prot
, a
.flags
, a
.fd
,
73 a
.offset
>> PAGE_SHIFT
);
78 struct sel_arg_struct
{
80 fd_set __user
*inp
, *outp
, *exp
;
81 struct timeval __user
*tvp
;
84 asmlinkage
int old_select(struct sel_arg_struct __user
*arg
)
86 struct sel_arg_struct a
;
88 if (copy_from_user(&a
, arg
, sizeof(a
)))
90 /* sys_select() does the appropriate kernel locking */
91 return sys_select(a
.n
, a
.inp
, a
.outp
, a
.exp
, a
.tvp
);
95 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
97 * This is really horribly ugly.
99 asmlinkage
int sys_ipc (uint call
, int first
, int second
,
100 int third
, void __user
*ptr
, long fifth
)
104 version
= call
>> 16; /* hack for backward compatibility */
110 return sys_semop (first
, ptr
, second
);
112 return sys_semget (first
, second
, third
);
117 if (get_user(fourth
.__pad
, (void __user
*__user
*) ptr
))
119 return sys_semctl (first
, second
, third
, fourth
);
127 return sys_msgsnd (first
, ptr
, second
, third
);
131 struct ipc_kludge tmp
;
134 if (copy_from_user (&tmp
, ptr
, sizeof (tmp
)))
136 return sys_msgrcv (first
, tmp
.msgp
, second
,
140 return sys_msgrcv (first
, ptr
,
141 second
, fifth
, third
);
144 return sys_msgget ((key_t
) first
, second
);
146 return sys_msgctl (first
, second
, ptr
);
156 ret
= do_shmat (first
, ptr
, second
, &raddr
);
159 return put_user (raddr
, (ulong __user
*) third
);
163 return sys_shmdt (ptr
);
165 return sys_shmget (first
, second
, third
);
167 return sys_shmctl (first
, second
, ptr
);
175 /* Convert virtual (user) address VADDR to physical address PADDR */
176 #define virt_to_phys_040(vaddr) \
178 unsigned long _mmusr, _paddr; \
180 __asm__ __volatile__ (".chip 68040\n\t" \
182 "movec %%mmusr,%0\n\t" \
186 _paddr = (_mmusr & MMU_R_040) ? (_mmusr & PAGE_MASK) : 0; \
191 cache_flush_040 (unsigned long addr
, int scope
, int cache
, unsigned long len
)
193 unsigned long paddr
, i
;
197 case FLUSH_SCOPE_ALL
:
200 case FLUSH_CACHE_DATA
:
201 /* This nop is needed for some broken versions of the 68040. */
202 __asm__
__volatile__ ("nop\n\t"
207 case FLUSH_CACHE_INSN
:
208 __asm__
__volatile__ ("nop\n\t"
214 case FLUSH_CACHE_BOTH
:
215 __asm__
__volatile__ ("nop\n\t"
223 case FLUSH_SCOPE_LINE
:
224 /* Find the physical address of the first mapped page in the
226 if ((paddr
= virt_to_phys_040(addr
))) {
227 paddr
+= addr
& ~(PAGE_MASK
| 15);
228 len
= (len
+ (addr
& 15) + 15) >> 4;
230 unsigned long tmp
= PAGE_SIZE
- (addr
& ~PAGE_MASK
);
239 if ((paddr
= virt_to_phys_040(addr
)))
246 len
= (len
+ 15) >> 4;
248 i
= (PAGE_SIZE
- (paddr
& ~PAGE_MASK
)) >> 4;
253 case FLUSH_CACHE_DATA
:
254 __asm__
__volatile__ ("nop\n\t"
256 "cpushl %%dc,(%0)\n\t"
260 case FLUSH_CACHE_INSN
:
261 __asm__
__volatile__ ("nop\n\t"
263 "cpushl %%ic,(%0)\n\t"
268 case FLUSH_CACHE_BOTH
:
269 __asm__
__volatile__ ("nop\n\t"
271 "cpushl %%bc,(%0)\n\t"
279 * No need to page align here since it is done by
280 * virt_to_phys_040().
284 /* Recompute physical address when crossing a page
288 if ((paddr
= virt_to_phys_040(addr
)))
302 case FLUSH_SCOPE_PAGE
:
303 len
+= (addr
& ~PAGE_MASK
) + (PAGE_SIZE
- 1);
304 for (len
>>= PAGE_SHIFT
; len
--; addr
+= PAGE_SIZE
)
306 if (!(paddr
= virt_to_phys_040(addr
)))
310 case FLUSH_CACHE_DATA
:
311 __asm__
__volatile__ ("nop\n\t"
313 "cpushp %%dc,(%0)\n\t"
317 case FLUSH_CACHE_INSN
:
318 __asm__
__volatile__ ("nop\n\t"
320 "cpushp %%ic,(%0)\n\t"
325 case FLUSH_CACHE_BOTH
:
326 __asm__
__volatile__ ("nop\n\t"
328 "cpushp %%bc,(%0)\n\t"
339 #define virt_to_phys_060(vaddr) \
341 unsigned long paddr; \
342 __asm__ __volatile__ (".chip 68060\n\t" \
351 cache_flush_060 (unsigned long addr
, int scope
, int cache
, unsigned long len
)
353 unsigned long paddr
, i
;
357 * cpush %dc : flush DC, remains valid (with our %cacr setup)
358 * cpush %ic : invalidate IC
359 * cpush %bc : flush DC + invalidate IC
363 case FLUSH_SCOPE_ALL
:
366 case FLUSH_CACHE_DATA
:
367 __asm__
__volatile__ (".chip 68060\n\t"
371 case FLUSH_CACHE_INSN
:
372 __asm__
__volatile__ (".chip 68060\n\t"
377 case FLUSH_CACHE_BOTH
:
378 __asm__
__volatile__ (".chip 68060\n\t"
385 case FLUSH_SCOPE_LINE
:
386 /* Find the physical address of the first mapped page in the
390 if (!(paddr
= virt_to_phys_060(addr
))) {
391 unsigned long tmp
= PAGE_SIZE
- (addr
& ~PAGE_MASK
);
400 if ((paddr
= virt_to_phys_060(addr
)))
408 len
= (len
+ 15) >> 4;
409 i
= (PAGE_SIZE
- (paddr
& ~PAGE_MASK
)) >> 4;
414 case FLUSH_CACHE_DATA
:
415 __asm__
__volatile__ (".chip 68060\n\t"
416 "cpushl %%dc,(%0)\n\t"
420 case FLUSH_CACHE_INSN
:
421 __asm__
__volatile__ (".chip 68060\n\t"
422 "cpushl %%ic,(%0)\n\t"
427 case FLUSH_CACHE_BOTH
:
428 __asm__
__volatile__ (".chip 68060\n\t"
429 "cpushl %%bc,(%0)\n\t"
438 * We just want to jump to the first cache line
445 /* Recompute physical address when crossing a page
449 if ((paddr
= virt_to_phys_060(addr
)))
463 case FLUSH_SCOPE_PAGE
:
464 len
+= (addr
& ~PAGE_MASK
) + (PAGE_SIZE
- 1);
465 addr
&= PAGE_MASK
; /* Workaround for bug in some
466 revisions of the 68060 */
467 for (len
>>= PAGE_SHIFT
; len
--; addr
+= PAGE_SIZE
)
469 if (!(paddr
= virt_to_phys_060(addr
)))
473 case FLUSH_CACHE_DATA
:
474 __asm__
__volatile__ (".chip 68060\n\t"
475 "cpushp %%dc,(%0)\n\t"
479 case FLUSH_CACHE_INSN
:
480 __asm__
__volatile__ (".chip 68060\n\t"
481 "cpushp %%ic,(%0)\n\t"
486 case FLUSH_CACHE_BOTH
:
487 __asm__
__volatile__ (".chip 68060\n\t"
488 "cpushp %%bc,(%0)\n\t"
499 /* sys_cacheflush -- flush (part of) the processor cache. */
501 sys_cacheflush (unsigned long addr
, int scope
, int cache
, unsigned long len
)
503 struct vm_area_struct
*vma
;
507 if (scope
< FLUSH_SCOPE_LINE
|| scope
> FLUSH_SCOPE_ALL
||
508 cache
& ~FLUSH_CACHE_BOTH
)
511 if (scope
== FLUSH_SCOPE_ALL
) {
512 /* Only the superuser may explicitly flush the whole cache. */
514 if (!capable(CAP_SYS_ADMIN
))
518 * Verify that the specified address region actually belongs
521 vma
= find_vma (current
->mm
, addr
);
523 /* Check for overflow. */
524 if (addr
+ len
< addr
)
526 if (vma
== NULL
|| addr
< vma
->vm_start
|| addr
+ len
> vma
->vm_end
)
530 if (CPU_IS_020_OR_030
) {
531 if (scope
== FLUSH_SCOPE_LINE
&& len
< 256) {
533 __asm__ ("movec %%cacr, %0" : "=r" (cacr
));
534 if (cache
& FLUSH_CACHE_INSN
)
536 if (cache
& FLUSH_CACHE_DATA
)
540 __asm__
__volatile__ ("movec %1, %%caar\n\t"
543 : "r" (cacr
), "r" (addr
));
547 /* Flush the whole cache, even if page granularity requested. */
549 __asm__ ("movec %%cacr, %0" : "=r" (cacr
));
550 if (cache
& FLUSH_CACHE_INSN
)
552 if (cache
& FLUSH_CACHE_DATA
)
554 __asm__
__volatile__ ("movec %0, %%cacr" : : "r" (cacr
));
560 * 040 or 060: don't blindly trust 'scope', someone could
561 * try to flush a few megs of memory.
564 if (len
>=3*PAGE_SIZE
&& scope
<FLUSH_SCOPE_PAGE
)
565 scope
=FLUSH_SCOPE_PAGE
;
566 if (len
>=10*PAGE_SIZE
&& scope
<FLUSH_SCOPE_ALL
)
567 scope
=FLUSH_SCOPE_ALL
;
569 ret
= cache_flush_040 (addr
, scope
, cache
, len
);
570 } else if (CPU_IS_060
) {
571 ret
= cache_flush_060 (addr
, scope
, cache
, len
);
579 asmlinkage
int sys_getpagesize(void)
585 * Do a system call from kernel instead of calling sys_execve so we
586 * end up with proper pt_regs.
588 int kernel_execve(const char *filename
, char *const argv
[], char *const envp
[])
590 register long __res
asm ("%d0") = __NR_execve
;
591 register long __a
asm ("%d1") = (long)(filename
);
592 register long __b
asm ("%d2") = (long)(argv
);
593 register long __c
asm ("%d3") = (long)(envp
);
594 asm volatile ("trap #0" : "+d" (__res
)
595 : "d" (__a
), "d" (__b
), "d" (__c
));