]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
1da177e4 LT |
10 | #include <linux/errno.h> |
11 | #include <linux/sched.h> | |
12 | #include <linux/mm.h> | |
cfcd8c4f | 13 | #include <linux/fs.h> |
1da177e4 | 14 | #include <linux/smp.h> |
1da177e4 LT |
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> | |
cba4fbbf | 23 | #include <linux/ipc.h> |
1da177e4 LT |
24 | |
25 | #include <asm/uaccess.h> | |
26 | #include <asm/cachectl.h> | |
27 | #include <asm/cacheflush.h> | |
fe74290d AB |
28 | #include <asm/syscall.h> |
29 | #include <asm/unistd.h> | |
1da177e4 LT |
30 | |
31 | /* | |
32 | * sys_tas() - test-and-set | |
1da177e4 | 33 | */ |
fd2c903b | 34 | asmlinkage int sys_tas(int __user *addr) |
1da177e4 LT |
35 | { |
36 | int oldval; | |
37 | ||
38 | if (!access_ok(VERIFY_WRITE, addr, sizeof (int))) | |
39 | return -EFAULT; | |
40 | ||
cf535ea5 HT |
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 | ); | |
1da177e4 LT |
75 | |
76 | return oldval; | |
77 | } | |
1da177e4 | 78 | |
1da177e4 LT |
79 | /* |
80 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. | |
81 | * | |
82 | * This is really horribly ugly. | |
83 | */ | |
84 | asmlinkage int sys_ipc(uint call, int first, int second, | |
85 | int third, void __user *ptr, long fifth) | |
86 | { | |
87 | int version, ret; | |
88 | ||
89 | version = call >> 16; /* hack for backward compatibility */ | |
90 | call &= 0xffff; | |
91 | ||
92 | switch (call) { | |
93 | case SEMOP: | |
94 | return sys_semtimedop(first, (struct sembuf __user *)ptr, | |
95 | second, NULL); | |
96 | case SEMTIMEDOP: | |
97 | return sys_semtimedop(first, (struct sembuf __user *)ptr, | |
98 | second, (const struct timespec __user *)fifth); | |
99 | case SEMGET: | |
100 | return sys_semget (first, second, third); | |
101 | case SEMCTL: { | |
102 | union semun fourth; | |
103 | if (!ptr) | |
104 | return -EINVAL; | |
105 | if (get_user(fourth.__pad, (void __user * __user *) ptr)) | |
106 | return -EFAULT; | |
107 | return sys_semctl (first, second, third, fourth); | |
108 | } | |
109 | ||
110 | case MSGSND: | |
111 | return sys_msgsnd (first, (struct msgbuf __user *) ptr, | |
112 | second, third); | |
113 | case MSGRCV: | |
114 | switch (version) { | |
115 | case 0: { | |
116 | struct ipc_kludge tmp; | |
117 | if (!ptr) | |
118 | return -EINVAL; | |
119 | ||
120 | if (copy_from_user(&tmp, | |
121 | (struct ipc_kludge __user *) ptr, | |
122 | sizeof (tmp))) | |
123 | return -EFAULT; | |
124 | return sys_msgrcv (first, tmp.msgp, second, | |
125 | tmp.msgtyp, third); | |
126 | } | |
127 | default: | |
128 | return sys_msgrcv (first, | |
129 | (struct msgbuf __user *) ptr, | |
130 | second, fifth, third); | |
131 | } | |
132 | case MSGGET: | |
133 | return sys_msgget ((key_t) first, second); | |
134 | case MSGCTL: | |
135 | return sys_msgctl (first, second, | |
136 | (struct msqid_ds __user *) ptr); | |
137 | case SHMAT: { | |
138 | ulong raddr; | |
139 | ||
140 | if (!access_ok(VERIFY_WRITE, (ulong __user *) third, | |
141 | sizeof(ulong))) | |
142 | return -EFAULT; | |
143 | ret = do_shmat (first, (char __user *) ptr, second, &raddr); | |
144 | if (ret) | |
145 | return ret; | |
146 | return put_user (raddr, (ulong __user *) third); | |
147 | } | |
148 | case SHMDT: | |
149 | return sys_shmdt ((char __user *)ptr); | |
150 | case SHMGET: | |
151 | return sys_shmget (first, second, third); | |
152 | case SHMCTL: | |
153 | return sys_shmctl (first, second, | |
154 | (struct shmid_ds __user *) ptr); | |
155 | default: | |
156 | return -ENOSYS; | |
157 | } | |
158 | } | |
159 | ||
fd2c903b | 160 | asmlinkage int sys_uname(struct old_utsname __user * name) |
1da177e4 LT |
161 | { |
162 | int err; | |
163 | if (!name) | |
164 | return -EFAULT; | |
165 | down_read(&uts_sem); | |
e9ff3990 | 166 | err = copy_to_user(name, utsname(), sizeof (*name)); |
1da177e4 LT |
167 | up_read(&uts_sem); |
168 | return err?-EFAULT:0; | |
169 | } | |
170 | ||
171 | asmlinkage int sys_cacheflush(void *addr, int bytes, int cache) | |
172 | { | |
5aa8b6c1 | 173 | /* This should flush more selectively ... */ |
1da177e4 LT |
174 | _flush_cache_all(); |
175 | return 0; | |
176 | } | |
177 | ||
178 | asmlinkage int sys_cachectl(char *addr, int nbytes, int op) | |
179 | { | |
180 | /* Not implemented yet. */ | |
181 | return -ENOSYS; | |
182 | } | |
183 | ||
fe74290d AB |
184 | /* |
185 | * Do a system call from kernel instead of calling sys_execve so we | |
186 | * end up with proper pt_regs. | |
187 | */ | |
188 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) | |
189 | { | |
190 | register long __scno __asm__ ("r7") = __NR_execve; | |
191 | register long __arg3 __asm__ ("r2") = (long)(envp); | |
192 | register long __arg2 __asm__ ("r1") = (long)(argv); | |
193 | register long __res __asm__ ("r0") = (long)(filename); | |
194 | __asm__ __volatile__ ( | |
195 | "trap #" SYSCALL_VECTOR "|| nop" | |
196 | : "=r" (__res) | |
197 | : "r" (__scno), "0" (__res), "r" (__arg2), | |
198 | "r" (__arg3) | |
199 | : "memory"); | |
200 | return __res; | |
201 | } |