1 /* $Id: sys_sparc.c,v 1.47 2000/11/29 05:56:12 anton Exp $
2 * linux/arch/sparc64/kernel/sys_sparc.c
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/sparc
9 #include <linux/config.h>
10 #include <linux/errno.h>
11 #include <linux/types.h>
12 #include <linux/sched.h>
14 #include <linux/file.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/mman.h>
21 #include <linux/utsname.h>
22 #include <linux/smp.h>
23 #include <linux/smp_lock.h>
24 #include <linux/malloc.h>
25 #include <linux/ipc.h>
26 #include <linux/personality.h>
28 #include <asm/uaccess.h>
30 #include <asm/utrap.h>
31 #include <asm/perfctr.h>
33 /* #define DEBUG_UNIMP_SYSCALL */
35 /* XXX Make this per-binary type, this way we can detect the type of
36 * XXX a binary. Every Sparc executable calls this very early on.
38 asmlinkage
unsigned long sys_getpagesize(void)
43 #define COLOUR_ALIGN(addr) (((addr)+SHMLBA-1)&~(SHMLBA-1))
45 unsigned long get_unmapped_area(unsigned long addr
, unsigned long len
)
47 struct vm_area_struct
* vmm
;
48 unsigned long task_size
= TASK_SIZE
;
50 if (current
->thread
.flags
& SPARC_FLAG_32BIT
)
51 task_size
= 0xf0000000UL
;
52 if (len
> task_size
|| len
> -PAGE_OFFSET
)
55 addr
= TASK_UNMAPPED_BASE
;
57 if (current
->thread
.flags
& SPARC_FLAG_MMAPSHARED
)
58 addr
= COLOUR_ALIGN(addr
);
60 addr
= PAGE_ALIGN(addr
);
64 for (vmm
= find_vma(current
->mm
, addr
); ; vmm
= vmm
->vm_next
) {
65 /* At this point: (!vmm || addr < vmm->vm_end). */
66 if (addr
< PAGE_OFFSET
&& -PAGE_OFFSET
- len
< addr
) {
68 vmm
= find_vma(current
->mm
, PAGE_OFFSET
);
72 if (!vmm
|| addr
+ len
<= vmm
->vm_start
)
75 if (current
->thread
.flags
& SPARC_FLAG_MMAPSHARED
)
76 addr
= COLOUR_ALIGN(addr
);
80 extern asmlinkage
unsigned long sys_brk(unsigned long brk
);
82 asmlinkage
unsigned long sparc_brk(unsigned long brk
)
84 /* People could try to be nasty and use ta 0x6d in 32bit programs */
85 if ((current
->thread
.flags
& SPARC_FLAG_32BIT
) &&
87 return current
->mm
->brk
;
89 if ((current
->mm
->brk
& PAGE_OFFSET
) != (brk
& PAGE_OFFSET
))
90 return current
->mm
->brk
;
95 * sys_pipe() is the normal C calling standard for creating
96 * a pipe. It's not the way unix traditionally does this, though.
98 asmlinkage
int sparc_pipe(struct pt_regs
*regs
)
106 regs
->u_regs
[UREG_I1
] = fd
[1];
113 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
115 * This is really horribly ugly.
118 asmlinkage
int sys_ipc (unsigned call
, int first
, int second
, unsigned long third
, void *ptr
, long fifth
)
122 /* No need for backward compatibility. We can start fresh... */
127 err
= sys_semop (first
, (struct sembuf
*)ptr
, second
);
130 err
= sys_semget (first
, second
, (int)third
);
138 if(get_user(fourth
.__pad
, (void **)ptr
))
140 err
= sys_semctl (first
, second
| IPC_64
, (int)third
, fourth
);
150 err
= sys_msgsnd (first
, (struct msgbuf
*) ptr
,
154 err
= sys_msgrcv (first
, (struct msgbuf
*) ptr
, second
, fifth
, (int)third
);
157 err
= sys_msgget ((key_t
) first
, second
);
160 err
= sys_msgctl (first
, second
| IPC_64
, (struct msqid_ds
*) ptr
);
169 err
= sys_shmat (first
, (char *) ptr
, second
, (ulong
*) third
);
172 err
= sys_shmdt ((char *)ptr
);
175 err
= sys_shmget (first
, second
, (int)third
);
178 err
= sys_shmctl (first
, second
| IPC_64
, (struct shmid_ds
*) ptr
);
190 extern asmlinkage
int sys_newuname(struct new_utsname
* name
);
192 asmlinkage
int sparc64_newuname(struct new_utsname
* name
)
194 int ret
= sys_newuname(name
);
196 if (current
->personality
== PER_LINUX32
&& !ret
) {
197 ret
= copy_to_user(name
->machine
, "sparc\0\0", 8);
202 extern asmlinkage
long sys_personality(unsigned long);
204 asmlinkage
int sparc64_personality(unsigned long personality
)
207 if (current
->personality
== PER_LINUX32
&& personality
== PER_LINUX
)
208 personality
= PER_LINUX32
;
209 ret
= sys_personality(personality
);
210 if (ret
== PER_LINUX32
)
215 /* Linux version of mmap */
216 asmlinkage
unsigned long sys_mmap(unsigned long addr
, unsigned long len
,
217 unsigned long prot
, unsigned long flags
, unsigned long fd
,
220 struct file
* file
= NULL
;
221 unsigned long retval
= -EBADF
;
223 if (!(flags
& MAP_ANONYMOUS
)) {
228 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
229 len
= PAGE_ALIGN(len
);
232 if (current
->thread
.flags
& SPARC_FLAG_32BIT
) {
233 if (len
> 0xf0000000UL
||
234 ((flags
& MAP_FIXED
) && addr
> 0xf0000000UL
- len
))
237 if (len
> -PAGE_OFFSET
||
238 ((flags
& MAP_FIXED
) &&
239 addr
< PAGE_OFFSET
&& addr
+ len
> -PAGE_OFFSET
))
243 if (flags
& MAP_SHARED
)
244 current
->thread
.flags
|= SPARC_FLAG_MMAPSHARED
;
246 down(¤t
->mm
->mmap_sem
);
247 retval
= do_mmap(file
, addr
, len
, prot
, flags
, off
);
248 up(¤t
->mm
->mmap_sem
);
250 current
->thread
.flags
&= ~(SPARC_FLAG_MMAPSHARED
);
259 asmlinkage
long sys64_munmap(unsigned long addr
, size_t len
)
263 if (len
> -PAGE_OFFSET
||
264 (addr
< PAGE_OFFSET
&& addr
+ len
> -PAGE_OFFSET
))
266 down(¤t
->mm
->mmap_sem
);
267 ret
= do_munmap(current
->mm
, addr
, len
);
268 up(¤t
->mm
->mmap_sem
);
272 extern unsigned long do_mremap(unsigned long addr
,
273 unsigned long old_len
, unsigned long new_len
,
274 unsigned long flags
, unsigned long new_addr
);
276 asmlinkage
unsigned long sys64_mremap(unsigned long addr
,
277 unsigned long old_len
, unsigned long new_len
,
278 unsigned long flags
, unsigned long new_addr
)
280 struct vm_area_struct
*vma
;
281 unsigned long ret
= -EINVAL
;
282 if (current
->thread
.flags
& SPARC_FLAG_32BIT
)
284 if (old_len
> -PAGE_OFFSET
|| new_len
> -PAGE_OFFSET
)
286 if (addr
< PAGE_OFFSET
&& addr
+ old_len
> -PAGE_OFFSET
)
288 down(¤t
->mm
->mmap_sem
);
289 vma
= find_vma(current
->mm
, addr
);
290 if (vma
&& (vma
->vm_flags
& VM_SHARED
))
291 current
->thread
.flags
|= SPARC_FLAG_MMAPSHARED
;
292 if (flags
& MREMAP_FIXED
) {
293 if (new_addr
< PAGE_OFFSET
&&
294 new_addr
+ new_len
> -PAGE_OFFSET
)
296 } else if (addr
< PAGE_OFFSET
&& addr
+ new_len
> -PAGE_OFFSET
) {
298 if (!(flags
& MREMAP_MAYMOVE
))
300 new_addr
= get_unmapped_area(addr
, new_len
);
303 flags
|= MREMAP_FIXED
;
305 ret
= do_mremap(addr
, old_len
, new_len
, flags
, new_addr
);
307 current
->thread
.flags
&= ~(SPARC_FLAG_MMAPSHARED
);
308 up(¤t
->mm
->mmap_sem
);
313 /* we come to here via sys_nis_syscall so it can setup the regs argument */
314 asmlinkage
unsigned long
315 c_sys_nis_syscall (struct pt_regs
*regs
)
319 /* Don't make the system unusable, if someone goes stuck */
323 printk ("Unimplemented SPARC system call %ld\n",regs
->u_regs
[1]);
324 #ifdef DEBUG_UNIMP_SYSCALL
331 /* #define DEBUG_SPARC_BREAKPOINT */
334 sparc_breakpoint (struct pt_regs
*regs
)
338 #ifdef DEBUG_SPARC_BREAKPOINT
339 printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs
->tpc
, regs
->tnpc
);
341 info
.si_signo
= SIGTRAP
;
343 info
.si_code
= TRAP_BRKPT
;
344 info
.si_addr
= (void *)regs
->tpc
;
346 force_sig_info(SIGTRAP
, &info
, current
);
347 #ifdef DEBUG_SPARC_BREAKPOINT
348 printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs
->tpc
, regs
->tnpc
);
352 extern void check_pending(int signum
);
354 asmlinkage
int sys_getdomainname(char *name
, int len
)
361 nlen
= strlen(system_utsname
.domainname
) + 1;
365 if(len
> __NEW_UTS_LEN
)
367 if(copy_to_user(name
, system_utsname
.domainname
, len
))
375 /* only AP+ systems have sys_aplib */
376 asmlinkage
int sys_aplib(void)
381 asmlinkage
int solaris_syscall(struct pt_regs
*regs
)
383 static int count
= 0;
385 regs
->tpc
= regs
->tnpc
;
388 printk ("For Solaris binary emulation you need solaris module loaded\n");
391 send_sig(SIGSEGV
, current
, 1);
396 #ifndef CONFIG_SUNOS_EMUL
397 asmlinkage
int sunos_syscall(struct pt_regs
*regs
)
399 static int count
= 0;
401 regs
->tpc
= regs
->tnpc
;
404 printk ("SunOS binary emulation not compiled in\n");
405 force_sig(SIGSEGV
, current
);
411 asmlinkage
int sys_utrap_install(utrap_entry_t type
, utrap_handler_t new_p
,
412 utrap_handler_t new_d
,
413 utrap_handler_t
*old_p
, utrap_handler_t
*old_d
)
415 if (type
< UT_INSTRUCTION_EXCEPTION
|| type
> UT_TRAP_INSTRUCTION_31
)
417 if (new_p
== (utrap_handler_t
)(long)UTH_NOCHANGE
) {
419 if (!current
->thread
.utraps
) {
420 if (put_user(NULL
, old_p
))
423 if (put_user((utrap_handler_t
)(current
->thread
.utraps
[type
]), old_p
))
428 if (put_user(NULL
, old_d
))
433 if (!current
->thread
.utraps
) {
434 current
->thread
.utraps
=
435 kmalloc((UT_TRAP_INSTRUCTION_31
+1)*sizeof(long), GFP_KERNEL
);
436 if (!current
->thread
.utraps
) return -ENOMEM
;
437 current
->thread
.utraps
[0] = 1;
438 memset(current
->thread
.utraps
+1, 0, UT_TRAP_INSTRUCTION_31
*sizeof(long));
440 if ((utrap_handler_t
)current
->thread
.utraps
[type
] != new_p
&&
441 current
->thread
.utraps
[0] > 1) {
442 long *p
= current
->thread
.utraps
;
444 current
->thread
.utraps
=
445 kmalloc((UT_TRAP_INSTRUCTION_31
+1)*sizeof(long),
447 if (!current
->thread
.utraps
) {
448 current
->thread
.utraps
= p
;
452 current
->thread
.utraps
[0] = 1;
453 memcpy(current
->thread
.utraps
+1, p
+1,
454 UT_TRAP_INSTRUCTION_31
*sizeof(long));
458 if (put_user((utrap_handler_t
)(current
->thread
.utraps
[type
]), old_p
))
462 if (put_user(NULL
, old_d
))
465 current
->thread
.utraps
[type
] = (long)new_p
;
470 long sparc_memory_ordering(unsigned long model
, struct pt_regs
*regs
)
474 regs
->tstate
= (regs
->tstate
& ~TSTATE_MM
) | (model
<< 14);
479 sys_rt_sigaction(int sig
, const struct sigaction
*act
, struct sigaction
*oact
,
480 void *restorer
, size_t sigsetsize
)
482 struct k_sigaction new_ka
, old_ka
;
485 /* XXX: Don't preclude handling different sized sigset_t's. */
486 if (sigsetsize
!= sizeof(sigset_t
))
490 new_ka
.ka_restorer
= restorer
;
491 if (copy_from_user(&new_ka
.sa
, act
, sizeof(*act
)))
495 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
498 if (copy_to_user(oact
, &old_ka
.sa
, sizeof(*oact
)))
505 /* Invoked by rtrap code to update performance counters in
509 update_perfctrs(void)
511 unsigned long pic
, tmp
;
514 tmp
= (current
->thread
.kernel_cntd0
+= (unsigned int)pic
);
515 __put_user(tmp
, current
->thread
.user_cntd0
);
516 tmp
= (current
->thread
.kernel_cntd1
+= (pic
>> 32));
517 __put_user(tmp
, current
->thread
.user_cntd1
);
522 sys_perfctr(int opcode
, unsigned long arg0
, unsigned long arg1
, unsigned long arg2
)
528 current
->thread
.pcr_reg
= arg2
;
529 current
->thread
.user_cntd0
= (u64
*) arg0
;
530 current
->thread
.user_cntd1
= (u64
*) arg1
;
531 current
->thread
.kernel_cntd0
=
532 current
->thread
.kernel_cntd1
= 0;
535 current
->thread
.flags
|= SPARC_FLAG_PERFCTR
;
540 if ((current
->thread
.flags
& SPARC_FLAG_PERFCTR
) != 0) {
541 current
->thread
.user_cntd0
=
542 current
->thread
.user_cntd1
= NULL
;
543 current
->thread
.pcr_reg
= 0;
545 current
->thread
.flags
&= ~(SPARC_FLAG_PERFCTR
);
551 unsigned long pic
, tmp
;
553 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
558 tmp
= (current
->thread
.kernel_cntd0
+= (unsigned int)pic
);
559 err
|= __put_user(tmp
, current
->thread
.user_cntd0
);
560 tmp
= (current
->thread
.kernel_cntd1
+= (pic
>> 32));
561 err
|= __put_user(tmp
, current
->thread
.user_cntd1
);
567 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
571 current
->thread
.kernel_cntd0
=
572 current
->thread
.kernel_cntd1
= 0;
576 case PERFCTR_SETPCR
: {
577 u64
*user_pcr
= (u64
*)arg0
;
578 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
582 err
|= __get_user(current
->thread
.pcr_reg
, user_pcr
);
583 write_pcr(current
->thread
.pcr_reg
);
584 current
->thread
.kernel_cntd0
=
585 current
->thread
.kernel_cntd1
= 0;
590 case PERFCTR_GETPCR
: {
591 u64
*user_pcr
= (u64
*)arg0
;
592 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
596 err
|= __put_user(current
->thread
.pcr_reg
, user_pcr
);