| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * linux/arch/m32r/kernel/sys_m32r.c | 
 | 3 |  * | 
 | 4 |  * This file contains various random system calls that | 
 | 5 |  * have a non-standard calling sequence on the Linux/M32R platform. | 
 | 6 |  * | 
 | 7 |  * Taken from i386 version. | 
 | 8 |  */ | 
 | 9 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/errno.h> | 
 | 11 | #include <linux/sched.h> | 
 | 12 | #include <linux/mm.h> | 
 | 13 | #include <linux/smp.h> | 
 | 14 | #include <linux/smp_lock.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 |  | 
 | 24 | #include <asm/uaccess.h> | 
 | 25 | #include <asm/cachectl.h> | 
 | 26 | #include <asm/cacheflush.h> | 
 | 27 | #include <asm/ipc.h> | 
| Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 28 | #include <asm/syscall.h> | 
 | 29 | #include <asm/unistd.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 |  | 
 | 31 | /* | 
 | 32 |  * sys_tas() - test-and-set | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 |  */ | 
| Al Viro | fd2c903 | 2006-10-11 17:24:55 +0100 | [diff] [blame] | 34 | asmlinkage int sys_tas(int __user *addr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { | 
 | 36 | 	int oldval; | 
 | 37 |  | 
 | 38 | 	if (!access_ok(VERIFY_WRITE, addr, sizeof (int))) | 
 | 39 | 		return -EFAULT; | 
 | 40 |  | 
| Hirokazu Takata | cf535ea | 2006-02-20 18:28:17 -0800 | [diff] [blame] | 41 | 	/* atomic operation: | 
 | 42 | 	 *   oldval = *addr; *addr = 1; | 
 | 43 | 	 */ | 
 | 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. | 
 | 56 | 		 */ | 
 | 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 */ | 
 | 74 | 	); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 |  | 
 | 76 | 	return oldval; | 
 | 77 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 |  | 
 | 79 | /* | 
 | 80 |  * sys_pipe() is the normal C calling standard for creating | 
 | 81 |  * a pipe. It's not the way Unix traditionally does this, though. | 
 | 82 |  */ | 
 | 83 | asmlinkage int | 
 | 84 | sys_pipe(unsigned long r0, unsigned long r1, unsigned long r2, | 
 | 85 | 	unsigned long r3, unsigned long r4, unsigned long r5, | 
 | 86 | 	unsigned long r6, struct pt_regs regs) | 
 | 87 | { | 
 | 88 | 	int fd[2]; | 
 | 89 | 	int error; | 
 | 90 |  | 
 | 91 | 	error = do_pipe(fd); | 
 | 92 | 	if (!error) { | 
| Al Viro | fd2c903 | 2006-10-11 17:24:55 +0100 | [diff] [blame] | 93 | 		if (copy_to_user((void __user *)r0, fd, 2*sizeof(int))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | 			error = -EFAULT; | 
 | 95 | 	} | 
 | 96 | 	return error; | 
 | 97 | } | 
 | 98 |  | 
 | 99 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | 
 | 100 | 	unsigned long prot, unsigned long flags, | 
 | 101 | 	unsigned long fd, unsigned long pgoff) | 
 | 102 | { | 
 | 103 | 	int error = -EBADF; | 
 | 104 | 	struct file *file = NULL; | 
 | 105 |  | 
 | 106 | 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 
 | 107 | 	if (!(flags & MAP_ANONYMOUS)) { | 
 | 108 | 		file = fget(fd); | 
 | 109 | 		if (!file) | 
 | 110 | 			goto out; | 
 | 111 | 	} | 
 | 112 |  | 
 | 113 | 	down_write(¤t->mm->mmap_sem); | 
 | 114 | 	error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | 
 | 115 | 	up_write(¤t->mm->mmap_sem); | 
 | 116 |  | 
 | 117 | 	if (file) | 
 | 118 | 		fput(file); | 
 | 119 | out: | 
 | 120 | 	return error; | 
 | 121 | } | 
 | 122 |  | 
 | 123 | /* | 
 | 124 |  * sys_ipc() is the de-multiplexer for the SysV IPC calls.. | 
 | 125 |  * | 
 | 126 |  * This is really horribly ugly. | 
 | 127 |  */ | 
 | 128 | asmlinkage int sys_ipc(uint call, int first, int second, | 
 | 129 | 		       int third, void __user *ptr, long fifth) | 
 | 130 | { | 
 | 131 | 	int version, ret; | 
 | 132 |  | 
 | 133 | 	version = call >> 16; /* hack for backward compatibility */ | 
 | 134 | 	call &= 0xffff; | 
 | 135 |  | 
 | 136 | 	switch (call) { | 
 | 137 | 	case SEMOP: | 
 | 138 | 		return sys_semtimedop(first, (struct sembuf __user *)ptr, | 
 | 139 | 				      second, NULL); | 
 | 140 | 	case SEMTIMEDOP: | 
 | 141 | 		return sys_semtimedop(first, (struct sembuf __user *)ptr, | 
 | 142 | 				      second, (const struct timespec __user *)fifth); | 
 | 143 | 	case SEMGET: | 
 | 144 | 		return sys_semget (first, second, third); | 
 | 145 | 	case SEMCTL: { | 
 | 146 | 		union semun fourth; | 
 | 147 | 		if (!ptr) | 
 | 148 | 			return -EINVAL; | 
 | 149 | 		if (get_user(fourth.__pad, (void __user * __user *) ptr)) | 
 | 150 | 			return -EFAULT; | 
 | 151 | 		return sys_semctl (first, second, third, fourth); | 
 | 152 | 		} | 
 | 153 |  | 
 | 154 | 	case MSGSND: | 
 | 155 | 		return sys_msgsnd (first, (struct msgbuf __user *) ptr, | 
 | 156 | 				   second, third); | 
 | 157 | 	case MSGRCV: | 
 | 158 | 		switch (version) { | 
 | 159 | 		case 0: { | 
 | 160 | 			struct ipc_kludge tmp; | 
 | 161 | 			if (!ptr) | 
 | 162 | 				return -EINVAL; | 
 | 163 |  | 
 | 164 | 			if (copy_from_user(&tmp, | 
 | 165 | 					   (struct ipc_kludge __user *) ptr, | 
 | 166 | 					   sizeof (tmp))) | 
 | 167 | 				return -EFAULT; | 
 | 168 | 			return sys_msgrcv (first, tmp.msgp, second, | 
 | 169 | 					   tmp.msgtyp, third); | 
 | 170 | 			} | 
 | 171 | 		default: | 
 | 172 | 			return sys_msgrcv (first, | 
 | 173 | 					   (struct msgbuf __user *) ptr, | 
 | 174 | 					   second, fifth, third); | 
 | 175 | 		} | 
 | 176 | 	case MSGGET: | 
 | 177 | 		return sys_msgget ((key_t) first, second); | 
 | 178 | 	case MSGCTL: | 
 | 179 | 		return sys_msgctl (first, second, | 
 | 180 | 				   (struct msqid_ds __user *) ptr); | 
 | 181 | 	case SHMAT: { | 
 | 182 | 		ulong raddr; | 
 | 183 |  | 
 | 184 | 		if (!access_ok(VERIFY_WRITE, (ulong __user *) third, | 
 | 185 | 				      sizeof(ulong))) | 
 | 186 | 			return -EFAULT; | 
 | 187 | 		ret = do_shmat (first, (char __user *) ptr, second, &raddr); | 
 | 188 | 		if (ret) | 
 | 189 | 			return ret; | 
 | 190 | 		return put_user (raddr, (ulong __user *) third); | 
 | 191 | 		} | 
 | 192 | 	case SHMDT: | 
 | 193 | 		return sys_shmdt ((char __user *)ptr); | 
 | 194 | 	case SHMGET: | 
 | 195 | 		return sys_shmget (first, second, third); | 
 | 196 | 	case SHMCTL: | 
 | 197 | 		return sys_shmctl (first, second, | 
 | 198 | 				   (struct shmid_ds __user *) ptr); | 
 | 199 | 	default: | 
 | 200 | 		return -ENOSYS; | 
 | 201 | 	} | 
 | 202 | } | 
 | 203 |  | 
| Al Viro | fd2c903 | 2006-10-11 17:24:55 +0100 | [diff] [blame] | 204 | asmlinkage int sys_uname(struct old_utsname __user * name) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { | 
 | 206 | 	int err; | 
 | 207 | 	if (!name) | 
 | 208 | 		return -EFAULT; | 
 | 209 | 	down_read(&uts_sem); | 
| Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 210 | 	err = copy_to_user(name, utsname(), sizeof (*name)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | 	up_read(&uts_sem); | 
 | 212 | 	return err?-EFAULT:0; | 
 | 213 | } | 
 | 214 |  | 
 | 215 | asmlinkage int sys_cacheflush(void *addr, int bytes, int cache) | 
 | 216 | { | 
 | 217 | 	/* This should flush more selectivly ...  */ | 
 | 218 | 	_flush_cache_all(); | 
 | 219 | 	return 0; | 
 | 220 | } | 
 | 221 |  | 
 | 222 | asmlinkage int sys_cachectl(char *addr, int nbytes, int op) | 
 | 223 | { | 
 | 224 | 	/* Not implemented yet. */ | 
 | 225 | 	return -ENOSYS; | 
 | 226 | } | 
 | 227 |  | 
| Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 228 | /* | 
 | 229 |  * Do a system call from kernel instead of calling sys_execve so we | 
 | 230 |  * end up with proper pt_regs. | 
 | 231 |  */ | 
 | 232 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) | 
 | 233 | { | 
 | 234 | 	register long __scno __asm__ ("r7") = __NR_execve; | 
 | 235 | 	register long __arg3 __asm__ ("r2") = (long)(envp); | 
 | 236 | 	register long __arg2 __asm__ ("r1") = (long)(argv); | 
 | 237 | 	register long __res __asm__ ("r0") = (long)(filename); | 
 | 238 | 	__asm__ __volatile__ ( | 
 | 239 | 		"trap #" SYSCALL_VECTOR "|| nop" | 
 | 240 | 		: "=r" (__res) | 
 | 241 | 		: "r" (__scno), "0" (__res), "r" (__arg2), | 
 | 242 | 			"r" (__arg3) | 
 | 243 | 		: "memory"); | 
 | 244 | 	return __res; | 
 | 245 | } |