Merge git://git.kernel.org/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[linux-2.6] / arch / ia64 / kernel / fsys.S
1 /*
2  * This file contains the light-weight system call handlers (fsyscall-handlers).
3  *
4  * Copyright (C) 2003 Hewlett-Packard Co
5  *      David Mosberger-Tang <davidm@hpl.hp.com>
6  *
7  * 25-Sep-03 davidm     Implement fsys_rt_sigprocmask().
8  * 18-Feb-03 louisk     Implement fsys_gettimeofday().
9  * 28-Feb-03 davidm     Fixed several bugs in fsys_gettimeofday().  Tuned it some more,
10  *                      probably broke it along the way... ;-)
11  * 13-Jul-04 clameter   Implement fsys_clock_gettime and revise fsys_gettimeofday to make
12  *                      it capable of using memory based clocks without falling back to C code.
13  * 08-Feb-07 Fenghua Yu Implement fsys_getcpu.
14  *
15  */
16
17 #include <asm/asmmacro.h>
18 #include <asm/errno.h>
19 #include <asm/asm-offsets.h>
20 #include <asm/percpu.h>
21 #include <asm/thread_info.h>
22 #include <asm/sal.h>
23 #include <asm/signal.h>
24 #include <asm/system.h>
25 #include <asm/unistd.h>
26
27 #include "entry.h"
28
29 /*
30  * See Documentation/ia64/fsys.txt for details on fsyscalls.
31  *
32  * On entry to an fsyscall handler:
33  *   r10        = 0 (i.e., defaults to "successful syscall return")
34  *   r11        = saved ar.pfs (a user-level value)
35  *   r15        = system call number
36  *   r16        = "current" task pointer (in normal kernel-mode, this is in r13)
37  *   r32-r39    = system call arguments
38  *   b6         = return address (a user-level value)
39  *   ar.pfs     = previous frame-state (a user-level value)
40  *   PSR.be     = cleared to zero (i.e., little-endian byte order is in effect)
41  *   all other registers may contain values passed in from user-mode
42  *
43  * On return from an fsyscall handler:
44  *   r11        = saved ar.pfs (as passed into the fsyscall handler)
45  *   r15        = system call number (as passed into the fsyscall handler)
46  *   r32-r39    = system call arguments (as passed into the fsyscall handler)
47  *   b6         = return address (as passed into the fsyscall handler)
48  *   ar.pfs     = previous frame-state (as passed into the fsyscall handler)
49  */
50
51 ENTRY(fsys_ni_syscall)
52         .prologue
53         .altrp b6
54         .body
55         mov r8=ENOSYS
56         mov r10=-1
57         FSYS_RETURN
58 END(fsys_ni_syscall)
59
60 ENTRY(fsys_getpid)
61         .prologue
62         .altrp b6
63         .body
64         add r9=TI_FLAGS+IA64_TASK_SIZE,r16
65         ;;
66         ld4 r9=[r9]
67         add r8=IA64_TASK_TGID_OFFSET,r16
68         ;;
69         and r9=TIF_ALLWORK_MASK,r9
70         ld4 r8=[r8]                             // r8 = current->tgid
71         ;;
72         cmp.ne p8,p0=0,r9
73 (p8)    br.spnt.many fsys_fallback_syscall
74         FSYS_RETURN
75 END(fsys_getpid)
76
77 ENTRY(fsys_getppid)
78         .prologue
79         .altrp b6
80         .body
81         add r17=IA64_TASK_GROUP_LEADER_OFFSET,r16
82         ;;
83         ld8 r17=[r17]                           // r17 = current->group_leader
84         add r9=TI_FLAGS+IA64_TASK_SIZE,r16
85         ;;
86
87         ld4 r9=[r9]
88         add r17=IA64_TASK_REAL_PARENT_OFFSET,r17 // r17 = &current->group_leader->real_parent
89         ;;
90         and r9=TIF_ALLWORK_MASK,r9
91
92 1:      ld8 r18=[r17]                           // r18 = current->group_leader->real_parent
93         ;;
94         cmp.ne p8,p0=0,r9
95         add r8=IA64_TASK_TGID_OFFSET,r18        // r8 = &current->group_leader->real_parent->tgid
96         ;;
97
98         /*
99          * The .acq is needed to ensure that the read of tgid has returned its data before
100          * we re-check "real_parent".
101          */
102         ld4.acq r8=[r8]                         // r8 = current->group_leader->real_parent->tgid
103 #ifdef CONFIG_SMP
104         /*
105          * Re-read current->group_leader->real_parent.
106          */
107         ld8 r19=[r17]                           // r19 = current->group_leader->real_parent
108 (p8)    br.spnt.many fsys_fallback_syscall
109         ;;
110         cmp.ne p6,p0=r18,r19                    // did real_parent change?
111         mov r19=0                       // i must not leak kernel bits...
112 (p6)    br.cond.spnt.few 1b                     // yes -> redo the read of tgid and the check
113         ;;
114         mov r17=0                       // i must not leak kernel bits...
115         mov r18=0                       // i must not leak kernel bits...
116 #else
117         mov r17=0                       // i must not leak kernel bits...
118         mov r18=0                       // i must not leak kernel bits...
119         mov r19=0                       // i must not leak kernel bits...
120 #endif
121         FSYS_RETURN
122 END(fsys_getppid)
123
124 ENTRY(fsys_set_tid_address)
125         .prologue
126         .altrp b6
127         .body
128         add r9=TI_FLAGS+IA64_TASK_SIZE,r16
129         ;;
130         ld4 r9=[r9]
131         tnat.z p6,p7=r32                // check argument register for being NaT
132         ;;
133         and r9=TIF_ALLWORK_MASK,r9
134         add r8=IA64_TASK_PID_OFFSET,r16
135         add r18=IA64_TASK_CLEAR_CHILD_TID_OFFSET,r16
136         ;;
137         ld4 r8=[r8]
138         cmp.ne p8,p0=0,r9
139         mov r17=-1
140         ;;
141 (p6)    st8 [r18]=r32
142 (p7)    st8 [r18]=r17
143 (p8)    br.spnt.many fsys_fallback_syscall
144         ;;
145         mov r17=0                       // i must not leak kernel bits...
146         mov r18=0                       // i must not leak kernel bits...
147         FSYS_RETURN
148 END(fsys_set_tid_address)
149
150 /*
151  * Ensure that the time interpolator structure is compatible with the asm code
152  */
153 #if IA64_TIME_INTERPOLATOR_SOURCE_OFFSET !=0 || IA64_TIME_INTERPOLATOR_SHIFT_OFFSET != 2 \
154         || IA64_TIME_INTERPOLATOR_JITTER_OFFSET != 3 || IA64_TIME_INTERPOLATOR_NSEC_OFFSET != 4
155 #error fsys_gettimeofday incompatible with changes to struct time_interpolator
156 #endif
157 #define CLOCK_REALTIME 0
158 #define CLOCK_MONOTONIC 1
159 #define CLOCK_DIVIDE_BY_1000 0x4000
160 #define CLOCK_ADD_MONOTONIC 0x8000
161
162 ENTRY(fsys_gettimeofday)
163         .prologue
164         .altrp b6
165         .body
166         mov r31 = r32
167         tnat.nz p6,p0 = r33             // guard against NaT argument
168 (p6)    br.cond.spnt.few .fail_einval
169         mov r30 = CLOCK_DIVIDE_BY_1000
170         ;;
171 .gettime:
172         // Register map
173         // Incoming r31 = pointer to address where to place result
174         //          r30 = flags determining how time is processed
175         // r2,r3 = temp r4-r7 preserved
176         // r8 = result nanoseconds
177         // r9 = result seconds
178         // r10 = temporary storage for clock difference
179         // r11 = preserved: saved ar.pfs
180         // r12 = preserved: memory stack
181         // r13 = preserved: thread pointer
182         // r14 = address of mask / mask
183         // r15 = preserved: system call number
184         // r16 = preserved: current task pointer
185         // r17 = wall to monotonic use
186         // r18 = time_interpolator->offset
187         // r19 = address of wall_to_monotonic
188         // r20 = pointer to struct time_interpolator / pointer to time_interpolator->address
189         // r21 = shift factor
190         // r22 = address of time interpolator->last_counter
191         // r23 = address of time_interpolator->last_cycle
192         // r24 = adress of time_interpolator->offset
193         // r25 = last_cycle value
194         // r26 = last_counter value
195         // r27 = pointer to xtime
196         // r28 = sequence number at the beginning of critcal section
197         // r29 = address of seqlock
198         // r30 = time processing flags / memory address
199         // r31 = pointer to result
200         // Predicates
201         // p6,p7 short term use
202         // p8 = timesource ar.itc
203         // p9 = timesource mmio64
204         // p10 = timesource mmio32
205         // p11 = timesource not to be handled by asm code
206         // p12 = memory time source ( = p9 | p10)
207         // p13 = do cmpxchg with time_interpolator_last_cycle
208         // p14 = Divide by 1000
209         // p15 = Add monotonic
210         //
211         // Note that instructions are optimized for McKinley. McKinley can process two
212         // bundles simultaneously and therefore we continuously try to feed the CPU
213         // two bundles and then a stop.
214         tnat.nz p6,p0 = r31     // branch deferred since it does not fit into bundle structure
215         mov pr = r30,0xc000     // Set predicates according to function
216         add r2 = TI_FLAGS+IA64_TASK_SIZE,r16
217         movl r20 = time_interpolator
218         ;;
219         ld8 r20 = [r20]         // get pointer to time_interpolator structure
220         movl r29 = xtime_lock
221         ld4 r2 = [r2]           // process work pending flags
222         movl r27 = xtime
223         ;;      // only one bundle here
224         ld8 r21 = [r20]         // first quad with control information
225         and r2 = TIF_ALLWORK_MASK,r2
226 (p6)    br.cond.spnt.few .fail_einval   // deferred branch
227         ;;
228         add r10 = IA64_TIME_INTERPOLATOR_ADDRESS_OFFSET,r20
229         extr r3 = r21,32,32     // time_interpolator->nsec_per_cyc
230         extr r8 = r21,0,16      // time_interpolator->source
231         cmp.ne p6, p0 = 0, r2   // Fallback if work is scheduled
232 (p6)    br.cond.spnt.many fsys_fallback_syscall
233         ;;
234         cmp.eq p8,p12 = 0,r8    // Check for cpu timer
235         cmp.eq p9,p0 = 1,r8     // MMIO64 ?
236         extr r2 = r21,24,8      // time_interpolator->jitter
237         cmp.eq p10,p0 = 2,r8    // MMIO32 ?
238         cmp.ltu p11,p0 = 2,r8   // function or other clock
239 (p11)   br.cond.spnt.many fsys_fallback_syscall
240         ;;
241         setf.sig f7 = r3        // Setup for scaling of counter
242 (p15)   movl r19 = wall_to_monotonic
243 (p12)   ld8 r30 = [r10]
244         cmp.ne p13,p0 = r2,r0   // need jitter compensation?
245         extr r21 = r21,16,8     // shift factor
246         ;;
247 .time_redo:
248         .pred.rel.mutex p8,p9,p10
249         ld4.acq r28 = [r29]     // xtime_lock.sequence. Must come first for locking purposes
250         ;;
251         and r28 = ~1,r28        // Make sequence even to force retry if odd
252         ;;
253 (p8)    mov r2 = ar.itc         // CPU_TIMER. 36 clocks latency!!!
254         add r22 = IA64_TIME_INTERPOLATOR_LAST_COUNTER_OFFSET,r20
255 (p9)    ld8 r2 = [r30]          // readq(ti->address). Could also have latency issues..
256 (p10)   ld4 r2 = [r30]          // readw(ti->address)
257 (p13)   add r23 = IA64_TIME_INTERPOLATOR_LAST_CYCLE_OFFSET,r20
258         ;;                      // could be removed by moving the last add upward
259         ld8 r26 = [r22]         // time_interpolator->last_counter
260 (p13)   ld8 r25 = [r23]         // time interpolator->last_cycle
261         add r24 = IA64_TIME_INTERPOLATOR_OFFSET_OFFSET,r20
262 (p15)   ld8 r17 = [r19],IA64_TIMESPEC_TV_NSEC_OFFSET
263         ld8 r9 = [r27],IA64_TIMESPEC_TV_NSEC_OFFSET
264         add r14 = IA64_TIME_INTERPOLATOR_MASK_OFFSET, r20
265         ;;
266         ld8 r18 = [r24]         // time_interpolator->offset
267         ld8 r8 = [r27],-IA64_TIMESPEC_TV_NSEC_OFFSET    // xtime.tv_nsec
268 (p13)   sub r3 = r25,r2 // Diff needed before comparison (thanks davidm)
269         ;;
270         ld8 r14 = [r14]         // time_interpolator->mask
271 (p13)   cmp.gt.unc p6,p7 = r3,r0        // check if it is less than last. p6,p7 cleared
272         sub r10 = r2,r26        // current_counter - last_counter
273         ;;
274 (p6)    sub r10 = r25,r26       // time we got was less than last_cycle
275 (p7)    mov ar.ccv = r25        // more than last_cycle. Prep for cmpxchg
276         ;;
277         and r10 = r10,r14       // Apply mask
278         ;;
279         setf.sig f8 = r10
280         nop.i 123
281         ;;
282 (p7)    cmpxchg8.rel r3 = [r23],r2,ar.ccv
283 EX(.fail_efault, probe.w.fault r31, 3)  // This takes 5 cycles and we have spare time
284         xmpy.l f8 = f8,f7       // nsec_per_cyc*(counter-last_counter)
285 (p15)   add r9 = r9,r17         // Add wall to monotonic.secs to result secs
286         ;;
287 (p15)   ld8 r17 = [r19],-IA64_TIMESPEC_TV_NSEC_OFFSET
288 (p7)    cmp.ne p7,p0 = r25,r3   // if cmpxchg not successful redo
289         // simulate tbit.nz.or p7,p0 = r28,0
290         getf.sig r2 = f8
291         mf
292         add r8 = r8,r18         // Add time interpolator offset
293         ;;
294         ld4 r10 = [r29]         // xtime_lock.sequence
295 (p15)   add r8 = r8, r17        // Add monotonic.nsecs to nsecs
296         shr.u r2 = r2,r21
297         ;;              // overloaded 3 bundles!
298         // End critical section.
299         add r8 = r8,r2          // Add xtime.nsecs
300         cmp4.ne.or p7,p0 = r28,r10
301 (p7)    br.cond.dpnt.few .time_redo     // sequence number changed ?
302         // Now r8=tv->tv_nsec and r9=tv->tv_sec
303         mov r10 = r0
304         movl r2 = 1000000000
305         add r23 = IA64_TIMESPEC_TV_NSEC_OFFSET, r31
306 (p14)   movl r3 = 2361183241434822607   // Prep for / 1000 hack
307         ;;
308 .time_normalize:
309         mov r21 = r8
310         cmp.ge p6,p0 = r8,r2
311 (p14)   shr.u r20 = r8, 3               // We can repeat this if necessary just wasting some time
312         ;;
313 (p14)   setf.sig f8 = r20
314 (p6)    sub r8 = r8,r2
315 (p6)    add r9 = 1,r9                   // two nops before the branch.
316 (p14)   setf.sig f7 = r3                // Chances for repeats are 1 in 10000 for gettod
317 (p6)    br.cond.dpnt.few .time_normalize
318         ;;
319         // Divided by 8 though shift. Now divide by 125
320         // The compiler was able to do that with a multiply
321         // and a shift and we do the same
322 EX(.fail_efault, probe.w.fault r23, 3)          // This also costs 5 cycles
323 (p14)   xmpy.hu f8 = f8, f7                     // xmpy has 5 cycles latency so use it...
324         ;;
325         mov r8 = r0
326 (p14)   getf.sig r2 = f8
327         ;;
328 (p14)   shr.u r21 = r2, 4
329         ;;
330 EX(.fail_efault, st8 [r31] = r9)
331 EX(.fail_efault, st8 [r23] = r21)
332         FSYS_RETURN
333 .fail_einval:
334         mov r8 = EINVAL
335         mov r10 = -1
336         FSYS_RETURN
337 .fail_efault:
338         mov r8 = EFAULT
339         mov r10 = -1
340         FSYS_RETURN
341 END(fsys_gettimeofday)
342
343 ENTRY(fsys_clock_gettime)
344         .prologue
345         .altrp b6
346         .body
347         cmp4.ltu p6, p0 = CLOCK_MONOTONIC, r32
348         // Fallback if this is not CLOCK_REALTIME or CLOCK_MONOTONIC
349 (p6)    br.spnt.few fsys_fallback_syscall
350         mov r31 = r33
351         shl r30 = r32,15
352         br.many .gettime
353 END(fsys_clock_gettime)
354
355 /*
356  * long fsys_rt_sigprocmask (int how, sigset_t *set, sigset_t *oset, size_t sigsetsize).
357  */
358 #if _NSIG_WORDS != 1
359 # error Sorry, fsys_rt_sigprocmask() needs to be updated for _NSIG_WORDS != 1.
360 #endif
361 ENTRY(fsys_rt_sigprocmask)
362         .prologue
363         .altrp b6
364         .body
365
366         add r2=IA64_TASK_BLOCKED_OFFSET,r16
367         add r9=TI_FLAGS+IA64_TASK_SIZE,r16
368         cmp4.ltu p6,p0=SIG_SETMASK,r32
369
370         cmp.ne p15,p0=r0,r34                    // oset != NULL?
371         tnat.nz p8,p0=r34
372         add r31=IA64_TASK_SIGHAND_OFFSET,r16
373         ;;
374         ld8 r3=[r2]                             // read/prefetch current->blocked
375         ld4 r9=[r9]
376         tnat.nz.or p6,p0=r35
377
378         cmp.ne.or p6,p0=_NSIG_WORDS*8,r35
379         tnat.nz.or p6,p0=r32
380 (p6)    br.spnt.few .fail_einval                // fail with EINVAL
381         ;;
382 #ifdef CONFIG_SMP
383         ld8 r31=[r31]                           // r31 <- current->sighand
384 #endif
385         and r9=TIF_ALLWORK_MASK,r9
386         tnat.nz.or p8,p0=r33
387         ;;
388         cmp.ne p7,p0=0,r9
389         cmp.eq p6,p0=r0,r33                     // set == NULL?
390         add r31=IA64_SIGHAND_SIGLOCK_OFFSET,r31 // r31 <- current->sighand->siglock
391 (p8)    br.spnt.few .fail_efault                // fail with EFAULT
392 (p7)    br.spnt.many fsys_fallback_syscall      // got pending kernel work...
393 (p6)    br.dpnt.many .store_mask                // -> short-circuit to just reading the signal mask
394
395         /* Argh, we actually have to do some work and _update_ the signal mask: */
396
397 EX(.fail_efault, probe.r.fault r33, 3)          // verify user has read-access to *set
398 EX(.fail_efault, ld8 r14=[r33])                 // r14 <- *set
399         mov r17=(1 << (SIGKILL - 1)) | (1 << (SIGSTOP - 1))
400         ;;
401
402         rsm psr.i                               // mask interrupt delivery
403         mov ar.ccv=0
404         andcm r14=r14,r17                       // filter out SIGKILL & SIGSTOP
405
406 #ifdef CONFIG_SMP
407         mov r17=1
408         ;;
409         cmpxchg4.acq r18=[r31],r17,ar.ccv       // try to acquire the lock
410         mov r8=EINVAL                   // default to EINVAL
411         ;;
412         ld8 r3=[r2]                     // re-read current->blocked now that we hold the lock
413         cmp4.ne p6,p0=r18,r0
414 (p6)    br.cond.spnt.many .lock_contention
415         ;;
416 #else
417         ld8 r3=[r2]                     // re-read current->blocked now that we hold the lock
418         mov r8=EINVAL                   // default to EINVAL
419 #endif
420         add r18=IA64_TASK_PENDING_OFFSET+IA64_SIGPENDING_SIGNAL_OFFSET,r16
421         add r19=IA64_TASK_SIGNAL_OFFSET,r16
422         cmp4.eq p6,p0=SIG_BLOCK,r32
423         ;;
424         ld8 r19=[r19]                   // r19 <- current->signal
425         cmp4.eq p7,p0=SIG_UNBLOCK,r32
426         cmp4.eq p8,p0=SIG_SETMASK,r32
427         ;;
428         ld8 r18=[r18]                   // r18 <- current->pending.signal
429         .pred.rel.mutex p6,p7,p8
430 (p6)    or r14=r3,r14                   // SIG_BLOCK
431 (p7)    andcm r14=r3,r14                // SIG_UNBLOCK
432
433 (p8)    mov r14=r14                     // SIG_SETMASK
434 (p6)    mov r8=0                        // clear error code
435         // recalc_sigpending()
436         add r17=IA64_SIGNAL_GROUP_STOP_COUNT_OFFSET,r19
437
438         add r19=IA64_SIGNAL_SHARED_PENDING_OFFSET+IA64_SIGPENDING_SIGNAL_OFFSET,r19
439         ;;
440         ld4 r17=[r17]           // r17 <- current->signal->group_stop_count
441 (p7)    mov r8=0                // clear error code
442
443         ld8 r19=[r19]           // r19 <- current->signal->shared_pending
444         ;;
445         cmp4.gt p6,p7=r17,r0    // p6/p7 <- (current->signal->group_stop_count > 0)?
446 (p8)    mov r8=0                // clear error code
447
448         or r18=r18,r19          // r18 <- current->pending | current->signal->shared_pending
449         ;;
450         // r18 <- (current->pending | current->signal->shared_pending) & ~current->blocked:
451         andcm r18=r18,r14
452         add r9=TI_FLAGS+IA64_TASK_SIZE,r16
453         ;;
454
455 (p7)    cmp.ne.or.andcm p6,p7=r18,r0            // p6/p7 <- signal pending
456         mov r19=0                                       // i must not leak kernel bits...
457 (p6)    br.cond.dpnt.many .sig_pending
458         ;;
459
460 1:      ld4 r17=[r9]                            // r17 <- current->thread_info->flags
461         ;;
462         mov ar.ccv=r17
463         and r18=~_TIF_SIGPENDING,r17            // r18 <- r17 & ~(1 << TIF_SIGPENDING)
464         ;;
465
466         st8 [r2]=r14                            // update current->blocked with new mask
467         cmpxchg4.acq r8=[r9],r18,ar.ccv         // current->thread_info->flags <- r18
468         ;;
469         cmp.ne p6,p0=r17,r8                     // update failed?
470 (p6)    br.cond.spnt.few 1b                     // yes -> retry
471
472 #ifdef CONFIG_SMP
473         st4.rel [r31]=r0                        // release the lock
474 #endif
475         ssm psr.i
476         ;;
477
478         srlz.d                                  // ensure psr.i is set again
479         mov r18=0                                       // i must not leak kernel bits...
480
481 .store_mask:
482 EX(.fail_efault, (p15) probe.w.fault r34, 3)    // verify user has write-access to *oset
483 EX(.fail_efault, (p15) st8 [r34]=r3)
484         mov r2=0                                        // i must not leak kernel bits...
485         mov r3=0                                        // i must not leak kernel bits...
486         mov r8=0                                // return 0
487         mov r9=0                                        // i must not leak kernel bits...
488         mov r14=0                                       // i must not leak kernel bits...
489         mov r17=0                                       // i must not leak kernel bits...
490         mov r31=0                                       // i must not leak kernel bits...
491         FSYS_RETURN
492
493 .sig_pending:
494 #ifdef CONFIG_SMP
495         st4.rel [r31]=r0                        // release the lock
496 #endif
497         ssm psr.i
498         ;;
499         srlz.d
500         br.sptk.many fsys_fallback_syscall      // with signal pending, do the heavy-weight syscall
501
502 #ifdef CONFIG_SMP
503 .lock_contention:
504         /* Rather than spinning here, fall back on doing a heavy-weight syscall.  */
505         ssm psr.i
506         ;;
507         srlz.d
508         br.sptk.many fsys_fallback_syscall
509 #endif
510 END(fsys_rt_sigprocmask)
511
512 /*
513  * fsys_getcpu doesn't use the third parameter in this implementation. It reads
514  * current_thread_info()->cpu and corresponding node in cpu_to_node_map.
515  */
516 ENTRY(fsys_getcpu)
517         .prologue
518         .altrp b6
519         .body
520         ;;
521         add r2=TI_FLAGS+IA64_TASK_SIZE,r16
522         tnat.nz p6,p0 = r32                     // guard against NaT argument
523         add r3=TI_CPU+IA64_TASK_SIZE,r16
524         ;;
525         ld4 r3=[r3]                             // M r3 = thread_info->cpu
526         ld4 r2=[r2]                             // M r2 = thread_info->flags
527 (p6)    br.cond.spnt.few .fail_einval           // B
528         ;;
529         tnat.nz p7,p0 = r33                     // I guard against NaT argument
530 (p7)    br.cond.spnt.few .fail_einval           // B
531 #ifdef CONFIG_NUMA
532         movl r17=cpu_to_node_map
533         ;;
534 EX(.fail_efault, probe.w.fault r32, 3)          // M This takes 5 cycles
535 EX(.fail_efault, probe.w.fault r33, 3)          // M This takes 5 cycles
536         shladd r18=r3,1,r17
537         ;;
538         ld2 r20=[r18]                           // r20 = cpu_to_node_map[cpu]
539         and r2 = TIF_ALLWORK_MASK,r2
540         ;;
541         cmp.ne p8,p0=0,r2
542 (p8)    br.spnt.many fsys_fallback_syscall
543         ;;
544         ;;
545 EX(.fail_efault, st4 [r32] = r3)
546 EX(.fail_efault, st2 [r33] = r20)
547         mov r8=0
548         ;;
549 #else
550 EX(.fail_efault, probe.w.fault r32, 3)          // M This takes 5 cycles
551 EX(.fail_efault, probe.w.fault r33, 3)          // M This takes 5 cycles
552         and r2 = TIF_ALLWORK_MASK,r2
553         ;;
554         cmp.ne p8,p0=0,r2
555 (p8)    br.spnt.many fsys_fallback_syscall
556         ;;
557 EX(.fail_efault, st4 [r32] = r3)
558 EX(.fail_efault, st2 [r33] = r0)
559         mov r8=0
560         ;;
561 #endif
562         FSYS_RETURN
563 END(fsys_getcpu)
564
565 ENTRY(fsys_fallback_syscall)
566         .prologue
567         .altrp b6
568         .body
569         /*
570          * We only get here from light-weight syscall handlers.  Thus, we already
571          * know that r15 contains a valid syscall number.  No need to re-check.
572          */
573         adds r17=-1024,r15
574         movl r14=sys_call_table
575         ;;
576         rsm psr.i
577         shladd r18=r17,3,r14
578         ;;
579         ld8 r18=[r18]                           // load normal (heavy-weight) syscall entry-point
580         mov r29=psr                             // read psr (12 cyc load latency)
581         mov r27=ar.rsc
582         mov r21=ar.fpsr
583         mov r26=ar.pfs
584 END(fsys_fallback_syscall)
585         /* FALL THROUGH */
586 GLOBAL_ENTRY(fsys_bubble_down)
587         .prologue
588         .altrp b6
589         .body
590         /*
591          * We get here for syscalls that don't have a lightweight
592          * handler.  For those, we need to bubble down into the kernel
593          * and that requires setting up a minimal pt_regs structure,
594          * and initializing the CPU state more or less as if an
595          * interruption had occurred.  To make syscall-restarts work,
596          * we setup pt_regs such that cr_iip points to the second
597          * instruction in syscall_via_break.  Decrementing the IP
598          * hence will restart the syscall via break and not
599          * decrementing IP will return us to the caller, as usual.
600          * Note that we preserve the value of psr.pp rather than
601          * initializing it from dcr.pp.  This makes it possible to
602          * distinguish fsyscall execution from other privileged
603          * execution.
604          *
605          * On entry:
606          *      - normal fsyscall handler register usage, except
607          *        that we also have:
608          *      - r18: address of syscall entry point
609          *      - r21: ar.fpsr
610          *      - r26: ar.pfs
611          *      - r27: ar.rsc
612          *      - r29: psr
613          *
614          * We used to clear some PSR bits here but that requires slow
615          * serialization.  Fortuntely, that isn't really necessary.
616          * The rationale is as follows: we used to clear bits
617          * ~PSR_PRESERVED_BITS in PSR.L.  Since
618          * PSR_PRESERVED_BITS==PSR.{UP,MFL,MFH,PK,DT,PP,SP,RT,IC}, we
619          * ended up clearing PSR.{BE,AC,I,DFL,DFH,DI,DB,SI,TB}.
620          * However,
621          *
622          * PSR.BE : already is turned off in __kernel_syscall_via_epc()
623          * PSR.AC : don't care (kernel normally turns PSR.AC on)
624          * PSR.I  : already turned off by the time fsys_bubble_down gets
625          *          invoked
626          * PSR.DFL: always 0 (kernel never turns it on)
627          * PSR.DFH: don't care --- kernel never touches f32-f127 on its own
628          *          initiative
629          * PSR.DI : always 0 (kernel never turns it on)
630          * PSR.SI : always 0 (kernel never turns it on)
631          * PSR.DB : don't care --- kernel never enables kernel-level
632          *          breakpoints
633          * PSR.TB : must be 0 already; if it wasn't zero on entry to
634          *          __kernel_syscall_via_epc, the branch to fsys_bubble_down
635          *          will trigger a taken branch; the taken-trap-handler then
636          *          converts the syscall into a break-based system-call.
637          */
638         /*
639          * Reading psr.l gives us only bits 0-31, psr.it, and psr.mc.
640          * The rest we have to synthesize.
641          */
642 #       define PSR_ONE_BITS             ((3 << IA64_PSR_CPL0_BIT)       \
643                                          | (0x1 << IA64_PSR_RI_BIT)     \
644                                          | IA64_PSR_BN | IA64_PSR_I)
645
646         invala                                  // M0|1
647         movl r14=ia64_ret_from_syscall          // X
648
649         nop.m 0
650         movl r28=__kernel_syscall_via_break     // X    create cr.iip
651         ;;
652
653         mov r2=r16                              // A    get task addr to addl-addressable register
654         adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r16 // A
655         mov r31=pr                              // I0   save pr (2 cyc)
656         ;;
657         st1 [r16]=r0                            // M2|3 clear current->thread.on_ustack flag
658         addl r22=IA64_RBS_OFFSET,r2             // A    compute base of RBS
659         add r3=TI_FLAGS+IA64_TASK_SIZE,r2       // A
660         ;;
661         ld4 r3=[r3]                             // M0|1 r3 = current_thread_info()->flags
662         lfetch.fault.excl.nt1 [r22]             // M0|1 prefetch register backing-store
663         nop.i 0
664         ;;
665         mov ar.rsc=0                            // M2   set enforced lazy mode, pl 0, LE, loadrs=0
666         nop.m 0
667         nop.i 0
668         ;;
669         mov r23=ar.bspstore                     // M2 (12 cyc) save ar.bspstore
670         mov.m r24=ar.rnat                       // M2 (5 cyc) read ar.rnat (dual-issues!)
671         nop.i 0
672         ;;
673         mov ar.bspstore=r22                     // M2 (6 cyc) switch to kernel RBS
674         movl r8=PSR_ONE_BITS                    // X
675         ;;
676         mov r25=ar.unat                         // M2 (5 cyc) save ar.unat
677         mov r19=b6                              // I0   save b6 (2 cyc)
678         mov r20=r1                              // A    save caller's gp in r20
679         ;;
680         or r29=r8,r29                           // A    construct cr.ipsr value to save
681         mov b6=r18                              // I0   copy syscall entry-point to b6 (7 cyc)
682         addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r2 // A compute base of memory stack
683
684         mov r18=ar.bsp                          // M2   save (kernel) ar.bsp (12 cyc)
685         cmp.ne pKStk,pUStk=r0,r0                // A    set pKStk <- 0, pUStk <- 1
686         br.call.sptk.many b7=ia64_syscall_setup // B
687         ;;
688         mov ar.rsc=0x3                          // M2   set eager mode, pl 0, LE, loadrs=0
689         mov rp=r14                              // I0   set the real return addr
690         and r3=_TIF_SYSCALL_TRACEAUDIT,r3       // A
691         ;;
692         ssm psr.i                               // M2   we're on kernel stacks now, reenable irqs
693         cmp.eq p8,p0=r3,r0                      // A
694 (p10)   br.cond.spnt.many ia64_ret_from_syscall // B    return if bad call-frame or r15 is a NaT
695
696         nop.m 0
697 (p8)    br.call.sptk.many b6=b6                 // B    (ignore return address)
698         br.cond.spnt ia64_trace_syscall         // B
699 END(fsys_bubble_down)
700
701         .rodata
702         .align 8
703         .globl fsyscall_table
704
705         data8 fsys_bubble_down
706 fsyscall_table:
707         data8 fsys_ni_syscall
708         data8 0                         // exit                 // 1025
709         data8 0                         // read
710         data8 0                         // write
711         data8 0                         // open
712         data8 0                         // close
713         data8 0                         // creat                // 1030
714         data8 0                         // link
715         data8 0                         // unlink
716         data8 0                         // execve
717         data8 0                         // chdir
718         data8 0                         // fchdir               // 1035
719         data8 0                         // utimes
720         data8 0                         // mknod
721         data8 0                         // chmod
722         data8 0                         // chown
723         data8 0                         // lseek                // 1040
724         data8 fsys_getpid               // getpid
725         data8 fsys_getppid              // getppid
726         data8 0                         // mount
727         data8 0                         // umount
728         data8 0                         // setuid               // 1045
729         data8 0                         // getuid
730         data8 0                         // geteuid
731         data8 0                         // ptrace
732         data8 0                         // access
733         data8 0                         // sync                 // 1050
734         data8 0                         // fsync
735         data8 0                         // fdatasync
736         data8 0                         // kill
737         data8 0                         // rename
738         data8 0                         // mkdir                // 1055
739         data8 0                         // rmdir
740         data8 0                         // dup
741         data8 0                         // pipe
742         data8 0                         // times
743         data8 0                         // brk                  // 1060
744         data8 0                         // setgid
745         data8 0                         // getgid
746         data8 0                         // getegid
747         data8 0                         // acct
748         data8 0                         // ioctl                // 1065
749         data8 0                         // fcntl
750         data8 0                         // umask
751         data8 0                         // chroot
752         data8 0                         // ustat
753         data8 0                         // dup2                 // 1070
754         data8 0                         // setreuid
755         data8 0                         // setregid
756         data8 0                         // getresuid
757         data8 0                         // setresuid
758         data8 0                         // getresgid            // 1075
759         data8 0                         // setresgid
760         data8 0                         // getgroups
761         data8 0                         // setgroups
762         data8 0                         // getpgid
763         data8 0                         // setpgid              // 1080
764         data8 0                         // setsid
765         data8 0                         // getsid
766         data8 0                         // sethostname
767         data8 0                         // setrlimit
768         data8 0                         // getrlimit            // 1085
769         data8 0                         // getrusage
770         data8 fsys_gettimeofday         // gettimeofday
771         data8 0                         // settimeofday
772         data8 0                         // select
773         data8 0                         // poll                 // 1090
774         data8 0                         // symlink
775         data8 0                         // readlink
776         data8 0                         // uselib
777         data8 0                         // swapon
778         data8 0                         // swapoff              // 1095
779         data8 0                         // reboot
780         data8 0                         // truncate
781         data8 0                         // ftruncate
782         data8 0                         // fchmod
783         data8 0                         // fchown               // 1100
784         data8 0                         // getpriority
785         data8 0                         // setpriority
786         data8 0                         // statfs
787         data8 0                         // fstatfs
788         data8 0                         // gettid               // 1105
789         data8 0                         // semget
790         data8 0                         // semop
791         data8 0                         // semctl
792         data8 0                         // msgget
793         data8 0                         // msgsnd               // 1110
794         data8 0                         // msgrcv
795         data8 0                         // msgctl
796         data8 0                         // shmget
797         data8 0                         // shmat
798         data8 0                         // shmdt                // 1115
799         data8 0                         // shmctl
800         data8 0                         // syslog
801         data8 0                         // setitimer
802         data8 0                         // getitimer
803         data8 0                                                 // 1120
804         data8 0
805         data8 0
806         data8 0                         // vhangup
807         data8 0                         // lchown
808         data8 0                         // remap_file_pages     // 1125
809         data8 0                         // wait4
810         data8 0                         // sysinfo
811         data8 0                         // clone
812         data8 0                         // setdomainname
813         data8 0                         // newuname             // 1130
814         data8 0                         // adjtimex
815         data8 0
816         data8 0                         // init_module
817         data8 0                         // delete_module
818         data8 0                                                 // 1135
819         data8 0
820         data8 0                         // quotactl
821         data8 0                         // bdflush
822         data8 0                         // sysfs
823         data8 0                         // personality          // 1140
824         data8 0                         // afs_syscall
825         data8 0                         // setfsuid
826         data8 0                         // setfsgid
827         data8 0                         // getdents
828         data8 0                         // flock                // 1145
829         data8 0                         // readv
830         data8 0                         // writev
831         data8 0                         // pread64
832         data8 0                         // pwrite64
833         data8 0                         // sysctl               // 1150
834         data8 0                         // mmap
835         data8 0                         // munmap
836         data8 0                         // mlock
837         data8 0                         // mlockall
838         data8 0                         // mprotect             // 1155
839         data8 0                         // mremap
840         data8 0                         // msync
841         data8 0                         // munlock
842         data8 0                         // munlockall
843         data8 0                         // sched_getparam       // 1160
844         data8 0                         // sched_setparam
845         data8 0                         // sched_getscheduler
846         data8 0                         // sched_setscheduler
847         data8 0                         // sched_yield
848         data8 0                         // sched_get_priority_max       // 1165
849         data8 0                         // sched_get_priority_min
850         data8 0                         // sched_rr_get_interval
851         data8 0                         // nanosleep
852         data8 0                         // nfsservctl
853         data8 0                         // prctl                // 1170
854         data8 0                         // getpagesize
855         data8 0                         // mmap2
856         data8 0                         // pciconfig_read
857         data8 0                         // pciconfig_write
858         data8 0                         // perfmonctl           // 1175
859         data8 0                         // sigaltstack
860         data8 0                         // rt_sigaction
861         data8 0                         // rt_sigpending
862         data8 fsys_rt_sigprocmask       // rt_sigprocmask
863         data8 0                         // rt_sigqueueinfo      // 1180
864         data8 0                         // rt_sigreturn
865         data8 0                         // rt_sigsuspend
866         data8 0                         // rt_sigtimedwait
867         data8 0                         // getcwd
868         data8 0                         // capget               // 1185
869         data8 0                         // capset
870         data8 0                         // sendfile
871         data8 0
872         data8 0
873         data8 0                         // socket               // 1190
874         data8 0                         // bind
875         data8 0                         // connect
876         data8 0                         // listen
877         data8 0                         // accept
878         data8 0                         // getsockname          // 1195
879         data8 0                         // getpeername
880         data8 0                         // socketpair
881         data8 0                         // send
882         data8 0                         // sendto
883         data8 0                         // recv                 // 1200
884         data8 0                         // recvfrom
885         data8 0                         // shutdown
886         data8 0                         // setsockopt
887         data8 0                         // getsockopt
888         data8 0                         // sendmsg              // 1205
889         data8 0                         // recvmsg
890         data8 0                         // pivot_root
891         data8 0                         // mincore
892         data8 0                         // madvise
893         data8 0                         // newstat              // 1210
894         data8 0                         // newlstat
895         data8 0                         // newfstat
896         data8 0                         // clone2
897         data8 0                         // getdents64
898         data8 0                         // getunwind            // 1215
899         data8 0                         // readahead
900         data8 0                         // setxattr
901         data8 0                         // lsetxattr
902         data8 0                         // fsetxattr
903         data8 0                         // getxattr             // 1220
904         data8 0                         // lgetxattr
905         data8 0                         // fgetxattr
906         data8 0                         // listxattr
907         data8 0                         // llistxattr
908         data8 0                         // flistxattr           // 1225
909         data8 0                         // removexattr
910         data8 0                         // lremovexattr
911         data8 0                         // fremovexattr
912         data8 0                         // tkill
913         data8 0                         // futex                // 1230
914         data8 0                         // sched_setaffinity
915         data8 0                         // sched_getaffinity
916         data8 fsys_set_tid_address      // set_tid_address
917         data8 0                         // fadvise64_64
918         data8 0                         // tgkill               // 1235
919         data8 0                         // exit_group
920         data8 0                         // lookup_dcookie
921         data8 0                         // io_setup
922         data8 0                         // io_destroy
923         data8 0                         // io_getevents         // 1240
924         data8 0                         // io_submit
925         data8 0                         // io_cancel
926         data8 0                         // epoll_create
927         data8 0                         // epoll_ctl
928         data8 0                         // epoll_wait           // 1245
929         data8 0                         // restart_syscall
930         data8 0                         // semtimedop
931         data8 0                         // timer_create
932         data8 0                         // timer_settime
933         data8 0                         // timer_gettime        // 1250
934         data8 0                         // timer_getoverrun
935         data8 0                         // timer_delete
936         data8 0                         // clock_settime
937         data8 fsys_clock_gettime        // clock_gettime
938         data8 0                         // clock_getres         // 1255
939         data8 0                         // clock_nanosleep
940         data8 0                         // fstatfs64
941         data8 0                         // statfs64
942         data8 0                         // mbind
943         data8 0                         // get_mempolicy        // 1260
944         data8 0                         // set_mempolicy
945         data8 0                         // mq_open
946         data8 0                         // mq_unlink
947         data8 0                         // mq_timedsend
948         data8 0                         // mq_timedreceive      // 1265
949         data8 0                         // mq_notify
950         data8 0                         // mq_getsetattr
951         data8 0                         // kexec_load
952         data8 0                         // vserver
953         data8 0                         // waitid               // 1270
954         data8 0                         // add_key
955         data8 0                         // request_key
956         data8 0                         // keyctl
957         data8 0                         // ioprio_set
958         data8 0                         // ioprio_get           // 1275
959         data8 0                         // move_pages
960         data8 0                         // inotify_init
961         data8 0                         // inotify_add_watch
962         data8 0                         // inotify_rm_watch
963         data8 0                         // migrate_pages        // 1280
964         data8 0                         // openat
965         data8 0                         // mkdirat
966         data8 0                         // mknodat
967         data8 0                         // fchownat
968         data8 0                         // futimesat            // 1285
969         data8 0                         // newfstatat
970         data8 0                         // unlinkat
971         data8 0                         // renameat
972         data8 0                         // linkat
973         data8 0                         // symlinkat            // 1290
974         data8 0                         // readlinkat
975         data8 0                         // fchmodat
976         data8 0                         // faccessat
977         data8 0
978         data8 0                                                 // 1295
979         data8 0                         // unshare
980         data8 0                         // splice
981         data8 0                         // set_robust_list
982         data8 0                         // get_robust_list
983         data8 0                         // sync_file_range      // 1300
984         data8 0                         // tee
985         data8 0                         // vmsplice
986         data8 0
987         data8 fsys_getcpu               // getcpu               // 1304
988
989         // fill in zeros for the remaining entries
990         .zero:
991         .space fsyscall_table + 8*NR_syscalls - .zero, 0