head.S 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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/facility.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 0x200
  59. #
  60. # subroutine to wait for end I/O
  61. #
  62. .Lirqwait:
  63. mvc 0x1f0(16),.Lnewpsw # set up IO interrupt psw
  64. lpsw .Lwaitpsw
  65. .Lioint:
  66. br %r14
  67. .align 8
  68. .Lnewpsw:
  69. .quad 0x0000000080000000,.Lioint
  70. .Lwaitpsw:
  71. .long 0x020a0000,0x80000000+.Lioint
  72. #
  73. # subroutine for loading cards from the reader
  74. #
  75. .Lloader:
  76. la %r4,0(%r14)
  77. la %r3,.Lorb # r2 = address of orb into r2
  78. la %r5,.Lirb # r4 = address of irb
  79. la %r6,.Lccws
  80. la %r7,20
  81. .Linit:
  82. st %r2,4(%r6) # initialize CCW data addresses
  83. la %r2,0x50(%r2)
  84. la %r6,8(%r6)
  85. bct 7,.Linit
  86. lctl %c6,%c6,.Lcr6 # set IO subclass mask
  87. slr %r2,%r2
  88. .Lldlp:
  89. ssch 0(%r3) # load chunk of 1600 bytes
  90. bnz .Llderr
  91. .Lwait4irq:
  92. bas %r14,.Lirqwait
  93. c %r1,0xb8 # compare subchannel number
  94. bne .Lwait4irq
  95. tsch 0(%r5)
  96. slr %r0,%r0
  97. ic %r0,8(%r5) # get device status
  98. chi %r0,8 # channel end ?
  99. be .Lcont
  100. chi %r0,12 # channel end + device end ?
  101. be .Lcont
  102. l %r0,4(%r5)
  103. s %r0,8(%r3) # r0/8 = number of ccws executed
  104. mhi %r0,10 # *10 = number of bytes in ccws
  105. lh %r3,10(%r5) # get residual count
  106. sr %r0,%r3 # #ccws*80-residual=#bytes read
  107. ar %r2,%r0
  108. br %r4 # r2 contains the total size
  109. .Lcont:
  110. ahi %r2,0x640 # add 0x640 to total size
  111. la %r6,.Lccws
  112. la %r7,20
  113. .Lincr:
  114. l %r0,4(%r6) # update CCW data addresses
  115. ahi %r0,0x640
  116. st %r0,4(%r6)
  117. ahi %r6,8
  118. bct 7,.Lincr
  119. b .Lldlp
  120. .Llderr:
  121. lpsw .Lcrash
  122. .align 8
  123. .Lorb: .long 0x00000000,0x0080ff00,.Lccws
  124. .Lirb: .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  125. .Lcr6: .long 0xff000000
  126. .Lloadp:.long 0,0
  127. .align 8
  128. .Lcrash:.long 0x000a0000,0x00000000
  129. .align 8
  130. .Lccws: .rept 19
  131. .long 0x02600050,0x00000000
  132. .endr
  133. .long 0x02200050,0x00000000
  134. iplstart:
  135. mvi __LC_AR_MODE_ID,1 # set esame flag
  136. slr %r0,%r0 # set cpuid to zero
  137. lhi %r1,2 # mode 2 = esame (dump)
  138. sigp %r1,%r0,0x12 # switch to esame mode
  139. bras %r13,0f
  140. .fill 16,4,0x0
  141. 0: lmh %r0,%r15,0(%r13) # clear high-order half of gprs
  142. sam31 # switch to 31 bit addressing mode
  143. lh %r1,0xb8 # test if subchannel number
  144. bct %r1,.Lnoload # is valid
  145. l %r1,0xb8 # load ipl subchannel number
  146. la %r2,IPL_BS # load start address
  147. bas %r14,.Lloader # load rest of ipl image
  148. l %r12,.Lparm # pointer to parameter area
  149. st %r1,IPL_DEVICE+ARCH_OFFSET-PARMAREA(%r12) # save ipl device number
  150. #
  151. # load parameter file from ipl device
  152. #
  153. .Lagain1:
  154. l %r2,.Linitrd # ramdisk loc. is temp
  155. bas %r14,.Lloader # load parameter file
  156. ltr %r2,%r2 # got anything ?
  157. bz .Lnopf
  158. chi %r2,895
  159. bnh .Lnotrunc
  160. la %r2,895
  161. .Lnotrunc:
  162. l %r4,.Linitrd
  163. clc 0(3,%r4),.L_hdr # if it is HDRx
  164. bz .Lagain1 # skip dataset header
  165. clc 0(3,%r4),.L_eof # if it is EOFx
  166. bz .Lagain1 # skip dateset trailer
  167. la %r5,0(%r4,%r2)
  168. lr %r3,%r2
  169. la %r3,COMMAND_LINE-PARMAREA(%r12) # load adr. of command line
  170. mvc 0(256,%r3),0(%r4)
  171. mvc 256(256,%r3),256(%r4)
  172. mvc 512(256,%r3),512(%r4)
  173. mvc 768(122,%r3),768(%r4)
  174. slr %r0,%r0
  175. b .Lcntlp
  176. .Ldelspc:
  177. ic %r0,0(%r2,%r3)
  178. chi %r0,0x20 # is it a space ?
  179. be .Lcntlp
  180. ahi %r2,1
  181. b .Leolp
  182. .Lcntlp:
  183. brct %r2,.Ldelspc
  184. .Leolp:
  185. slr %r0,%r0
  186. stc %r0,0(%r2,%r3) # terminate buffer
  187. .Lnopf:
  188. #
  189. # load ramdisk from ipl device
  190. #
  191. .Lagain2:
  192. l %r2,.Linitrd # addr of ramdisk
  193. st %r2,INITRD_START+ARCH_OFFSET-PARMAREA(%r12)
  194. bas %r14,.Lloader # load ramdisk
  195. st %r2,INITRD_SIZE+ARCH_OFFSET-PARMAREA(%r12) # store size of rd
  196. ltr %r2,%r2
  197. bnz .Lrdcont
  198. st %r2,INITRD_START+ARCH_OFFSET-PARMAREA(%r12) # no ramdisk found
  199. .Lrdcont:
  200. l %r2,.Linitrd
  201. clc 0(3,%r2),.L_hdr # skip HDRx and EOFx
  202. bz .Lagain2
  203. clc 0(3,%r2),.L_eof
  204. bz .Lagain2
  205. #
  206. # reset files in VM reader
  207. #
  208. stidp .Lcpuid # store cpuid
  209. tm .Lcpuid,0xff # running VM ?
  210. bno .Lnoreset
  211. la %r2,.Lreset
  212. lhi %r3,26
  213. diag %r2,%r3,8
  214. la %r5,.Lirb
  215. stsch 0(%r5) # check if irq is pending
  216. tm 30(%r5),0x0f # by verifying if any of the
  217. bnz .Lwaitforirq # activity or status control
  218. tm 31(%r5),0xff # bits is set in the schib
  219. bz .Lnoreset
  220. .Lwaitforirq:
  221. bas %r14,.Lirqwait # wait for IO interrupt
  222. c %r1,0xb8 # compare subchannel number
  223. bne .Lwaitforirq
  224. la %r5,.Lirb
  225. tsch 0(%r5)
  226. .Lnoreset:
  227. b .Lnoload
  228. #
  229. # everything loaded, go for it
  230. #
  231. .Lnoload:
  232. l %r1,.Lstartup
  233. br %r1
  234. .Linitrd:.long _end # default address of initrd
  235. .Lparm: .long PARMAREA
  236. .Lstartup: .long startup
  237. .Lreset:.byte 0xc3,0xc8,0xc1,0xd5,0xc7,0xc5,0x40,0xd9,0xc4,0xd9,0x40
  238. .byte 0xc1,0xd3,0xd3,0x40,0xd2,0xc5,0xc5,0xd7,0x40,0xd5,0xd6
  239. .byte 0xc8,0xd6,0xd3,0xc4 # "change rdr all keep nohold"
  240. .L_eof: .long 0xc5d6c600 /* C'EOF' */
  241. .L_hdr: .long 0xc8c4d900 /* C'HDR' */
  242. .align 8
  243. .Lcpuid:.fill 8,1,0
  244. #
  245. # startup-code at 0x10000, running in absolute addressing mode
  246. # this is called either by the ipl loader or directly by PSW restart
  247. # or linload or SALIPL
  248. #
  249. .org 0x10000
  250. ENTRY(startup)
  251. j .Lep_startup_normal
  252. .org 0x10008
  253. #
  254. # This is a list of s390 kernel entry points. At address 0x1000f the number of
  255. # valid entry points is stored.
  256. #
  257. # IMPORTANT: Do not change this table, it is s390 kernel ABI!
  258. #
  259. .ascii "S390EP"
  260. .byte 0x00,0x01
  261. #
  262. # kdump startup-code at 0x10010, running in 64 bit absolute addressing mode
  263. #
  264. .org 0x10010
  265. ENTRY(startup_kdump)
  266. j .Lep_startup_kdump
  267. .Lep_startup_normal:
  268. mvi __LC_AR_MODE_ID,1 # set esame flag
  269. slr %r0,%r0 # set cpuid to zero
  270. lhi %r1,2 # mode 2 = esame (dump)
  271. sigp %r1,%r0,0x12 # switch to esame mode
  272. bras %r13,0f
  273. .fill 16,4,0x0
  274. 0: lmh %r0,%r15,0(%r13) # clear high-order half of gprs
  275. sam64 # switch to 64 bit addressing mode
  276. basr %r13,0 # get base
  277. .LPG0:
  278. xc 0x200(256),0x200 # partially clear lowcore
  279. xc 0x300(256),0x300
  280. xc 0xe00(256),0xe00
  281. xc 0xf00(256),0xf00
  282. lctlg %c0,%c15,0x200(%r0) # initialize control registers
  283. stck __LC_LAST_UPDATE_CLOCK
  284. spt 6f-.LPG0(%r13)
  285. mvc __LC_LAST_UPDATE_TIMER(8),6f-.LPG0(%r13)
  286. l %r15,.Lstack-.LPG0(%r13)
  287. ahi %r15,-STACK_FRAME_OVERHEAD
  288. brasl %r14,verify_facilities
  289. # For uncompressed images, continue in
  290. # arch/s390/kernel/head64.S. For compressed images, continue in
  291. # arch/s390/boot/compressed/head.S.
  292. jg startup_continue
  293. .Lstack:
  294. .long 0x8000 + (1<<(PAGE_SHIFT+THREAD_ORDER))
  295. .align 8
  296. 6: .long 0x7fffffff,0xffffffff
  297. #include "head_kdump.S"
  298. #
  299. # params at 10400 (setup.h)
  300. #
  301. .org PARMAREA
  302. .long 0,0 # IPL_DEVICE
  303. .long 0,0 # INITRD_START
  304. .long 0,0 # INITRD_SIZE
  305. .long 0,0 # OLDMEM_BASE
  306. .long 0,0 # OLDMEM_SIZE
  307. .org COMMAND_LINE
  308. .byte "root=/dev/ram0 ro"
  309. .byte 0
  310. .org 0x11000