Merge branch 'mini2440-dev-extras' into mini2440-dev
[linux-2.6/mini2440.git] / arch / m32r / kernel / sys_m32r.c
blob305ac852bbed417dda77de7a9b100c6a401bc75d
1 /*
2 * linux/arch/m32r/kernel/sys_m32r.c
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/M32R platform.
7 * Taken from i386 version.
8 */
10 #include <linux/errno.h>
11 #include <linux/sched.h>
12 #include <linux/mm.h>
13 #include <linux/fs.h>
14 #include <linux/smp.h>
15 #include <linux/sem.h>
16 #include <linux/msg.h>
17 #include <linux/shm.h>
18 #include <linux/stat.h>
19 #include <linux/syscalls.h>
20 #include <linux/mman.h>
21 #include <linux/file.h>
22 #include <linux/utsname.h>
23 #include <linux/ipc.h>
25 #include <asm/uaccess.h>
26 #include <asm/cachectl.h>
27 #include <asm/cacheflush.h>
28 #include <asm/syscall.h>
29 #include <asm/unistd.h>
32 * sys_tas() - test-and-set
34 asmlinkage int sys_tas(int __user *addr)
36 int oldval;
38 if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
39 return -EFAULT;
41 /* atomic operation:
42 * oldval = *addr; *addr = 1;
44 __asm__ __volatile__ (
45 DCACHE_CLEAR("%0", "r4", "%1")
46 " .fillinsn\n"
47 "1:\n"
48 " lock %0, @%1 -> unlock %2, @%1\n"
49 "2:\n"
50 /* NOTE:
51 * The m32r processor can accept interrupts only
52 * at the 32-bit instruction boundary.
53 * So, in the above code, the "unlock" instruction
54 * can be executed continuously after the "lock"
55 * instruction execution without any interruptions.
57 ".section .fixup,\"ax\"\n"
58 " .balign 4\n"
59 "3: ldi %0, #%3\n"
60 " seth r14, #high(2b)\n"
61 " or3 r14, r14, #low(2b)\n"
62 " jmp r14\n"
63 ".previous\n"
64 ".section __ex_table,\"a\"\n"
65 " .balign 4\n"
66 " .long 1b,3b\n"
67 ".previous\n"
68 : "=&r" (oldval)
69 : "r" (addr), "r" (1), "i"(-EFAULT)
70 : "r14", "memory"
71 #ifdef CONFIG_CHIP_M32700_TS1
72 , "r4"
73 #endif /* CONFIG_CHIP_M32700_TS1 */
76 return oldval;
79 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
80 unsigned long prot, unsigned long flags,
81 unsigned long fd, unsigned long pgoff)
83 int error = -EBADF;
84 struct file *file = NULL;
86 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
87 if (!(flags & MAP_ANONYMOUS)) {
88 file = fget(fd);
89 if (!file)
90 goto out;
93 down_write(&current->mm->mmap_sem);
94 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
95 up_write(&current->mm->mmap_sem);
97 if (file)
98 fput(file);
99 out:
100 return error;
104 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
106 * This is really horribly ugly.
108 asmlinkage int sys_ipc(uint call, int first, int second,
109 int third, void __user *ptr, long fifth)
111 int version, ret;
113 version = call >> 16; /* hack for backward compatibility */
114 call &= 0xffff;
116 switch (call) {
117 case SEMOP:
118 return sys_semtimedop(first, (struct sembuf __user *)ptr,
119 second, NULL);
120 case SEMTIMEDOP:
121 return sys_semtimedop(first, (struct sembuf __user *)ptr,
122 second, (const struct timespec __user *)fifth);
123 case SEMGET:
124 return sys_semget (first, second, third);
125 case SEMCTL: {
126 union semun fourth;
127 if (!ptr)
128 return -EINVAL;
129 if (get_user(fourth.__pad, (void __user * __user *) ptr))
130 return -EFAULT;
131 return sys_semctl (first, second, third, fourth);
134 case MSGSND:
135 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
136 second, third);
137 case MSGRCV:
138 switch (version) {
139 case 0: {
140 struct ipc_kludge tmp;
141 if (!ptr)
142 return -EINVAL;
144 if (copy_from_user(&tmp,
145 (struct ipc_kludge __user *) ptr,
146 sizeof (tmp)))
147 return -EFAULT;
148 return sys_msgrcv (first, tmp.msgp, second,
149 tmp.msgtyp, third);
151 default:
152 return sys_msgrcv (first,
153 (struct msgbuf __user *) ptr,
154 second, fifth, third);
156 case MSGGET:
157 return sys_msgget ((key_t) first, second);
158 case MSGCTL:
159 return sys_msgctl (first, second,
160 (struct msqid_ds __user *) ptr);
161 case SHMAT: {
162 ulong raddr;
164 if (!access_ok(VERIFY_WRITE, (ulong __user *) third,
165 sizeof(ulong)))
166 return -EFAULT;
167 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
168 if (ret)
169 return ret;
170 return put_user (raddr, (ulong __user *) third);
172 case SHMDT:
173 return sys_shmdt ((char __user *)ptr);
174 case SHMGET:
175 return sys_shmget (first, second, third);
176 case SHMCTL:
177 return sys_shmctl (first, second,
178 (struct shmid_ds __user *) ptr);
179 default:
180 return -ENOSYS;
184 asmlinkage int sys_uname(struct old_utsname __user * name)
186 int err;
187 if (!name)
188 return -EFAULT;
189 down_read(&uts_sem);
190 err = copy_to_user(name, utsname(), sizeof (*name));
191 up_read(&uts_sem);
192 return err?-EFAULT:0;
195 asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
197 /* This should flush more selectively ... */
198 _flush_cache_all();
199 return 0;
202 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
204 /* Not implemented yet. */
205 return -ENOSYS;
209 * Do a system call from kernel instead of calling sys_execve so we
210 * end up with proper pt_regs.
212 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
214 register long __scno __asm__ ("r7") = __NR_execve;
215 register long __arg3 __asm__ ("r2") = (long)(envp);
216 register long __arg2 __asm__ ("r1") = (long)(argv);
217 register long __res __asm__ ("r0") = (long)(filename);
218 __asm__ __volatile__ (
219 "trap #" SYSCALL_VECTOR "|| nop"
220 : "=r" (__res)
221 : "r" (__scno), "0" (__res), "r" (__arg2),
222 "r" (__arg3)
223 : "memory");
224 return __res;