blob: d00de17b3778ef9fde54a971de2175922ab5b03d [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
29 .long 0,RAMDISK_ORIGIN # INITRD_START
30 .long 0,RAMDISK_SIZE # INITRD_SIZE
31
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
40.LPG1: GET_IPL_DEVICE
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)
45
46#
47# clear bss memory
48#
49 l %r2,.Lbss_bgn-.LPG1(%r13) # start of bss
50 l %r3,.Lbss_end-.LPG1(%r13) # end of bss
51 sr %r3,%r2 # length of bss
52 sr %r4,%r4
53 sr %r5,%r5 # set src,length and pad to zero
54 sr %r0,%r0
55 mvcle %r2,%r4,0 # clear mem
56 jo .-4 # branch back, if not finish
57
58 l %r2,.Lrcp-.LPG1(%r13) # Read SCP forced command word
59.Lservicecall:
60 stosm .Lpmask-.LPG1(%r13),0x01 # authorize ext interrupts
61
62 stctl %r0, %r0,.Lcr-.LPG1(%r13) # get cr0
63 la %r1,0x200 # set bit 22
64 o %r1,.Lcr-.LPG1(%r13) # or old cr0 with r1
65 st %r1,.Lcr-.LPG1(%r13)
66 lctl %r0, %r0,.Lcr-.LPG1(%r13) # load modified cr0
67
68 mvc __LC_EXT_NEW_PSW(8),.Lpcext-.LPG1(%r13) # set postcall psw
69 la %r1, .Lsclph-.LPG1(%r13)
70 a %r1,__LC_EXT_NEW_PSW+4 # set handler
71 st %r1,__LC_EXT_NEW_PSW+4
72
Heiko Carstensb1b70302006-06-29 14:58:17 +020073 l %r4,.Lsccbaddr-.LPG1(%r13) # %r4 is our index for sccb stuff
74 lr %r1,%r4 # our sccb
Heiko Carstens0ad775d2005-11-07 00:59:12 -080075 .insn rre,0xb2200000,%r2,%r1 # service call
76 ipm %r1
77 srl %r1,28 # get cc code
78 xr %r3, %r3
79 chi %r1,3
80 be .Lfchunk-.LPG1(%r13) # leave
81 chi %r1,2
82 be .Lservicecall-.LPG1(%r13)
83 lpsw .Lwaitsclp-.LPG1(%r13)
84.Lsclph:
Heiko Carstensb1b70302006-06-29 14:58:17 +020085 lh %r1,.Lsccbr-.Lsccb(%r4)
Heiko Carstens0ad775d2005-11-07 00:59:12 -080086 chi %r1,0x10 # 0x0010 is the sucess code
87 je .Lprocsccb # let's process the sccb
88 chi %r1,0x1f0
89 bne .Lfchunk-.LPG1(%r13) # unhandled error code
90 c %r2, .Lrcp-.LPG1(%r13) # Did we try Read SCP forced
91 bne .Lfchunk-.LPG1(%r13) # if no, give up
92 l %r2, .Lrcp2-.LPG1(%r13) # try with Read SCP
93 b .Lservicecall-.LPG1(%r13)
94.Lprocsccb:
95 lhi %r1,0
Heiko Carstensb1b70302006-06-29 14:58:17 +020096 icm %r1,3,.Lscpincr1-.Lsccb(%r4) # use this one if != 0
Heiko Carstens0ad775d2005-11-07 00:59:12 -080097 jnz .Lscnd
98 lhi %r1,0x800 # otherwise report 2GB
99.Lscnd:
100 lhi %r3,0x800 # limit reported memory size to 2GB
101 cr %r1,%r3
102 jl .Lno2gb
103 lr %r1,%r3
104.Lno2gb:
105 xr %r3,%r3 # same logic
Heiko Carstensb1b70302006-06-29 14:58:17 +0200106 ic %r3,.Lscpa1-.Lsccb(%r4)
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800107 chi %r3,0x00
108 jne .Lcompmem
Heiko Carstensb1b70302006-06-29 14:58:17 +0200109 l %r3,.Lscpa2-.Lsccb(%r4)
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800110.Lcompmem:
111 mr %r2,%r1 # mem in MB on 128-bit
112 l %r1,.Lonemb-.LPG1(%r13)
113 mr %r2,%r1 # mem size in bytes in %r3
114 b .Lfchunk-.LPG1(%r13)
115
116 .align 4
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800117.Lpmask:
118 .byte 0
119.align 8
120.Lpcext:.long 0x00080000,0x80000000
121.Lcr:
122 .long 0x00 # place holder for cr0
123.Lwaitsclp:
124 .long 0x010a0000,0x80000000 + .Lsclph
125.Lrcp:
126 .int 0x00120001 # Read SCP forced code
127.Lrcp2:
128 .int 0x00020001 # Read SCP code
129.Lonemb:
130 .int 0x100000
131.Lfchunk:
132
133#
134# find memory chunks.
135#
136 lr %r9,%r3 # end of mem
137 mvc __LC_PGM_NEW_PSW(8),.Lpcmem-.LPG1(%r13)
138 la %r1,1 # test in increments of 128KB
139 sll %r1,17
140 l %r3,.Lmchunk-.LPG1(%r13) # get pointer to memory_chunk array
141 slr %r4,%r4 # set start of chunk to zero
142 slr %r5,%r5 # set end of chunk to zero
143 slr %r6,%r6 # set access code to zero
144 la %r10, MEMORY_CHUNKS # number of chunks
145.Lloop:
146 tprot 0(%r5),0 # test protection of first byte
147 ipm %r7
148 srl %r7,28
149 clr %r6,%r7 # compare cc with last access code
150 be .Lsame-.LPG1(%r13)
151 b .Lchkmem-.LPG1(%r13)
152.Lsame:
153 ar %r5,%r1 # add 128KB to end of chunk
154 bno .Lloop-.LPG1(%r13) # r1 < 0x80000000 -> loop
155.Lchkmem: # > 2GB or tprot got a program check
156 clr %r4,%r5 # chunk size > 0?
157 be .Lchkloop-.LPG1(%r13)
158 st %r4,0(%r3) # store start address of chunk
159 lr %r0,%r5
160 slr %r0,%r4
161 st %r0,4(%r3) # store size of chunk
162 st %r6,8(%r3) # store type of chunk
163 la %r3,12(%r3)
164 l %r4,.Lmemsize-.LPG1(%r13) # address of variable memory_size
165 st %r5,0(%r4) # store last end to memory size
166 ahi %r10,-1 # update chunk number
167.Lchkloop:
168 lr %r6,%r7 # set access code to last cc
169 # we got an exception or we're starting a new
170 # chunk , we must check if we should
171 # still try to find valid memory (if we detected
172 # the amount of available storage), and if we
173 # have chunks left
174 xr %r0,%r0
175 clr %r0,%r9 # did we detect memory?
176 je .Ldonemem # if not, leave
177 chi %r10,0 # do we have chunks left?
178 je .Ldonemem
179 alr %r5,%r1 # add 128KB to end of chunk
180 lr %r4,%r5 # potential new chunk
181 clr %r5,%r9 # should we go on?
182 jl .Lloop
183.Ldonemem:
184 l %r12,.Lmflags-.LPG1(%r13) # get address of machine_flags
185#
186# find out if we are running under VM
187#
188 stidp __LC_CPUID # store cpuid
189 tm __LC_CPUID,0xff # running under VM ?
190 bno .Lnovm-.LPG1(%r13)
191 oi 3(%r12),1 # set VM flag
192.Lnovm:
193 lh %r0,__LC_CPUID+4 # get cpu version
194 chi %r0,0x7490 # running on a P/390 ?
195 bne .Lnop390-.LPG1(%r13)
196 oi 3(%r12),4 # set P/390 flag
197.Lnop390:
198
199#
200# find out if we have an IEEE fpu
201#
202 mvc __LC_PGM_NEW_PSW(8),.Lpcfpu-.LPG1(%r13)
203 efpc %r0,0 # test IEEE extract fpc instruction
204 oi 3(%r12),2 # set IEEE fpu flag
205.Lchkfpu:
206
207#
208# find out if we have the CSP instruction
209#
210 mvc __LC_PGM_NEW_PSW(8),.Lpccsp-.LPG1(%r13)
211 la %r0,0
212 lr %r1,%r0
213 la %r2,4
214 csp %r0,%r2 # Test CSP instruction
215 oi 3(%r12),8 # set CSP flag
216.Lchkcsp:
217
218#
219# find out if we have the MVPG instruction
220#
221 mvc __LC_PGM_NEW_PSW(8),.Lpcmvpg-.LPG1(%r13)
222 sr %r0,%r0
223 la %r1,0
224 la %r2,0
225 mvpg %r1,%r2 # Test CSP instruction
226 oi 3(%r12),16 # set MVPG flag
227.Lchkmvpg:
228
229#
230# find out if we have the IDTE instruction
231#
232 mvc __LC_PGM_NEW_PSW(8),.Lpcidte-.LPG1(%r13)
233 .long 0xb2b10000 # store facility list
234 tm 0xc8,0x08 # check bit for clearing-by-ASCE
235 bno .Lchkidte-.LPG1(%r13)
236 lhi %r1,2094
237 lhi %r2,0
238 .long 0xb98e2001
239 oi 3(%r12),0x80 # set IDTE flag
240.Lchkidte:
241
242 lpsw .Lentry-.LPG1(13) # jump to _stext in primary-space,
243 # virtual and never return ...
244 .align 8
245.Lentry:.long 0x00080000,0x80000000 + _stext
246.Lctl: .long 0x04b50002 # cr0: various things
247 .long 0 # cr1: primary space segment table
248 .long .Lduct # cr2: dispatchable unit control table
249 .long 0 # cr3: instruction authorization
250 .long 0 # cr4: instruction authorization
251 .long 0xffffffff # cr5: primary-aste origin
252 .long 0 # cr6: I/O interrupts
253 .long 0 # cr7: secondary space segment table
254 .long 0 # cr8: access registers translation
255 .long 0 # cr9: tracing off
256 .long 0 # cr10: tracing off
257 .long 0 # cr11: tracing off
258 .long 0 # cr12: tracing off
259 .long 0 # cr13: home space segment table
260 .long 0xc0000000 # cr14: machine check handling off
261 .long 0 # cr15: linkage stack operations
Heiko Carstensb1b70302006-06-29 14:58:17 +0200262.Lduct: .long 0,0,0,0,0,0,0,0
263 .long 0,0,0,0,0,0,0,0
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800264.Lpcmem:.long 0x00080000,0x80000000 + .Lchkmem
265.Lpcfpu:.long 0x00080000,0x80000000 + .Lchkfpu
266.Lpccsp:.long 0x00080000,0x80000000 + .Lchkcsp
267.Lpcmvpg:.long 0x00080000,0x80000000 + .Lchkmvpg
268.Lpcidte:.long 0x00080000,0x80000000 + .Lchkidte
269.Lmemsize:.long memory_size
270.Lmchunk:.long memory_chunk
271.Lmflags:.long machine_flags
272.Lbss_bgn: .long __bss_start
273.Lbss_end: .long _end
Heiko Carstensb1b70302006-06-29 14:58:17 +0200274.Lparmaddr: .long PARMAREA
275.Lsccbaddr: .long .Lsccb
276 .align 4096
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800277.Lsccb:
278 .hword 0x1000 # length, one page
279 .byte 0x00,0x00,0x00
280 .byte 0x80 # variable response bit set
281.Lsccbr:
282 .hword 0x00 # response code
283.Lscpincr1:
284 .hword 0x00
285.Lscpa1:
286 .byte 0x00
287 .fill 89,1,0
288.Lscpa2:
289 .int 0x00
290.Lscpincr2:
291 .quad 0x00
292 .fill 3984,1,0
Heiko Carstensb1b70302006-06-29 14:58:17 +0200293 .align 4096
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800294
295#ifdef CONFIG_SHARED_KERNEL
296 .org 0x100000
297#endif
298
299#
Heiko Carstensb1b70302006-06-29 14:58:17 +0200300# startup-code, running in absolute addressing mode
Heiko Carstens0ad775d2005-11-07 00:59:12 -0800301#
302 .globl _stext
303_stext: basr %r13,0 # get base
304.LPG3:
305#
306# Setup stack
307#
308 l %r15,.Linittu-.LPG3(%r13)
309 mvc __LC_CURRENT(4),__TI_task(%r15)
310 ahi %r15,1<<(PAGE_SHIFT+THREAD_ORDER) # init_task_union+THREAD_SIZE
311 st %r15,__LC_KERNEL_STACK # set end of kernel stack
312 ahi %r15,-96
313 xc __SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15) # clear backchain
314
315# check control registers
316 stctl %c0,%c15,0(%r15)
317 oi 2(%r15),0x40 # enable sigp emergency signal
318 oi 0(%r15),0x10 # switch on low address protection
319 lctl %c0,%c15,0(%r15)
320
321#
322 lam 0,15,.Laregs-.LPG3(%r13) # load access regs needed by uaccess
323 l %r14,.Lstart-.LPG3(%r13)
324 basr %r14,%r14 # call start_kernel
325#
326# We returned from start_kernel ?!? PANIK
327#
328 basr %r13,0
329 lpsw .Ldw-.(%r13) # load disabled wait psw
330#
331 .align 8
332.Ldw: .long 0x000a0000,0x00000000
333.Linittu:.long init_thread_union
334.Lstart:.long start_kernel
335.Laregs:.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0