1 /* $Id: sys_sparc.c,v 1.43 2000/07/06 01:41:29 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>
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 unsigned long get_unmapped_area(unsigned long addr
, unsigned long len
)
45 struct vm_area_struct
* vmm
;
46 unsigned long task_size
= TASK_SIZE
;
48 if (current
->thread
.flags
& SPARC_FLAG_32BIT
)
49 task_size
= 0xf0000000UL
;
50 if (len
> task_size
|| len
> -PAGE_OFFSET
)
53 addr
= TASK_UNMAPPED_BASE
;
54 addr
= PAGE_ALIGN(addr
);
58 for (vmm
= find_vma(current
->mm
, addr
); ; vmm
= vmm
->vm_next
) {
59 /* At this point: (!vmm || addr < vmm->vm_end). */
60 if (addr
< PAGE_OFFSET
&& -PAGE_OFFSET
- len
< addr
) {
62 vmm
= find_vma(current
->mm
, PAGE_OFFSET
);
66 if (!vmm
|| addr
+ len
<= vmm
->vm_start
)
72 extern asmlinkage
unsigned long sys_brk(unsigned long brk
);
74 asmlinkage
unsigned long sparc_brk(unsigned long brk
)
76 /* People could try to be nasty and use ta 0x6d in 32bit programs */
77 if ((current
->thread
.flags
& SPARC_FLAG_32BIT
) &&
79 return current
->mm
->brk
;
81 if ((current
->mm
->brk
& PAGE_OFFSET
) != (brk
& PAGE_OFFSET
))
82 return current
->mm
->brk
;
87 * sys_pipe() is the normal C calling standard for creating
88 * a pipe. It's not the way unix traditionally does this, though.
90 asmlinkage
int sparc_pipe(struct pt_regs
*regs
)
98 regs
->u_regs
[UREG_I1
] = fd
[1];
105 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
107 * This is really horribly ugly.
110 asmlinkage
int sys_ipc (unsigned call
, int first
, int second
, unsigned long third
, void *ptr
, long fifth
)
114 /* No need for backward compatibility. We can start fresh... */
119 err
= sys_semop (first
, (struct sembuf
*)ptr
, second
);
122 err
= sys_semget (first
, second
, (int)third
);
130 if(get_user(fourth
.__pad
, (void **)ptr
))
132 err
= sys_semctl (first
, second
| IPC_64
, (int)third
, fourth
);
142 err
= sys_msgsnd (first
, (struct msgbuf
*) ptr
,
146 err
= sys_msgrcv (first
, (struct msgbuf
*) ptr
, second
, fifth
, (int)third
);
149 err
= sys_msgget ((key_t
) first
, second
);
152 err
= sys_msgctl (first
, second
| IPC_64
, (struct msqid_ds
*) ptr
);
161 err
= sys_shmat (first
, (char *) ptr
, second
, (ulong
*) third
);
164 err
= sys_shmdt ((char *)ptr
);
167 err
= sys_shmget (first
, second
, (int)third
);
170 err
= sys_shmctl (first
, second
| IPC_64
, (struct shmid_ds
*) ptr
);
182 extern asmlinkage
int sys_newuname(struct new_utsname
* name
);
184 asmlinkage
int sparc64_newuname(struct new_utsname
* name
)
186 int ret
= sys_newuname(name
);
188 if (current
->personality
== PER_LINUX32
&& !ret
) {
189 ret
= copy_to_user(name
->machine
, "sparc\0\0", 8);
194 extern asmlinkage
long sys_personality(unsigned long);
196 asmlinkage
int sparc64_personality(unsigned long personality
)
199 if (current
->personality
== PER_LINUX32
&& personality
== PER_LINUX
)
200 personality
= PER_LINUX32
;
201 ret
= sys_personality(personality
);
202 if (ret
== PER_LINUX32
)
207 /* Linux version of mmap */
208 asmlinkage
unsigned long sys_mmap(unsigned long addr
, unsigned long len
,
209 unsigned long prot
, unsigned long flags
, unsigned long fd
,
212 struct file
* file
= NULL
;
213 unsigned long retval
= -EBADF
;
215 if (!(flags
& MAP_ANONYMOUS
)) {
220 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
221 len
= PAGE_ALIGN(len
);
224 if (current
->thread
.flags
& SPARC_FLAG_32BIT
) {
225 if (len
> 0xf0000000UL
||
226 ((flags
& MAP_FIXED
) && addr
> 0xf0000000UL
- len
))
229 if (len
> -PAGE_OFFSET
||
230 ((flags
& MAP_FIXED
) &&
231 addr
< PAGE_OFFSET
&& addr
+ len
> -PAGE_OFFSET
))
235 down(¤t
->mm
->mmap_sem
);
236 retval
= do_mmap(file
, addr
, len
, prot
, flags
, off
);
237 up(¤t
->mm
->mmap_sem
);
246 asmlinkage
long sys64_munmap(unsigned long addr
, size_t len
)
250 if (len
> -PAGE_OFFSET
||
251 (addr
< PAGE_OFFSET
&& addr
+ len
> -PAGE_OFFSET
))
253 down(¤t
->mm
->mmap_sem
);
254 ret
= do_munmap(current
->mm
, addr
, len
);
255 up(¤t
->mm
->mmap_sem
);
259 extern unsigned long do_mremap(unsigned long addr
,
260 unsigned long old_len
, unsigned long new_len
,
261 unsigned long flags
, unsigned long new_addr
);
263 asmlinkage
unsigned long sys64_mremap(unsigned long addr
,
264 unsigned long old_len
, unsigned long new_len
,
265 unsigned long flags
, unsigned long new_addr
)
267 unsigned long ret
= -EINVAL
;
268 if (current
->thread
.flags
& SPARC_FLAG_32BIT
)
270 if (old_len
> -PAGE_OFFSET
|| new_len
> -PAGE_OFFSET
)
272 if (addr
< PAGE_OFFSET
&& addr
+ old_len
> -PAGE_OFFSET
)
274 down(¤t
->mm
->mmap_sem
);
275 if (flags
& MREMAP_FIXED
) {
276 if (new_addr
< PAGE_OFFSET
&&
277 new_addr
+ new_len
> -PAGE_OFFSET
)
279 } else if (addr
< PAGE_OFFSET
&& addr
+ new_len
> -PAGE_OFFSET
) {
281 if (!(flags
& MREMAP_MAYMOVE
))
283 new_addr
= get_unmapped_area (addr
, new_len
);
286 flags
|= MREMAP_FIXED
;
288 ret
= do_mremap(addr
, old_len
, new_len
, flags
, new_addr
);
290 up(¤t
->mm
->mmap_sem
);
295 /* we come to here via sys_nis_syscall so it can setup the regs argument */
296 asmlinkage
unsigned long
297 c_sys_nis_syscall (struct pt_regs
*regs
)
301 /* Don't make the system unusable, if someone goes stuck */
302 if (count
++ > 5) return -ENOSYS
;
304 printk ("Unimplemented SPARC system call %ld\n",regs
->u_regs
[1]);
305 #ifdef DEBUG_UNIMP_SYSCALL
312 /* #define DEBUG_SPARC_BREAKPOINT */
315 sparc_breakpoint (struct pt_regs
*regs
)
320 #ifdef DEBUG_SPARC_BREAKPOINT
321 printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs
->tpc
, regs
->tnpc
);
323 info
.si_signo
= SIGTRAP
;
325 info
.si_code
= TRAP_BRKPT
;
326 info
.si_addr
= (void *)regs
->tpc
;
328 force_sig_info(SIGTRAP
, &info
, current
);
329 #ifdef DEBUG_SPARC_BREAKPOINT
330 printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs
->tpc
, regs
->tnpc
);
335 extern void check_pending(int signum
);
337 asmlinkage
int sys_getdomainname(char *name
, int len
)
344 nlen
= strlen(system_utsname
.domainname
) + 1;
348 if(len
> __NEW_UTS_LEN
)
350 if(copy_to_user(name
, system_utsname
.domainname
, len
))
358 /* only AP+ systems have sys_aplib */
359 asmlinkage
int sys_aplib(void)
364 asmlinkage
int solaris_syscall(struct pt_regs
*regs
)
366 static int count
= 0;
368 regs
->tpc
= regs
->tnpc
;
371 printk ("For Solaris binary emulation you need solaris module loaded\n");
374 send_sig(SIGSEGV
, current
, 1);
379 #ifndef CONFIG_SUNOS_EMUL
380 asmlinkage
int sunos_syscall(struct pt_regs
*regs
)
382 static int count
= 0;
384 regs
->tpc
= regs
->tnpc
;
387 printk ("SunOS binary emulation not compiled in\n");
388 force_sig(SIGSEGV
, current
);
394 asmlinkage
int sys_utrap_install(utrap_entry_t type
, utrap_handler_t new_p
,
395 utrap_handler_t new_d
,
396 utrap_handler_t
*old_p
, utrap_handler_t
*old_d
)
398 if (type
< UT_INSTRUCTION_EXCEPTION
|| type
> UT_TRAP_INSTRUCTION_31
)
400 if (new_p
== (utrap_handler_t
)(long)UTH_NOCHANGE
) {
402 if (!current
->thread
.utraps
)
403 put_user_ret(NULL
, old_p
, -EFAULT
);
405 put_user_ret((utrap_handler_t
)(current
->thread
.utraps
[type
]), old_p
, -EFAULT
);
408 put_user_ret(NULL
, old_d
, -EFAULT
);
412 if (!current
->thread
.utraps
) {
413 current
->thread
.utraps
= kmalloc((UT_TRAP_INSTRUCTION_31
+1)*sizeof(long), GFP_KERNEL
);
414 if (!current
->thread
.utraps
) return -ENOMEM
;
415 current
->thread
.utraps
[0] = 1;
416 memset(current
->thread
.utraps
+1, 0, UT_TRAP_INSTRUCTION_31
*sizeof(long));
418 if ((utrap_handler_t
)current
->thread
.utraps
[type
] != new_p
&& current
->thread
.utraps
[0] > 1) {
419 long *p
= current
->thread
.utraps
;
421 current
->thread
.utraps
= kmalloc((UT_TRAP_INSTRUCTION_31
+1)*sizeof(long), GFP_KERNEL
);
422 if (!current
->thread
.utraps
) {
423 current
->thread
.utraps
= p
;
427 current
->thread
.utraps
[0] = 1;
428 memcpy(current
->thread
.utraps
+1, p
+1, UT_TRAP_INSTRUCTION_31
*sizeof(long));
432 put_user_ret((utrap_handler_t
)(current
->thread
.utraps
[type
]), old_p
, -EFAULT
);
434 put_user_ret(NULL
, old_d
, -EFAULT
);
435 current
->thread
.utraps
[type
] = (long)new_p
;
440 long sparc_memory_ordering(unsigned long model
, struct pt_regs
*regs
)
444 regs
->tstate
= (regs
->tstate
& ~TSTATE_MM
) | (model
<< 14);
449 sys_rt_sigaction(int sig
, const struct sigaction
*act
, struct sigaction
*oact
,
450 void *restorer
, size_t sigsetsize
)
452 struct k_sigaction new_ka
, old_ka
;
455 /* XXX: Don't preclude handling different sized sigset_t's. */
456 if (sigsetsize
!= sizeof(sigset_t
))
460 new_ka
.ka_restorer
= restorer
;
461 if (copy_from_user(&new_ka
.sa
, act
, sizeof(*act
)))
465 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
468 if (copy_to_user(oact
, &old_ka
.sa
, sizeof(*oact
)))
475 /* Invoked by rtrap code to update performance counters in
479 update_perfctrs(void)
481 unsigned long pic
, tmp
;
484 tmp
= (current
->thread
.kernel_cntd0
+= (unsigned int)pic
);
485 __put_user(tmp
, current
->thread
.user_cntd0
);
486 tmp
= (current
->thread
.kernel_cntd1
+= (pic
>> 32));
487 __put_user(tmp
, current
->thread
.user_cntd1
);
492 sys_perfctr(int opcode
, unsigned long arg0
, unsigned long arg1
, unsigned long arg2
)
498 current
->thread
.pcr_reg
= arg2
;
499 current
->thread
.user_cntd0
= (u64
*) arg0
;
500 current
->thread
.user_cntd1
= (u64
*) arg1
;
501 current
->thread
.kernel_cntd0
=
502 current
->thread
.kernel_cntd1
= 0;
505 current
->thread
.flags
|= SPARC_FLAG_PERFCTR
;
510 if ((current
->thread
.flags
& SPARC_FLAG_PERFCTR
) != 0) {
511 current
->thread
.user_cntd0
=
512 current
->thread
.user_cntd1
= NULL
;
513 current
->thread
.pcr_reg
= 0;
515 current
->thread
.flags
&= ~(SPARC_FLAG_PERFCTR
);
521 unsigned long pic
, tmp
;
523 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
528 tmp
= (current
->thread
.kernel_cntd0
+= (unsigned int)pic
);
529 err
|= __put_user(tmp
, current
->thread
.user_cntd0
);
530 tmp
= (current
->thread
.kernel_cntd1
+= (pic
>> 32));
531 err
|= __put_user(tmp
, current
->thread
.user_cntd1
);
537 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
541 current
->thread
.kernel_cntd0
=
542 current
->thread
.kernel_cntd1
= 0;
546 case PERFCTR_SETPCR
: {
547 u64
*user_pcr
= (u64
*)arg0
;
548 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
552 err
|= __get_user(current
->thread
.pcr_reg
, user_pcr
);
553 write_pcr(current
->thread
.pcr_reg
);
554 current
->thread
.kernel_cntd0
=
555 current
->thread
.kernel_cntd1
= 0;
560 case PERFCTR_GETPCR
: {
561 u64
*user_pcr
= (u64
*)arg0
;
562 if (!(current
->thread
.flags
& SPARC_FLAG_PERFCTR
)) {
566 err
|= __put_user(current
->thread
.pcr_reg
, user_pcr
);