head.S 8.5 KB

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