head.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. * CRISv32 kernel startup code.
  3. *
  4. * Copyright (C) 2003, Axis Communications AB
  5. */
  6. #include <linux/config.h>
  7. #define ASSEMBLER_MACROS_ONLY
  8. /*
  9. * The macros found in mmu_defs_asm.h uses the ## concatenation operator, so
  10. * -traditional must not be used when assembling this file.
  11. */
  12. #include <asm/arch/hwregs/reg_rdwr.h>
  13. #include <asm/arch/hwregs/asm/mmu_defs_asm.h>
  14. #include <asm/arch/hwregs/asm/reg_map_asm.h>
  15. #include <asm/arch/hwregs/asm/config_defs_asm.h>
  16. #include <asm/arch/hwregs/asm/bif_core_defs_asm.h>
  17. #define CRAMFS_MAGIC 0x28cd3d45
  18. #define RAM_INIT_MAGIC 0x56902387
  19. #define COMMAND_LINE_MAGIC 0x87109563
  20. ;; NOTE: R8 and R9 carry information from the decompressor (if the
  21. ;; kernel was compressed). They must not be used in the code below
  22. ;; until they are read!
  23. ;; Exported symbols.
  24. .global etrax_irv
  25. .global romfs_start
  26. .global romfs_length
  27. .global romfs_in_flash
  28. .global swapper_pg_dir
  29. .global crisv32_nand_boot
  30. .global crisv32_nand_cramfs_offset
  31. ;; Dummy section to make it bootable with current VCS simulator
  32. #ifdef CONFIG_ETRAXFS_SIM
  33. .section ".boot", "ax"
  34. ba tstart
  35. nop
  36. #endif
  37. .text
  38. tstart:
  39. ;; This is the entry point of the kernel. The CPU is currently in
  40. ;; supervisor mode.
  41. ;;
  42. ;; 0x00000000 if flash.
  43. ;; 0x40004000 if DRAM.
  44. ;;
  45. di
  46. ;; Start clocks for used blocks.
  47. move.d REG_ADDR(config, regi_config, rw_clk_ctrl), $r1
  48. move.d [$r1], $r0
  49. or.d REG_STATE(config, rw_clk_ctrl, cpu, yes) | \
  50. REG_STATE(config, rw_clk_ctrl, bif, yes) | \
  51. REG_STATE(config, rw_clk_ctrl, fix_io, yes), $r0
  52. move.d $r0, [$r1]
  53. ;; Set up waitstates etc
  54. move.d REG_ADDR(bif_core, regi_bif_core, rw_grp1_cfg), $r0
  55. move.d CONFIG_ETRAX_MEM_GRP1_CONFIG, $r1
  56. move.d $r1, [$r0]
  57. move.d REG_ADDR(bif_core, regi_bif_core, rw_grp2_cfg), $r0
  58. move.d CONFIG_ETRAX_MEM_GRP2_CONFIG, $r1
  59. move.d $r1, [$r0]
  60. move.d REG_ADDR(bif_core, regi_bif_core, rw_grp3_cfg), $r0
  61. move.d CONFIG_ETRAX_MEM_GRP3_CONFIG, $r1
  62. move.d $r1, [$r0]
  63. move.d REG_ADDR(bif_core, regi_bif_core, rw_grp4_cfg), $r0
  64. move.d CONFIG_ETRAX_MEM_GRP4_CONFIG, $r1
  65. move.d $r1, [$r0]
  66. #ifdef CONFIG_ETRAXFS_SIM
  67. ;; Set up minimal flash waitstates
  68. move.d 0, $r10
  69. move.d REG_ADDR(bif_core, regi_bif_core, rw_grp1_cfg), $r11
  70. move.d $r10, [$r11]
  71. #endif
  72. ;; Setup and enable the MMU. Use same configuration for both the data
  73. ;; and the instruction MMU.
  74. ;;
  75. ;; Note; 3 cycles is needed for a bank-select to take effect. Further;
  76. ;; bank 1 is the instruction MMU, bank 2 is the data MMU.
  77. #ifndef CONFIG_ETRAXFS_SIM
  78. move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \
  79. | REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 4) \
  80. | REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb), $r0
  81. #else
  82. ;; Map the virtual DRAM to the RW eprom area at address 0.
  83. ;; Also map 0xa for the hook calls,
  84. move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \
  85. | REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 0) \
  86. | REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb) \
  87. | REG_FIELD(mmu, rw_mm_kbase_hi, base_a, 0xa), $r0
  88. #endif
  89. ;; Temporary map of 0x40 -> 0x40 and 0x00 -> 0x00.
  90. move.d REG_FIELD(mmu, rw_mm_kbase_lo, base_4, 4) \
  91. | REG_FIELD(mmu, rw_mm_kbase_lo, base_0, 0), $r1
  92. ;; Enable certain page protections and setup linear mapping
  93. ;; for f,e,c,b,4,0.
  94. #ifndef CONFIG_ETRAXFS_SIM
  95. move.d REG_STATE(mmu, rw_mm_cfg, we, on) \
  96. | REG_STATE(mmu, rw_mm_cfg, acc, on) \
  97. | REG_STATE(mmu, rw_mm_cfg, ex, on) \
  98. | REG_STATE(mmu, rw_mm_cfg, inv, on) \
  99. | REG_STATE(mmu, rw_mm_cfg, seg_f, linear) \
  100. | REG_STATE(mmu, rw_mm_cfg, seg_e, linear) \
  101. | REG_STATE(mmu, rw_mm_cfg, seg_d, page) \
  102. | REG_STATE(mmu, rw_mm_cfg, seg_c, linear) \
  103. | REG_STATE(mmu, rw_mm_cfg, seg_b, linear) \
  104. | REG_STATE(mmu, rw_mm_cfg, seg_a, page) \
  105. | REG_STATE(mmu, rw_mm_cfg, seg_9, page) \
  106. | REG_STATE(mmu, rw_mm_cfg, seg_8, page) \
  107. | REG_STATE(mmu, rw_mm_cfg, seg_7, page) \
  108. | REG_STATE(mmu, rw_mm_cfg, seg_6, page) \
  109. | REG_STATE(mmu, rw_mm_cfg, seg_5, page) \
  110. | REG_STATE(mmu, rw_mm_cfg, seg_4, linear) \
  111. | REG_STATE(mmu, rw_mm_cfg, seg_3, page) \
  112. | REG_STATE(mmu, rw_mm_cfg, seg_2, page) \
  113. | REG_STATE(mmu, rw_mm_cfg, seg_1, page) \
  114. | REG_STATE(mmu, rw_mm_cfg, seg_0, linear), $r2
  115. #else
  116. move.d REG_STATE(mmu, rw_mm_cfg, we, on) \
  117. | REG_STATE(mmu, rw_mm_cfg, acc, on) \
  118. | REG_STATE(mmu, rw_mm_cfg, ex, on) \
  119. | REG_STATE(mmu, rw_mm_cfg, inv, on) \
  120. | REG_STATE(mmu, rw_mm_cfg, seg_f, linear) \
  121. | REG_STATE(mmu, rw_mm_cfg, seg_e, linear) \
  122. | REG_STATE(mmu, rw_mm_cfg, seg_d, page) \
  123. | REG_STATE(mmu, rw_mm_cfg, seg_c, linear) \
  124. | REG_STATE(mmu, rw_mm_cfg, seg_b, linear) \
  125. | REG_STATE(mmu, rw_mm_cfg, seg_a, linear) \
  126. | REG_STATE(mmu, rw_mm_cfg, seg_9, page) \
  127. | REG_STATE(mmu, rw_mm_cfg, seg_8, page) \
  128. | REG_STATE(mmu, rw_mm_cfg, seg_7, page) \
  129. | REG_STATE(mmu, rw_mm_cfg, seg_6, page) \
  130. | REG_STATE(mmu, rw_mm_cfg, seg_5, page) \
  131. | REG_STATE(mmu, rw_mm_cfg, seg_4, linear) \
  132. | REG_STATE(mmu, rw_mm_cfg, seg_3, page) \
  133. | REG_STATE(mmu, rw_mm_cfg, seg_2, page) \
  134. | REG_STATE(mmu, rw_mm_cfg, seg_1, page) \
  135. | REG_STATE(mmu, rw_mm_cfg, seg_0, linear), $r2
  136. #endif
  137. ;; Update instruction MMU.
  138. move 1, $srs
  139. nop
  140. nop
  141. nop
  142. move $r0, $s2 ; kbase_hi.
  143. move $r1, $s1 ; kbase_lo.
  144. move $r2, $s0 ; mm_cfg, virtual memory configuration.
  145. ;; Update data MMU.
  146. move 2, $srs
  147. nop
  148. nop
  149. nop
  150. move $r0, $s2 ; kbase_hi.
  151. move $r1, $s1 ; kbase_lo
  152. move $r2, $s0 ; mm_cfg, virtual memory configuration.
  153. ;; Enable data and instruction MMU.
  154. move 0, $srs
  155. moveq 0xf, $r0 ; IMMU, DMMU, DCache, Icache on
  156. nop
  157. nop
  158. nop
  159. move $r0, $s0
  160. nop
  161. nop
  162. nop
  163. #ifdef CONFIG_SMP
  164. ;; Read CPU ID
  165. move 0, $srs
  166. nop
  167. nop
  168. nop
  169. move $s10, $r0
  170. cmpq 0, $r0
  171. beq master_cpu
  172. nop
  173. slave_cpu:
  174. ; A slave waits for cpu_now_booting to be equal to CPU ID.
  175. move.d cpu_now_booting, $r1
  176. slave_wait:
  177. cmp.d [$r1], $r0
  178. bne slave_wait
  179. nop
  180. ; Time to boot-up. Get stack location provided by master CPU.
  181. move.d smp_init_current_idle_thread, $r1
  182. move.d [$r1], $sp
  183. add.d 8192, $sp
  184. move.d ebp_start, $r0 ; Defined in linker-script.
  185. move $r0, $ebp
  186. jsr smp_callin
  187. nop
  188. master_cpu:
  189. #endif
  190. #ifndef CONFIG_ETRAXFS_SIM
  191. ;; Check if starting from DRAM or flash.
  192. lapcq ., $r0
  193. and.d 0x7fffffff, $r0 ; Mask off the non-cache bit.
  194. cmp.d 0x10000, $r0 ; Arbitrary, something above this code.
  195. blo _inflash0
  196. nop
  197. #endif
  198. jump _inram ; Jump to cached RAM.
  199. nop
  200. ;; Jumpgate.
  201. _inflash0:
  202. jump _inflash
  203. nop
  204. ;; Put the following in a section so that storage for it can be
  205. ;; reclaimed after init is finished.
  206. .section ".init.text", "ax"
  207. _inflash:
  208. ;; Initialize DRAM.
  209. cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?
  210. beq _dram_initialized
  211. nop
  212. #include "../lib/dram_init.S"
  213. _dram_initialized:
  214. ;; Copy the text and data section to DRAM. This depends on that the
  215. ;; variables used below are correctly set up by the linker script.
  216. ;; The calculated value stored in R4 is used below.
  217. moveq 0, $r0 ; Source.
  218. move.d text_start, $r1 ; Destination.
  219. move.d __vmlinux_end, $r2
  220. move.d $r2, $r4
  221. sub.d $r1, $r4
  222. 1: move.w [$r0+], $r3
  223. move.w $r3, [$r1+]
  224. cmp.d $r2, $r1
  225. blo 1b
  226. nop
  227. ;; Keep CRAMFS in flash.
  228. moveq 0, $r0
  229. move.d romfs_length, $r1
  230. move.d $r0, [$r1]
  231. move.d [$r4], $r0 ; cramfs_super.magic
  232. cmp.d CRAMFS_MAGIC, $r0
  233. bne 1f
  234. nop
  235. addoq +4, $r4, $acr
  236. move.d [$acr], $r0
  237. move.d romfs_length, $r1
  238. move.d $r0, [$r1]
  239. add.d 0xf0000000, $r4 ; Add cached flash start in virtual memory.
  240. move.d romfs_start, $r1
  241. move.d $r4, [$r1]
  242. 1: moveq 1, $r0
  243. move.d romfs_in_flash, $r1
  244. move.d $r0, [$r1]
  245. jump _start_it ; Jump to cached code.
  246. nop
  247. _inram:
  248. ;; Check if booting from NAND flash (in that case we just remember the offset
  249. ;; into the flash where cramfs should be).
  250. move.d REG_ADDR(config, regi_config, r_bootsel), $r0
  251. move.d [$r0], $r0
  252. and.d REG_MASK(config, r_bootsel, boot_mode), $r0
  253. cmp.d REG_STATE(config, r_bootsel, boot_mode, nand), $r0
  254. bne move_cramfs
  255. moveq 1,$r0
  256. move.d crisv32_nand_boot, $r1
  257. move.d $r0, [$r1]
  258. move.d crisv32_nand_cramfs_offset, $r1
  259. move.d $r9, [$r1]
  260. moveq 1, $r0
  261. move.d romfs_in_flash, $r1
  262. move.d $r0, [$r1]
  263. jump _start_it
  264. nop
  265. move_cramfs:
  266. ;; Move the cramfs after BSS.
  267. moveq 0, $r0
  268. move.d romfs_length, $r1
  269. move.d $r0, [$r1]
  270. #ifndef CONFIG_ETRAXFS_SIM
  271. ;; The kernel could have been unpacked to DRAM by the loader, but
  272. ;; the cramfs image could still be inte the flash immediately
  273. ;; following the compressed kernel image. The loaded passes the address
  274. ;; of the bute succeeding the last compressed byte in the flash in
  275. ;; register R9 when starting the kernel.
  276. cmp.d 0x0ffffff8, $r9
  277. bhs _no_romfs_in_flash ; R9 points outside the flash area.
  278. nop
  279. #else
  280. ba _no_romfs_in_flash
  281. nop
  282. #endif
  283. move.d [$r9], $r0 ; cramfs_super.magic
  284. cmp.d CRAMFS_MAGIC, $r0
  285. bne _no_romfs_in_flash
  286. nop
  287. addoq +4, $r9, $acr
  288. move.d [$acr], $r0
  289. move.d romfs_length, $r1
  290. move.d $r0, [$r1]
  291. add.d 0xf0000000, $r9 ; Add cached flash start in virtual memory.
  292. move.d romfs_start, $r1
  293. move.d $r9, [$r1]
  294. moveq 1, $r0
  295. move.d romfs_in_flash, $r1
  296. move.d $r0, [$r1]
  297. jump _start_it ; Jump to cached code.
  298. nop
  299. _no_romfs_in_flash:
  300. ;; Look for cramfs.
  301. #ifndef CONFIG_ETRAXFS_SIM
  302. move.d __vmlinux_end, $r0
  303. #else
  304. move.d __end, $r0
  305. #endif
  306. move.d [$r0], $r1
  307. cmp.d CRAMFS_MAGIC, $r1
  308. bne 2f
  309. nop
  310. addoq +4, $r0, $acr
  311. move.d [$acr], $r2
  312. move.d _end, $r1
  313. move.d romfs_start, $r3
  314. move.d $r1, [$r3]
  315. move.d romfs_length, $r3
  316. move.d $r2, [$r3]
  317. #ifndef CONFIG_ETRAXFS_SIM
  318. add.d $r2, $r0
  319. add.d $r2, $r1
  320. lsrq 1, $r2 ; Size is in bytes, we copy words.
  321. addq 1, $r2
  322. 1:
  323. move.w [$r0], $r3
  324. move.w $r3, [$r1]
  325. subq 2, $r0
  326. subq 2, $r1
  327. subq 1, $r2
  328. bne 1b
  329. nop
  330. #endif
  331. 2:
  332. moveq 0, $r0
  333. move.d romfs_in_flash, $r1
  334. move.d $r0, [$r1]
  335. jump _start_it ; Jump to cached code.
  336. nop
  337. _start_it:
  338. ;; Check if kernel command line is supplied
  339. cmp.d COMMAND_LINE_MAGIC, $r10
  340. bne no_command_line
  341. nop
  342. move.d 256, $r13
  343. move.d cris_command_line, $r10
  344. or.d 0x80000000, $r11 ; Make it virtual
  345. 1:
  346. move.b [$r11+], $r12
  347. move.b $r12, [$r10+]
  348. subq 1, $r13
  349. bne 1b
  350. nop
  351. no_command_line:
  352. ;; The kernel stack contains a task structure for each task. This
  353. ;; the initial kernel stack is in the same page as the init_task,
  354. ;; but starts at the top of the page, i.e. + 8192 bytes.
  355. move.d init_thread_union + 8192, $sp
  356. move.d ebp_start, $r0 ; Defined in linker-script.
  357. move $r0, $ebp
  358. move.d etrax_irv, $r1 ; Set the exception base register and pointer.
  359. move.d $r0, [$r1]
  360. #ifndef CONFIG_ETRAXFS_SIM
  361. ;; Clear the BSS region from _bss_start to _end.
  362. move.d __bss_start, $r0
  363. move.d _end, $r1
  364. 1: clear.d [$r0+]
  365. cmp.d $r1, $r0
  366. blo 1b
  367. nop
  368. #endif
  369. #ifdef CONFIG_ETRAXFS_SIM
  370. /* Set the watchdog timeout to something big. Will be removed when */
  371. /* watchdog can be disabled with command line option */
  372. move.d 0x7fffffff, $r10
  373. jsr CPU_WATCHDOG_TIMEOUT
  374. nop
  375. #endif
  376. ; Initialize registers to increase determinism
  377. move.d __bss_start, $r0
  378. movem [$r0], $r13
  379. jump start_kernel ; Jump to start_kernel() in init/main.c.
  380. nop
  381. .data
  382. etrax_irv:
  383. .dword 0
  384. romfs_start:
  385. .dword 0
  386. romfs_length:
  387. .dword 0
  388. romfs_in_flash:
  389. .dword 0
  390. crisv32_nand_boot:
  391. .dword 0
  392. crisv32_nand_cramfs_offset:
  393. .dword 0
  394. swapper_pg_dir = 0xc0002000
  395. .section ".init.data", "aw"
  396. #include "../lib/hw_settings.S"