head.S 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Copyright IBM Corp. 1999, 2010
  3. *
  4. * Author(s): Hartmut Penner <hp@de.ibm.com>
  5. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  6. * Rob van der Heij <rvdhei@iae.nl>
  7. * Heiko Carstens <heiko.carstens@de.ibm.com>
  8. *
  9. * There are 5 different IPL methods
  10. * 1) load the image directly into ram at address 0 and do an PSW restart
  11. * 2) linload will load the image from address 0x10000 to memory 0x10000
  12. * and start the code thru LPSW 0x0008000080010000 (VM only, deprecated)
  13. * 3) generate the tape ipl header, store the generated image on a tape
  14. * and ipl from it
  15. * In case of SL tape you need to IPL 5 times to get past VOL1 etc
  16. * 4) generate the vm reader ipl header, move the generated image to the
  17. * VM reader (use option NOH!) and do a ipl from reader (VM only)
  18. * 5) direct call of start by the SALIPL loader
  19. * We use the cpuid to distinguish between VM and native ipl
  20. * params for kernel are pushed to 0x10400 (see setup.h)
  21. *
  22. */
  23. #include <linux/init.h>
  24. #include <linux/linkage.h>
  25. #include <asm/asm-offsets.h>
  26. #include <asm/thread_info.h>
  27. #include <asm/page.h>
  28. #include <asm/ptrace.h>
  29. #define ARCH_OFFSET 4
  30. __HEAD
  31. #define IPL_BS 0x730
  32. .org 0
  33. .long 0x00080000,0x80000000+iplstart # The first 24 bytes are loaded
  34. .long 0x02000018,0x60000050 # by ipl to addresses 0-23.
  35. .long 0x02000068,0x60000050 # (a PSW and two CCWs).
  36. .fill 80-24,1,0x40 # bytes 24-79 are discarded !!
  37. .long 0x020000f0,0x60000050 # The next 160 byte are loaded
  38. .long 0x02000140,0x60000050 # to addresses 0x18-0xb7
  39. .long 0x02000190,0x60000050 # They form the continuation
  40. .long 0x020001e0,0x60000050 # of the CCW program started
  41. .long 0x02000230,0x60000050 # by ipl and load the range
  42. .long 0x02000280,0x60000050 # 0x0f0-0x730 from the image
  43. .long 0x020002d0,0x60000050 # to the range 0x0f0-0x730
  44. .long 0x02000320,0x60000050 # in memory. At the end of
  45. .long 0x02000370,0x60000050 # the channel program the PSW
  46. .long 0x020003c0,0x60000050 # at location 0 is loaded.
  47. .long 0x02000410,0x60000050 # Initial processing starts
  48. .long 0x02000460,0x60000050 # at 0x200 = iplstart.
  49. .long 0x020004b0,0x60000050
  50. .long 0x02000500,0x60000050
  51. .long 0x02000550,0x60000050
  52. .long 0x020005a0,0x60000050
  53. .long 0x020005f0,0x60000050
  54. .long 0x02000640,0x60000050
  55. .long 0x02000690,0x60000050
  56. .long 0x020006e0,0x20000050
  57. .org 0x200
  58. #
  59. # subroutine to wait for end I/O
  60. #
  61. .Lirqwait:
  62. mvc 0x1f0(16),.Lnewpsw # set up IO interrupt psw
  63. lpsw .Lwaitpsw
  64. .Lioint:
  65. br %r14
  66. .align 8
  67. .Lnewpsw:
  68. .quad 0x0000000080000000,.Lioint
  69. .Lwaitpsw:
  70. .long 0x020a0000,0x80000000+.Lioint
  71. #
  72. # subroutine for loading cards from the reader
  73. #
  74. .Lloader:
  75. la %r4,0(%r14)
  76. la %r3,.Lorb # r2 = address of orb into r2
  77. la %r5,.Lirb # r4 = address of irb
  78. la %r6,.Lccws
  79. la %r7,20
  80. .Linit:
  81. st %r2,4(%r6) # initialize CCW data addresses
  82. la %r2,0x50(%r2)
  83. la %r6,8(%r6)
  84. bct 7,.Linit
  85. lctl %c6,%c6,.Lcr6 # set IO subclass mask
  86. slr %r2,%r2
  87. .Lldlp:
  88. ssch 0(%r3) # load chunk of 1600 bytes
  89. bnz .Llderr
  90. .Lwait4irq:
  91. bas %r14,.Lirqwait
  92. c %r1,0xb8 # compare subchannel number
  93. bne .Lwait4irq
  94. tsch 0(%r5)
  95. slr %r0,%r0
  96. ic %r0,8(%r5) # get device status
  97. chi %r0,8 # channel end ?
  98. be .Lcont
  99. chi %r0,12 # channel end + device end ?
  100. be .Lcont
  101. l %r0,4(%r5)
  102. s %r0,8(%r3) # r0/8 = number of ccws executed
  103. mhi %r0,10 # *10 = number of bytes in ccws
  104. lh %r3,10(%r5) # get residual count
  105. sr %r0,%r3 # #ccws*80-residual=#bytes read
  106. ar %r2,%r0
  107. br %r4 # r2 contains the total size
  108. .Lcont:
  109. ahi %r2,0x640 # add 0x640 to total size
  110. la %r6,.Lccws
  111. la %r7,20
  112. .Lincr:
  113. l %r0,4(%r6) # update CCW data addresses
  114. ahi %r0,0x640
  115. st %r0,4(%r6)
  116. ahi %r6,8
  117. bct 7,.Lincr
  118. b .Lldlp
  119. .Llderr:
  120. lpsw .Lcrash
  121. .align 8
  122. .Lorb: .long 0x00000000,0x0080ff00,.Lccws
  123. .Lirb: .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  124. .Lcr6: .long 0xff000000
  125. .Lloadp:.long 0,0
  126. .align 8
  127. .Lcrash:.long 0x000a0000,0x00000000
  128. .align 8
  129. .Lccws: .rept 19
  130. .long 0x02600050,0x00000000
  131. .endr
  132. .long 0x02200050,0x00000000
  133. iplstart:
  134. mvi __LC_AR_MODE_ID,1 # set esame flag
  135. slr %r0,%r0 # set cpuid to zero
  136. lhi %r1,2 # mode 2 = esame (dump)
  137. sigp %r1,%r0,0x12 # switch to esame mode
  138. bras %r13,0f
  139. .fill 16,4,0x0
  140. 0: lmh %r0,%r15,0(%r13) # clear high-order half of gprs
  141. sam31 # switch to 31 bit addressing mode
  142. lh %r1,0xb8 # test if subchannel number
  143. bct %r1,.Lnoload # is valid
  144. l %r1,0xb8 # load ipl subchannel number
  145. la %r2,IPL_BS # load start address
  146. bas %r14,.Lloader # load rest of ipl image
  147. l %r12,.Lparm # pointer to parameter area
  148. st %r1,IPL_DEVICE+ARCH_OFFSET-PARMAREA(%r12) # save ipl device number
  149. #
  150. # load parameter file from ipl device
  151. #
  152. .Lagain1:
  153. l %r2,.Linitrd # ramdisk loc. is temp
  154. bas %r14,.Lloader # load parameter file
  155. ltr %r2,%r2 # got anything ?
  156. bz .Lnopf
  157. chi %r2,895
  158. bnh .Lnotrunc
  159. la %r2,895
  160. .Lnotrunc:
  161. l %r4,.Linitrd
  162. clc 0(3,%r4),.L_hdr # if it is HDRx
  163. bz .Lagain1 # skip dataset header
  164. clc 0(3,%r4),.L_eof # if it is EOFx
  165. bz .Lagain1 # skip dateset trailer
  166. la %r5,0(%r4,%r2)
  167. lr %r3,%r2
  168. la %r3,COMMAND_LINE-PARMAREA(%r12) # load adr. of command line
  169. mvc 0(256,%r3),0(%r4)
  170. mvc 256(256,%r3),256(%r4)
  171. mvc 512(256,%r3),512(%r4)
  172. mvc 768(122,%r3),768(%r4)
  173. slr %r0,%r0
  174. b .Lcntlp
  175. .Ldelspc:
  176. ic %r0,0(%r2,%r3)
  177. chi %r0,0x20 # is it a space ?
  178. be .Lcntlp
  179. ahi %r2,1
  180. b .Leolp
  181. .Lcntlp:
  182. brct %r2,.Ldelspc
  183. .Leolp:
  184. slr %r0,%r0
  185. stc %r0,0(%r2,%r3) # terminate buffer
  186. .Lnopf:
  187. #
  188. # load ramdisk from ipl device
  189. #
  190. .Lagain2:
  191. l %r2,.Linitrd # addr of ramdisk
  192. st %r2,INITRD_START+ARCH_OFFSET-PARMAREA(%r12)
  193. bas %r14,.Lloader # load ramdisk
  194. st %r2,INITRD_SIZE+ARCH_OFFSET-PARMAREA(%r12) # store size of rd
  195. ltr %r2,%r2
  196. bnz .Lrdcont
  197. st %r2,INITRD_START+ARCH_OFFSET-PARMAREA(%r12) # no ramdisk found
  198. .Lrdcont:
  199. l %r2,.Linitrd
  200. clc 0(3,%r2),.L_hdr # skip HDRx and EOFx
  201. bz .Lagain2
  202. clc 0(3,%r2),.L_eof
  203. bz .Lagain2
  204. #
  205. # reset files in VM reader
  206. #
  207. stidp .Lcpuid # store cpuid
  208. tm .Lcpuid,0xff # running VM ?
  209. bno .Lnoreset
  210. la %r2,.Lreset
  211. lhi %r3,26
  212. diag %r2,%r3,8
  213. la %r5,.Lirb
  214. stsch 0(%r5) # check if irq is pending
  215. tm 30(%r5),0x0f # by verifying if any of the
  216. bnz .Lwaitforirq # activity or status control
  217. tm 31(%r5),0xff # bits is set in the schib
  218. bz .Lnoreset
  219. .Lwaitforirq:
  220. bas %r14,.Lirqwait # wait for IO interrupt
  221. c %r1,0xb8 # compare subchannel number
  222. bne .Lwaitforirq
  223. la %r5,.Lirb
  224. tsch 0(%r5)
  225. .Lnoreset:
  226. b .Lnoload
  227. #
  228. # everything loaded, go for it
  229. #
  230. .Lnoload:
  231. l %r1,.Lstartup
  232. br %r1
  233. .Linitrd:.long _end # default address of initrd
  234. .Lparm: .long PARMAREA
  235. .Lstartup: .long startup
  236. .Lreset:.byte 0xc3,0xc8,0xc1,0xd5,0xc7,0xc5,0x40,0xd9,0xc4,0xd9,0x40
  237. .byte 0xc1,0xd3,0xd3,0x40,0xd2,0xc5,0xc5,0xd7,0x40,0xd5,0xd6
  238. .byte 0xc8,0xd6,0xd3,0xc4 # "change rdr all keep nohold"
  239. .L_eof: .long 0xc5d6c600 /* C'EOF' */
  240. .L_hdr: .long 0xc8c4d900 /* C'HDR' */
  241. .align 8
  242. .Lcpuid:.fill 8,1,0
  243. #
  244. # startup-code at 0x10000, running in absolute addressing mode
  245. # this is called either by the ipl loader or directly by PSW restart
  246. # or linload or SALIPL
  247. #
  248. .org 0x10000
  249. ENTRY(startup)
  250. j .Lep_startup_normal
  251. .org 0x10008
  252. #
  253. # This is a list of s390 kernel entry points. At address 0x1000f the number of
  254. # valid entry points is stored.
  255. #
  256. # IMPORTANT: Do not change this table, it is s390 kernel ABI!
  257. #
  258. .ascii "S390EP"
  259. .byte 0x00,0x01
  260. #
  261. # kdump startup-code at 0x10010, running in 64 bit absolute addressing mode
  262. #
  263. .org 0x10010
  264. ENTRY(startup_kdump)
  265. j .Lep_startup_kdump
  266. .Lep_startup_normal:
  267. mvi __LC_AR_MODE_ID,1 # set esame flag
  268. slr %r0,%r0 # set cpuid to zero
  269. lhi %r1,2 # mode 2 = esame (dump)
  270. sigp %r1,%r0,0x12 # switch to esame mode
  271. bras %r13,0f
  272. .fill 16,4,0x0
  273. 0: lmh %r0,%r15,0(%r13) # clear high-order half of gprs
  274. sam64 # switch to 64 bit addressing mode
  275. basr %r13,0 # get base
  276. .LPG0:
  277. xc 0x200(256),0x200 # partially clear lowcore
  278. xc 0x300(256),0x300
  279. xc 0xe00(256),0xe00
  280. lctlg %c0,%c15,0x200(%r0) # initialize control registers
  281. stck __LC_LAST_UPDATE_CLOCK
  282. spt 6f-.LPG0(%r13)
  283. mvc __LC_LAST_UPDATE_TIMER(8),6f-.LPG0(%r13)
  284. xc __LC_STFL_FAC_LIST(8),__LC_STFL_FAC_LIST
  285. # check capabilities against MARCH_{G5,Z900,Z990,Z9_109,Z10}
  286. .insn s,0xb2b10000,0 # store facilities @ __LC_STFL_FAC_LIST
  287. tm __LC_STFL_FAC_LIST,0x01 # stfle available ?
  288. jz 0f
  289. la %r0,1
  290. .insn s,0xb2b00000,__LC_STFL_FAC_LIST # store facility list extended
  291. # verify if all required facilities are supported by the machine
  292. 0: la %r1,__LC_STFL_FAC_LIST
  293. la %r2,3f+8-.LPG0(%r13)
  294. l %r3,0(%r2)
  295. 1: l %r0,0(%r1)
  296. n %r0,4(%r2)
  297. cl %r0,4(%r2)
  298. jne 2f
  299. la %r1,4(%r1)
  300. la %r2,4(%r2)
  301. ahi %r3,-1
  302. jnz 1b
  303. j 4f
  304. 2: l %r15,.Lstack-.LPG0(%r13)
  305. ahi %r15,-STACK_FRAME_OVERHEAD
  306. la %r2,.Lals_string-.LPG0(%r13)
  307. l %r3,.Lsclp_print-.LPG0(%r13)
  308. basr %r14,%r3
  309. lpsw 3f-.LPG0(%r13) # machine type not good enough, crash
  310. .Lals_string:
  311. .asciz "The Linux kernel requires more recent processor hardware"
  312. .Lsclp_print:
  313. .long _sclp_print_early
  314. .Lstack:
  315. .long 0x8000 + (1<<(PAGE_SHIFT+THREAD_ORDER))
  316. .align 16
  317. 3: .long 0x000a0000,0x8badcccc
  318. # List of facilities that are required. If not all facilities are present
  319. # the kernel will crash. Format is number of facility words with bits set,
  320. # followed by the facility words.
  321. #if defined(CONFIG_MARCH_Z13)
  322. .long 2, 0xc100eff2, 0xf46cc800
  323. #elif defined(CONFIG_MARCH_ZEC12)
  324. .long 2, 0xc100eff2, 0xf46cc800
  325. #elif defined(CONFIG_MARCH_Z196)
  326. .long 2, 0xc100eff2, 0xf46c0000
  327. #elif defined(CONFIG_MARCH_Z10)
  328. .long 2, 0xc100eff2, 0xf0680000
  329. #elif defined(CONFIG_MARCH_Z9_109)
  330. .long 1, 0xc100efc2
  331. #elif defined(CONFIG_MARCH_Z990)
  332. .long 1, 0xc0002000
  333. #elif defined(CONFIG_MARCH_Z900)
  334. .long 1, 0xc0000000
  335. #endif
  336. 4:
  337. /* Continue with startup code in head64.S */
  338. jg startup_continue
  339. .align 8
  340. 6: .long 0x7fffffff,0xffffffff
  341. #include "head_kdump.S"
  342. #
  343. # params at 10400 (setup.h)
  344. #
  345. .org PARMAREA
  346. .long 0,0 # IPL_DEVICE
  347. .long 0,0 # INITRD_START
  348. .long 0,0 # INITRD_SIZE
  349. .long 0,0 # OLDMEM_BASE
  350. .long 0,0 # OLDMEM_SIZE
  351. .org COMMAND_LINE
  352. .byte "root=/dev/ram0 ro"
  353. .byte 0
  354. .org 0x11000