1 /* $Id: sys_sparc.c,v 1.36 2000/02/16 07:31:35 davem 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>
27 #include <asm/uaccess.h>
29 #include <asm/utrap.h>
30 #include <asm/perfctr.h>
32 /* #define DEBUG_UNIMP_SYSCALL */
34 /* XXX Make this per-binary type, this way we can detect the type of
35 * XXX a binary. Every Sparc executable calls this very early on.
37 asmlinkage
unsigned long sys_getpagesize(void)
42 unsigned long get_unmapped_area(unsigned long addr
, unsigned long len
)
44 struct vm_area_struct
* vmm
;
45 unsigned long task_size
= TASK_SIZE
;
47 if (current
->thread
.flags
& SPARC_FLAG_32BIT
)
48 task_size
= 0xf0000000UL
;
49 if (len
> task_size
|| len
> -PAGE_OFFSET
)
52 addr
= TASK_UNMAPPED_BASE
;
53 addr
= PAGE_ALIGN(addr
);
57 for (vmm
= find_vma(current
->mm
, addr
); ; vmm
= vmm
->vm_next
) {
58 /* At this point: (!vmm || addr < vmm->vm_end). */
59 if (addr
< PAGE_OFFSET
&& -PAGE_OFFSET
- len
< addr
) {
61 vmm
= find_vma(current
->mm
, PAGE_OFFSET
);
65 if (!vmm
|| addr
+ len
<= vmm
->vm_start
)
71 extern asmlinkage
unsigned long sys_brk(unsigned long brk
);
73 asmlinkage
unsigned long sparc_brk(unsigned long brk
)
75 /* People could try to be nasty and use ta 0x6d in 32bit programs */
76 if ((current
->thread
.flags
& SPARC_FLAG_32BIT
) &&
78 return current
->mm
->brk
;
80 if ((current
->mm
->brk
& PAGE_OFFSET
) != (brk
& PAGE_OFFSET
))
81 return current
->mm
->brk
;
86 * sys_pipe() is the normal C calling standard for creating
87 * a pipe. It's not the way unix traditionally does this, though.
89 asmlinkage
int sparc_pipe(struct pt_regs
*regs
)
98 regs
->u_regs
[UREG_I1
] = fd
[1];
106 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
108 * This is really horribly ugly.
111 asmlinkage
int sys_ipc (unsigned call
, int first
, int second
, unsigned long third
, void *ptr
, long fifth
)
116 /* No need for backward compatibility. We can start fresh... */
121 err
= sys_semop (first
, (struct sembuf
*)ptr
, second
);
124 err
= sys_semget (first
, second
, (int)third
);
132 if(get_user(fourth
.__pad
, (void **)ptr
))
134 err
= sys_semctl (first
, second
| IPC_64
, (int)third
, fourth
);
144 err
= sys_msgsnd (first
, (struct msgbuf
*) ptr
,
148 err
= sys_msgrcv (first
, (struct msgbuf
*) ptr
, second
, fifth
, (int)third
);
151 err
= sys_msgget ((key_t
) first
, second
);
154 err
= sys_msgctl (first
, second
| IPC_64
, (struct msqid_ds
*) ptr
);
163 err
= sys_shmat (first
, (char *) ptr
, second
, (ulong
*) third
);
166 err
= sys_shmdt ((char *)ptr
);
169 err
= sys_shmget (first
, second
, (int)third
);
172 err
= sys_shmctl (first
, second
| IPC_64
, (struct shmid_ds
*) ptr
);
185 /* Linux version of mmap */
186 asmlinkage
unsigned long sys_mmap(unsigned long addr
, unsigned long len
,
187 unsigned long prot
, unsigned long flags
, unsigned long fd
,
190 struct file
* file
= NULL
;
191 unsigned long retval
= -EBADF
;
193 if (!(flags
& MAP_ANONYMOUS
)) {
198 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
199 len
= PAGE_ALIGN(len
);
202 down(¤t
->mm
->mmap_sem
);
205 if (current
->thread
.flags
& SPARC_FLAG_32BIT
) {
206 if (len
> 0xf0000000UL
||
207 ((flags
& MAP_FIXED
) && addr
> 0xf0000000UL
- len
))
210 if (len
> -PAGE_OFFSET
||
211 ((flags
& MAP_FIXED
) &&
212 addr
< PAGE_OFFSET
&& addr
+ len
> -PAGE_OFFSET
))
216 retval
= do_mmap(file
, addr
, len
, prot
, flags
, off
);
220 up(¤t
->mm
->mmap_sem
);
227 asmlinkage
long sys64_munmap(unsigned long addr
, size_t len
)
231 if (len
> -PAGE_OFFSET
||
232 (addr
< PAGE_OFFSET
&& addr
+ len
> -PAGE_OFFSET
))
234 down(¤t
->mm
->mmap_sem
);
235 ret
= do_munmap(addr
, len
);
236 up(¤t
->mm
->mmap_sem
);
240 extern unsigned long do_mremap(unsigned long addr
,
241 unsigned long old_len
, unsigned long new_len
,
242 unsigned long flags
, unsigned long new_addr
);
244 asmlinkage
unsigned long sys64_mremap(unsigned long addr
,
245 unsigned long old_len
, unsigned long new_len
,
246 unsigned long flags
, unsigned long new_addr
)
248 unsigned long ret
= -EINVAL
;
249 if (current
->thread
.flags
& SPARC_FLAG_32BIT
)
251 if (old_len
> -PAGE_OFFSET
|| new_len
> -PAGE_OFFSET
)
253 if (addr
< PAGE_OFFSET
&& addr
+ old_len
> -PAGE_OFFSET
)
255 down(¤t
->mm
->mmap_sem
);
256 if (flags
& MREMAP_FIXED
) {
257 if (new_addr
< PAGE_OFFSET
&&
258 new_addr
+ new_len
> -PAGE_OFFSET
)
260 } else if (addr
< PAGE_OFFSET
&& addr
+ new_len
> -PAGE_OFFSET
) {
262 if (!(flags
& MREMAP_MAYMOVE
))
264 new_addr
= get_unmapped_area (addr
, new_len
);
267 flags
|= MREMAP_FIXED
;
269 ret
= do_mremap(addr
, old_len
, new_len
, flags
, new_addr
);
271 up(¤t
->mm
->mmap_sem
);
276 /* we come to here via sys_nis_syscall so it can setup the regs argument */
277 asmlinkage
unsigned long
278 c_sys_nis_syscall (struct pt_regs
*regs
)
282 /* Don't make the system unusable, if someone goes stuck */
283 if (count
++ > 5) return -ENOSYS
;
285 printk ("Unimplemented SPARC system call %ld\n",regs
->u_regs
[1]);
286 #ifdef DEBUG_UNIMP_SYSCALL
293 /* #define DEBUG_SPARC_BREAKPOINT */
296 sparc_breakpoint (struct pt_regs
*regs
)
301 #ifdef DEBUG_SPARC_BREAKPOINT
302 printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs
->tpc
, regs
->tnpc
);
304 info
.si_signo
= SIGTRAP
;
306 info
.si_code
= TRAP_BRKPT
;
307 info
.si_addr
= (void *)regs
->tpc
;
309 force_sig_info(SIGTRAP
, &info
, current
);
310 #ifdef DEBUG_SPARC_BREAKPOINT
311 printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs
->tpc
, regs
->tnpc
);
316 extern void check_pending(int signum
);
318 asmlinkage
int sys_getdomainname(char *name
, int len
)
325 nlen
= strlen(system_utsname
.domainname
) + 1;
329 if(len
> __NEW_UTS_LEN
)
331 if(copy_to_user(name
, system_utsname
.domainname
, len
))
339 /* only AP+ systems have sys_aplib */
340 asmlinkage
int sys_aplib(void)
345 asmlinkage
int solaris_syscall(struct pt_regs
*regs
)
347 static int count
= 0;
349 regs
->tpc
= regs
->tnpc
;
352 printk ("For Solaris binary emulation you need solaris module loaded\n");
354 send_sig(SIGSEGV
, current
, 1);
359 #ifndef CONFIG_SUNOS_EMUL
360 asmlinkage
int sunos_syscall(struct pt_regs
*regs
)
362 static int count
= 0;
364 regs
->tpc
= regs
->tnpc
;
367 printk ("SunOS binary emulation not compiled in\n");
368 force_sig(SIGSEGV
, current
);
374 asmlinkage
int sys_utrap_install(utrap_entry_t type
, utrap_handler_t new_p
,
375 utrap_handler_t new_d
,
376 utrap_handler_t
*old_p
, utrap_handler_t
*old_d
)
378 if (type
< UT_INSTRUCTION_EXCEPTION
|| type
> UT_TRAP_INSTRUCTION_31
)
380 if (new_p
== (utrap_handler_t
)(long)UTH_NOCHANGE
) {
382 if (!current
->thread
.utraps
)
383 put_user_ret(NULL
, old_p
, -EFAULT
);
385 put_user_ret((utrap_handler_t
)(current
->thread
.utraps
[type
]), old_p
, -EFAULT
);
388 put_user_ret(NULL
, old_d
, -EFAULT
);
392 if (!current
->thread
.utraps
) {
393 current
->thread
.utraps
= kmalloc((UT_TRAP_INSTRUCTION_31
+1)*sizeof(long), GFP_KERNEL
);
394 if (!current
->thread
.utraps
) return -ENOMEM
;
395 current
->thread
.utraps
[0] = 1;
396 memset(current
->thread
.utraps
+1, 0, UT_TRAP_INSTRUCTION_31
*sizeof(long));
398 if ((utrap_handler_t
)current
->thread
.utraps
[type
] != new_p
&& current
->thread
.utraps
[0] > 1) {
399 long *p
= current
->thread
.utraps
;
401 current
->thread
.utraps
= kmalloc((UT_TRAP_INSTRUCTION_31
+1)*sizeof(long), GFP_KERNEL
);
402 if (!current
->thread
.utraps
) {
403 current
->thread
.utraps
= p
;
407 current
->thread
.utraps
[0] = 1;
408 memcpy(current
->thread
.utraps
+1, p
+1, UT_TRAP_INSTRUCTION_31
*sizeof(long));
412 put_user_ret((utrap_handler_t
)(current
->thread
.utraps
[type
]), old_p
, -EFAULT
);
414 put_user_ret(NULL
, old_d
, -EFAULT
);
415 current
->thread
.utraps
[type
] = (long)new_p
;
420 long sparc_memory_ordering(unsigned long model
, struct pt_regs
*regs
)
424 regs
->tstate
= (regs
->tstate
& ~TSTATE_MM
) | (model
<< 14);
429 sys_rt_sigaction(int sig
, const struct sigaction
*act
, struct sigaction
*oact
,
430 void *restorer
, size_t sigsetsize
)
432 struct k_sigaction new_ka
, old_ka
;
435 /* XXX: Don't preclude handling different sized sigset_t's. */
436 if (sigsetsize
!= sizeof(sigset_t
))
440 new_ka
.ka_restorer
= restorer
;
441 if (copy_from_user(&new_ka
.sa
, act
, sizeof(*act
)))
445 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
448 if (copy_to_user(oact
, &old_ka
.sa
, sizeof(*oact
)))
455 /* Invoked by rtrap code to update performance counters in
459 update_perfctrs(void)
461 unsigned long pic
, tmp
;
464 tmp
= (current
->thread
.kernel_cntd0
+= (unsigned int)pic
);
465 __put_user(tmp
, current
->thread
.user_cntd0
);
466 tmp
= (current
->thread
.kernel_cntd1
+= (pic
>> 32));
467 __put_user(tmp
, current
->thread
.user_cntd1
);
472 sys_perfctr(int opcode
, unsigned long arg0
, unsigned long arg1
, unsigned long arg2
)
478 current
->thread
.pcr_reg
= arg2
;
479 current
->thread
.user_cntd0
= (u64
*) arg0
;
480 current
->thread
.user_cntd1
= (u64
*) arg1
;
481 current
->thread
.kernel_cntd0
=
482 current
->thread
.kernel_cntd1
= 0;
485 current
->thread
.flags
|= SPARC_FLAG_PERFCTR
;
490 if ((current
->thread
.flags
& SPARC_FLAG_PERFCTR
) != 0) {
491 current
->thread
.user_cntd0
=
492 current
->thread
.user_cntd1
= NULL
;
493 current
->thread
.pcr_reg
= 0;
495 current
->thread
.flags
&= ~(SPARC_FLAG_PERFCTR
);
501 unsigned long pic
, tmp
;
503 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
508 tmp
= (current
->thread
.kernel_cntd0
+= (unsigned int)pic
);
509 err
|= __put_user(tmp
, current
->thread
.user_cntd0
);
510 tmp
= (current
->thread
.kernel_cntd1
+= (pic
>> 32));
511 err
|= __put_user(tmp
, current
->thread
.user_cntd1
);
517 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
521 current
->thread
.kernel_cntd0
=
522 current
->thread
.kernel_cntd1
= 0;
526 case PERFCTR_SETPCR
: {
527 u64
*user_pcr
= (u64
*)arg0
;
528 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
532 err
|= __get_user(current
->thread
.pcr_reg
, user_pcr
);
533 write_pcr(current
->thread
.pcr_reg
);
534 current
->thread
.kernel_cntd0
=
535 current
->thread
.kernel_cntd1
= 0;
540 case PERFCTR_GETPCR
: {
541 u64
*user_pcr
= (u64
*)arg0
;
542 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
546 err
|= __put_user(current
->thread
.pcr_reg
, user_pcr
);