1 /* $Id: sys_sparc.c,v 1.56 2000/01/04 11:01:26 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
)
264 #ifdef DEBUG_SPARC_BREAKPOINT
265 printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs
->pc
, regs
->npc
);
267 force_sig(SIGTRAP
, current
);
268 #ifdef DEBUG_SPARC_BREAKPOINT
269 printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs
->pc
, regs
->npc
);
275 sparc_sigaction (int sig
, const struct old_sigaction
*act
,
276 struct old_sigaction
*oact
)
278 struct k_sigaction new_ka
, old_ka
;
282 current
->thread
.new_signal
= 1;
289 if (verify_area(VERIFY_READ
, act
, sizeof(*act
)) ||
290 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
291 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
))
293 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
);
294 __get_user(mask
, &act
->sa_mask
);
295 siginitset(&new_ka
.sa
.sa_mask
, mask
);
296 new_ka
.ka_restorer
= NULL
;
299 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
302 /* In the clone() case we could copy half consistant
303 * state to the user, however this could sleep and
304 * deadlock us if we held the signal lock on SMP. So for
305 * now I take the easy way out and do no locking.
307 if (verify_area(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
308 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
309 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
))
311 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
312 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
);
319 sys_rt_sigaction(int sig
, const struct sigaction
*act
, struct sigaction
*oact
,
320 void *restorer
, size_t sigsetsize
)
322 struct k_sigaction new_ka
, old_ka
;
325 /* XXX: Don't preclude handling different sized sigset_t's. */
326 if (sigsetsize
!= sizeof(sigset_t
))
329 /* All tasks which use RT signals (effectively) use
332 current
->thread
.new_signal
= 1;
335 new_ka
.ka_restorer
= restorer
;
336 if (copy_from_user(&new_ka
.sa
, act
, sizeof(*act
)))
340 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
343 if (copy_to_user(oact
, &old_ka
.sa
, sizeof(*oact
)))
350 /* Just in case some old old binary calls this. */
351 asmlinkage
int sys_pause(void)
353 current
->state
= TASK_INTERRUPTIBLE
;
355 return -ERESTARTNOHAND
;
358 asmlinkage
int sys_getdomainname(char *name
, int len
)
365 nlen
= strlen(system_utsname
.domainname
) + 1;
369 if(len
> __NEW_UTS_LEN
)
371 if(copy_to_user(name
, system_utsname
.domainname
, len
))
380 #ifndef CONFIG_AP1000
381 /* only AP+ systems have sys_aplib */
382 asmlinkage
int sys_aplib(void)