blob: 130fb02305c179ac14b6937c23b19c7019df3ac2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstens54dfe5d2006-02-01 03:06:38 -08002 * arch/s390/kernel/entry64.S
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * S390 low-level entry points.
4 *
Carsten Ottecd3b70f2010-05-17 10:00:04 +02005 * Copyright (C) IBM Corp. 1999,2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
Heiko Carstens25d83cb2006-09-28 16:56:37 +02007 * Hartmut Penner (hp@de.ibm.com),
8 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
Heiko Carstens77fa2242005-06-25 14:55:30 -07009 * Heiko Carstens <heiko.carstens@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
Heiko Carstens2bc89b52008-02-05 16:50:40 +010012#include <linux/init.h>
Jan Glauber144d6342011-07-24 10:48:19 +020013#include <linux/linkage.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>
21
22/*
23 * Stack layout for the system_call stack entry.
24 * The first few entries are identical to the user_regs_struct.
25 */
Heiko Carstens25d83cb2006-09-28 16:56:37 +020026SP_PTREGS = STACK_FRAME_OVERHEAD
27SP_ARGS = STACK_FRAME_OVERHEAD + __PT_ARGS
28SP_PSW = STACK_FRAME_OVERHEAD + __PT_PSW
29SP_R0 = STACK_FRAME_OVERHEAD + __PT_GPRS
30SP_R1 = STACK_FRAME_OVERHEAD + __PT_GPRS + 8
31SP_R2 = STACK_FRAME_OVERHEAD + __PT_GPRS + 16
32SP_R3 = STACK_FRAME_OVERHEAD + __PT_GPRS + 24
33SP_R4 = STACK_FRAME_OVERHEAD + __PT_GPRS + 32
34SP_R5 = STACK_FRAME_OVERHEAD + __PT_GPRS + 40
35SP_R6 = STACK_FRAME_OVERHEAD + __PT_GPRS + 48
36SP_R7 = STACK_FRAME_OVERHEAD + __PT_GPRS + 56
37SP_R8 = STACK_FRAME_OVERHEAD + __PT_GPRS + 64
38SP_R9 = STACK_FRAME_OVERHEAD + __PT_GPRS + 72
39SP_R10 = STACK_FRAME_OVERHEAD + __PT_GPRS + 80
40SP_R11 = STACK_FRAME_OVERHEAD + __PT_GPRS + 88
41SP_R12 = STACK_FRAME_OVERHEAD + __PT_GPRS + 96
42SP_R13 = STACK_FRAME_OVERHEAD + __PT_GPRS + 104
43SP_R14 = STACK_FRAME_OVERHEAD + __PT_GPRS + 112
44SP_R15 = STACK_FRAME_OVERHEAD + __PT_GPRS + 120
45SP_ORIG_R2 = STACK_FRAME_OVERHEAD + __PT_ORIG_GPR2
Martin Schwidefsky20b40a72011-10-30 15:16:47 +010046SP_SVC_CODE = STACK_FRAME_OVERHEAD + __PT_SVC_CODE
Heiko Carstens25d83cb2006-09-28 16:56:37 +020047SP_SIZE = STACK_FRAME_OVERHEAD + __PT_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
50STACK_SIZE = 1 << STACK_SHIFT
51
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020052_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +010053 _TIF_MCCK_PENDING | _TIF_PER_TRAP )
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020054_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
Heiko Carstens54dfe5d2006-02-01 03:06:38 -080055 _TIF_MCCK_PENDING)
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +010056_TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
57 _TIF_SYSCALL_TRACEPOINT)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +020058_TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define BASED(name) name-system_call(%r13)
61
Martin Schwidefsky603d1a52011-07-24 10:48:18 +020062 .macro SPP newpp
63#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
64 tm __LC_MACHINE_FLAGS+6,0x20 # MACHINE_FLAG_SPP
65 jz .+8
66 .insn s,0xb2800000,\newpp
67#endif
68 .endm
69
Carsten Ottecd3b70f2010-05-17 10:00:04 +020070 .macro HANDLE_SIE_INTERCEPT
71#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +020072 tm __TI_flags+6(%r12),_TIF_SIE>>8
Carsten Ottecd3b70f2010-05-17 10:00:04 +020073 jz 0f
Martin Schwidefskyddd6f952011-12-27 11:27:13 +010074 SPP BASED(.Lhost_id) # set host id
Martin Schwidefsky603d1a52011-07-24 10:48:18 +020075 clc SP_PSW+8(8,%r15),BASED(.Lsie_loop)
76 jl 0f
77 clc SP_PSW+8(8,%r15),BASED(.Lsie_done)
78 jhe 0f
79 mvc SP_PSW+8(8,%r15),BASED(.Lsie_loop)
Heiko Carstens2ffbb3f2010-05-26 23:26:21 +0200800:
Carsten Ottecd3b70f2010-05-17 10:00:04 +020081#endif
82 .endm
83
Heiko Carstens1f194a42006-07-03 00:24:46 -070084#ifdef CONFIG_TRACE_IRQFLAGS
85 .macro TRACE_IRQS_ON
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +020086 basr %r2,%r0
87 brasl %r14,trace_hardirqs_on_caller
Heiko Carstens1f194a42006-07-03 00:24:46 -070088 .endm
89
90 .macro TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +020091 basr %r2,%r0
92 brasl %r14,trace_hardirqs_off_caller
Heiko Carstens1f194a42006-07-03 00:24:46 -070093 .endm
94#else
95#define TRACE_IRQS_ON
96#define TRACE_IRQS_OFF
Heiko Carstens411788e2007-11-20 11:13:32 +010097#endif
98
99#ifdef CONFIG_LOCKDEP
100 .macro LOCKDEP_SYS_EXIT
101 tm SP_PSW+1(%r15),0x01 # returning to user ?
102 jz 0f
103 brasl %r14,lockdep_sys_exit
1040:
105 .endm
106#else
Heiko Carstens523b44c2007-10-11 22:11:12 +0200107#define LOCKDEP_SYS_EXIT
Heiko Carstens1f194a42006-07-03 00:24:46 -0700108#endif
109
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200110 .macro UPDATE_VTIME lc_from,lc_to,lc_sum
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 lg %r10,\lc_from
112 slg %r10,\lc_to
113 alg %r10,\lc_sum
114 stg %r10,\lc_sum
115 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117/*
118 * Register usage in interrupt handlers:
119 * R9 - pointer to current task structure
120 * R13 - pointer to literal pool
121 * R14 - return register for function calls
122 * R15 - kernel stack pointer
123 */
124
Martin Schwidefsky987ad702007-07-10 11:24:18 +0200125 .macro SAVE_ALL_SVC psworg,savearea
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200126 stmg %r11,%r15,\savearea
Martin Schwidefsky987ad702007-07-10 11:24:18 +0200127 lg %r15,__LC_KERNEL_STACK # problem state -> load ksp
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200128 aghi %r15,-SP_SIZE # make room for registers & psw
129 lg %r11,__LC_LAST_BREAK
Martin Schwidefsky987ad702007-07-10 11:24:18 +0200130 .endm
131
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200132 .macro SAVE_ALL_PGM psworg,savearea
133 stmg %r11,%r15,\savearea
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 tm \psworg+1,0x01 # test problem state bit
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200135#ifdef CONFIG_CHECK_STACK
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200136 jnz 1f
137 tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
138 jnz 2f
139 la %r12,\psworg
140 j stack_overflow
141#else
142 jz 2f
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200143#endif
Martin Schwidefsky86f25522010-05-17 10:00:05 +02001441: lg %r15,__LC_KERNEL_STACK # problem state -> load ksp
1452: aghi %r15,-SP_SIZE # make room for registers & psw
146 larl %r13,system_call
147 lg %r11,__LC_LAST_BREAK
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200148 .endm
149
150 .macro SAVE_ALL_ASYNC psworg,savearea
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200151 stmg %r11,%r15,\savearea
152 larl %r13,system_call
153 lg %r11,__LC_LAST_BREAK
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200154 la %r12,\psworg
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 tm \psworg+1,0x01 # test problem state bit
156 jnz 1f # from user -> load kernel stack
157 clc \psworg+8(8),BASED(.Lcritical_end)
158 jhe 0f
159 clc \psworg+8(8),BASED(.Lcritical_start)
160 jl 0f
161 brasl %r14,cleanup_critical
Peter Oberparleiter6add9f72005-09-16 19:27:42 -0700162 tm 1(%r12),0x01 # retest problem state after cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 jnz 1f
1640: lg %r14,__LC_ASYNC_STACK # are we already on the async. stack ?
165 slgr %r14,%r15
166 srag %r14,%r14,STACK_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#ifdef CONFIG_CHECK_STACK
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200168 jnz 1f
169 tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
170 jnz 2f
171 j stack_overflow
172#else
173 jz 2f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#endif
Martin Schwidefsky86f25522010-05-17 10:00:05 +02001751: lg %r15,__LC_ASYNC_STACK # load async stack
1762: aghi %r15,-SP_SIZE # make room for registers & psw
Heiko Carstens77fa2242005-06-25 14:55:30 -0700177 .endm
178
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200179 .macro CREATE_STACK_FRAME savearea
180 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 stg %r2,SP_ORIG_R2(%r15) # store original content of gpr 2
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200182 mvc SP_R11(40,%r15),\savearea # move %r11-%r15 to stack
183 stmg %r0,%r10,SP_R0(%r15) # store gprs %r0-%r10 to kernel stack
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200184 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700186 .macro RESTORE_ALL psworg,sync
187 mvc \psworg(16),SP_PSW(%r15) # move user PSW to lowcore
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 .if !\sync
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700189 ni \psworg+1,0xfd # clear wait state bit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 .endif
Martin Schwidefskyc742b312008-12-31 15:11:42 +0100191 lg %r14,__LC_VDSO_PER_CPU
192 lmg %r0,%r13,SP_R0(%r15) # load gprs 0-13 of user
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100193 stpt __LC_EXIT_TIMER
Martin Schwidefskyc742b312008-12-31 15:11:42 +0100194 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
195 lmg %r14,%r15,SP_R14(%r15) # load grps 14-15 of user
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700196 lpswe \psworg # back to caller
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 .endm
198
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200199 .macro LAST_BREAK
200 srag %r10,%r11,23
201 jz 0f
202 stg %r11,__TI_last_break(%r12)
2030:
204 .endm
205
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200206 .macro REENABLE_IRQS
207 mvc __SF_EMPTY(1,%r15),SP_PSW(%r15)
208 ni __SF_EMPTY(%r15),0xbf
209 ssm __SF_EMPTY(%r15)
210 .endm
211
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100212 .section .kprobes.text, "ax"
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214/*
215 * Scheduler resume function, called by switch_to
216 * gpr2 = (task_struct *) prev
217 * gpr3 = (task_struct *) next
218 * Returns:
219 * gpr2 = prev
220 */
Jan Glauber144d6342011-07-24 10:48:19 +0200221ENTRY(__switch_to)
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100222 lg %r4,__THREAD_info(%r2) # get thread_info of prev
223 lg %r5,__THREAD_info(%r3) # get thread_info of next
Heiko Carstens77fa2242005-06-25 14:55:30 -0700224 tm __TI_flags+7(%r4),_TIF_MCCK_PENDING # machine check pending?
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100225 jz 0f
226 ni __TI_flags+7(%r4),255-_TIF_MCCK_PENDING # clear flag in prev
227 oi __TI_flags+7(%r5),_TIF_MCCK_PENDING # set it in next
2280: stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
229 stg %r15,__THREAD_ksp(%r2) # store kernel stack of prev
230 lg %r15,__THREAD_ksp(%r3) # load kernel stack of next
231 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
232 lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
233 stg %r3,__LC_CURRENT # store task struct of next
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200234 mvc __LC_CURRENT_PID+4(4,%r0),__TASK_pid(%r3) # store pid of next
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100235 stg %r5,__LC_THREAD_INFO # store thread info of next
236 aghi %r5,STACK_SIZE # end of kernel stack of next
237 stg %r5,__LC_KERNEL_STACK # store end of kernel stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 br %r14
239
240__critical_start:
241/*
242 * SVC interrupt handler routine. System calls are synchronous events and
243 * are executed with interrupts enabled.
244 */
245
Jan Glauber144d6342011-07-24 10:48:19 +0200246ENTRY(system_call)
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100247 stpt __LC_SYNC_ENTER_TIMER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248sysc_saveall:
Martin Schwidefsky987ad702007-07-10 11:24:18 +0200249 SAVE_ALL_SVC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200250 CREATE_STACK_FRAME __LC_SAVE_AREA
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100251 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200252 mvc SP_PSW(16,%r15),__LC_SVC_OLD_PSW
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100253 mvc SP_SVC_CODE(4,%r15),__LC_SVC_ILC
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100254 oi __TI_flags+7(%r12),_TIF_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255sysc_vtime:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
257sysc_stime:
258 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
259sysc_update:
260 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200261 LAST_BREAK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262sysc_do_svc:
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100263 llgh %r7,SP_SVC_CODE+2(%r15)
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200264 slag %r7,%r7,2 # shift and test for svc 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 jnz sysc_nr_ok
266 # svc 0: system call number in %r1
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200267 llgfr %r1,%r1 # clear high word in r1
268 cghi %r1,NR_syscalls
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 jnl sysc_nr_ok
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100270 sth %r1,SP_SVC_CODE+2(%r15)
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200271 slag %r7,%r1,2 # shift and test for svc 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272sysc_nr_ok:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200273 larl %r10,sys_call_table
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800274#ifdef CONFIG_COMPAT
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200275 tm __TI_flags+5(%r12),(_TIF_31BIT>>16) # running in 31 bit mode ?
Heiko Carstensc5630772005-09-03 15:58:04 -0700276 jno sysc_noemu
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200277 larl %r10,sys_call_table_emu # use 31 bit emulation system calls
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278sysc_noemu:
279#endif
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100280 tm __TI_flags+6(%r12),_TIF_TRACE >> 8
Martin Schwidefskybaa07152010-10-25 16:10:40 +0200281 mvc SP_ARGS(8,%r15),SP_R7(%r15)
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200282 lgf %r8,0(%r7,%r10) # load address of system call routine
283 jnz sysc_tracesys
284 basr %r14,%r8 # call sys_xxxx
285 stg %r2,SP_R2(%r15) # store return value (change R2 on stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287sysc_return:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200288 LOCKDEP_SYS_EXIT
289sysc_tif:
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100290 tm SP_PSW+1(%r15),0x01 # returning to user ?
291 jno sysc_restore
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200292 tm __TI_flags+7(%r12),_TIF_WORK_SVC
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200293 jnz sysc_work # there is work to do (signals etc.)
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100294 ni __TI_flags+7(%r12),255-_TIF_SYSCALL
Heiko Carstens411788e2007-11-20 11:13:32 +0100295sysc_restore:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200296 RESTORE_ALL __LC_RETURN_PSW,1
Heiko Carstens411788e2007-11-20 11:13:32 +0100297sysc_done:
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299#
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200300# One of the work bits is on. Find out which one.
301#
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100302sysc_work:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200303 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700304 jo sysc_mcck_pending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200305 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 jo sysc_reschedule
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200307 tm __TI_flags+7(%r12),_TIF_SIGPENDING
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200308 jo sysc_sigpending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200309 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200310 jo sysc_notify_resume
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100311 tm __TI_flags+7(%r12),_TIF_PER_TRAP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 jo sysc_singlestep
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200313 j sysc_return # beware of critical section cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315#
316# _TIF_NEED_RESCHED is set, call schedule
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200317#
318sysc_reschedule:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200319 larl %r14,sysc_return
320 jg schedule # return point is sysc_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322#
Heiko Carstens77fa2242005-06-25 14:55:30 -0700323# _TIF_MCCK_PENDING is set, call handler
324#
325sysc_mcck_pending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200326 larl %r14,sysc_return
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200327 jg s390_handle_mcck # TIF bit will be cleared by handler
Heiko Carstens77fa2242005-06-25 14:55:30 -0700328
329#
Roland McGrath02a029b2008-04-30 00:53:08 -0700330# _TIF_SIGPENDING is set, call do_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331#
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200332sysc_sigpending:
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100333 ni __TI_flags+7(%r12),255-_TIF_PER_TRAP # clear TIF_PER_TRAP
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200334 la %r2,SP_PTREGS(%r15) # load pt_regs
335 brasl %r14,do_signal # call do_signal
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100336 tm __TI_flags+7(%r12),_TIF_SYSCALL
337 jno sysc_return
338 lmg %r2,%r6,SP_R2(%r15) # load svc arguments
339 lghi %r7,0 # svc 0 returns -ENOSYS
340 lh %r1,SP_SVC_CODE+2(%r15) # load new svc number
341 cghi %r1,NR_syscalls
342 jnl sysc_nr_ok # invalid svc number -> do svc 0
343 slag %r7,%r1,2
344 j sysc_nr_ok # restart svc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346#
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200347# _TIF_NOTIFY_RESUME is set, call do_notify_resume
348#
349sysc_notify_resume:
350 la %r2,SP_PTREGS(%r15) # load pt_regs
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200351 larl %r14,sysc_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200352 jg do_notify_resume # call do_notify_resume
353
354#
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100355# _TIF_PER_TRAP is set, call do_per_trap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356#
357sysc_singlestep:
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100358 ni __TI_flags+7(%r12),255-(_TIF_SYSCALL | _TIF_PER_TRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 la %r2,SP_PTREGS(%r15) # address of register-save area
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200360 larl %r14,sysc_return # load adr. of system return
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100361 jg do_per_trap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200364# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
365# and after the system call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#
367sysc_tracesys:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200368 la %r2,SP_PTREGS(%r15) # load pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 la %r3,0
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100370 llgh %r0,SP_SVC_CODE+2(%r15)
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200371 stg %r0,SP_R2(%r15)
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200372 brasl %r14,do_syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 lghi %r0,NR_syscalls
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200374 clgr %r0,%r2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 jnh sysc_tracenogo
Martin Schwidefsky59da2132008-11-27 11:05:55 +0100376 sllg %r7,%r2,2 # svc number *4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 lgf %r8,0(%r7,%r10)
378sysc_tracego:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200379 lmg %r3,%r6,SP_R3(%r15)
Martin Schwidefskybaa07152010-10-25 16:10:40 +0200380 mvc SP_ARGS(8,%r15),SP_R7(%r15)
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200381 lg %r2,SP_ORIG_R2(%r15)
382 basr %r14,%r8 # call sys_xxx
383 stg %r2,SP_R2(%r15) # store return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384sysc_tracenogo:
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100385 tm __TI_flags+6(%r12),_TIF_TRACE >> 8
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200386 jz sysc_return
387 la %r2,SP_PTREGS(%r15) # load pt_regs
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200388 larl %r14,sysc_return # return point is sysc_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200389 jg do_syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391#
392# a new process exits the kernel with ret_from_fork
393#
Jan Glauber144d6342011-07-24 10:48:19 +0200394ENTRY(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 lg %r13,__LC_SVC_NEW_PSW+8
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200396 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 tm SP_PSW+1(%r15),0x01 # forking a kernel thread ?
398 jo 0f
399 stg %r15,SP_R15(%r15) # store stack pointer for new kthread
Heiko Carstens25d83cb2006-09-28 16:56:37 +02004000: brasl %r14,schedule_tail
Heiko Carstens1f194a42006-07-03 00:24:46 -0700401 TRACE_IRQS_ON
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200402 stosm 24(%r15),0x03 # reenable interrupts
Al Viro8f2961c2008-12-25 13:37:58 +0100403 j sysc_tracenogo
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405#
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200406# kernel_execve function needs to deal with pt_regs that is not
407# at the usual place
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408#
Jan Glauber144d6342011-07-24 10:48:19 +0200409ENTRY(kernel_execve)
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200410 stmg %r12,%r15,96(%r15)
411 lgr %r14,%r15
412 aghi %r15,-SP_SIZE
413 stg %r14,__SF_BACKCHAIN(%r15)
414 la %r12,SP_PTREGS(%r15)
415 xc 0(__PT_SIZE,%r12),0(%r12)
416 lgr %r5,%r12
417 brasl %r14,do_execve
418 ltgfr %r2,%r2
419 je 0f
420 aghi %r15,SP_SIZE
421 lmg %r12,%r15,96(%r15)
422 br %r14
423 # execve succeeded.
4240: stnsm __SF_EMPTY(%r15),0xfc # disable interrupts
425 lg %r15,__LC_KERNEL_STACK # load ksp
426 aghi %r15,-SP_SIZE # make room for registers & psw
427 lg %r13,__LC_SVC_NEW_PSW+8
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200428 mvc SP_PTREGS(__PT_SIZE,%r15),0(%r12) # copy pt_regs
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200429 lg %r12,__LC_THREAD_INFO
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200430 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
431 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
432 brasl %r14,execve_tail
433 j sysc_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435/*
436 * Program check handler routine
437 */
438
Jan Glauber144d6342011-07-24 10:48:19 +0200439ENTRY(pgm_check_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440/*
441 * First we need to check for a special case:
442 * Single stepping an instruction that disables the PER event mask will
443 * cause a PER event AFTER the mask has been set. Example: SVC or LPSW.
444 * For a single stepped SVC the program check handler gets control after
445 * the SVC new PSW has been loaded. But we want to execute the SVC first and
446 * then handle the PER event. Therefore we update the SVC old PSW to point
447 * to the pgm_check_handler and branch to the SVC handler after we checked
448 * if we have to load the kernel stack register.
449 * For every other possible cause for PER event without the PER mask set
450 * we just ignore the PER event (FIXME: is there anything we have to do
451 * for LPSW?).
452 */
Martin Schwidefskyc185b782008-12-25 13:39:25 +0100453 stpt __LC_SYNC_ENTER_TIMER
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200454 tm __LC_PGM_INT_CODE+1,0x80 # check whether we got a per exception
455 jnz pgm_per # got per exception -> special case
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200456 SAVE_ALL_PGM __LC_PGM_OLD_PSW,__LC_SAVE_AREA
457 CREATE_STACK_FRAME __LC_SAVE_AREA
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200458 mvc SP_PSW(16,%r15),__LC_PGM_OLD_PSW
459 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200460 HANDLE_SIE_INTERCEPT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
462 jz pgm_no_vtime
463 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
464 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
465 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200466 LAST_BREAK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467pgm_no_vtime:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200468 stg %r11,SP_ARGS(%r15)
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200469 lgf %r3,__LC_PGM_ILC # load program interruption code
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200470 lg %r4,__LC_TRANS_EXC_CODE
471 REENABLE_IRQS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 lghi %r8,0x7f
473 ngr %r8,%r3
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200474 sll %r8,3
475 larl %r1,pgm_check_table
476 lg %r1,0(%r8,%r1) # load address of handler routine
477 la %r2,SP_PTREGS(%r15) # address of register-save area
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200478 basr %r14,%r1 # branch to interrupt-handler
479pgm_exit:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200480 j sysc_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482#
483# handle per exception
484#
485pgm_per:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200486 tm __LC_PGM_OLD_PSW,0x40 # test if per event recording is on
487 jnz pgm_per_std # ok, normal per event from user space
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488# ok its one of the special cases, now we need to find out which one
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200489 clc __LC_PGM_OLD_PSW(16),__LC_SVC_NEW_PSW
490 je pgm_svcper
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491# no interesting special case, ignore PER event
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200492 lpswe __LC_PGM_OLD_PSW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494#
495# Normal per exception
496#
497pgm_per_std:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200498 SAVE_ALL_PGM __LC_PGM_OLD_PSW,__LC_SAVE_AREA
499 CREATE_STACK_FRAME __LC_SAVE_AREA
500 mvc SP_PSW(16,%r15),__LC_PGM_OLD_PSW
501 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200502 HANDLE_SIE_INTERCEPT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
504 jz pgm_no_vtime2
505 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
506 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
507 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200508 LAST_BREAK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509pgm_no_vtime2:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200510 lg %r1,__TI_task(%r12)
Michael Grundy4ba069b2006-09-20 15:58:39 +0200511 tm SP_PSW+1(%r15),0x01 # kernel per event ?
512 jz kernel_per
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100513 mvc __THREAD_per_cause(2,%r1),__LC_PER_CAUSE
514 mvc __THREAD_per_address(8,%r1),__LC_PER_ADDRESS
515 mvc __THREAD_per_paid(1,%r1),__LC_PER_PAID
516 oi __TI_flags+7(%r12),_TIF_PER_TRAP # set TIF_PER_TRAP
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200517 lgf %r3,__LC_PGM_ILC # load program interruption code
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200518 lg %r4,__LC_TRANS_EXC_CODE
519 REENABLE_IRQS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 lghi %r8,0x7f
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200521 ngr %r8,%r3 # clear per-event-bit and ilc
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200522 je pgm_exit2
523 sll %r8,3
524 larl %r1,pgm_check_table
525 lg %r1,0(%r8,%r1) # load address of handler routine
526 la %r2,SP_PTREGS(%r15) # address of register-save area
527 basr %r14,%r1 # branch to interrupt-handler
528pgm_exit2:
Heiko Carstensf5cdac22010-07-27 19:29:37 +0200529 j sysc_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531#
532# it was a single stepped SVC that is causing all the trouble
533#
534pgm_svcper:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200535 SAVE_ALL_PGM __LC_SVC_OLD_PSW,__LC_SAVE_AREA
536 CREATE_STACK_FRAME __LC_SAVE_AREA
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100537 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200538 mvc SP_PSW(16,%r15),__LC_SVC_OLD_PSW
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100539 mvc SP_SVC_CODE(4,%r15),__LC_SVC_ILC
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100540 oi __TI_flags+7(%r12),(_TIF_SYSCALL | _TIF_PER_TRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
542 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
543 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200544 LAST_BREAK
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200545 lg %r8,__TI_task(%r12)
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100546 mvc __THREAD_per_cause(2,%r8),__LC_PER_CAUSE
547 mvc __THREAD_per_address(8,%r8),__LC_PER_ADDRESS
548 mvc __THREAD_per_paid(1,%r8),__LC_PER_PAID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200550 lmg %r2,%r6,SP_R2(%r15) # load svc arguments
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 j sysc_do_svc
552
Michael Grundy4ba069b2006-09-20 15:58:39 +0200553#
554# per was called from kernel, must be kprobes
555#
556kernel_per:
Martin Schwidefsky9ec27082010-10-29 16:50:45 +0200557 REENABLE_IRQS
Michael Grundy4ba069b2006-09-20 15:58:39 +0200558 la %r2,SP_PTREGS(%r15) # address of register-save area
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100559 brasl %r14,do_per_trap
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200560 j pgm_exit
Michael Grundy4ba069b2006-09-20 15:58:39 +0200561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562/*
563 * IO interrupt handler routine
564 */
Jan Glauber144d6342011-07-24 10:48:19 +0200565ENTRY(io_int_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 stck __LC_INT_CLOCK
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100567 stpt __LC_ASYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200568 SAVE_ALL_ASYNC __LC_IO_OLD_PSW,__LC_SAVE_AREA+40
569 CREATE_STACK_FRAME __LC_SAVE_AREA+40
570 mvc SP_PSW(16,%r15),0(%r12) # move user PSW to stack
571 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200572 HANDLE_SIE_INTERCEPT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
574 jz io_no_vtime
575 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
576 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
577 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200578 LAST_BREAK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579io_no_vtime:
Heiko Carstens1f194a42006-07-03 00:24:46 -0700580 TRACE_IRQS_OFF
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200581 la %r2,SP_PTREGS(%r15) # address of register-save area
582 brasl %r14,do_IRQ # call standard irq handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583io_return:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200584 LOCKDEP_SYS_EXIT
585 TRACE_IRQS_ON
586io_tif:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200587 tm __TI_flags+7(%r12),_TIF_WORK_INT
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200588 jnz io_work # there is work to do (signals etc.)
Heiko Carstens411788e2007-11-20 11:13:32 +0100589io_restore:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200590 RESTORE_ALL __LC_RETURN_PSW,0
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700591io_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Martin Schwidefsky26889052008-05-07 09:22:52 +0200593#
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200594# There is work todo, find out in which context we have been interrupted:
595# 1) if we return to user space we can do all _TIF_WORK_INT work
596# 2) if we return to kernel code and kvm is enabled check if we need to
597# modify the psw to leave SIE
598# 3) if we return to kernel code and preemptive scheduling is enabled check
599# the preemption counter and if it is zero call preempt_schedule_irq
600# Before any work can be done, a switch to the kernel stack is required.
Martin Schwidefsky26889052008-05-07 09:22:52 +0200601#
602io_work:
603 tm SP_PSW+1(%r15),0x01 # returning to user ?
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200604 jo io_work_user # yes -> do resched & signal
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200605#ifdef CONFIG_PREEMPT
Martin Schwidefsky26889052008-05-07 09:22:52 +0200606 # check for preemptive scheduling
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200607 icm %r0,15,__TI_precount(%r12)
Martin Schwidefsky26889052008-05-07 09:22:52 +0200608 jnz io_restore # preemption is disabled
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200609 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
610 jno io_restore
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 # switch to kernel stack
612 lg %r1,SP_R15(%r15)
613 aghi %r1,-SP_SIZE
614 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200615 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 lgr %r15,%r1
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200617 # TRACE_IRQS_ON already done at io_return, call
618 # TRACE_IRQS_OFF to keep things symmetrical
619 TRACE_IRQS_OFF
620 brasl %r14,preempt_schedule_irq
621 j io_return
622#else
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200623 j io_restore
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200624#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200626#
627# Need to do work before returning to userspace, switch to kernel stack
628#
Martin Schwidefsky26889052008-05-07 09:22:52 +0200629io_work_user:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 lg %r1,__LC_KERNEL_STACK
631 aghi %r1,-SP_SIZE
632 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200633 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 lgr %r15,%r1
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636#
637# One of the work bits is on. Find out which one.
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200638# Checked are: _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_NEED_RESCHED
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800639# and _TIF_MCCK_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640#
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200641io_work_tif:
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200642 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700643 jo io_mcck_pending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200644 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 jo io_reschedule
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200646 tm __TI_flags+7(%r12),_TIF_SIGPENDING
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200647 jo io_sigpending
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200648 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
Martin Schwidefsky43d399d2010-05-17 10:00:01 +0200649 jo io_notify_resume
650 j io_return # beware of critical section cleanup
Christian Borntraeger0eaeafa2008-05-07 09:22:53 +0200651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652#
Heiko Carstens77fa2242005-06-25 14:55:30 -0700653# _TIF_MCCK_PENDING is set, call handler
654#
655io_mcck_pending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200656 # TRACE_IRQS_ON already done at io_return
Heiko Carstensb771aea2007-07-27 12:29:18 +0200657 brasl %r14,s390_handle_mcck # TIF bit will be cleared by handler
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200658 TRACE_IRQS_OFF
659 j io_return
Heiko Carstens77fa2242005-06-25 14:55:30 -0700660
661#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662# _TIF_NEED_RESCHED is set, call schedule
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200663#
664io_reschedule:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200665 # TRACE_IRQS_ON already done at io_return
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200666 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
667 brasl %r14,schedule # call scheduler
668 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
Heiko Carstens411788e2007-11-20 11:13:32 +0100669 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200670 j io_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672#
Roland McGrath02a029b2008-04-30 00:53:08 -0700673# _TIF_SIGPENDING or is set, call do_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200675io_sigpending:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200676 # TRACE_IRQS_ON already done at io_return
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200677 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
678 la %r2,SP_PTREGS(%r15) # load pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 brasl %r14,do_signal # call do_signal
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200680 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
Heiko Carstens411788e2007-11-20 11:13:32 +0100681 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200682 j io_return
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200684#
685# _TIF_NOTIFY_RESUME or is set, call do_notify_resume
686#
687io_notify_resume:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200688 # TRACE_IRQS_ON already done at io_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200689 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
690 la %r2,SP_PTREGS(%r15) # load pt_regs
691 brasl %r14,do_notify_resume # call do_notify_resume
692 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
693 TRACE_IRQS_OFF
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200694 j io_return
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696/*
697 * External interrupt handler routine
698 */
Jan Glauber144d6342011-07-24 10:48:19 +0200699ENTRY(ext_int_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 stck __LC_INT_CLOCK
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100701 stpt __LC_ASYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200702 SAVE_ALL_ASYNC __LC_EXT_OLD_PSW,__LC_SAVE_AREA+40
703 CREATE_STACK_FRAME __LC_SAVE_AREA+40
704 mvc SP_PSW(16,%r15),0(%r12) # move user PSW to stack
705 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200706 HANDLE_SIE_INTERCEPT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
708 jz ext_no_vtime
709 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
710 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
711 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200712 LAST_BREAK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713ext_no_vtime:
Heiko Carstens1f194a42006-07-03 00:24:46 -0700714 TRACE_IRQS_OFF
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200715 lghi %r1,4096
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200716 la %r2,SP_PTREGS(%r15) # address of register-save area
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200717 llgf %r3,__LC_CPU_ADDRESS # get cpu address + interruption code
718 llgf %r4,__LC_EXT_PARAMS # get external parameter
719 lg %r5,__LC_EXT_PARAMS2-4096(%r1) # get 64 bit external parameter
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200720 brasl %r14,do_extint
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 j io_return
722
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700723__critical_end:
724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725/*
726 * Machine check handler routines
727 */
Jan Glauber144d6342011-07-24 10:48:19 +0200728ENTRY(mcck_int_handler)
Martin Schwidefsky63779812010-05-17 10:00:03 +0200729 stck __LC_MCCK_CLOCK
Heiko Carstens77fa2242005-06-25 14:55:30 -0700730 la %r1,4095 # revalidate r1
731 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200732 lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200733 stmg %r11,%r15,__LC_SAVE_AREA+80
734 larl %r13,system_call
735 lg %r11,__LC_LAST_BREAK
Heiko Carstens77fa2242005-06-25 14:55:30 -0700736 la %r12,__LC_MCK_OLD_PSW
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200737 tm __LC_MCCK_CODE,0x80 # system damage?
Heiko Carstens77fa2242005-06-25 14:55:30 -0700738 jo mcck_int_main # yes -> rest of mcck code invalid
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200739 la %r14,4095
Martin Schwidefsky63779812010-05-17 10:00:03 +0200740 mvc __LC_MCCK_ENTER_TIMER(8),__LC_CPU_TIMER_SAVE_AREA-4095(%r14)
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200741 tm __LC_MCCK_CODE+5,0x02 # stored cpu timer value valid?
742 jo 1f
743 la %r14,__LC_SYNC_ENTER_TIMER
744 clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
745 jl 0f
746 la %r14,__LC_ASYNC_ENTER_TIMER
7470: clc 0(8,%r14),__LC_EXIT_TIMER
748 jl 0f
749 la %r14,__LC_EXIT_TIMER
7500: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
751 jl 0f
752 la %r14,__LC_LAST_UPDATE_TIMER
7530: spt 0(%r14)
Martin Schwidefsky63779812010-05-17 10:00:03 +0200754 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
Martin Schwidefskyc185b782008-12-25 13:39:25 +01007551: tm __LC_MCCK_CODE+2,0x09 # mwp + ia of old psw valid?
Heiko Carstens77fa2242005-06-25 14:55:30 -0700756 jno mcck_int_main # no -> skip cleanup critical
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200757 tm __LC_MCK_OLD_PSW+1,0x01 # test problem state bit
Heiko Carstens77fa2242005-06-25 14:55:30 -0700758 jnz mcck_int_main # from user -> load kernel stack
759 clc __LC_MCK_OLD_PSW+8(8),BASED(.Lcritical_end)
760 jhe mcck_int_main
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200761 clc __LC_MCK_OLD_PSW+8(8),BASED(.Lcritical_start)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700762 jl mcck_int_main
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200763 brasl %r14,cleanup_critical
Heiko Carstens77fa2242005-06-25 14:55:30 -0700764mcck_int_main:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200765 lg %r14,__LC_PANIC_STACK # are we already on the panic stack?
Heiko Carstens77fa2242005-06-25 14:55:30 -0700766 slgr %r14,%r15
767 srag %r14,%r14,PAGE_SHIFT
768 jz 0f
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200769 lg %r15,__LC_PANIC_STACK # load panic stack
Martin Schwidefsky86f25522010-05-17 10:00:05 +02007700: aghi %r15,-SP_SIZE # make room for registers & psw
771 CREATE_STACK_FRAME __LC_SAVE_AREA+80
772 mvc SP_PSW(16,%r15),0(%r12)
773 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700774 tm __LC_MCCK_CODE+2,0x08 # mwp of old psw valid?
775 jno mcck_no_vtime # no -> no timer update
Martin Schwidefsky603d1a52011-07-24 10:48:18 +0200776 HANDLE_SIE_INTERCEPT
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200777 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700778 jz mcck_no_vtime
Martin Schwidefsky63779812010-05-17 10:00:03 +0200779 UPDATE_VTIME __LC_EXIT_TIMER,__LC_MCCK_ENTER_TIMER,__LC_USER_TIMER
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700780 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
Martin Schwidefsky63779812010-05-17 10:00:03 +0200781 mvc __LC_LAST_UPDATE_TIMER(8),__LC_MCCK_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200782 LAST_BREAK
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700783mcck_no_vtime:
Heiko Carstens77fa2242005-06-25 14:55:30 -0700784 la %r2,SP_PTREGS(%r15) # load pt_regs
785 brasl %r14,s390_do_machine_check
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200786 tm SP_PSW+1(%r15),0x01 # returning to user ?
Heiko Carstens77fa2242005-06-25 14:55:30 -0700787 jno mcck_return
788 lg %r1,__LC_KERNEL_STACK # switch to kernel stack
789 aghi %r1,-SP_SIZE
790 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
791 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
792 lgr %r15,%r1
793 stosm __SF_EMPTY(%r15),0x04 # turn dat on
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200794 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
Heiko Carstens77fa2242005-06-25 14:55:30 -0700795 jno mcck_return
Heiko Carstens1f194a42006-07-03 00:24:46 -0700796 TRACE_IRQS_OFF
Heiko Carstens77fa2242005-06-25 14:55:30 -0700797 brasl %r14,s390_handle_mcck
Heiko Carstens1f194a42006-07-03 00:24:46 -0700798 TRACE_IRQS_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799mcck_return:
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200800 mvc __LC_RETURN_MCCK_PSW(16),SP_PSW(%r15) # move return PSW
801 ni __LC_RETURN_MCCK_PSW+1,0xfd # clear wait state bit
802 lmg %r0,%r15,SP_R0(%r15) # load gprs 0-15
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200803 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
804 jno 0f
805 stpt __LC_EXIT_TIMER
Martin Schwidefskyc185b782008-12-25 13:39:25 +01008060: lpswe __LC_RETURN_MCCK_PSW # back to caller
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200807mcck_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809/*
810 * Restart interruption handler, kick starter for additional CPUs
811 */
Heiko Carstens84b36a82007-06-19 13:10:03 +0200812#ifdef CONFIG_SMP
Heiko Carstens2bc89b52008-02-05 16:50:40 +0100813 __CPUINIT
Jan Glauber144d6342011-07-24 10:48:19 +0200814ENTRY(restart_int_handler)
Martin Schwidefsky5b409ed2009-04-14 15:36:27 +0200815 basr %r1,0
816restart_base:
817 spt restart_vtime-restart_base(%r1)
818 stck __LC_LAST_UPDATE_CLOCK
819 mvc __LC_LAST_UPDATE_TIMER(8),restart_vtime-restart_base(%r1)
820 mvc __LC_EXIT_TIMER(8),restart_vtime-restart_base(%r1)
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200821 lg %r15,__LC_SAVE_AREA+120 # load ksp
822 lghi %r10,__LC_CREGS_SAVE_AREA
823 lctlg %c0,%c15,0(%r10) # get new ctl regs
824 lghi %r10,__LC_AREGS_SAVE_AREA
825 lam %a0,%a15,0(%r10)
826 lmg %r6,%r15,__SF_GPRS(%r15) # load registers from clone
Martin Schwidefsky5b409ed2009-04-14 15:36:27 +0200827 lg %r1,__LC_THREAD_INFO
828 mvc __LC_USER_TIMER(8),__TI_user_timer(%r1)
829 mvc __LC_SYSTEM_TIMER(8),__TI_system_timer(%r1)
830 xc __LC_STEAL_TIMER(8),__LC_STEAL_TIMER
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200831 stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on
Michael Holzheu8eb4bd62011-05-10 17:13:39 +0200832 brasl %r14,start_secondary
Martin Schwidefsky5b409ed2009-04-14 15:36:27 +0200833 .align 8
834restart_vtime:
835 .long 0x7fffffff,0xffffffff
Heiko Carstens84b36a82007-06-19 13:10:03 +0200836 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837#else
838/*
839 * If we do not run with SMP enabled, let the new CPU crash ...
840 */
Jan Glauber144d6342011-07-24 10:48:19 +0200841ENTRY(restart_int_handler)
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200842 basr %r1,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843restart_base:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200844 lpswe restart_crash-restart_base(%r1)
845 .align 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846restart_crash:
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200847 .long 0x000a0000,0x00000000,0x00000000,0x00000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848restart_go:
849#endif
850
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200851#
852# PSW restart interrupt handler
853#
854ENTRY(psw_restart_int_handler)
Martin Schwidefsky0edc8fa2011-10-30 15:16:45 +0100855 stg %r15,__LC_SAVE_AREA+120(%r0) # save r15
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200856 larl %r15,restart_stack # load restart stack
857 lg %r15,0(%r15)
858 aghi %r15,-SP_SIZE # make room for pt_regs
859 stmg %r0,%r14,SP_R0(%r15) # store gprs %r0-%r14 to stack
Martin Schwidefsky0edc8fa2011-10-30 15:16:45 +0100860 mvc SP_R15(8,%r15),__LC_SAVE_AREA+120(%r0)# store saved %r15 to stack
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200861 mvc SP_PSW(16,%r15),__LC_RST_OLD_PSW(%r0)# store restart old psw
862 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) # set backchain to 0
863 brasl %r14,do_restart
864
865 larl %r14,restart_psw_crash # load disabled wait PSW if
866 lpswe 0(%r14) # do_restart returns
867 .align 8
868restart_psw_crash:
869 .quad 0x0002000080000000,0x0000000000000000 + restart_psw_crash
870
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100871 .section .kprobes.text, "ax"
872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873#ifdef CONFIG_CHECK_STACK
874/*
875 * The synchronous or the asynchronous stack overflowed. We are dead.
876 * No need to properly save the registers, we are going to panic anyway.
877 * Setup a pt_regs so that show_trace can provide a good call trace.
878 */
879stack_overflow:
880 lg %r15,__LC_PANIC_STACK # change to panic stack
Heiko Carstens9514e232006-09-20 15:59:22 +0200881 aghi %r15,-SP_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 mvc SP_PSW(16,%r15),0(%r12) # move user PSW to stack
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200883 stmg %r0,%r10,SP_R0(%r15) # store gprs %r0-%r10 to kernel stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 la %r1,__LC_SAVE_AREA
885 chi %r12,__LC_SVC_OLD_PSW
886 je 0f
887 chi %r12,__LC_PGM_OLD_PSW
888 je 0f
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200889 la %r1,__LC_SAVE_AREA+40
8900: mvc SP_R11(40,%r15),0(%r1) # move %r11-%r15 to stack
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200891 mvc SP_ARGS(8,%r15),__LC_LAST_BREAK
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200892 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) # clear back chain
893 la %r2,SP_PTREGS(%r15) # load pt_regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 jg kernel_stack_overflow
895#endif
896
897cleanup_table_system_call:
898 .quad system_call, sysc_do_svc
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200899cleanup_table_sysc_tif:
900 .quad sysc_tif, sysc_restore
901cleanup_table_sysc_restore:
902 .quad sysc_restore, sysc_done
903cleanup_table_io_tif:
904 .quad io_tif, io_restore
905cleanup_table_io_restore:
906 .quad io_restore, io_done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908cleanup_critical:
909 clc 8(8,%r12),BASED(cleanup_table_system_call)
910 jl 0f
911 clc 8(8,%r12),BASED(cleanup_table_system_call+8)
912 jl cleanup_system_call
9130:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200914 clc 8(8,%r12),BASED(cleanup_table_sysc_tif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 jl 0f
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200916 clc 8(8,%r12),BASED(cleanup_table_sysc_tif+8)
917 jl cleanup_sysc_tif
Linus Torvalds1da177e2005-04-16 15:20:36 -07009180:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200919 clc 8(8,%r12),BASED(cleanup_table_sysc_restore)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 jl 0f
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200921 clc 8(8,%r12),BASED(cleanup_table_sysc_restore+8)
922 jl cleanup_sysc_restore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009230:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200924 clc 8(8,%r12),BASED(cleanup_table_io_tif)
Martin Schwidefsky63b12242006-06-29 14:58:05 +0200925 jl 0f
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200926 clc 8(8,%r12),BASED(cleanup_table_io_tif+8)
927 jl cleanup_io_tif
Martin Schwidefsky63b12242006-06-29 14:58:05 +02009280:
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200929 clc 8(8,%r12),BASED(cleanup_table_io_restore)
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -0700930 jl 0f
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200931 clc 8(8,%r12),BASED(cleanup_table_io_restore+8)
932 jl cleanup_io_restore
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -07009330:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 br %r14
935
936cleanup_system_call:
937 mvc __LC_RETURN_PSW(16),0(%r12)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+8)
939 jh 0f
Martin Schwidefsky63779812010-05-17 10:00:03 +0200940 mvc __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
941 cghi %r12,__LC_MCK_OLD_PSW
942 je 0f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
Martin Schwidefsky63779812010-05-17 10:00:03 +02009440: cghi %r12,__LC_MCK_OLD_PSW
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200945 la %r12,__LC_SAVE_AREA+80
Martin Schwidefsky63779812010-05-17 10:00:03 +0200946 je 0f
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200947 la %r12,__LC_SAVE_AREA+40
Linus Torvalds1da177e2005-04-16 15:20:36 -07009480: clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+16)
949 jhe cleanup_vtime
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn)
951 jh 0f
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200952 mvc __LC_SAVE_AREA(40),0(%r12)
9530: lg %r15,__LC_KERNEL_STACK # problem state -> load ksp
954 aghi %r15,-SP_SIZE # make room for registers & psw
955 stg %r15,32(%r12)
956 stg %r11,0(%r12)
957 CREATE_STACK_FRAME __LC_SAVE_AREA
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100958 mvc 8(8,%r12),__LC_THREAD_INFO
959 lg %r12,__LC_THREAD_INFO
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200960 mvc SP_PSW(16,%r15),__LC_SVC_OLD_PSW
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100961 mvc SP_SVC_CODE(4,%r15),__LC_SVC_ILC
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100962 oi __TI_flags+7(%r12),_TIF_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963cleanup_vtime:
964 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+24)
965 jhe cleanup_stime
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
967cleanup_stime:
968 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+32)
969 jh cleanup_update
970 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
971cleanup_update:
972 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200973 srag %r12,%r11,23
974 lg %r12,__LC_THREAD_INFO
975 jz 0f
976 stg %r11,__TI_last_break(%r12)
9770: mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_system_call+8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 la %r12,__LC_RETURN_PSW
979 br %r14
980cleanup_system_call_insn:
981 .quad sysc_saveall
Heiko Carstens25d83cb2006-09-28 16:56:37 +0200982 .quad system_call
983 .quad sysc_vtime
984 .quad sysc_stime
985 .quad sysc_update
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200987cleanup_sysc_tif:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 mvc __LC_RETURN_PSW(8),0(%r12)
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200989 mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_sysc_tif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 la %r12,__LC_RETURN_PSW
991 br %r14
992
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200993cleanup_sysc_restore:
994 clc 8(8,%r12),BASED(cleanup_sysc_restore_insn)
Martin Schwidefsky63779812010-05-17 10:00:03 +0200995 je 2f
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +0200996 clc 8(8,%r12),BASED(cleanup_sysc_restore_insn+8)
Martin Schwidefskyc742b312008-12-31 15:11:42 +0100997 jhe 0f
Martin Schwidefsky63779812010-05-17 10:00:03 +0200998 mvc __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
999 cghi %r12,__LC_MCK_OLD_PSW
1000 je 0f
Martin Schwidefskyc742b312008-12-31 15:11:42 +01001001 mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
10020: mvc __LC_RETURN_PSW(16),SP_PSW(%r15)
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -07001003 cghi %r12,__LC_MCK_OLD_PSW
Martin Schwidefsky86f25522010-05-17 10:00:05 +02001004 la %r12,__LC_SAVE_AREA+80
Martin Schwidefsky63779812010-05-17 10:00:03 +02001005 je 1f
Martin Schwidefsky86f25522010-05-17 10:00:05 +02001006 la %r12,__LC_SAVE_AREA+40
10071: mvc 0(40,%r12),SP_R11(%r15)
1008 lmg %r0,%r10,SP_R0(%r15)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 lg %r15,SP_R15(%r15)
Martin Schwidefsky63779812010-05-17 10:00:03 +020010102: la %r12,__LC_RETURN_PSW
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 br %r14
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +02001012cleanup_sysc_restore_insn:
Heiko Carstens411788e2007-11-20 11:13:32 +01001013 .quad sysc_done - 4
Martin Schwidefskyc742b312008-12-31 15:11:42 +01001014 .quad sysc_done - 16
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +02001016cleanup_io_tif:
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -07001017 mvc __LC_RETURN_PSW(8),0(%r12)
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +02001018 mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_io_tif)
Martin Schwidefsky176b1802010-04-09 13:43:00 +02001019 la %r12,__LC_RETURN_PSW
1020 br %r14
1021
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +02001022cleanup_io_restore:
1023 clc 8(8,%r12),BASED(cleanup_io_restore_insn)
Martin Schwidefsky63779812010-05-17 10:00:03 +02001024 je 1f
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +02001025 clc 8(8,%r12),BASED(cleanup_io_restore_insn+8)
Martin Schwidefskyc742b312008-12-31 15:11:42 +01001026 jhe 0f
Martin Schwidefsky63779812010-05-17 10:00:03 +02001027 mvc __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
Martin Schwidefskyc742b312008-12-31 15:11:42 +010010280: mvc __LC_RETURN_PSW(16),SP_PSW(%r15)
Martin Schwidefsky86f25522010-05-17 10:00:05 +02001029 mvc __LC_SAVE_AREA+80(40),SP_R11(%r15)
1030 lmg %r0,%r10,SP_R0(%r15)
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -07001031 lg %r15,SP_R15(%r15)
Martin Schwidefsky63779812010-05-17 10:00:03 +020010321: la %r12,__LC_RETURN_PSW
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -07001033 br %r14
Martin Schwidefsky6a2df3a2010-05-17 10:00:02 +02001034cleanup_io_restore_insn:
Heiko Carstens411788e2007-11-20 11:13:32 +01001035 .quad io_done - 4
Martin Schwidefskyc742b312008-12-31 15:11:42 +01001036 .quad io_done - 16
Martin Schwidefskyae6aa2e2005-09-03 15:57:56 -07001037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038/*
1039 * Integer constants
1040 */
Heiko Carstens25d83cb2006-09-28 16:56:37 +02001041 .align 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042.Lcritical_start:
Heiko Carstens25d83cb2006-09-28 16:56:37 +02001043 .quad __critical_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044.Lcritical_end:
Heiko Carstens25d83cb2006-09-28 16:56:37 +02001045 .quad __critical_end
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001047#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
1048/*
1049 * sie64a calling convention:
1050 * %r2 pointer to sie control block
1051 * %r3 guest register save area
1052 */
Jan Glauber144d6342011-07-24 10:48:19 +02001053ENTRY(sie64a)
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001054 stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
1055 stg %r2,__SF_EMPTY(%r15) # save control block pointer
1056 stg %r3,__SF_EMPTY+8(%r15) # save guest register save area
Martin Schwidefskyddd6f952011-12-27 11:27:13 +01001057 xc __SF_EMPTY+16(8,%r15),__SF_EMPTY+16(%r15) # host id == 0
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001058 lmg %r0,%r13,0(%r3) # load guest gprs 0-13
1059 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
1060 oi __TI_flags+6(%r14),_TIF_SIE>>8
1061sie_loop:
1062 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
1063 tm __TI_flags+7(%r14),_TIF_EXIT_SIE
1064 jnz sie_exit
Christian Borntraeger480e5922011-09-20 17:07:28 +02001065 lg %r14,__LC_GMAP # get gmap pointer
1066 ltgr %r14,%r14
1067 jz sie_gmap
1068 lctlg %c1,%c1,__GMAP_ASCE(%r14) # load primary asce
1069sie_gmap:
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001070 lg %r14,__SF_EMPTY(%r15) # get control block pointer
1071 SPP __SF_EMPTY(%r15) # set guest id
1072 sie 0(%r14)
1073sie_done:
Martin Schwidefskyddd6f952011-12-27 11:27:13 +01001074 SPP __SF_EMPTY+16(%r15) # set host id
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001075 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
1076sie_exit:
Christian Borntraeger480e5922011-09-20 17:07:28 +02001077 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001078 ni __TI_flags+6(%r14),255-(_TIF_SIE>>8)
1079 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
1080 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
1081 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
1082 lghi %r2,0
1083 br %r14
1084sie_fault:
Carsten Otte69ba9742011-10-30 15:16:59 +01001085 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001086 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
1087 ni __TI_flags+6(%r14),255-(_TIF_SIE>>8)
1088 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
1089 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
1090 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
1091 lghi %r2,-EFAULT
1092 br %r14
1093
1094 .align 8
1095.Lsie_loop:
1096 .quad sie_loop
1097.Lsie_done:
1098 .quad sie_done
Martin Schwidefskyddd6f952011-12-27 11:27:13 +01001099.Lhost_id:
1100 .quad 0
Martin Schwidefsky603d1a52011-07-24 10:48:18 +02001101
1102 .section __ex_table,"a"
1103 .quad sie_loop,sie_fault
1104 .previous
1105#endif
1106
Heiko Carstens25d83cb2006-09-28 16:56:37 +02001107 .section .rodata, "a"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108#define SYSCALL(esa,esame,emu) .long esame
Heiko Carstens9bf12262009-06-12 10:26:47 +02001109 .globl sys_call_table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110sys_call_table:
1111#include "syscalls.S"
1112#undef SYSCALL
1113
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001114#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116#define SYSCALL(esa,esame,emu) .long emu
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117sys_call_table_emu:
1118#include "syscalls.S"
1119#undef SYSCALL
1120#endif