blob: b3dcdcdc80c0a36185b62d193daee15644c1fd2c [file] [log] [blame]
Heiko Carstens0ad775d2005-11-07 00:59:12 -08001/*
2 * arch/s390/kernel/head31.S
3 *
Heiko Carstensb1b70302006-06-29 14:58:17 +02004 * Copyright (C) IBM Corp. 2005,2006
Heiko Carstens0ad775d2005-11-07 00:59:12 -08005 *
6 * Author(s): Hartmut Penner <hp@de.ibm.com>
7 * Martin Schwidefsky <schwidefsky@de.ibm.com>
8 * Rob van der Heij <rvdhei@iae.nl>
9 * Heiko Carstens <heiko.carstens@de.ibm.com>
10 *
11 */
12
13#
14# startup-code at 0x10000, running in absolute addressing mode
15# this is called either by the ipl loader or directly by PSW restart
16# or linload or SALIPL
17#
18 .org 0x10000
Heiko Carstensb1b70302006-06-29 14:58:17 +020019startup:basr %r13,0 # get base
20.LPG0: l %r13,0f-.LPG0(%r13)
21 b 0(%r13)
220: .long startup_continue
23
24#
25# params at 10400 (setup.h)
26#
27 .org PARMAREA
28 .long 0,0 # IPL_DEVICE
Heiko Carstens65912a82006-09-20 15:58:41 +020029 .long 0,0 # INITRD_START
30 .long 0,0 # INITRD_SIZE
Heiko Carstensb1b70302006-06-29 14:58:17 +020031
32 .org COMMAND_LINE
33 .byte "root=/dev/ram0 ro"
34 .byte 0
35
36 .org 0x11000
37
38startup_continue:
39 basr %r13,0 # get base
Heiko Carstense87bfe52006-09-20 15:59:15 +020040.LPG1: mvi __LC_AR_MODE_ID,0 # set ESA flag (mode 0)
Heiko Carstens0ad775d2005-11-07 00:59:12 -080041 lctl %c0,%c15,.Lctl-.LPG1(%r13) # load control registers
Heiko Carstensb1b70302006-06-29 14:58:17 +020042 l %r12,.Lparmaddr-.LPG1(%r13) # pointer to parameter area
43 # move IPL device to lowcore
Heiko Carstens0ad775d2005-11-07 00:59:12 -080044 mvc __LC_IPLDEV(4),IPL_DEVICE-PARMAREA(%r12)
Heiko Carstense87bfe52006-09-20 15:59:15 +020045#
46# Setup stack
47#
48 l %r15,.Linittu-.LPG1(%r13)
49 mvc __LC_CURRENT(4),__TI_task(%r15)
50 ahi %r15,1<<(PAGE_SHIFT+THREAD_ORDER) # init_task_union+THREAD_SIZE
51 st %r15,__LC_KERNEL_STACK # set end of kernel stack
52 ahi %r15,-96
53 xc __SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15) # clear backchain
Hongjie Yangfe355b72007-02-05 21:18:24 +010054#
55# Save ipl parameters, clear bss memory, initialize storage key for kernel pages,
56# and create a kernel NSS if the SAVESYS= parm is defined
57#
58 l %r14,.Lstartup_init-.LPG1(%r13)
Heiko Carstense87bfe52006-09-20 15:59:15 +020059 basr %r14,%r14
Heiko Carstens0ad775d2005-11-07 00:59:12 -080060
61 l %r2,.Lrcp-.LPG1(%r13) # Read SCP forced command word
62.Lservicecall:
63 stosm .Lpmask-.LPG1(%r13),0x01 # authorize ext interrupts
64
65 stctl %r0, %r0,.Lcr-.LPG1(%r13) # get cr0
66 la %r1,0x200 # set bit 22
67 o %r1,.Lcr-.LPG1(%r13) # or old cr0 with r1
68 st %r1,.Lcr-.LPG1(%r13)
69 lctl %r0, %r0,.Lcr-.LPG1(%r13) # load modified cr0
70
71 mvc __LC_EXT_NEW_PSW(8),.Lpcext-.LPG1(%r13) # set postcall psw
72 la %r1, .Lsclph-.LPG1(%r13)
73 a %r1,__LC_EXT_NEW_PSW+4 # set handler
74 st %r1,__LC_EXT_NEW_PSW+4
75
Heiko Carstensb1b70302006-06-29 14:58:17 +020076 l %r4,.Lsccbaddr-.LPG1(%r13) # %r4 is our index for sccb stuff
77 lr %r1,%r4 # our sccb
Heiko Carstens0ad775d2005-11-07 00:59:12 -080078 .insn rre,0xb2200000,%r2,%r1 # service call
79 ipm %r1
80 srl %r1,28 # get cc code
81 xr %r3, %r3
82 chi %r1,3
83 be .Lfchunk-.LPG1(%r13) # leave
84 chi %r1,2
85 be .Lservicecall-.LPG1(%r13)
86 lpsw .Lwaitsclp-.LPG1(%r13)
87.Lsclph:
Heiko Carstensb1b70302006-06-29 14:58:17 +020088 lh %r1,.Lsccbr-.Lsccb(%r4)
Heiko Carstens0ad775d2005-11-07 00:59:12 -080089 chi %r1,0x10 # 0x0010 is the sucess code
90 je .Lprocsccb # let's process the sccb
91 chi %r1,0x1f0
92 bne .Lfchunk-.LPG1(%r13) # unhandled error code
93 c %r2, .Lrcp-.LPG1(%r13) # Did we try Read SCP forced
94 bne .Lfchunk-.LPG1(%r13) # if no, give up
95 l %r2, .Lrcp2-.LPG1(%r13) # try with Read SCP
96 b .Lservicecall-.LPG1(%r13)
97.Lprocsccb:
98 lhi %r1,0
Heiko Carstensb1b70302006-06-29 14:58:17 +020099 icm %r1,3,.Lscpincr1-.Lsccb(%r4) # use this one if != 0
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800100 jnz .Lscnd
101 lhi %r1,0x800 # otherwise report 2GB
102.Lscnd:
103 lhi %r3,0x800 # limit reported memory size to 2GB
104 cr %r1,%r3
105 jl .Lno2gb
106 lr %r1,%r3
107.Lno2gb:
108 xr %r3,%r3 # same logic
Heiko Carstensb1b70302006-06-29 14:58:17 +0200109 ic %r3,.Lscpa1-.Lsccb(%r4)
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800110 chi %r3,0x00
111 jne .Lcompmem
Heiko Carstensb1b70302006-06-29 14:58:17 +0200112 l %r3,.Lscpa2-.Lsccb(%r4)
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800113.Lcompmem:
114 mr %r2,%r1 # mem in MB on 128-bit
115 l %r1,.Lonemb-.LPG1(%r13)
116 mr %r2,%r1 # mem size in bytes in %r3
117 b .Lfchunk-.LPG1(%r13)
118
119 .align 4
Heiko Carstense87bfe52006-09-20 15:59:15 +0200120.Linittu:
121 .long init_thread_union
Hongjie Yangfe355b72007-02-05 21:18:24 +0100122.Lstartup_init:
123 .long startup_init
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800124.Lpmask:
125 .byte 0
Heiko Carstensbaf2aeb32006-12-04 15:40:36 +0100126 .align 8
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800127.Lpcext:.long 0x00080000,0x80000000
128.Lcr:
129 .long 0x00 # place holder for cr0
Heiko Carstensbaf2aeb32006-12-04 15:40:36 +0100130 .align 8
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800131.Lwaitsclp:
132 .long 0x010a0000,0x80000000 + .Lsclph
133.Lrcp:
134 .int 0x00120001 # Read SCP forced code
135.Lrcp2:
136 .int 0x00020001 # Read SCP code
137.Lonemb:
138 .int 0x100000
139.Lfchunk:
140
141#
142# find memory chunks.
143#
144 lr %r9,%r3 # end of mem
145 mvc __LC_PGM_NEW_PSW(8),.Lpcmem-.LPG1(%r13)
146 la %r1,1 # test in increments of 128KB
147 sll %r1,17
148 l %r3,.Lmchunk-.LPG1(%r13) # get pointer to memory_chunk array
149 slr %r4,%r4 # set start of chunk to zero
150 slr %r5,%r5 # set end of chunk to zero
151 slr %r6,%r6 # set access code to zero
Heiko Carstens36a2bd42006-12-04 15:40:38 +0100152 la %r10,MEMORY_CHUNKS # number of chunks
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800153.Lloop:
154 tprot 0(%r5),0 # test protection of first byte
155 ipm %r7
156 srl %r7,28
157 clr %r6,%r7 # compare cc with last access code
158 be .Lsame-.LPG1(%r13)
Hongjie Yangdd401e22007-01-09 10:18:36 +0100159 lhi %r8,0 # no program checks
160 b .Lsavchk-.LPG1(%r13)
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800161.Lsame:
162 ar %r5,%r1 # add 128KB to end of chunk
163 bno .Lloop-.LPG1(%r13) # r1 < 0x80000000 -> loop
164.Lchkmem: # > 2GB or tprot got a program check
Hongjie Yangdd401e22007-01-09 10:18:36 +0100165 lhi %r8,1 # set program check flag
166.Lsavchk:
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800167 clr %r4,%r5 # chunk size > 0?
168 be .Lchkloop-.LPG1(%r13)
169 st %r4,0(%r3) # store start address of chunk
170 lr %r0,%r5
171 slr %r0,%r4
172 st %r0,4(%r3) # store size of chunk
173 st %r6,8(%r3) # store type of chunk
174 la %r3,12(%r3)
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800175 ahi %r10,-1 # update chunk number
176.Lchkloop:
177 lr %r6,%r7 # set access code to last cc
178 # we got an exception or we're starting a new
179 # chunk , we must check if we should
180 # still try to find valid memory (if we detected
181 # the amount of available storage), and if we
182 # have chunks left
183 xr %r0,%r0
184 clr %r0,%r9 # did we detect memory?
185 je .Ldonemem # if not, leave
186 chi %r10,0 # do we have chunks left?
187 je .Ldonemem
Hongjie Yangdd401e22007-01-09 10:18:36 +0100188 chi %r8,1 # program check ?
189 je .Lpgmchk
190 lr %r4,%r5 # potential new chunk
191 alr %r5,%r1 # add 128KB to end of chunk
192 j .Llpcnt
193.Lpgmchk:
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800194 alr %r5,%r1 # add 128KB to end of chunk
195 lr %r4,%r5 # potential new chunk
Hongjie Yangdd401e22007-01-09 10:18:36 +0100196.Llpcnt:
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800197 clr %r5,%r9 # should we go on?
198 jl .Lloop
199.Ldonemem:
200 l %r12,.Lmflags-.LPG1(%r13) # get address of machine_flags
201#
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800202# find out if we have an IEEE fpu
203#
204 mvc __LC_PGM_NEW_PSW(8),.Lpcfpu-.LPG1(%r13)
205 efpc %r0,0 # test IEEE extract fpc instruction
206 oi 3(%r12),2 # set IEEE fpu flag
207.Lchkfpu:
208
209#
210# find out if we have the CSP instruction
211#
212 mvc __LC_PGM_NEW_PSW(8),.Lpccsp-.LPG1(%r13)
213 la %r0,0
214 lr %r1,%r0
215 la %r2,4
216 csp %r0,%r2 # Test CSP instruction
217 oi 3(%r12),8 # set CSP flag
218.Lchkcsp:
219
220#
221# find out if we have the MVPG instruction
222#
223 mvc __LC_PGM_NEW_PSW(8),.Lpcmvpg-.LPG1(%r13)
224 sr %r0,%r0
225 la %r1,0
226 la %r2,0
227 mvpg %r1,%r2 # Test CSP instruction
228 oi 3(%r12),16 # set MVPG flag
229.Lchkmvpg:
230
231#
232# find out if we have the IDTE instruction
233#
234 mvc __LC_PGM_NEW_PSW(8),.Lpcidte-.LPG1(%r13)
235 .long 0xb2b10000 # store facility list
236 tm 0xc8,0x08 # check bit for clearing-by-ASCE
237 bno .Lchkidte-.LPG1(%r13)
238 lhi %r1,2094
239 lhi %r2,0
240 .long 0xb98e2001
241 oi 3(%r12),0x80 # set IDTE flag
242.Lchkidte:
243
Martin Schwidefsky3c1fcfe2006-09-30 23:27:45 -0700244#
245# find out if the diag 0x9c is available
246#
247 mvc __LC_PGM_NEW_PSW(8),.Lpcdiag9c-.LPG1(%r13)
Heiko Carstenscb601d42006-10-04 20:02:15 +0200248 stap __LC_CPUID+4 # store cpu address
249 lh %r1,__LC_CPUID+4
250 diag %r1,0,0x9c # test diag 0x9c
251 oi 2(%r12),1 # set diag9c flag
Martin Schwidefsky3c1fcfe2006-09-30 23:27:45 -0700252.Lchkdiag9c:
253
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800254 lpsw .Lentry-.LPG1(13) # jump to _stext in primary-space,
255 # virtual and never return ...
256 .align 8
257.Lentry:.long 0x00080000,0x80000000 + _stext
258.Lctl: .long 0x04b50002 # cr0: various things
259 .long 0 # cr1: primary space segment table
260 .long .Lduct # cr2: dispatchable unit control table
261 .long 0 # cr3: instruction authorization
262 .long 0 # cr4: instruction authorization
263 .long 0xffffffff # cr5: primary-aste origin
264 .long 0 # cr6: I/O interrupts
265 .long 0 # cr7: secondary space segment table
266 .long 0 # cr8: access registers translation
267 .long 0 # cr9: tracing off
268 .long 0 # cr10: tracing off
269 .long 0 # cr11: tracing off
270 .long 0 # cr12: tracing off
271 .long 0 # cr13: home space segment table
272 .long 0xc0000000 # cr14: machine check handling off
273 .long 0 # cr15: linkage stack operations
Heiko Carstensb1b70302006-06-29 14:58:17 +0200274.Lduct: .long 0,0,0,0,0,0,0,0
275 .long 0,0,0,0,0,0,0,0
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800276.Lpcmem:.long 0x00080000,0x80000000 + .Lchkmem
277.Lpcfpu:.long 0x00080000,0x80000000 + .Lchkfpu
278.Lpccsp:.long 0x00080000,0x80000000 + .Lchkcsp
279.Lpcmvpg:.long 0x00080000,0x80000000 + .Lchkmvpg
280.Lpcidte:.long 0x00080000,0x80000000 + .Lchkidte
Martin Schwidefsky3c1fcfe2006-09-30 23:27:45 -0700281.Lpcdiag9c:.long 0x00080000,0x80000000 + .Lchkdiag9c
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800282.Lmchunk:.long memory_chunk
283.Lmflags:.long machine_flags
284.Lbss_bgn: .long __bss_start
285.Lbss_end: .long _end
Heiko Carstensb1b70302006-06-29 14:58:17 +0200286.Lparmaddr: .long PARMAREA
287.Lsccbaddr: .long .Lsccb
Heiko Carstense87bfe52006-09-20 15:59:15 +0200288
289 .globl ipl_schib
290ipl_schib:
291 .rept 13
292 .long 0
293 .endr
294
295 .globl ipl_flags
296ipl_flags:
297 .long 0
298 .globl ipl_devno
299ipl_devno:
300 .word 0
301
Heiko Carstensdc8f5d22006-07-18 13:44:57 +0200302 .org 0x12000
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200303.globl s390_readinfo_sccb
304s390_readinfo_sccb:
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800305.Lsccb:
306 .hword 0x1000 # length, one page
307 .byte 0x00,0x00,0x00
308 .byte 0x80 # variable response bit set
309.Lsccbr:
310 .hword 0x00 # response code
311.Lscpincr1:
312 .hword 0x00
313.Lscpa1:
314 .byte 0x00
315 .fill 89,1,0
316.Lscpa2:
317 .int 0x00
318.Lscpincr2:
319 .quad 0x00
320 .fill 3984,1,0
Heiko Carstensdc8f5d22006-07-18 13:44:57 +0200321 .org 0x13000
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800322
323#ifdef CONFIG_SHARED_KERNEL
324 .org 0x100000
325#endif
326
327#
Heiko Carstensb1b70302006-06-29 14:58:17 +0200328# startup-code, running in absolute addressing mode
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800329#
330 .globl _stext
331_stext: basr %r13,0 # get base
332.LPG3:
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800333# check control registers
334 stctl %c0,%c15,0(%r15)
335 oi 2(%r15),0x40 # enable sigp emergency signal
336 oi 0(%r15),0x10 # switch on low address protection
337 lctl %c0,%c15,0(%r15)
338
339#
340 lam 0,15,.Laregs-.LPG3(%r13) # load access regs needed by uaccess
341 l %r14,.Lstart-.LPG3(%r13)
342 basr %r14,%r14 # call start_kernel
343#
344# We returned from start_kernel ?!? PANIK
345#
346 basr %r13,0
347 lpsw .Ldw-.(%r13) # load disabled wait psw
348#
349 .align 8
350.Ldw: .long 0x000a0000,0x00000000
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800351.Lstart:.long start_kernel
352.Laregs:.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0