head.S 11 KB

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