1 /* $Id: sys_sparc.c,v 1.57 2000/01/21 11:38:42 jj Exp $
2 * linux/arch/sparc/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/errno.h>
10 #include <linux/types.h>
11 #include <linux/sched.h>
12 #include <linux/config.h>
15 #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>
25 #include <asm/uaccess.h>
28 /* #define DEBUG_UNIMP_SYSCALL */
30 /* XXX Make this per-binary type, this way we can detect the type of
31 * XXX a binary. Every Sparc executable calls this very early on.
33 asmlinkage
unsigned long sys_getpagesize(void)
35 return PAGE_SIZE
; /* Possibly older binaries want 8192 on sun4's? */
38 extern asmlinkage
unsigned long sys_brk(unsigned long brk
);
40 asmlinkage
unsigned long sparc_brk(unsigned long brk
)
43 if(brk
>= 0x20000000 && brk
< 0xe0000000)
44 return current
->mm
->brk
;
50 * sys_pipe() is the normal C calling standard for creating
51 * a pipe. It's not the way unix traditionally does this, though.
53 asmlinkage
int sparc_pipe(struct pt_regs
*regs
)
62 regs
->u_regs
[UREG_I1
] = fd
[1];
70 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
72 * This is really horribly ugly.
75 asmlinkage
int sys_ipc (uint call
, int first
, int second
, int third
, void *ptr
, long fifth
)
80 version
= call
>> 16; /* hack for backward compatibility */
86 err
= sys_semop (first
, (struct sembuf
*)ptr
, second
);
89 err
= sys_semget (first
, second
, third
);
97 if(get_user(fourth
.__pad
, (void **)ptr
))
99 err
= sys_semctl (first
, second
, third
, fourth
);
109 err
= sys_msgsnd (first
, (struct msgbuf
*) ptr
,
115 struct ipc_kludge tmp
;
120 if(copy_from_user(&tmp
,(struct ipc_kludge
*) ptr
, sizeof (tmp
)))
122 err
= sys_msgrcv (first
, tmp
.msgp
, second
, tmp
.msgtyp
, third
);
126 err
= sys_msgrcv (first
, (struct msgbuf
*) ptr
, second
, fifth
, third
);
130 err
= sys_msgget ((key_t
) first
, second
);
133 err
= sys_msgctl (first
, second
, (struct msqid_ds
*) ptr
);
145 err
= sys_shmat (first
, (char *) ptr
, second
, &raddr
);
149 if(put_user (raddr
, (ulong
*) third
))
154 case 1: /* iBCS2 emulator entry point */
155 err
= sys_shmat (first
, (char *) ptr
, second
, (ulong
*) third
);
159 err
= sys_shmdt ((char *)ptr
);
162 err
= sys_shmget (first
, second
, third
);
165 err
= sys_shmctl (first
, second
, (struct shmid_ds
*) ptr
);
178 /* Linux version of mmap */
179 static unsigned long do_mmap2(unsigned long addr
, unsigned long len
,
180 unsigned long prot
, unsigned long flags
, unsigned long fd
,
183 struct file
* file
= NULL
;
184 unsigned long retval
= -EBADF
;
186 if (!(flags
& MAP_ANONYMOUS
)) {
192 down(¤t
->mm
->mmap_sem
);
195 len
= PAGE_ALIGN(len
);
196 if(!(flags
& MAP_FIXED
) &&
197 (!addr
|| (ARCH_SUN4C_SUN4
&&
198 (addr
>= 0x20000000 && addr
< 0xe0000000)))) {
199 addr
= get_unmapped_area(0, len
);
202 if (ARCH_SUN4C_SUN4
&&
203 (addr
>= 0x20000000 && addr
< 0xe0000000)) {
209 /* See asm-sparc/uaccess.h */
211 if((len
> (TASK_SIZE
- PAGE_SIZE
)) || (addr
> (TASK_SIZE
-len
-PAGE_SIZE
)))
214 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
215 retval
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
219 up(¤t
->mm
->mmap_sem
);
226 asmlinkage
unsigned long sys_mmap2(unsigned long addr
, unsigned long len
,
227 unsigned long prot
, unsigned long flags
, unsigned long fd
,
230 /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
232 return do_mmap2(addr
, len
, prot
, flags
, fd
, pgoff
>> (PAGE_SHIFT
- 12));
235 asmlinkage
unsigned long sys_mmap(unsigned long addr
, unsigned long len
,
236 unsigned long prot
, unsigned long flags
, unsigned long fd
,
239 return do_mmap2(addr
, len
, prot
, flags
, fd
, off
>> PAGE_SHIFT
);
242 /* we come to here via sys_nis_syscall so it can setup the regs argument */
243 asmlinkage
unsigned long
244 c_sys_nis_syscall (struct pt_regs
*regs
)
246 static int count
= 0;
248 if (count
++ > 5) return -ENOSYS
;
250 printk ("%s[%d]: Unimplemented SPARC system call %d\n", current
->comm
, current
->pid
, (int)regs
->u_regs
[1]);
251 #ifdef DEBUG_UNIMP_SYSCALL
258 /* #define DEBUG_SPARC_BREAKPOINT */
261 sparc_breakpoint (struct pt_regs
*regs
)
266 #ifdef DEBUG_SPARC_BREAKPOINT
267 printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs
->pc
, regs
->npc
);
269 info
.si_signo
= SIGTRAP
;
271 info
.si_code
= TRAP_BRKPT
;
272 info
.si_addr
= (void *)regs
->pc
;
274 force_sig_info(SIGTRAP
, &info
, current
);
276 #ifdef DEBUG_SPARC_BREAKPOINT
277 printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs
->pc
, regs
->npc
);
283 sparc_sigaction (int sig
, const struct old_sigaction
*act
,
284 struct old_sigaction
*oact
)
286 struct k_sigaction new_ka
, old_ka
;
290 current
->thread
.new_signal
= 1;
297 if (verify_area(VERIFY_READ
, act
, sizeof(*act
)) ||
298 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
299 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
))
301 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
);
302 __get_user(mask
, &act
->sa_mask
);
303 siginitset(&new_ka
.sa
.sa_mask
, mask
);
304 new_ka
.ka_restorer
= NULL
;
307 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
310 /* In the clone() case we could copy half consistant
311 * state to the user, however this could sleep and
312 * deadlock us if we held the signal lock on SMP. So for
313 * now I take the easy way out and do no locking.
315 if (verify_area(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
316 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
317 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
))
319 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
320 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
);
327 sys_rt_sigaction(int sig
, const struct sigaction
*act
, struct sigaction
*oact
,
328 void *restorer
, size_t sigsetsize
)
330 struct k_sigaction new_ka
, old_ka
;
333 /* XXX: Don't preclude handling different sized sigset_t's. */
334 if (sigsetsize
!= sizeof(sigset_t
))
337 /* All tasks which use RT signals (effectively) use
340 current
->thread
.new_signal
= 1;
343 new_ka
.ka_restorer
= restorer
;
344 if (copy_from_user(&new_ka
.sa
, act
, sizeof(*act
)))
348 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
351 if (copy_to_user(oact
, &old_ka
.sa
, sizeof(*oact
)))
358 /* Just in case some old old binary calls this. */
359 asmlinkage
int sys_pause(void)
361 current
->state
= TASK_INTERRUPTIBLE
;
363 return -ERESTARTNOHAND
;
366 asmlinkage
int sys_getdomainname(char *name
, int len
)
373 nlen
= strlen(system_utsname
.domainname
) + 1;
377 if(len
> __NEW_UTS_LEN
)
379 if(copy_to_user(name
, system_utsname
.domainname
, len
))
388 #ifndef CONFIG_AP1000
389 /* only AP+ systems have sys_aplib */
390 asmlinkage
int sys_aplib(void)