blob: 9532fe23be47ec5b2d8da50ed2dce67e1a1f73b5 [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>
Martin Schwidefsky1f44a2252013-06-27 09:01:09 +020022#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Martin Schwidefskyc5328902011-12-27 11:27:15 +010024__PT_R0 = __PT_GPRS
25__PT_R1 = __PT_GPRS + 8
26__PT_R2 = __PT_GPRS + 16
27__PT_R3 = __PT_GPRS + 24
28__PT_R4 = __PT_GPRS + 32
29__PT_R5 = __PT_GPRS + 40
30__PT_R6 = __PT_GPRS + 48
31__PT_R7 = __PT_GPRS + 56
32__PT_R8 = __PT_GPRS + 64
33__PT_R9 = __PT_GPRS + 72
34__PT_R10 = __PT_GPRS + 80
35__PT_R11 = __PT_GPRS + 88
36__PT_R12 = __PT_GPRS + 96
37__PT_R13 = __PT_GPRS + 104
38__PT_R14 = __PT_GPRS + 112
39__PT_R15 = __PT_GPRS + 120
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
42STACK_SIZE = 1 << STACK_SHIFT
Martin Schwidefskydc7ee002013-04-24 10:20:43 +020043STACK_INIT = STACK_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020045_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +010046 _TIF_MCCK_PENDING | _TIF_PER_TRAP )
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020047_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
Heiko Carstens54dfe5d2006-02-01 03:06:38 -080048 _TIF_MCCK_PENDING)
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +010049_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
50 _TIF_SYSCALL_TRACEPOINT)
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
Heiko Carstens61aa4882013-11-01 10:08:20 +010077#if IS_ENABLED(CONFIG_KVM)
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
Martin Schwidefsky7c470532013-05-17 14:41:37 +020084 .macro HANDLE_SIE_INTERCEPT scratch,reason
Heiko Carstens61aa4882013-11-01 10:08:20 +010085#if IS_ENABLED(CONFIG_KVM)
Martin Schwidefsky6022afc2012-05-09 16:27:36 +020086 tmhh %r8,0x0001 # interrupting from user ?
Martin Schwidefsky7c470532013-05-17 14:41:37 +020087 jnz .+62
Martin Schwidefskyc5328902011-12-27 11:27:15 +010088 lgr \scratch,%r9
Martin Schwidefsky7c470532013-05-17 14:41:37 +020089 slg \scratch,BASED(.Lsie_critical)
90 clg \scratch,BASED(.Lsie_critical_length)
91 .if \reason==1
Christian Borntraegerce6a04a2012-11-15 09:35:16 +010092 # 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
Martin Schwidefsky7c470532013-05-17 14:41:37 +020095 jh .+42
Christian Borntraegerce6a04a2012-11-15 09:35:16 +010096 .else
Martin Schwidefsky7c470532013-05-17 14:41:37 +020097 jhe .+42
Christian Borntraegerce6a04a2012-11-15 09:35:16 +010098 .endif
Martin Schwidefsky7c470532013-05-17 14:41:37 +020099 lg %r14,__SF_EMPTY(%r15) # get control block pointer
100 LPP __SF_EMPTY+16(%r15) # set host id
Christian Borntraeger95d38fd2013-05-17 14:41:34 +0200101 ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200102 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
103 larl %r9,sie_exit # skip forward to sie_exit
104 mvi __SF_EMPTY+31(%r15),\reason # set exit reason
Carsten Ottecd3b70f2010-05-17 10:00:04 +0200105#endif
106 .endm
107
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100108 .macro CHECK_STACK stacksize,savearea
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200109#ifdef CONFIG_CHECK_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100110 tml %r15,\stacksize - CONFIG_STACK_GUARD
111 lghi %r14,\savearea
112 jz stack_overflow
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200113#endif
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200114 .endm
115
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100116 .macro SWITCH_ASYNC savearea,stack,shift
117 tmhh %r8,0x0001 # interrupting from user ?
118 jnz 1f
119 lgr %r14,%r9
120 slg %r14,BASED(.Lcritical_start)
121 clg %r14,BASED(.Lcritical_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 jhe 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100123 lghi %r11,\savearea # inside critical section, do cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 brasl %r14,cleanup_critical
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100125 tmhh %r8,0x0001 # retest problem state after cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 jnz 1f
Martin Schwidefskyc5328902011-12-27 11:27:15 +01001270: lg %r14,\stack # are we already on the target stack?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 slgr %r14,%r15
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100129 srag %r14,%r14,\shift
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200130 jnz 1f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100131 CHECK_STACK 1<<\shift,\savearea
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200132 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100133 j 2f
1341: lg %r15,\stack # load target stack
Martin Schwidefskydc7ee002013-04-24 10:20:43 +02001352: la %r11,STACK_FRAME_OVERHEAD(%r15)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700136 .endm
137
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100138 .macro UPDATE_VTIME scratch,enter_timer
139 lg \scratch,__LC_EXIT_TIMER
140 slg \scratch,\enter_timer
141 alg \scratch,__LC_USER_TIMER
142 stg \scratch,__LC_USER_TIMER
143 lg \scratch,__LC_LAST_UPDATE_TIMER
144 slg \scratch,__LC_EXIT_TIMER
145 alg \scratch,__LC_SYSTEM_TIMER
146 stg \scratch,__LC_SYSTEM_TIMER
147 mvc __LC_LAST_UPDATE_TIMER(8),\enter_timer
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200148 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100150 .macro LAST_BREAK scratch
151 srag \scratch,%r10,23
152 jz .+10
153 stg %r10,__TI_last_break(%r12)
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200154 .endm
155
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200156 .macro REENABLE_IRQS
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100157 stg %r8,__LC_RETURN_PSW
158 ni __LC_RETURN_PSW,0xbf
159 ssm __LC_RETURN_PSW
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200160 .endm
161
Heiko Carstens473e66b2012-05-09 16:27:39 +0200162 .macro STCK savearea
Heiko Carstensd652d592012-05-14 10:35:22 +0200163#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
Heiko Carstens473e66b2012-05-09 16:27:39 +0200164 .insn s,0xb27c0000,\savearea # store clock fast
165#else
166 .insn s,0xb2050000,\savearea # store clock
167#endif
168 .endm
169
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100170 .section .kprobes.text, "ax"
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/*
173 * Scheduler resume function, called by switch_to
174 * gpr2 = (task_struct *) prev
175 * gpr3 = (task_struct *) next
176 * Returns:
177 * gpr2 = prev
178 */
Jan Glauber144d6342011-07-24 10:48:19 +0200179ENTRY(__switch_to)
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200180 stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
181 stg %r15,__THREAD_ksp(%r2) # store kernel stack of prev
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100182 lg %r4,__THREAD_info(%r2) # get thread_info of prev
183 lg %r5,__THREAD_info(%r3) # get thread_info of next
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200184 lgr %r15,%r5
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200185 aghi %r15,STACK_INIT # end of kernel stack of next
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +0200186 stg %r3,__LC_CURRENT # store task struct of next
187 stg %r5,__LC_THREAD_INFO # store thread info of next
188 stg %r15,__LC_KERNEL_STACK # store end of kernel stack
189 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
190 mvc __LC_CURRENT_PID+4(4,%r0),__TASK_pid(%r3) # store pid of next
191 lg %r15,__THREAD_ksp(%r3) # load kernel stack of next
Heiko Carstens77fa2242005-06-25 14:55:30 -0700192 tm __TI_flags+7(%r4),_TIF_MCCK_PENDING # machine check pending?
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100193 jz 0f
194 ni __TI_flags+7(%r4),255-_TIF_MCCK_PENDING # clear flag in prev
195 oi __TI_flags+7(%r5),_TIF_MCCK_PENDING # set it in next
Martin Schwidefskyeda0c6d2012-05-15 09:20:06 +02001960: lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 br %r14
198
199__critical_start:
200/*
201 * SVC interrupt handler routine. System calls are synchronous events and
202 * are executed with interrupts enabled.
203 */
204
Jan Glauber144d6342011-07-24 10:48:19 +0200205ENTRY(system_call)
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100206 stpt __LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100207sysc_stmg:
208 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
209 lg %r10,__LC_LAST_BREAK
210 lg %r12,__LC_THREAD_INFO
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100211sysc_per:
212 lg %r15,__LC_KERNEL_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100213 la %r11,STACK_FRAME_OVERHEAD(%r15) # pointer to pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214sysc_vtime:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100215 UPDATE_VTIME %r13,__LC_SYNC_ENTER_TIMER
216 LAST_BREAK %r13
217 stmg %r0,%r7,__PT_R0(%r11)
218 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
219 mvc __PT_PSW(16,%r11),__LC_SVC_OLD_PSW
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100220 mvc __PT_INT_CODE(4,%r11),__LC_SVC_ILC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221sysc_do_svc:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100222 oi __TI_flags+7(%r12),_TIF_SYSCALL
Martin Schwidefsky61649882013-04-24 12:58:39 +0200223 lg %r10,__TI_sysc_table(%r12) # address of system call table
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100224 llgh %r8,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100225 slag %r8,%r8,2 # shift and test for svc 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 jnz sysc_nr_ok
227 # svc 0: system call number in %r1
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100228 llgfr %r1,%r1 # clear high word in r1
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200229 cghi %r1,NR_syscalls
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 jnl sysc_nr_ok
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100231 sth %r1,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100232 slag %r8,%r1,2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233sysc_nr_ok:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100234 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
235 stg %r2,__PT_ORIG_GPR2(%r11)
236 stg %r7,STACK_FRAME_OVERHEAD(%r15)
237 lgf %r9,0(%r8,%r10) # get system call add.
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100238 tm __TI_flags+6(%r12),_TIF_TRACE >> 8
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200239 jnz sysc_tracesys
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100240 basr %r14,%r9 # call sys_xxxx
241 stg %r2,__PT_R2(%r11) # store return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243sysc_return:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200244 LOCKDEP_SYS_EXIT
245sysc_tif:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100246 tm __PT_PSW+1(%r11),0x01 # returning to user ?
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100247 jno sysc_restore
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200248 tm __TI_flags+7(%r12),_TIF_WORK_SVC
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100249 jnz sysc_work # check for work
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100250 ni __TI_flags+7(%r12),255-_TIF_SYSCALL
Heiko Carstens411788e2007-11-20 11:13:32 +0100251sysc_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100252 lg %r14,__LC_VDSO_PER_CPU
253 lmg %r0,%r10,__PT_R0(%r11)
254 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
255 stpt __LC_EXIT_TIMER
256 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
257 lmg %r11,%r15,__PT_R11(%r11)
258 lpswe __LC_RETURN_PSW
Heiko Carstens411788e2007-11-20 11:13:32 +0100259sysc_done:
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200262# One of the work bits is on. Find out which one.
263#
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100264sysc_work:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200265 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700266 jo sysc_mcck_pending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200267 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 jo sysc_reschedule
Martin Schwidefsky39efd4e2012-11-21 16:36:27 +0100269 tm __TI_flags+7(%r12),_TIF_PER_TRAP
270 jo sysc_singlestep
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200271 tm __TI_flags+7(%r12),_TIF_SIGPENDING
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200272 jo sysc_sigpending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200273 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200274 jo sysc_notify_resume
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200275 j sysc_return # beware of critical section cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277#
278# _TIF_NEED_RESCHED is set, call schedule
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200279#
280sysc_reschedule:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200281 larl %r14,sysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100282 jg schedule
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284#
Heiko Carstens77fa2242005-06-25 14:55:30 -0700285# _TIF_MCCK_PENDING is set, call handler
286#
287sysc_mcck_pending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200288 larl %r14,sysc_return
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200289 jg s390_handle_mcck # TIF bit will be cleared by handler
Heiko Carstens77fa2242005-06-25 14:55:30 -0700290
291#
Roland McGrath02a029b2008-04-30 00:53:08 -0700292# _TIF_SIGPENDING is set, call do_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293#
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200294sysc_sigpending:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100295 lgr %r2,%r11 # pass pointer to pt_regs
296 brasl %r14,do_signal
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100297 tm __TI_flags+7(%r12),_TIF_SYSCALL
298 jno sysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100299 lmg %r2,%r7,__PT_R2(%r11) # load svc arguments
Martin Schwidefskydbbfe482013-09-27 15:24:38 +0200300 lg %r10,__TI_sysc_table(%r12) # address of system call table
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100301 lghi %r8,0 # svc 0 returns -ENOSYS
Martin Schwidefsky450e47d2012-10-09 13:33:53 +0200302 llgh %r1,__PT_INT_CODE+2(%r11) # load new svc number
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100303 cghi %r1,NR_syscalls
304 jnl sysc_nr_ok # invalid svc number -> do svc 0
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100305 slag %r8,%r1,2
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100306 j sysc_nr_ok # restart svc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308#
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200309# _TIF_NOTIFY_RESUME is set, call do_notify_resume
310#
311sysc_notify_resume:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100312 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200313 larl %r14,sysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100314 jg do_notify_resume
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200315
316#
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100317# _TIF_PER_TRAP is set, call do_per_trap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#
319sysc_singlestep:
Martin Schwidefsky39efd4e2012-11-21 16:36:27 +0100320 ni __TI_flags+7(%r12),255-_TIF_PER_TRAP
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100321 lgr %r2,%r11 # pass pointer to pt_regs
322 larl %r14,sysc_return
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100323 jg do_per_trap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200326# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
327# and after the system call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#
329sysc_tracesys:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100330 lgr %r2,%r11 # pass pointer to pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 la %r3,0
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100332 llgh %r0,__PT_INT_CODE+2(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100333 stg %r0,__PT_R2(%r11)
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200334 brasl %r14,do_syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 lghi %r0,NR_syscalls
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200336 clgr %r0,%r2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 jnh sysc_tracenogo
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100338 sllg %r8,%r2,2
339 lgf %r9,0(%r8,%r10)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340sysc_tracego:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100341 lmg %r3,%r7,__PT_R3(%r11)
342 stg %r7,STACK_FRAME_OVERHEAD(%r15)
343 lg %r2,__PT_ORIG_GPR2(%r11)
344 basr %r14,%r9 # call sys_xxx
345 stg %r2,__PT_R2(%r11) # store return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346sysc_tracenogo:
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100347 tm __TI_flags+6(%r12),_TIF_TRACE >> 8
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200348 jz sysc_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100349 lgr %r2,%r11 # pass pointer to pt_regs
350 larl %r14,sysc_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200351 jg do_syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353#
354# a new process exits the kernel with ret_from_fork
355#
Jan Glauber144d6342011-07-24 10:48:19 +0200356ENTRY(ret_from_fork)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100357 la %r11,STACK_FRAME_OVERHEAD(%r15)
358 lg %r12,__LC_THREAD_INFO
Al Viro30dcb092012-10-11 15:30:14 -0400359 brasl %r14,schedule_tail
360 TRACE_IRQS_ON
361 ssm __LC_SVC_NEW_PSW # reenable interrupts
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100362 tm __PT_PSW+1(%r11),0x01 # forking a kernel thread ?
Al Viro30dcb092012-10-11 15:30:14 -0400363 jne sysc_tracenogo
364 # it's a kernel thread
365 lmg %r9,%r10,__PT_R9(%r11) # load gprs
Al Viro37fe5d42012-09-10 18:03:41 -0400366ENTRY(kernel_thread_starter)
367 la %r2,0(%r10)
368 basr %r14,%r9
Al Viro30dcb092012-10-11 15:30:14 -0400369 j sysc_tracenogo
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371/*
372 * Program check handler routine
373 */
374
Jan Glauber144d6342011-07-24 10:48:19 +0200375ENTRY(pgm_check_handler)
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100376 stpt __LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100377 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
378 lg %r10,__LC_LAST_BREAK
379 lg %r12,__LC_THREAD_INFO
380 larl %r13,system_call
381 lmg %r8,%r9,__LC_PGM_OLD_PSW
Christian Borntraegerce6a04a2012-11-15 09:35:16 +0100382 HANDLE_SIE_INTERCEPT %r14,1
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100383 tmhh %r8,0x0001 # test problem state bit
384 jnz 1f # -> fault in user space
385 tmhh %r8,0x4000 # PER bit set in old PSW ?
386 jnz 0f # -> enabled, can't be a double fault
387 tm __LC_PGM_ILC+3,0x80 # check for per exception
388 jnz pgm_svcper # -> single stepped svc
3890: CHECK_STACK STACK_SIZE,__LC_SAVE_AREA_SYNC
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200390 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100391 j 2f
3921: UPDATE_VTIME %r14,__LC_SYNC_ENTER_TIMER
393 LAST_BREAK %r14
394 lg %r15,__LC_KERNEL_STACK
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200395 lg %r14,__TI_task(%r12)
396 lghi %r13,__LC_PGM_TDB
397 tm __LC_PGM_ILC+2,0x02 # check for transaction abort
398 jz 2f
399 mvc __THREAD_trap_tdb(256,%r14),0(%r13)
Martin Schwidefskydc7ee002013-04-24 10:20:43 +02004002: la %r11,STACK_FRAME_OVERHEAD(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100401 stmg %r0,%r7,__PT_R0(%r11)
402 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
403 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100404 mvc __PT_INT_CODE(4,%r11),__LC_PGM_ILC
405 mvc __PT_INT_PARM_LONG(8,%r11),__LC_TRANS_EXC_CODE
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100406 stg %r10,__PT_ARGS(%r11)
407 tm __LC_PGM_ILC+3,0x80 # check for per exception
408 jz 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100409 tmhh %r8,0x0001 # kernel per event ?
410 jz pgm_kprobe
411 oi __TI_flags+7(%r12),_TIF_PER_TRAP
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200412 mvc __THREAD_per_address(8,%r14),__LC_PER_ADDRESS
413 mvc __THREAD_per_cause(2,%r14),__LC_PER_CAUSE
414 mvc __THREAD_per_paid(1,%r14),__LC_PER_PAID
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +01004150: REENABLE_IRQS
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100416 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200417 larl %r1,pgm_check_table
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100418 llgh %r10,__PT_INT_CODE+2(%r11)
419 nill %r10,0x007f
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200420 sll %r10,2
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100421 je sysc_return
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200422 lgf %r1,0(%r10,%r1) # load address of handler routine
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100423 lgr %r2,%r11 # pass pointer to pt_regs
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200424 basr %r14,%r1 # branch to interrupt-handler
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200425 j sysc_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427#
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100428# PER event in supervisor state, must be kprobes
429#
430pgm_kprobe:
431 REENABLE_IRQS
432 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
433 lgr %r2,%r11 # pass pointer to pt_regs
434 brasl %r14,do_per_trap
435 j sysc_return
436
437#
438# single stepped system call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#
440pgm_svcper:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100441 oi __TI_flags+7(%r12),_TIF_PER_TRAP
442 mvc __LC_RETURN_PSW(8),__LC_SVC_NEW_PSW
443 larl %r14,sysc_per
444 stg %r14,__LC_RETURN_PSW+8
445 lpswe __LC_RETURN_PSW # branch to sysc_per and enable irqs
Michael Grundy4ba069b2006-09-20 15:58:39 +0200446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447/*
448 * IO interrupt handler routine
449 */
Jan Glauber144d6342011-07-24 10:48:19 +0200450ENTRY(io_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200451 STCK __LC_INT_CLOCK
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100452 stpt __LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100453 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
454 lg %r10,__LC_LAST_BREAK
455 lg %r12,__LC_THREAD_INFO
456 larl %r13,system_call
457 lmg %r8,%r9,__LC_IO_OLD_PSW
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200458 HANDLE_SIE_INTERCEPT %r14,2
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100459 SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
460 tmhh %r8,0x0001 # interrupting from user?
461 jz io_skip
462 UPDATE_VTIME %r14,__LC_ASYNC_ENTER_TIMER
463 LAST_BREAK %r14
464io_skip:
465 stmg %r0,%r7,__PT_R0(%r11)
466 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
467 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200468 mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
Heiko Carstens1f194a42006-07-03 00:24:46 -0700469 TRACE_IRQS_OFF
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100470 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200471io_loop:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100472 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky1f44a2252013-06-27 09:01:09 +0200473 lghi %r3,IO_INTERRUPT
474 tm __PT_INT_CODE+8(%r11),0x80 # adapter interrupt ?
475 jz io_call
476 lghi %r3,THIN_INTERRUPT
477io_call:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100478 brasl %r14,do_IRQ
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200479 tm __LC_MACHINE_FLAGS+6,0x10 # MACHINE_FLAG_LPAR
480 jz io_return
481 tpi 0
482 jz io_return
483 mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
484 j io_loop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485io_return:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200486 LOCKDEP_SYS_EXIT
487 TRACE_IRQS_ON
488io_tif:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200489 tm __TI_flags+7(%r12),_TIF_WORK_INT
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200490 jnz io_work # there is work to do (signals etc.)
Heiko Carstens411788e2007-11-20 11:13:32 +0100491io_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100492 lg %r14,__LC_VDSO_PER_CPU
493 lmg %r0,%r10,__PT_R0(%r11)
494 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100495 stpt __LC_EXIT_TIMER
496 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
497 lmg %r11,%r15,__PT_R11(%r11)
498 lpswe __LC_RETURN_PSW
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700499io_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Martin Schwidefsky26889052008-05-07 09:22:52 +0200501#
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200502# There is work todo, find out in which context we have been interrupted:
503# 1) if we return to user space we can do all _TIF_WORK_INT work
504# 2) if we return to kernel code and kvm is enabled check if we need to
505# modify the psw to leave SIE
506# 3) if we return to kernel code and preemptive scheduling is enabled check
507# the preemption counter and if it is zero call preempt_schedule_irq
508# Before any work can be done, a switch to the kernel stack is required.
Martin Schwidefsky26889052008-05-07 09:22:52 +0200509#
510io_work:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100511 tm __PT_PSW+1(%r11),0x01 # returning to user ?
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200512 jo io_work_user # yes -> do resched & signal
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200513#ifdef CONFIG_PREEMPT
Martin Schwidefsky26889052008-05-07 09:22:52 +0200514 # check for preemptive scheduling
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200515 icm %r0,15,__TI_precount(%r12)
Martin Schwidefsky26889052008-05-07 09:22:52 +0200516 jnz io_restore # preemption is disabled
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200517 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
518 jno io_restore
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 # switch to kernel stack
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100520 lg %r1,__PT_R15(%r11)
521 aghi %r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
522 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
523 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
524 la %r11,STACK_FRAME_OVERHEAD(%r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 lgr %r15,%r1
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200526 # TRACE_IRQS_ON already done at io_return, call
527 # TRACE_IRQS_OFF to keep things symmetrical
528 TRACE_IRQS_OFF
529 brasl %r14,preempt_schedule_irq
530 j io_return
531#else
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200532 j io_restore
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200533#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200535#
536# Need to do work before returning to userspace, switch to kernel stack
537#
Martin Schwidefsky26889052008-05-07 09:22:52 +0200538io_work_user:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 lg %r1,__LC_KERNEL_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100540 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
541 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
542 la %r11,STACK_FRAME_OVERHEAD(%r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 lgr %r15,%r1
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#
546# One of the work bits is on. Find out which one.
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200547# Checked are: _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_NEED_RESCHED
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800548# and _TIF_MCCK_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200550io_work_tif:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200551 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700552 jo io_mcck_pending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200553 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 jo io_reschedule
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200555 tm __TI_flags+7(%r12),_TIF_SIGPENDING
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200556 jo io_sigpending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200557 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200558 jo io_notify_resume
559 j io_return # beware of critical section cleanup
Christian Borntraeger0eaeafa2008-05-07 09:22:53 +0200560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#
Heiko Carstens77fa2242005-06-25 14:55:30 -0700562# _TIF_MCCK_PENDING is set, call handler
563#
564io_mcck_pending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200565 # TRACE_IRQS_ON already done at io_return
Heiko Carstensb771aea2007-07-27 12:29:18 +0200566 brasl %r14,s390_handle_mcck # TIF bit will be cleared by handler
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200567 TRACE_IRQS_OFF
568 j io_return
Heiko Carstens77fa2242005-06-25 14:55:30 -0700569
570#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571# _TIF_NEED_RESCHED is set, call schedule
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200572#
573io_reschedule:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200574 # TRACE_IRQS_ON already done at io_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100575 ssm __LC_SVC_NEW_PSW # reenable interrupts
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200576 brasl %r14,schedule # call scheduler
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100577 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Heiko Carstens411788e2007-11-20 11:13:32 +0100578 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200579 j io_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581#
Roland McGrath02a029b2008-04-30 00:53:08 -0700582# _TIF_SIGPENDING or is set, call do_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200584io_sigpending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200585 # TRACE_IRQS_ON already done at io_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100586 ssm __LC_SVC_NEW_PSW # reenable interrupts
587 lgr %r2,%r11 # pass pointer to pt_regs
588 brasl %r14,do_signal
589 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Heiko Carstens411788e2007-11-20 11:13:32 +0100590 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200591 j io_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200593#
594# _TIF_NOTIFY_RESUME or is set, call do_notify_resume
595#
596io_notify_resume:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200597 # TRACE_IRQS_ON already done at io_return
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100598 ssm __LC_SVC_NEW_PSW # reenable interrupts
599 lgr %r2,%r11 # pass pointer to pt_regs
600 brasl %r14,do_notify_resume
601 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200602 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200603 j io_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605/*
606 * External interrupt handler routine
607 */
Jan Glauber144d6342011-07-24 10:48:19 +0200608ENTRY(ext_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200609 STCK __LC_INT_CLOCK
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100610 stpt __LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100611 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
612 lg %r10,__LC_LAST_BREAK
613 lg %r12,__LC_THREAD_INFO
614 larl %r13,system_call
615 lmg %r8,%r9,__LC_EXT_OLD_PSW
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200616 HANDLE_SIE_INTERCEPT %r14,3
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100617 SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
618 tmhh %r8,0x0001 # interrupting from user ?
619 jz ext_skip
620 UPDATE_VTIME %r14,__LC_ASYNC_ENTER_TIMER
621 LAST_BREAK %r14
622ext_skip:
623 stmg %r0,%r7,__PT_R0(%r11)
624 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
625 stmg %r8,%r9,__PT_PSW(%r11)
Martin Schwidefsky48f6b002013-06-17 14:54:02 +0200626 lghi %r1,__LC_EXT_PARAMS2
627 mvc __PT_INT_CODE(4,%r11),__LC_EXT_CPU_ADDR
628 mvc __PT_INT_PARM(4,%r11),__LC_EXT_PARAMS
629 mvc __PT_INT_PARM_LONG(8,%r11),0(%r1)
Heiko Carstens1f194a42006-07-03 00:24:46 -0700630 TRACE_IRQS_OFF
Michael Holzheu0de9db32012-05-09 16:27:35 +0200631 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100632 lgr %r2,%r11 # pass pointer to pt_regs
Martin Schwidefsky1f44a2252013-06-27 09:01:09 +0200633 lghi %r3,EXT_INTERRUPT
634 brasl %r14,do_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 j io_return
636
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400637/*
638 * Load idle PSW. The second "half" of this function is in cleanup_idle.
639 */
640ENTRY(psw_idle)
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200641 stg %r3,__SF_EMPTY(%r15)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400642 larl %r1,psw_idle_lpsw+4
643 stg %r1,__SF_EMPTY+8(%r15)
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200644 STCK __CLOCK_IDLE_ENTER(%r2)
645 stpt __TIMER_IDLE_ENTER(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400646psw_idle_lpsw:
647 lpswe __SF_EMPTY(%r15)
648 br %r14
649psw_idle_end:
650
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700651__critical_end:
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653/*
654 * Machine check handler routines
655 */
Jan Glauber144d6342011-07-24 10:48:19 +0200656ENTRY(mcck_int_handler)
Heiko Carstens473e66b2012-05-09 16:27:39 +0200657 STCK __LC_MCCK_CLOCK
Heiko Carstens77fa2242005-06-25 14:55:30 -0700658 la %r1,4095 # revalidate r1
659 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200660 lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100661 lg %r10,__LC_LAST_BREAK
662 lg %r12,__LC_THREAD_INFO
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200663 larl %r13,system_call
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100664 lmg %r8,%r9,__LC_MCK_OLD_PSW
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200665 HANDLE_SIE_INTERCEPT %r14,4
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200666 tm __LC_MCCK_CODE,0x80 # system damage?
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100667 jo mcck_panic # yes -> rest of mcck code invalid
668 lghi %r14,__LC_CPU_TIMER_SAVE_AREA
669 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200670 tm __LC_MCCK_CODE+5,0x02 # stored cpu timer value valid?
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100671 jo 3f
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200672 la %r14,__LC_SYNC_ENTER_TIMER
673 clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
674 jl 0f
675 la %r14,__LC_ASYNC_ENTER_TIMER
6760: clc 0(8,%r14),__LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100677 jl 1f
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200678 la %r14,__LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +01006791: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
680 jl 2f
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200681 la %r14,__LC_LAST_UPDATE_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +01006822: spt 0(%r14)
Martin Schwidefsky63779812010-05-17 10:00:03 +0200683 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
Martin Schwidefskyc5328902011-12-27 11:27:15 +01006843: tm __LC_MCCK_CODE+2,0x09 # mwp + ia of old psw valid?
685 jno mcck_panic # no -> skip cleanup critical
686 SWITCH_ASYNC __LC_GPREGS_SAVE_AREA+64,__LC_PANIC_STACK,PAGE_SHIFT
687 tm %r8,0x0001 # interrupting from user ?
688 jz mcck_skip
689 UPDATE_VTIME %r14,__LC_MCCK_ENTER_TIMER
690 LAST_BREAK %r14
691mcck_skip:
Martin Schwidefsky6551fbd2013-02-28 16:28:41 +0100692 lghi %r14,__LC_GPREGS_SAVE_AREA+64
693 stmg %r0,%r7,__PT_R0(%r11)
694 mvc __PT_R8(64,%r11),0(%r14)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100695 stmg %r8,%r9,__PT_PSW(%r11)
696 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
697 lgr %r2,%r11 # pass pointer to pt_regs
Heiko Carstens77fa2242005-06-25 14:55:30 -0700698 brasl %r14,s390_do_machine_check
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100699 tm __PT_PSW+1(%r11),0x01 # returning to user ?
Heiko Carstens77fa2242005-06-25 14:55:30 -0700700 jno mcck_return
701 lg %r1,__LC_KERNEL_STACK # switch to kernel stack
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100702 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
703 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
704 la %r11,STACK_FRAME_OVERHEAD(%r1)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700705 lgr %r15,%r1
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100706 ssm __LC_PGM_NEW_PSW # turn dat on, keep irqs off
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200707 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700708 jno mcck_return
Heiko Carstens1f194a42006-07-03 00:24:46 -0700709 TRACE_IRQS_OFF
Heiko Carstens77fa2242005-06-25 14:55:30 -0700710 brasl %r14,s390_handle_mcck
Heiko Carstens1f194a42006-07-03 00:24:46 -0700711 TRACE_IRQS_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712mcck_return:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100713 lg %r14,__LC_VDSO_PER_CPU
714 lmg %r0,%r10,__PT_R0(%r11)
715 mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200716 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
717 jno 0f
718 stpt __LC_EXIT_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100719 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
7200: lmg %r11,%r15,__PT_R11(%r11)
721 lpswe __LC_RETURN_MCCK_PSW
722
723mcck_panic:
724 lg %r14,__LC_PANIC_STACK
725 slgr %r14,%r15
726 srag %r14,%r14,PAGE_SHIFT
727 jz 0f
728 lg %r15,__LC_PANIC_STACK
7290: aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
730 j mcck_skip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200732#
733# PSW restart interrupt handler
734#
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400735ENTRY(restart_int_handler)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100736 stg %r15,__LC_SAVE_AREA_RESTART
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400737 lg %r15,__LC_RESTART_STACK
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100738 aghi %r15,-__PT_SIZE # create pt_regs on stack
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400739 xc 0(__PT_SIZE,%r15),0(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100740 stmg %r0,%r14,__PT_R0(%r15)
741 mvc __PT_R15(8,%r15),__LC_SAVE_AREA_RESTART
742 mvc __PT_PSW(16,%r15),__LC_RST_OLD_PSW # store restart old psw
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400743 aghi %r15,-STACK_FRAME_OVERHEAD # create stack frame on stack
744 xc 0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
Heiko Carstensfbe76562012-06-05 09:59:52 +0200745 lg %r1,__LC_RESTART_FN # load fn, parm & source cpu
746 lg %r2,__LC_RESTART_DATA
747 lg %r3,__LC_RESTART_SOURCE
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400748 ltgr %r3,%r3 # test source cpu address
749 jm 1f # negative -> skip source stop
Heiko Carstenseb546192012-06-04 15:05:43 +02007500: sigp %r4,%r3,SIGP_SENSE # sigp sense to source cpu
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400751 brc 10,0b # wait for status stored
7521: basr %r14,%r1 # call function
753 stap __SF_EMPTY(%r15) # store cpu address
754 llgh %r3,__SF_EMPTY(%r15)
Heiko Carstenseb546192012-06-04 15:05:43 +02007552: sigp %r4,%r3,SIGP_STOP # sigp stop to current cpu
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400756 brc 2,2b
7573: j 3b
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200758
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100759 .section .kprobes.text, "ax"
760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761#ifdef CONFIG_CHECK_STACK
762/*
763 * The synchronous or the asynchronous stack overflowed. We are dead.
764 * No need to properly save the registers, we are going to panic anyway.
765 * Setup a pt_regs so that show_trace can provide a good call trace.
766 */
767stack_overflow:
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200768 lg %r15,__LC_PANIC_STACK # change to panic stack
769 la %r11,STACK_FRAME_OVERHEAD(%r15)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100770 stmg %r0,%r7,__PT_R0(%r11)
771 stmg %r8,%r9,__PT_PSW(%r11)
772 mvc __PT_R8(64,%r11),0(%r14)
773 stg %r10,__PT_ORIG_GPR2(%r11) # store last break to orig_gpr2
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100774 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
775 lgr %r2,%r11 # pass pointer to pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 jg kernel_stack_overflow
777#endif
778
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100779 .align 8
780cleanup_table:
781 .quad system_call
782 .quad sysc_do_svc
783 .quad sysc_tif
784 .quad sysc_restore
785 .quad sysc_done
786 .quad io_tif
787 .quad io_restore
788 .quad io_done
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400789 .quad psw_idle
790 .quad psw_idle_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792cleanup_critical:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100793 clg %r9,BASED(cleanup_table) # system_call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 jl 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100795 clg %r9,BASED(cleanup_table+8) # sysc_do_svc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 jl cleanup_system_call
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100797 clg %r9,BASED(cleanup_table+16) # sysc_tif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 jl 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100799 clg %r9,BASED(cleanup_table+24) # sysc_restore
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200800 jl cleanup_sysc_tif
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100801 clg %r9,BASED(cleanup_table+32) # sysc_done
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200802 jl cleanup_sysc_restore
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100803 clg %r9,BASED(cleanup_table+40) # io_tif
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200804 jl 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100805 clg %r9,BASED(cleanup_table+48) # io_restore
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200806 jl cleanup_io_tif
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100807 clg %r9,BASED(cleanup_table+56) # io_done
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200808 jl cleanup_io_restore
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400809 clg %r9,BASED(cleanup_table+64) # psw_idle
810 jl 0f
811 clg %r9,BASED(cleanup_table+72) # psw_idle_end
812 jl cleanup_idle
Martin Schwidefskyc5328902011-12-27 11:27:15 +01008130: br %r14
814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816cleanup_system_call:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100817 # check if stpt has been executed
818 clg %r9,BASED(cleanup_system_call_insn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 jh 0f
820 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100821 cghi %r11,__LC_SAVE_AREA_ASYNC
Martin Schwidefsky63779812010-05-17 10:00:03 +0200822 je 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100823 mvc __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
8240: # check if stmg has been executed
825 clg %r9,BASED(cleanup_system_call_insn+8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 jh 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100827 mvc __LC_SAVE_AREA_SYNC(64),0(%r11)
8280: # check if base register setup + TIF bit load has been done
829 clg %r9,BASED(cleanup_system_call_insn+16)
830 jhe 0f
831 # set up saved registers r10 and r12
832 stg %r10,16(%r11) # r10 last break
833 stg %r12,32(%r11) # r12 thread-info pointer
8340: # check if the user time update has been done
835 clg %r9,BASED(cleanup_system_call_insn+24)
836 jh 0f
837 lg %r15,__LC_EXIT_TIMER
838 slg %r15,__LC_SYNC_ENTER_TIMER
839 alg %r15,__LC_USER_TIMER
840 stg %r15,__LC_USER_TIMER
8410: # check if the system time update has been done
842 clg %r9,BASED(cleanup_system_call_insn+32)
843 jh 0f
844 lg %r15,__LC_LAST_UPDATE_TIMER
845 slg %r15,__LC_EXIT_TIMER
846 alg %r15,__LC_SYSTEM_TIMER
847 stg %r15,__LC_SYSTEM_TIMER
8480: # update accounting time stamp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100850 # do LAST_BREAK
851 lg %r9,16(%r11)
852 srag %r9,%r9,23
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200853 jz 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100854 mvc __TI_last_break(8,%r12),16(%r11)
8550: # set up saved register r11
856 lg %r15,__LC_KERNEL_STACK
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200857 la %r9,STACK_FRAME_OVERHEAD(%r15)
858 stg %r9,24(%r11) # r11 pt_regs pointer
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100859 # fill pt_regs
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200860 mvc __PT_R8(64,%r9),__LC_SAVE_AREA_SYNC
861 stmg %r0,%r7,__PT_R0(%r9)
862 mvc __PT_PSW(16,%r9),__LC_SVC_OLD_PSW
863 mvc __PT_INT_CODE(4,%r9),__LC_SVC_ILC
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100864 # setup saved register r15
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100865 stg %r15,56(%r11) # r15 stack pointer
866 # set new psw address and exit
867 larl %r9,sysc_do_svc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 br %r14
869cleanup_system_call_insn:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200870 .quad system_call
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100871 .quad sysc_stmg
872 .quad sysc_per
873 .quad sysc_vtime+18
874 .quad sysc_vtime+42
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200876cleanup_sysc_tif:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100877 larl %r9,sysc_tif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 br %r14
879
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200880cleanup_sysc_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100881 clg %r9,BASED(cleanup_sysc_restore_insn)
Martin Schwidefsky63779812010-05-17 10:00:03 +0200882 je 0f
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100883 lg %r9,24(%r11) # get saved pointer to pt_regs
884 mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
885 mvc 0(64,%r11),__PT_R8(%r9)
886 lmg %r0,%r7,__PT_R0(%r9)
8870: lmg %r8,%r9,__LC_RETURN_PSW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 br %r14
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200889cleanup_sysc_restore_insn:
Heiko Carstens411788e2007-11-20 11:13:32 +0100890 .quad sysc_done - 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200892cleanup_io_tif:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100893 larl %r9,io_tif
Martin Schwidefsky176b1802010-04-09 13:43:00 +0200894 br %r14
895
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200896cleanup_io_restore:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100897 clg %r9,BASED(cleanup_io_restore_insn)
898 je 0f
899 lg %r9,24(%r11) # get saved r11 pointer to pt_regs
900 mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100901 mvc 0(64,%r11),__PT_R8(%r9)
902 lmg %r0,%r7,__PT_R0(%r9)
9030: lmg %r8,%r9,__LC_RETURN_PSW
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700904 br %r14
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200905cleanup_io_restore_insn:
Heiko Carstens411788e2007-11-20 11:13:32 +0100906 .quad io_done - 4
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700907
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400908cleanup_idle:
909 # copy interrupt clock & cpu timer
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200910 mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_INT_CLOCK
911 mvc __TIMER_IDLE_EXIT(8,%r2),__LC_ASYNC_ENTER_TIMER
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400912 cghi %r11,__LC_SAVE_AREA_ASYNC
913 je 0f
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200914 mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_MCCK_CLOCK
915 mvc __TIMER_IDLE_EXIT(8,%r2),__LC_MCCK_ENTER_TIMER
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -04009160: # check if stck & stpt have been executed
917 clg %r9,BASED(cleanup_idle_insn)
918 jhe 1f
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200919 mvc __CLOCK_IDLE_ENTER(8,%r2),__CLOCK_IDLE_EXIT(%r2)
920 mvc __TIMER_IDLE_ENTER(8,%r2),__TIMER_IDLE_EXIT(%r2)
9211: # account system time going idle
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400922 lg %r9,__LC_STEAL_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200923 alg %r9,__CLOCK_IDLE_ENTER(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400924 slg %r9,__LC_LAST_UPDATE_CLOCK
925 stg %r9,__LC_STEAL_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200926 mvc __LC_LAST_UPDATE_CLOCK(8),__CLOCK_IDLE_EXIT(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400927 lg %r9,__LC_SYSTEM_TIMER
928 alg %r9,__LC_LAST_UPDATE_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200929 slg %r9,__TIMER_IDLE_ENTER(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400930 stg %r9,__LC_SYSTEM_TIMER
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200931 mvc __LC_LAST_UPDATE_TIMER(8),__TIMER_IDLE_EXIT(%r2)
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400932 # prepare return psw
Martin Schwidefsky0587d402013-08-23 14:45:58 +0200933 nihh %r8,0xfcfd # clear irq & wait state bits
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400934 lg %r9,48(%r11) # return from psw_idle
935 br %r14
936cleanup_idle_insn:
937 .quad psw_idle_lpsw
938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939/*
940 * Integer constants
941 */
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100942 .align 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943.Lcritical_start:
Martin Schwidefskyc5328902011-12-27 11:27:15 +0100944 .quad __critical_start
945.Lcritical_length:
946 .quad __critical_end - __critical_start
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Heiko Carstens61aa4882013-11-01 10:08:20 +0100949#if IS_ENABLED(CONFIG_KVM)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200950/*
951 * sie64a calling convention:
952 * %r2 pointer to sie control block
953 * %r3 guest register save area
954 */
Jan Glauber144d6342011-07-24 10:48:19 +0200955ENTRY(sie64a)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200956 stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
957 stg %r2,__SF_EMPTY(%r15) # save control block pointer
958 stg %r3,__SF_EMPTY+8(%r15) # save guest register save area
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200959 xc __SF_EMPTY+16(16,%r15),__SF_EMPTY+16(%r15) # host id & reason
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200960 lmg %r0,%r13,0(%r3) # load guest gprs 0-13
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
Christian Borntraeger49b99e12013-05-17 14:41:35 +0200967 oi __SIE_PROG0C+3(%r14),1 # we are going into SIE now
968 tm __SIE_PROG20+3(%r14),1 # last exit...
969 jnz sie_done
Hendrik Brueckner23d18e82013-02-11 18:11:09 +0100970 LPP __SF_EMPTY(%r15) # set guest id
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200971 sie 0(%r14)
972sie_done:
Hendrik Brueckner23d18e82013-02-11 18:11:09 +0100973 LPP __SF_EMPTY+16(%r15) # set host id
Christian Borntraeger95d38fd2013-05-17 14:41:34 +0200974 ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
Christian Borntraeger480e5922011-09-20 17:07:28 +0200975 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200976# some program checks are suppressing. C code (e.g. do_protection_exception)
977# will rewind the PSW by the ILC, which is 4 bytes in case of SIE. Other
978# instructions beween sie64a and sie_done should not cause program
979# interrupts. So lets use a nop (47 00 00 00) as a landing pad.
980# See also HANDLE_SIE_INTERCEPT
981rewind_pad:
982 nop 0
Heinz Graalfsb764bb12013-06-12 13:54:56 +0200983 .globl sie_exit
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200984sie_exit:
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200985 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
986 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
987 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200988 lg %r2,__SF_EMPTY+24(%r15) # return exit reason code
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200989 br %r14
990sie_fault:
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200991 lghi %r14,-EFAULT
992 stg %r14,__SF_EMPTY+24(%r15) # set exit reason code
993 j sie_exit
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200994
995 .align 8
Martin Schwidefsky7c470532013-05-17 14:41:37 +0200996.Lsie_critical:
997 .quad sie_gmap
998.Lsie_critical_length:
999 .quad sie_done - sie_gmap
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001000
Christian Borntraegerce6a04a2012-11-15 09:35:16 +01001001 EX_TABLE(rewind_pad,sie_fault)
Martin Schwidefsky7c470532013-05-17 14:41:37 +02001002 EX_TABLE(sie_exit,sie_fault)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001003#endif
1004
Heiko Carstens25d83cb2006-09-28 16:56:37 +02001005 .section .rodata, "a"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006#define SYSCALL(esa,esame,emu) .long esame
Heiko Carstens9bf12262009-06-12 10:26:47 +02001007 .globl sys_call_table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008sys_call_table:
1009#include "syscalls.S"
1010#undef SYSCALL
1011
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001012#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014#define SYSCALL(esa,esame,emu) .long emu
Martin Schwidefsky61649882013-04-24 12:58:39 +02001015 .globl sys_call_table_emu
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016sys_call_table_emu:
1017#include "syscalls.S"
1018#undef SYSCALL
1019#endif