blob: bc5864c5148b89c0de39d2291c83ad877d690e11 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S390 low-level entry points.
3 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 1999, 2012
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
Heiko Carstens25d83cb2006-09-28 16:56:37 +02006 * Hartmut Penner (hp@de.ibm.com),
7 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
Heiko Carstens77fa2242005-06-25 14:55:30 -07008 * Heiko Carstens <heiko.carstens@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Heiko Carstens2bc89b52008-02-05 16:50:40 +010011#include <linux/init.h>
Jan Glauber144d6342011-07-24 10:48:19 +020012#include <linux/linkage.h>
Heiko Carstenseb608fb2012-09-05 13:26:11 +020013#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/cache.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/errno.h>
16#include <asm/ptrace.h>
17#include <asm/thread_info.h>
Sam Ravnborg0013a852005-09-09 20:57:26 +020018#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/unistd.h>
20#include <asm/page.h>
Heiko Carstenseb546192012-06-04 15:05:43 +020021#include <asm/sigp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Martin Schwidefskyc5328902011-12-27 11:27:15 +010023__PT_R0 = __PT_GPRS
24__PT_R1 = __PT_GPRS + 8
25__PT_R2 = __PT_GPRS + 16
26__PT_R3 = __PT_GPRS + 24
27__PT_R4 = __PT_GPRS + 32
28__PT_R5 = __PT_GPRS + 40
29__PT_R6 = __PT_GPRS + 48
30__PT_R7 = __PT_GPRS + 56
31__PT_R8 = __PT_GPRS + 64
32__PT_R9 = __PT_GPRS + 72
33__PT_R10 = __PT_GPRS + 80
34__PT_R11 = __PT_GPRS + 88
35__PT_R12 = __PT_GPRS + 96
36__PT_R13 = __PT_GPRS + 104
37__PT_R14 = __PT_GPRS + 112
38__PT_R15 = __PT_GPRS + 120
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
41STACK_SIZE = 1 << STACK_SHIFT
Martin Schwidefskydc7ee002013-04-24 10:20:43 +020042STACK_INIT = STACK_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020044_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +010045 _TIF_MCCK_PENDING | _TIF_PER_TRAP )
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020046_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
Heiko Carstens54dfe5d2006-02-01 03:06:38 -080047 _TIF_MCCK_PENDING)
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +010048_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
49 _TIF_SYSCALL_TRACEPOINT)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +020050_TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#define BASED(name) name-system_call(%r13)
53
Martin Schwidefskyc5328902011-12-27 11:27:15 +010054 .macro TRACE_IRQS_ON
55#ifdef CONFIG_TRACE_IRQFLAGS
56 basr %r2,%r0
57 brasl %r14,trace_hardirqs_on_caller
58#endif
59 .endm
60
61 .macro TRACE_IRQS_OFF
62#ifdef CONFIG_TRACE_IRQFLAGS
63 basr %r2,%r0
64 brasl %r14,trace_hardirqs_off_caller
65#endif
66 .endm
67
68 .macro LOCKDEP_SYS_EXIT
69#ifdef CONFIG_LOCKDEP
70 tm __PT_PSW+1(%r11),0x01 # returning to user ?
71 jz .+10
72 brasl %r14,lockdep_sys_exit
73#endif
74 .endm
75
Hendrik Brueckner23d18e82013-02-11 18:11:09 +010076 .macro LPP newpp
Martin Schwidefsky603d1a52011-07-24 10:48:18 +020077#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
Hendrik Brueckner23d18e82013-02-11 18:11:09 +010078 tm __LC_MACHINE_FLAGS+6,0x20 # MACHINE_FLAG_LPP
Martin Schwidefsky603d1a52011-07-24 10:48:18 +020079 jz .+8
80 .insn s,0xb2800000,\newpp
81#endif
82 .endm
83
Christian Borntraegerce6a04a2012-11-15 09:35:16 +010084 .macro HANDLE_SIE_INTERCEPT scratch,pgmcheck
Carsten Ottecd3b70f2010-05-17 10:00:04 +020085#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
Martin Schwidefsky6022afc2012-05-09 16:27:36 +020086 tmhh %r8,0x0001 # interrupting from user ?
87 jnz .+42
Martin Schwidefskyc5328902011-12-27 11:27:15 +010088 lgr \scratch,%r9
89 slg \scratch,BASED(.Lsie_loop)
90 clg \scratch,BASED(.Lsie_length)
Christian Borntraegerce6a04a2012-11-15 09:35:16 +010091 .if \pgmcheck
92 # Some program interrupts are suppressing (e.g. protection).
93 # We must also check the instruction after SIE in that case.
94 # do_protection_exception will rewind to rewind_pad
95 jh .+22
96 .else
Martin Schwidefsky6022afc2012-05-09 16:27:36 +020097 jhe .+22
Christian Borntraegerce6a04a2012-11-15 09:35:16 +010098 .endif
Martin Schwidefskyc5328902011-12-27 11:27:15 +010099 lg %r9,BASED(.Lsie_loop)
Hendrik Brueckner23d18e82013-02-11 18:11:09 +0100100 LPP BASED(.Lhost_id) # set host id
Carsten Ottecd3b70f2010-05-17 10:00:04 +0200101#endif
102 .endm
103
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100104 .macro CHECK_STACK stacksize,savearea
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200105#ifdef CONFIG_CHECK_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100106 tml %r15,\stacksize - CONFIG_STACK_GUARD
107 lghi %r14,\savearea
108 jz stack_overflow
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200109#endif
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200110 .endm
111
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100112 .macro SWITCH_ASYNC savearea,stack,shift
113 tmhh %r8,0x0001 # interrupting from user ?
114 jnz 1f
115 lgr %r14,%r9
116 slg %r14,BASED(.Lcritical_start)
117 clg %r14,BASED(.Lcritical_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 jhe 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100119 lghi %r11,\savearea # inside critical section, do cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 brasl %r14,cleanup_critical
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100121 tmhh %r8,0x0001 # retest problem state after cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 jnz 1f
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001230: lg %r14,\stack # are we already on the target stack?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 slgr %r14,%r15
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100125 srag %r14,%r14,\shift
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200126 jnz 1f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100127 CHECK_STACK 1<<\shift,\savearea
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200128 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100129 j 2f
1301: lg %r15,\stack # load target stack
Martin Schwidefskydc7ee002013-04-24 10:20:43 +02001312: la %r11,STACK_FRAME_OVERHEAD(%r15)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700132 .endm
133
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100134 .macro UPDATE_VTIME scratch,enter_timer
135 lg \scratch,__LC_EXIT_TIMER
136 slg \scratch,\enter_timer
137 alg \scratch,__LC_USER_TIMER
138 stg \scratch,__LC_USER_TIMER
139 lg \scratch,__LC_LAST_UPDATE_TIMER
140 slg \scratch,__LC_EXIT_TIMER
141 alg \scratch,__LC_SYSTEM_TIMER
142 stg \scratch,__LC_SYSTEM_TIMER
143 mvc __LC_LAST_UPDATE_TIMER(8),\enter_timer
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200144 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100146 .macro LAST_BREAK scratch
147 srag \scratch,%r10,23
148 jz .+10
149 stg %r10,__TI_last_break(%r12)
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200150 .endm
151
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200152 .macro REENABLE_IRQS
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100153 stg %r8,__LC_RETURN_PSW
154 ni __LC_RETURN_PSW,0xbf
155 ssm __LC_RETURN_PSW
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200156 .endm
157
Heiko Carstens473e66b2012-05-09 16:27:39 +0200158 .macro STCK savearea
Heiko Carstensd652d592012-05-14 10:35:22 +0200159#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
Heiko Carstens473e66b2012-05-09 16:27:39 +0200160 .insn s,0xb27c0000,\savearea # store clock fast
161#else
162 .insn s,0xb2050000,\savearea # store clock
163#endif
164 .endm
165
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100166 .section .kprobes.text, "ax"
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/*
169 * Scheduler resume function, called by switch_to
170 * gpr2 = (task_struct *) prev
171 * gpr3 = (task_struct *) next
172 * Returns:
173 * gpr2 = prev
174 */
Jan Glauber144d6342011-07-24 10:48:19 +0200175ENTRY(__switch_to)
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200176 stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
177 stg %r15,__THREAD_ksp(%r2) # store kernel stack of prev
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100178 lg %r4,__THREAD_info(%r2) # get thread_info of prev
179 lg %r5,__THREAD_info(%r3) # get thread_info of next
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200180 lgr %r15,%r5
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200181 aghi %r15,STACK_INIT # end of kernel stack of next
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200182 stg %r3,__LC_CURRENT # store task struct of next
183 stg %r5,__LC_THREAD_INFO # store thread info of next
184 stg %r15,__LC_KERNEL_STACK # store end of kernel stack
185 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
186 mvc __LC_CURRENT_PID+4(4,%r0),__TASK_pid(%r3) # store pid of next
187 lg %r15,__THREAD_ksp(%r3) # load kernel stack of next
Heiko Carstens77fa2242005-06-25 14:55:30 -0700188 tm __TI_flags+7(%r4),_TIF_MCCK_PENDING # machine check pending?
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100189 jz 0f
190 ni __TI_flags+7(%r4),255-_TIF_MCCK_PENDING # clear flag in prev
191 oi __TI_flags+7(%r5),_TIF_MCCK_PENDING # set it in next
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +02001920: lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 br %r14
194
195__critical_start:
196/*
197 * SVC interrupt handler routine. System calls are synchronous events and
198 * are executed with interrupts enabled.
199 */
200
Jan Glauber144d6342011-07-24 10:48:19 +0200201ENTRY(system_call)
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100202 stpt __LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100203sysc_stmg:
204 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
205 lg %r10,__LC_LAST_BREAK
206 lg %r12,__LC_THREAD_INFO
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100207sysc_per:
208 lg %r15,__LC_KERNEL_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100209 la %r11,STACK_FRAME_OVERHEAD(%r15) # pointer to pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210sysc_vtime:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100211 UPDATE_VTIME %r13,__LC_SYNC_ENTER_TIMER
212 LAST_BREAK %r13
213 stmg %r0,%r7,__PT_R0(%r11)
214 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
215 mvc __PT_PSW(16,%r11),__LC_SVC_OLD_PSW
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100216 mvc __PT_INT_CODE(4,%r11),__LC_SVC_ILC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217sysc_do_svc:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100218 oi __TI_flags+7(%r12),_TIF_SYSCALL
Martin Schwidefsky61649882013-04-24 12:58:39 +0200219 lg %r10,__TI_sysc_table(%r12) # address of system call table
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100220 llgh %r8,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100221 slag %r8,%r8,2 # shift and test for svc 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 jnz sysc_nr_ok
223 # svc 0: system call number in %r1
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100224 llgfr %r1,%r1 # clear high word in r1
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200225 cghi %r1,NR_syscalls
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 jnl sysc_nr_ok
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100227 sth %r1,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100228 slag %r8,%r1,2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229sysc_nr_ok:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100230 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
231 stg %r2,__PT_ORIG_GPR2(%r11)
232 stg %r7,STACK_FRAME_OVERHEAD(%r15)
233 lgf %r9,0(%r8,%r10) # get system call add.
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100234 tm __TI_flags+6(%r12),_TIF_TRACE >> 8
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200235 jnz sysc_tracesys
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100236 basr %r14,%r9 # call sys_xxxx
237 stg %r2,__PT_R2(%r11) # store return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239sysc_return:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200240 LOCKDEP_SYS_EXIT
241sysc_tif:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100242 tm __PT_PSW+1(%r11),0x01 # returning to user ?
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100243 jno sysc_restore
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200244 tm __TI_flags+7(%r12),_TIF_WORK_SVC
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100245 jnz sysc_work # check for work
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100246 ni __TI_flags+7(%r12),255-_TIF_SYSCALL
Heiko Carstens411788e2007-11-20 11:13:32 +0100247sysc_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100248 lg %r14,__LC_VDSO_PER_CPU
249 lmg %r0,%r10,__PT_R0(%r11)
250 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
251 stpt __LC_EXIT_TIMER
252 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
253 lmg %r11,%r15,__PT_R11(%r11)
254 lpswe __LC_RETURN_PSW
Heiko Carstens411788e2007-11-20 11:13:32 +0100255sysc_done:
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200258# One of the work bits is on. Find out which one.
259#
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100260sysc_work:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200261 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700262 jo sysc_mcck_pending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200263 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 jo sysc_reschedule
Martin Schwidefsky39efd4e2012-11-21 16:36:27 +0100265 tm __TI_flags+7(%r12),_TIF_PER_TRAP
266 jo sysc_singlestep
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200267 tm __TI_flags+7(%r12),_TIF_SIGPENDING
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200268 jo sysc_sigpending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200269 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200270 jo sysc_notify_resume
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200271 j sysc_return # beware of critical section cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273#
274# _TIF_NEED_RESCHED is set, call schedule
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200275#
276sysc_reschedule:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200277 larl %r14,sysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100278 jg schedule
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280#
Heiko Carstens77fa2242005-06-25 14:55:30 -0700281# _TIF_MCCK_PENDING is set, call handler
282#
283sysc_mcck_pending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200284 larl %r14,sysc_return
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200285 jg s390_handle_mcck # TIF bit will be cleared by handler
Heiko Carstens77fa2242005-06-25 14:55:30 -0700286
287#
Roland McGrath02a029b2008-04-30 00:53:08 -0700288# _TIF_SIGPENDING is set, call do_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289#
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200290sysc_sigpending:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100291 lgr %r2,%r11 # pass pointer to pt_regs
292 brasl %r14,do_signal
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100293 tm __TI_flags+7(%r12),_TIF_SYSCALL
294 jno sysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100295 lmg %r2,%r7,__PT_R2(%r11) # load svc arguments
296 lghi %r8,0 # svc 0 returns -ENOSYS
Martin Schwidefsky450e47d2012-10-09 13:33:53 +0200297 llgh %r1,__PT_INT_CODE+2(%r11) # load new svc number
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100298 cghi %r1,NR_syscalls
299 jnl sysc_nr_ok # invalid svc number -> do svc 0
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100300 slag %r8,%r1,2
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100301 j sysc_nr_ok # restart svc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303#
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200304# _TIF_NOTIFY_RESUME is set, call do_notify_resume
305#
306sysc_notify_resume:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100307 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200308 larl %r14,sysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100309 jg do_notify_resume
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200310
311#
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100312# _TIF_PER_TRAP is set, call do_per_trap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#
314sysc_singlestep:
Martin Schwidefsky39efd4e2012-11-21 16:36:27 +0100315 ni __TI_flags+7(%r12),255-_TIF_PER_TRAP
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100316 lgr %r2,%r11 # pass pointer to pt_regs
317 larl %r14,sysc_return
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100318 jg do_per_trap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200321# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
322# and after the system call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#
324sysc_tracesys:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100325 lgr %r2,%r11 # pass pointer to pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 la %r3,0
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100327 llgh %r0,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100328 stg %r0,__PT_R2(%r11)
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200329 brasl %r14,do_syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 lghi %r0,NR_syscalls
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200331 clgr %r0,%r2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 jnh sysc_tracenogo
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100333 sllg %r8,%r2,2
334 lgf %r9,0(%r8,%r10)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335sysc_tracego:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100336 lmg %r3,%r7,__PT_R3(%r11)
337 stg %r7,STACK_FRAME_OVERHEAD(%r15)
338 lg %r2,__PT_ORIG_GPR2(%r11)
339 basr %r14,%r9 # call sys_xxx
340 stg %r2,__PT_R2(%r11) # store return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341sysc_tracenogo:
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100342 tm __TI_flags+6(%r12),_TIF_TRACE >> 8
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200343 jz sysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100344 lgr %r2,%r11 # pass pointer to pt_regs
345 larl %r14,sysc_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200346 jg do_syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348#
349# a new process exits the kernel with ret_from_fork
350#
Jan Glauber144d6342011-07-24 10:48:19 +0200351ENTRY(ret_from_fork)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100352 la %r11,STACK_FRAME_OVERHEAD(%r15)
353 lg %r12,__LC_THREAD_INFO
Al Viro30dcb092012-10-11 15:30:14 -0400354 brasl %r14,schedule_tail
355 TRACE_IRQS_ON
356 ssm __LC_SVC_NEW_PSW # reenable interrupts
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100357 tm __PT_PSW+1(%r11),0x01 # forking a kernel thread ?
Al Viro30dcb092012-10-11 15:30:14 -0400358 jne sysc_tracenogo
359 # it's a kernel thread
360 lmg %r9,%r10,__PT_R9(%r11) # load gprs
Al Viro37fe5d42012-09-10 18:03:41 -0400361ENTRY(kernel_thread_starter)
362 la %r2,0(%r10)
363 basr %r14,%r9
Al Viro30dcb092012-10-11 15:30:14 -0400364 j sysc_tracenogo
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366/*
367 * Program check handler routine
368 */
369
Jan Glauber144d6342011-07-24 10:48:19 +0200370ENTRY(pgm_check_handler)
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100371 stpt __LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100372 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
373 lg %r10,__LC_LAST_BREAK
374 lg %r12,__LC_THREAD_INFO
375 larl %r13,system_call
376 lmg %r8,%r9,__LC_PGM_OLD_PSW
Christian Borntraegerce6a04a2012-11-15 09:35:16 +0100377 HANDLE_SIE_INTERCEPT %r14,1
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100378 tmhh %r8,0x0001 # test problem state bit
379 jnz 1f # -> fault in user space
380 tmhh %r8,0x4000 # PER bit set in old PSW ?
381 jnz 0f # -> enabled, can't be a double fault
382 tm __LC_PGM_ILC+3,0x80 # check for per exception
383 jnz pgm_svcper # -> single stepped svc
3840: CHECK_STACK STACK_SIZE,__LC_SAVE_AREA_SYNC
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200385 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100386 j 2f
3871: UPDATE_VTIME %r14,__LC_SYNC_ENTER_TIMER
388 LAST_BREAK %r14
389 lg %r15,__LC_KERNEL_STACK
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200390 lg %r14,__TI_task(%r12)
391 lghi %r13,__LC_PGM_TDB
392 tm __LC_PGM_ILC+2,0x02 # check for transaction abort
393 jz 2f
394 mvc __THREAD_trap_tdb(256,%r14),0(%r13)
Martin Schwidefskydc7ee002013-04-24 10:20:43 +02003952: la %r11,STACK_FRAME_OVERHEAD(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100396 stmg %r0,%r7,__PT_R0(%r11)
397 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
398 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100399 mvc __PT_INT_CODE(4,%r11),__LC_PGM_ILC
400 mvc __PT_INT_PARM_LONG(8,%r11),__LC_TRANS_EXC_CODE
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100401 stg %r10,__PT_ARGS(%r11)
402 tm __LC_PGM_ILC+3,0x80 # check for per exception
403 jz 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100404 tmhh %r8,0x0001 # kernel per event ?
405 jz pgm_kprobe
406 oi __TI_flags+7(%r12),_TIF_PER_TRAP
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200407 mvc __THREAD_per_address(8,%r14),__LC_PER_ADDRESS
408 mvc __THREAD_per_cause(2,%r14),__LC_PER_CAUSE
409 mvc __THREAD_per_paid(1,%r14),__LC_PER_PAID
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +01004100: REENABLE_IRQS
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100411 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200412 larl %r1,pgm_check_table
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100413 llgh %r10,__PT_INT_CODE+2(%r11)
414 nill %r10,0x007f
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200415 sll %r10,2
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100416 je sysc_return
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200417 lgf %r1,0(%r10,%r1) # load address of handler routine
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100418 lgr %r2,%r11 # pass pointer to pt_regs
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200419 basr %r14,%r1 # branch to interrupt-handler
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200420 j sysc_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422#
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100423# PER event in supervisor state, must be kprobes
424#
425pgm_kprobe:
426 REENABLE_IRQS
427 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
428 lgr %r2,%r11 # pass pointer to pt_regs
429 brasl %r14,do_per_trap
430 j sysc_return
431
432#
433# single stepped system call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434#
435pgm_svcper:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100436 oi __TI_flags+7(%r12),_TIF_PER_TRAP
437 mvc __LC_RETURN_PSW(8),__LC_SVC_NEW_PSW
438 larl %r14,sysc_per
439 stg %r14,__LC_RETURN_PSW+8
440 lpswe __LC_RETURN_PSW # branch to sysc_per and enable irqs
Michael Grundy4ba069b2006-09-20 15:58:39 +0200441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442/*
443 * IO interrupt handler routine
444 */
Jan Glauber144d6342011-07-24 10:48:19 +0200445ENTRY(io_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200446 STCK __LC_INT_CLOCK
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100447 stpt __LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100448 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
449 lg %r10,__LC_LAST_BREAK
450 lg %r12,__LC_THREAD_INFO
451 larl %r13,system_call
452 lmg %r8,%r9,__LC_IO_OLD_PSW
Christian Borntraegerce6a04a2012-11-15 09:35:16 +0100453 HANDLE_SIE_INTERCEPT %r14,0
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100454 SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
455 tmhh %r8,0x0001 # interrupting from user?
456 jz io_skip
457 UPDATE_VTIME %r14,__LC_ASYNC_ENTER_TIMER
458 LAST_BREAK %r14
459io_skip:
460 stmg %r0,%r7,__PT_R0(%r11)
461 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
462 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200463 mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
Heiko Carstens1f194a42006-07-03 00:24:46 -0700464 TRACE_IRQS_OFF
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100465 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200466io_loop:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100467 lgr %r2,%r11 # pass pointer to pt_regs
468 brasl %r14,do_IRQ
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200469 tm __LC_MACHINE_FLAGS+6,0x10 # MACHINE_FLAG_LPAR
470 jz io_return
471 tpi 0
472 jz io_return
473 mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
474 j io_loop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475io_return:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200476 LOCKDEP_SYS_EXIT
477 TRACE_IRQS_ON
478io_tif:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200479 tm __TI_flags+7(%r12),_TIF_WORK_INT
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200480 jnz io_work # there is work to do (signals etc.)
Heiko Carstens411788e2007-11-20 11:13:32 +0100481io_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100482 lg %r14,__LC_VDSO_PER_CPU
483 lmg %r0,%r10,__PT_R0(%r11)
484 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100485 stpt __LC_EXIT_TIMER
486 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
487 lmg %r11,%r15,__PT_R11(%r11)
488 lpswe __LC_RETURN_PSW
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700489io_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Martin Schwidefsky26889052008-05-07 09:22:52 +0200491#
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200492# There is work todo, find out in which context we have been interrupted:
493# 1) if we return to user space we can do all _TIF_WORK_INT work
494# 2) if we return to kernel code and kvm is enabled check if we need to
495# modify the psw to leave SIE
496# 3) if we return to kernel code and preemptive scheduling is enabled check
497# the preemption counter and if it is zero call preempt_schedule_irq
498# Before any work can be done, a switch to the kernel stack is required.
Martin Schwidefsky26889052008-05-07 09:22:52 +0200499#
500io_work:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100501 tm __PT_PSW+1(%r11),0x01 # returning to user ?
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200502 jo io_work_user # yes -> do resched & signal
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200503#ifdef CONFIG_PREEMPT
Martin Schwidefsky26889052008-05-07 09:22:52 +0200504 # check for preemptive scheduling
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200505 icm %r0,15,__TI_precount(%r12)
Martin Schwidefsky26889052008-05-07 09:22:52 +0200506 jnz io_restore # preemption is disabled
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200507 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
508 jno io_restore
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 # switch to kernel stack
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100510 lg %r1,__PT_R15(%r11)
511 aghi %r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
512 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
513 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
514 la %r11,STACK_FRAME_OVERHEAD(%r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 lgr %r15,%r1
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200516 # TRACE_IRQS_ON already done at io_return, call
517 # TRACE_IRQS_OFF to keep things symmetrical
518 TRACE_IRQS_OFF
519 brasl %r14,preempt_schedule_irq
520 j io_return
521#else
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200522 j io_restore
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200523#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200525#
526# Need to do work before returning to userspace, switch to kernel stack
527#
Martin Schwidefsky26889052008-05-07 09:22:52 +0200528io_work_user:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 lg %r1,__LC_KERNEL_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100530 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
531 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
532 la %r11,STACK_FRAME_OVERHEAD(%r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 lgr %r15,%r1
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#
536# One of the work bits is on. Find out which one.
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200537# Checked are: _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_NEED_RESCHED
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800538# and _TIF_MCCK_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200540io_work_tif:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200541 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700542 jo io_mcck_pending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200543 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 jo io_reschedule
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200545 tm __TI_flags+7(%r12),_TIF_SIGPENDING
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200546 jo io_sigpending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200547 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200548 jo io_notify_resume
549 j io_return # beware of critical section cleanup
Christian Borntraeger0eaeafa2008-05-07 09:22:53 +0200550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#
Heiko Carstens77fa2242005-06-25 14:55:30 -0700552# _TIF_MCCK_PENDING is set, call handler
553#
554io_mcck_pending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200555 # TRACE_IRQS_ON already done at io_return
Heiko Carstensb771aea2007-07-27 12:29:18 +0200556 brasl %r14,s390_handle_mcck # TIF bit will be cleared by handler
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200557 TRACE_IRQS_OFF
558 j io_return
Heiko Carstens77fa2242005-06-25 14:55:30 -0700559
560#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561# _TIF_NEED_RESCHED is set, call schedule
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200562#
563io_reschedule:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200564 # TRACE_IRQS_ON already done at io_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100565 ssm __LC_SVC_NEW_PSW # reenable interrupts
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200566 brasl %r14,schedule # call scheduler
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100567 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Heiko Carstens411788e2007-11-20 11:13:32 +0100568 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200569 j io_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571#
Roland McGrath02a029b2008-04-30 00:53:08 -0700572# _TIF_SIGPENDING or is set, call do_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200574io_sigpending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200575 # TRACE_IRQS_ON already done at io_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100576 ssm __LC_SVC_NEW_PSW # reenable interrupts
577 lgr %r2,%r11 # pass pointer to pt_regs
578 brasl %r14,do_signal
579 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Heiko Carstens411788e2007-11-20 11:13:32 +0100580 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200581 j io_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200583#
584# _TIF_NOTIFY_RESUME or is set, call do_notify_resume
585#
586io_notify_resume:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200587 # TRACE_IRQS_ON already done at io_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100588 ssm __LC_SVC_NEW_PSW # reenable interrupts
589 lgr %r2,%r11 # pass pointer to pt_regs
590 brasl %r14,do_notify_resume
591 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200592 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200593 j io_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595/*
596 * External interrupt handler routine
597 */
Jan Glauber144d6342011-07-24 10:48:19 +0200598ENTRY(ext_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200599 STCK __LC_INT_CLOCK
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100600 stpt __LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100601 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
602 lg %r10,__LC_LAST_BREAK
603 lg %r12,__LC_THREAD_INFO
604 larl %r13,system_call
605 lmg %r8,%r9,__LC_EXT_OLD_PSW
Christian Borntraegerce6a04a2012-11-15 09:35:16 +0100606 HANDLE_SIE_INTERCEPT %r14,0
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100607 SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
608 tmhh %r8,0x0001 # interrupting from user ?
609 jz ext_skip
610 UPDATE_VTIME %r14,__LC_ASYNC_ENTER_TIMER
611 LAST_BREAK %r14
612ext_skip:
613 stmg %r0,%r7,__PT_R0(%r11)
614 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
615 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200616 lghi %r1,__LC_EXT_PARAMS2
617 mvc __PT_INT_CODE(4,%r11),__LC_EXT_CPU_ADDR
618 mvc __PT_INT_PARM(4,%r11),__LC_EXT_PARAMS
619 mvc __PT_INT_PARM_LONG(8,%r11),0(%r1)
Heiko Carstens1f194a42006-07-03 00:24:46 -0700620 TRACE_IRQS_OFF
Michael Holzheu0de9db32012-05-09 16:27:35 +0200621 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100622 lgr %r2,%r11 # pass pointer to pt_regs
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200623 brasl %r14,do_extint
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 j io_return
625
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400626/*
627 * Load idle PSW. The second "half" of this function is in cleanup_idle.
628 */
629ENTRY(psw_idle)
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200630 stg %r3,__SF_EMPTY(%r15)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400631 larl %r1,psw_idle_lpsw+4
632 stg %r1,__SF_EMPTY+8(%r15)
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200633 STCK __CLOCK_IDLE_ENTER(%r2)
634 stpt __TIMER_IDLE_ENTER(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400635psw_idle_lpsw:
636 lpswe __SF_EMPTY(%r15)
637 br %r14
638psw_idle_end:
639
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700640__critical_end:
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642/*
643 * Machine check handler routines
644 */
Jan Glauber144d6342011-07-24 10:48:19 +0200645ENTRY(mcck_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200646 STCK __LC_MCCK_CLOCK
Heiko Carstens77fa2242005-06-25 14:55:30 -0700647 la %r1,4095 # revalidate r1
648 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200649 lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100650 lg %r10,__LC_LAST_BREAK
651 lg %r12,__LC_THREAD_INFO
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200652 larl %r13,system_call
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100653 lmg %r8,%r9,__LC_MCK_OLD_PSW
Christian Borntraegerce6a04a2012-11-15 09:35:16 +0100654 HANDLE_SIE_INTERCEPT %r14,0
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200655 tm __LC_MCCK_CODE,0x80 # system damage?
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100656 jo mcck_panic # yes -> rest of mcck code invalid
657 lghi %r14,__LC_CPU_TIMER_SAVE_AREA
658 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200659 tm __LC_MCCK_CODE+5,0x02 # stored cpu timer value valid?
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100660 jo 3f
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200661 la %r14,__LC_SYNC_ENTER_TIMER
662 clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
663 jl 0f
664 la %r14,__LC_ASYNC_ENTER_TIMER
6650: clc 0(8,%r14),__LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100666 jl 1f
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200667 la %r14,__LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +01006681: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
669 jl 2f
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200670 la %r14,__LC_LAST_UPDATE_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +01006712: spt 0(%r14)
Martin Schwidefsky63779812010-05-17 10:00:03 +0200672 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01006733: tm __LC_MCCK_CODE+2,0x09 # mwp + ia of old psw valid?
674 jno mcck_panic # no -> skip cleanup critical
675 SWITCH_ASYNC __LC_GPREGS_SAVE_AREA+64,__LC_PANIC_STACK,PAGE_SHIFT
676 tm %r8,0x0001 # interrupting from user ?
677 jz mcck_skip
678 UPDATE_VTIME %r14,__LC_MCCK_ENTER_TIMER
679 LAST_BREAK %r14
680mcck_skip:
Martin Schwidefsky6551fbd2013-02-28 16:28:41 +0100681 lghi %r14,__LC_GPREGS_SAVE_AREA+64
682 stmg %r0,%r7,__PT_R0(%r11)
683 mvc __PT_R8(64,%r11),0(%r14)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100684 stmg %r8,%r9,__PT_PSW(%r11)
685 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
686 lgr %r2,%r11 # pass pointer to pt_regs
Heiko Carstens77fa2242005-06-25 14:55:30 -0700687 brasl %r14,s390_do_machine_check
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100688 tm __PT_PSW+1(%r11),0x01 # returning to user ?
Heiko Carstens77fa2242005-06-25 14:55:30 -0700689 jno mcck_return
690 lg %r1,__LC_KERNEL_STACK # switch to kernel stack
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100691 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
692 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
693 la %r11,STACK_FRAME_OVERHEAD(%r1)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700694 lgr %r15,%r1
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100695 ssm __LC_PGM_NEW_PSW # turn dat on, keep irqs off
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200696 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700697 jno mcck_return
Heiko Carstens1f194a42006-07-03 00:24:46 -0700698 TRACE_IRQS_OFF
Heiko Carstens77fa2242005-06-25 14:55:30 -0700699 brasl %r14,s390_handle_mcck
Heiko Carstens1f194a42006-07-03 00:24:46 -0700700 TRACE_IRQS_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701mcck_return:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100702 lg %r14,__LC_VDSO_PER_CPU
703 lmg %r0,%r10,__PT_R0(%r11)
704 mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200705 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
706 jno 0f
707 stpt __LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100708 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
7090: lmg %r11,%r15,__PT_R11(%r11)
710 lpswe __LC_RETURN_MCCK_PSW
711
712mcck_panic:
713 lg %r14,__LC_PANIC_STACK
714 slgr %r14,%r15
715 srag %r14,%r14,PAGE_SHIFT
716 jz 0f
717 lg %r15,__LC_PANIC_STACK
7180: aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
719 j mcck_skip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200721#
722# PSW restart interrupt handler
723#
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400724ENTRY(restart_int_handler)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100725 stg %r15,__LC_SAVE_AREA_RESTART
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400726 lg %r15,__LC_RESTART_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100727 aghi %r15,-__PT_SIZE # create pt_regs on stack
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400728 xc 0(__PT_SIZE,%r15),0(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100729 stmg %r0,%r14,__PT_R0(%r15)
730 mvc __PT_R15(8,%r15),__LC_SAVE_AREA_RESTART
731 mvc __PT_PSW(16,%r15),__LC_RST_OLD_PSW # store restart old psw
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400732 aghi %r15,-STACK_FRAME_OVERHEAD # create stack frame on stack
733 xc 0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
Heiko Carstensfbe76562012-06-05 09:59:52 +0200734 lg %r1,__LC_RESTART_FN # load fn, parm & source cpu
735 lg %r2,__LC_RESTART_DATA
736 lg %r3,__LC_RESTART_SOURCE
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400737 ltgr %r3,%r3 # test source cpu address
738 jm 1f # negative -> skip source stop
Heiko Carstenseb546192012-06-04 15:05:43 +02007390: sigp %r4,%r3,SIGP_SENSE # sigp sense to source cpu
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400740 brc 10,0b # wait for status stored
7411: basr %r14,%r1 # call function
742 stap __SF_EMPTY(%r15) # store cpu address
743 llgh %r3,__SF_EMPTY(%r15)
Heiko Carstenseb546192012-06-04 15:05:43 +02007442: sigp %r4,%r3,SIGP_STOP # sigp stop to current cpu
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400745 brc 2,2b
7463: j 3b
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200747
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100748 .section .kprobes.text, "ax"
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750#ifdef CONFIG_CHECK_STACK
751/*
752 * The synchronous or the asynchronous stack overflowed. We are dead.
753 * No need to properly save the registers, we are going to panic anyway.
754 * Setup a pt_regs so that show_trace can provide a good call trace.
755 */
756stack_overflow:
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200757 lg %r15,__LC_PANIC_STACK # change to panic stack
758 la %r11,STACK_FRAME_OVERHEAD(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100759 stmg %r0,%r7,__PT_R0(%r11)
760 stmg %r8,%r9,__PT_PSW(%r11)
761 mvc __PT_R8(64,%r11),0(%r14)
762 stg %r10,__PT_ORIG_GPR2(%r11) # store last break to orig_gpr2
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100763 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
764 lgr %r2,%r11 # pass pointer to pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 jg kernel_stack_overflow
766#endif
767
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100768 .align 8
769cleanup_table:
770 .quad system_call
771 .quad sysc_do_svc
772 .quad sysc_tif
773 .quad sysc_restore
774 .quad sysc_done
775 .quad io_tif
776 .quad io_restore
777 .quad io_done
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400778 .quad psw_idle
779 .quad psw_idle_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781cleanup_critical:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100782 clg %r9,BASED(cleanup_table) # system_call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 jl 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100784 clg %r9,BASED(cleanup_table+8) # sysc_do_svc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 jl cleanup_system_call
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100786 clg %r9,BASED(cleanup_table+16) # sysc_tif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 jl 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100788 clg %r9,BASED(cleanup_table+24) # sysc_restore
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200789 jl cleanup_sysc_tif
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100790 clg %r9,BASED(cleanup_table+32) # sysc_done
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200791 jl cleanup_sysc_restore
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100792 clg %r9,BASED(cleanup_table+40) # io_tif
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200793 jl 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100794 clg %r9,BASED(cleanup_table+48) # io_restore
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200795 jl cleanup_io_tif
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100796 clg %r9,BASED(cleanup_table+56) # io_done
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200797 jl cleanup_io_restore
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400798 clg %r9,BASED(cleanup_table+64) # psw_idle
799 jl 0f
800 clg %r9,BASED(cleanup_table+72) # psw_idle_end
801 jl cleanup_idle
Martin Schwidefskyc5328902011-12-27 11:27:15 +01008020: br %r14
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805cleanup_system_call:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100806 # check if stpt has been executed
807 clg %r9,BASED(cleanup_system_call_insn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 jh 0f
809 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100810 cghi %r11,__LC_SAVE_AREA_ASYNC
Martin Schwidefsky63779812010-05-17 10:00:03 +0200811 je 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100812 mvc __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
8130: # check if stmg has been executed
814 clg %r9,BASED(cleanup_system_call_insn+8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 jh 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100816 mvc __LC_SAVE_AREA_SYNC(64),0(%r11)
8170: # check if base register setup + TIF bit load has been done
818 clg %r9,BASED(cleanup_system_call_insn+16)
819 jhe 0f
820 # set up saved registers r10 and r12
821 stg %r10,16(%r11) # r10 last break
822 stg %r12,32(%r11) # r12 thread-info pointer
8230: # check if the user time update has been done
824 clg %r9,BASED(cleanup_system_call_insn+24)
825 jh 0f
826 lg %r15,__LC_EXIT_TIMER
827 slg %r15,__LC_SYNC_ENTER_TIMER
828 alg %r15,__LC_USER_TIMER
829 stg %r15,__LC_USER_TIMER
8300: # check if the system time update has been done
831 clg %r9,BASED(cleanup_system_call_insn+32)
832 jh 0f
833 lg %r15,__LC_LAST_UPDATE_TIMER
834 slg %r15,__LC_EXIT_TIMER
835 alg %r15,__LC_SYSTEM_TIMER
836 stg %r15,__LC_SYSTEM_TIMER
8370: # update accounting time stamp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100839 # do LAST_BREAK
840 lg %r9,16(%r11)
841 srag %r9,%r9,23
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200842 jz 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100843 mvc __TI_last_break(8,%r12),16(%r11)
8440: # set up saved register r11
845 lg %r15,__LC_KERNEL_STACK
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200846 la %r9,STACK_FRAME_OVERHEAD(%r15)
847 stg %r9,24(%r11) # r11 pt_regs pointer
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100848 # fill pt_regs
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200849 mvc __PT_R8(64,%r9),__LC_SAVE_AREA_SYNC
850 stmg %r0,%r7,__PT_R0(%r9)
851 mvc __PT_PSW(16,%r9),__LC_SVC_OLD_PSW
852 mvc __PT_INT_CODE(4,%r9),__LC_SVC_ILC
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100853 # setup saved register r15
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100854 stg %r15,56(%r11) # r15 stack pointer
855 # set new psw address and exit
856 larl %r9,sysc_do_svc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 br %r14
858cleanup_system_call_insn:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200859 .quad system_call
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100860 .quad sysc_stmg
861 .quad sysc_per
862 .quad sysc_vtime+18
863 .quad sysc_vtime+42
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200865cleanup_sysc_tif:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100866 larl %r9,sysc_tif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 br %r14
868
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200869cleanup_sysc_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100870 clg %r9,BASED(cleanup_sysc_restore_insn)
Martin Schwidefsky63779812010-05-17 10:00:03 +0200871 je 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100872 lg %r9,24(%r11) # get saved pointer to pt_regs
873 mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
874 mvc 0(64,%r11),__PT_R8(%r9)
875 lmg %r0,%r7,__PT_R0(%r9)
8760: lmg %r8,%r9,__LC_RETURN_PSW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 br %r14
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200878cleanup_sysc_restore_insn:
Heiko Carstens411788e2007-11-20 11:13:32 +0100879 .quad sysc_done - 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200881cleanup_io_tif:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100882 larl %r9,io_tif
Martin Schwidefsky176b1802010-04-09 13:43:00 +0200883 br %r14
884
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200885cleanup_io_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100886 clg %r9,BASED(cleanup_io_restore_insn)
887 je 0f
888 lg %r9,24(%r11) # get saved r11 pointer to pt_regs
889 mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100890 mvc 0(64,%r11),__PT_R8(%r9)
891 lmg %r0,%r7,__PT_R0(%r9)
8920: lmg %r8,%r9,__LC_RETURN_PSW
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700893 br %r14
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200894cleanup_io_restore_insn:
Heiko Carstens411788e2007-11-20 11:13:32 +0100895 .quad io_done - 4
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700896
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400897cleanup_idle:
898 # copy interrupt clock & cpu timer
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200899 mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_INT_CLOCK
900 mvc __TIMER_IDLE_EXIT(8,%r2),__LC_ASYNC_ENTER_TIMER
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400901 cghi %r11,__LC_SAVE_AREA_ASYNC
902 je 0f
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200903 mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_MCCK_CLOCK
904 mvc __TIMER_IDLE_EXIT(8,%r2),__LC_MCCK_ENTER_TIMER
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04009050: # check if stck & stpt have been executed
906 clg %r9,BASED(cleanup_idle_insn)
907 jhe 1f
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200908 mvc __CLOCK_IDLE_ENTER(8,%r2),__CLOCK_IDLE_EXIT(%r2)
909 mvc __TIMER_IDLE_ENTER(8,%r2),__TIMER_IDLE_EXIT(%r2)
9101: # account system time going idle
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400911 lg %r9,__LC_STEAL_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200912 alg %r9,__CLOCK_IDLE_ENTER(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400913 slg %r9,__LC_LAST_UPDATE_CLOCK
914 stg %r9,__LC_STEAL_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200915 mvc __LC_LAST_UPDATE_CLOCK(8),__CLOCK_IDLE_EXIT(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400916 lg %r9,__LC_SYSTEM_TIMER
917 alg %r9,__LC_LAST_UPDATE_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200918 slg %r9,__TIMER_IDLE_ENTER(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400919 stg %r9,__LC_SYSTEM_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200920 mvc __LC_LAST_UPDATE_TIMER(8),__TIMER_IDLE_EXIT(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400921 # prepare return psw
922 nihh %r8,0xfffd # clear wait state bit
923 lg %r9,48(%r11) # return from psw_idle
924 br %r14
925cleanup_idle_insn:
926 .quad psw_idle_lpsw
927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928/*
929 * Integer constants
930 */
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100931 .align 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932.Lcritical_start:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100933 .quad __critical_start
934.Lcritical_length:
935 .quad __critical_end - __critical_start
936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200938#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
939/*
940 * sie64a calling convention:
941 * %r2 pointer to sie control block
942 * %r3 guest register save area
943 */
Jan Glauber144d6342011-07-24 10:48:19 +0200944ENTRY(sie64a)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200945 stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
946 stg %r2,__SF_EMPTY(%r15) # save control block pointer
947 stg %r3,__SF_EMPTY+8(%r15) # save guest register save area
Martin Schwidefskyddd6f952011-12-27 11:27:13 +0100948 xc __SF_EMPTY+16(8,%r15),__SF_EMPTY+16(%r15) # host id == 0
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200949 lmg %r0,%r13,0(%r3) # load guest gprs 0-13
Christian Borntraegerce6a04a2012-11-15 09:35:16 +0100950# some program checks are suppressing. C code (e.g. do_protection_exception)
951# will rewind the PSW by the ILC, which is 4 bytes in case of SIE. Other
952# instructions in the sie_loop should not cause program interrupts. So
953# lets use a nop (47 00 00 00) as a landing pad.
954# See also HANDLE_SIE_INTERCEPT
955rewind_pad:
956 nop 0
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200957sie_loop:
958 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
959 tm __TI_flags+7(%r14),_TIF_EXIT_SIE
960 jnz sie_exit
Christian Borntraeger480e5922011-09-20 17:07:28 +0200961 lg %r14,__LC_GMAP # get gmap pointer
962 ltgr %r14,%r14
963 jz sie_gmap
964 lctlg %c1,%c1,__GMAP_ASCE(%r14) # load primary asce
965sie_gmap:
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200966 lg %r14,__SF_EMPTY(%r15) # get control block pointer
Hendrik Brueckner23d18e82013-02-11 18:11:09 +0100967 LPP __SF_EMPTY(%r15) # set guest id
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200968 sie 0(%r14)
969sie_done:
Hendrik Brueckner23d18e82013-02-11 18:11:09 +0100970 LPP __SF_EMPTY+16(%r15) # set host id
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200971 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
972sie_exit:
Christian Borntraeger480e5922011-09-20 17:07:28 +0200973 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200974 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
975 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
976 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
977 lghi %r2,0
978 br %r14
979sie_fault:
Carsten Otte69ba9742011-10-30 15:16:59 +0100980 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200981 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200982 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
983 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
984 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
985 lghi %r2,-EFAULT
986 br %r14
987
988 .align 8
989.Lsie_loop:
990 .quad sie_loop
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100991.Lsie_length:
992 .quad sie_done - sie_loop
Martin Schwidefskyddd6f952011-12-27 11:27:13 +0100993.Lhost_id:
994 .quad 0
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200995
Christian Borntraegerce6a04a2012-11-15 09:35:16 +0100996 EX_TABLE(rewind_pad,sie_fault)
Heiko Carstenseb608fb2012-09-05 13:26:11 +0200997 EX_TABLE(sie_loop,sie_fault)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200998#endif
999
Heiko Carstens25d83cb2006-09-28 16:56:37 +02001000 .section .rodata, "a"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001#define SYSCALL(esa,esame,emu) .long esame
Heiko Carstens9bf12262009-06-12 10:26:47 +02001002 .globl sys_call_table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003sys_call_table:
1004#include "syscalls.S"
1005#undef SYSCALL
1006
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001007#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009#define SYSCALL(esa,esame,emu) .long emu
Martin Schwidefsky61649882013-04-24 12:58:39 +02001010 .globl sys_call_table_emu
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011sys_call_table_emu:
1012#include "syscalls.S"
1013#undef SYSCALL
1014#endif