head.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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 <arch/memmap.h>
  12. #include <hwregs/reg_rdwr.h>
  13. #include <hwregs/intr_vect.h>
  14. #include <hwregs/asm/mmu_defs_asm.h>
  15. #include <hwregs/asm/reg_map_asm.h>
  16. #include <mach/startup.inc>
  17. #define CRAMFS_MAGIC 0x28cd3d45
  18. #define JHEAD_MAGIC 0x1FF528A6
  19. #define JHEAD_SIZE 8
  20. #define RAM_INIT_MAGIC 0x56902387
  21. #define COMMAND_LINE_MAGIC 0x87109563
  22. #define NAND_BOOT_MAGIC 0x9a9db001
  23. ;; NOTE: R8 and R9 carry information from the decompressor (if the
  24. ;; kernel was compressed). They must not be used in the code below
  25. ;; until they are read!
  26. ;; Exported symbols.
  27. .global etrax_irv
  28. .global romfs_start
  29. .global romfs_length
  30. .global romfs_in_flash
  31. .global nand_boot
  32. .global swapper_pg_dir
  33. ;; Dummy section to make it bootable with current VCS simulator
  34. #ifdef CONFIG_ETRAX_VCS_SIM
  35. .section ".boot", "ax"
  36. ba tstart
  37. nop
  38. #endif
  39. .text
  40. tstart:
  41. ;; This is the entry point of the kernel. The CPU is currently in
  42. ;; supervisor mode.
  43. ;;
  44. ;; 0x00000000 if flash.
  45. ;; 0x40004000 if DRAM.
  46. ;;
  47. di
  48. START_CLOCKS
  49. SETUP_WAIT_STATES
  50. GIO_INIT
  51. #ifdef CONFIG_SMP
  52. secondary_cpu_entry: /* Entry point for secondary CPUs */
  53. di
  54. #endif
  55. ;; Setup and enable the MMU. Use same configuration for both the data
  56. ;; and the instruction MMU.
  57. ;;
  58. ;; Note; 3 cycles is needed for a bank-select to take effect. Further;
  59. ;; bank 1 is the instruction MMU, bank 2 is the data MMU.
  60. #ifndef CONFIG_ETRAX_VCS_SIM
  61. move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \
  62. | REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 4) \
  63. | REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb), $r0
  64. #else
  65. ;; Map the virtual DRAM to the RW eprom area at address 0.
  66. ;; Also map 0xa for the hook calls,
  67. move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \
  68. | REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 4) \
  69. | REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb) \
  70. | REG_FIELD(mmu, rw_mm_kbase_hi, base_a, 0xa), $r0
  71. #endif
  72. ;; Temporary map of 0x40 -> 0x40 and 0x00 -> 0x00.
  73. move.d REG_FIELD(mmu, rw_mm_kbase_lo, base_4, 4) \
  74. | REG_FIELD(mmu, rw_mm_kbase_lo, base_0, 0), $r1
  75. ;; Enable certain page protections and setup linear mapping
  76. ;; for f,e,c,b,4,0.
  77. #ifndef CONFIG_ETRAX_VCS_SIM
  78. move.d REG_STATE(mmu, rw_mm_cfg, we, on) \
  79. | REG_STATE(mmu, rw_mm_cfg, acc, on) \
  80. | REG_STATE(mmu, rw_mm_cfg, ex, on) \
  81. | REG_STATE(mmu, rw_mm_cfg, inv, on) \
  82. | REG_STATE(mmu, rw_mm_cfg, seg_f, linear) \
  83. | REG_STATE(mmu, rw_mm_cfg, seg_e, linear) \
  84. | REG_STATE(mmu, rw_mm_cfg, seg_d, page) \
  85. | REG_STATE(mmu, rw_mm_cfg, seg_c, linear) \
  86. | REG_STATE(mmu, rw_mm_cfg, seg_b, linear) \
  87. | REG_STATE(mmu, rw_mm_cfg, seg_a, page) \
  88. | REG_STATE(mmu, rw_mm_cfg, seg_9, page) \
  89. | REG_STATE(mmu, rw_mm_cfg, seg_8, page) \
  90. | REG_STATE(mmu, rw_mm_cfg, seg_7, page) \
  91. | REG_STATE(mmu, rw_mm_cfg, seg_6, page) \
  92. | REG_STATE(mmu, rw_mm_cfg, seg_5, page) \
  93. | REG_STATE(mmu, rw_mm_cfg, seg_4, linear) \
  94. | REG_STATE(mmu, rw_mm_cfg, seg_3, page) \
  95. | REG_STATE(mmu, rw_mm_cfg, seg_2, page) \
  96. | REG_STATE(mmu, rw_mm_cfg, seg_1, page) \
  97. | REG_STATE(mmu, rw_mm_cfg, seg_0, linear), $r2
  98. #else
  99. move.d REG_STATE(mmu, rw_mm_cfg, we, on) \
  100. | REG_STATE(mmu, rw_mm_cfg, acc, on) \
  101. | REG_STATE(mmu, rw_mm_cfg, ex, on) \
  102. | REG_STATE(mmu, rw_mm_cfg, inv, on) \
  103. | REG_STATE(mmu, rw_mm_cfg, seg_f, linear) \
  104. | REG_STATE(mmu, rw_mm_cfg, seg_e, linear) \
  105. | REG_STATE(mmu, rw_mm_cfg, seg_d, page) \
  106. | REG_STATE(mmu, rw_mm_cfg, seg_c, linear) \
  107. | REG_STATE(mmu, rw_mm_cfg, seg_b, linear) \
  108. | REG_STATE(mmu, rw_mm_cfg, seg_a, linear) \
  109. | REG_STATE(mmu, rw_mm_cfg, seg_9, page) \
  110. | REG_STATE(mmu, rw_mm_cfg, seg_8, page) \
  111. | REG_STATE(mmu, rw_mm_cfg, seg_7, page) \
  112. | REG_STATE(mmu, rw_mm_cfg, seg_6, page) \
  113. | REG_STATE(mmu, rw_mm_cfg, seg_5, page) \
  114. | REG_STATE(mmu, rw_mm_cfg, seg_4, linear) \
  115. | REG_STATE(mmu, rw_mm_cfg, seg_3, page) \
  116. | REG_STATE(mmu, rw_mm_cfg, seg_2, page) \
  117. | REG_STATE(mmu, rw_mm_cfg, seg_1, page) \
  118. | REG_STATE(mmu, rw_mm_cfg, seg_0, linear), $r2
  119. #endif
  120. ;; Update instruction MMU.
  121. move 1, $srs
  122. nop
  123. nop
  124. nop
  125. move $r0, $s2 ; kbase_hi.
  126. move $r1, $s1 ; kbase_lo.
  127. move $r2, $s0 ; mm_cfg, virtual memory configuration.
  128. ;; Update data MMU.
  129. move 2, $srs
  130. nop
  131. nop
  132. nop
  133. move $r0, $s2 ; kbase_hi.
  134. move $r1, $s1 ; kbase_lo
  135. move $r2, $s0 ; mm_cfg, virtual memory configuration.
  136. ;; Enable data and instruction MMU.
  137. move 0, $srs
  138. moveq 0xf, $r0 ; IMMU, DMMU, DCache, Icache on
  139. nop
  140. nop
  141. nop
  142. move $r0, $s0
  143. nop
  144. nop
  145. nop
  146. #ifdef CONFIG_SMP
  147. ;; Read CPU ID
  148. move 0, $srs
  149. nop
  150. nop
  151. nop
  152. move $s12, $r0
  153. cmpq 0, $r0
  154. beq master_cpu
  155. nop
  156. slave_cpu:
  157. ; Time to boot-up. Get stack location provided by master CPU.
  158. move.d smp_init_current_idle_thread, $r1
  159. move.d [$r1], $sp
  160. add.d 8192, $sp
  161. move.d ebp_start, $r0 ; Defined in linker-script.
  162. move $r0, $ebp
  163. jsr smp_callin
  164. nop
  165. master_cpu:
  166. /* Set up entry point for secondary CPUs. The boot ROM has set up
  167. * EBP at start of internal memory. The CPU will get there
  168. * later when we issue an IPI to them... */
  169. move.d MEM_INTMEM_START + IPI_INTR_VECT * 4, $r0
  170. move.d secondary_cpu_entry, $r1
  171. move.d $r1, [$r0]
  172. #endif
  173. #ifndef CONFIG_ETRAX_VCS_SIM
  174. ; Check if starting from DRAM (network->RAM boot or unpacked
  175. ; compressed kernel), or directly from flash.
  176. lapcq ., $r0
  177. and.d 0x7fffffff, $r0 ; Mask off the non-cache bit.
  178. cmp.d 0x10000, $r0 ; Arbitrary, something above this code.
  179. blo _inflash0
  180. nop
  181. #endif
  182. jump _inram ; Jump to cached RAM.
  183. nop
  184. ;; Jumpgate.
  185. _inflash0:
  186. jump _inflash
  187. nop
  188. ;; Put the following in a section so that storage for it can be
  189. ;; reclaimed after init is finished.
  190. .section ".init.text", "ax"
  191. _inflash:
  192. ;; Initialize DRAM.
  193. cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?
  194. beq _dram_initialized
  195. nop
  196. #if defined CONFIG_ETRAXFS
  197. #include "../mach-fs/dram_init.S"
  198. #elif defined CONFIG_CRIS_MACH_ARTPEC3
  199. #include "../mach-a3/dram_init.S"
  200. #else
  201. #error Only ETRAXFS and ARTPEC-3 supported!
  202. #endif
  203. _dram_initialized:
  204. ;; Copy the text and data section to DRAM. This depends on that the
  205. ;; variables used below are correctly set up by the linker script.
  206. ;; The calculated value stored in R4 is used below.
  207. ;; Leave the cramfs file system (piggybacked after the kernel) in flash.
  208. moveq 0, $r0 ; Source.
  209. move.d text_start, $r1 ; Destination.
  210. move.d __vmlinux_end, $r2
  211. move.d $r2, $r4
  212. sub.d $r1, $r4
  213. 1: move.w [$r0+], $r3
  214. move.w $r3, [$r1+]
  215. cmp.d $r2, $r1
  216. blo 1b
  217. nop
  218. ;; Check for cramfs.
  219. moveq 0, $r0
  220. move.d romfs_length, $r1
  221. move.d $r0, [$r1]
  222. move.d [$r4], $r0 ; cramfs_super.magic
  223. cmp.d CRAMFS_MAGIC, $r0
  224. bne 1f
  225. nop
  226. ;; Set length and start of cramfs, set romfs_in_flash flag
  227. addoq +4, $r4, $acr
  228. move.d [$acr], $r0
  229. move.d romfs_length, $r1
  230. move.d $r0, [$r1]
  231. add.d 0xf0000000, $r4 ; Add cached flash start in virtual memory.
  232. move.d romfs_start, $r1
  233. move.d $r4, [$r1]
  234. 1: moveq 1, $r0
  235. move.d romfs_in_flash, $r1
  236. move.d $r0, [$r1]
  237. jump _start_it ; Jump to cached code.
  238. nop
  239. _inram:
  240. ;; Check if booting from NAND flash; if so, set appropriate flags
  241. ;; and move on.
  242. cmp.d NAND_BOOT_MAGIC, $r12
  243. bne move_cramfs ; not nand, jump
  244. moveq 1, $r0
  245. move.d nand_boot, $r1 ; tell axisflashmap we're booting from NAND
  246. move.d $r0, [$r1]
  247. moveq 0, $r0 ; tell axisflashmap romfs is not in
  248. move.d romfs_in_flash, $r1 ; (directly accessed) flash
  249. move.d $r0, [$r1]
  250. jump _start_it ; continue with boot
  251. nop
  252. move_cramfs:
  253. ;; kernel is in DRAM.
  254. ;; Must figure out if there is a piggybacked rootfs image or not.
  255. ;; Set romfs_length to 0 => no rootfs image available by default.
  256. moveq 0, $r0
  257. move.d romfs_length, $r1
  258. move.d $r0, [$r1]
  259. #ifndef CONFIG_ETRAX_VCS_SIM
  260. ;; The kernel could have been unpacked to DRAM by the loader, but
  261. ;; the cramfs image could still be in the flash immediately
  262. ;; following the compressed kernel image. The loader passes the address
  263. ;; of the byte succeeding the last compressed byte in the flash in
  264. ;; register R9 when starting the kernel.
  265. cmp.d 0x0ffffff8, $r9
  266. bhs _no_romfs_in_flash ; R9 points outside the flash area.
  267. nop
  268. #else
  269. ba _no_romfs_in_flash
  270. nop
  271. #endif
  272. ;; cramfs rootfs might to be in flash. Check for it.
  273. move.d [$r9], $r0 ; cramfs_super.magic
  274. cmp.d CRAMFS_MAGIC, $r0
  275. bne _no_romfs_in_flash
  276. nop
  277. ;; found cramfs in flash. set address and size, and romfs_in_flash flag.
  278. addoq +4, $r9, $acr
  279. move.d [$acr], $r0
  280. move.d romfs_length, $r1
  281. move.d $r0, [$r1]
  282. add.d 0xf0000000, $r9 ; Add cached flash start in virtual memory.
  283. move.d romfs_start, $r1
  284. move.d $r9, [$r1]
  285. moveq 1, $r0
  286. move.d romfs_in_flash, $r1
  287. move.d $r0, [$r1]
  288. jump _start_it ; Jump to cached code.
  289. nop
  290. _no_romfs_in_flash:
  291. ;; No romfs in flash, so look for cramfs, or jffs2 with jhead,
  292. ;; after kernel in RAM, as is the case with network->RAM boot.
  293. ;; For cramfs, partition starts with magic and length.
  294. ;; For jffs2, a jhead is prepended which contains with magic and length.
  295. ;; The jhead is not part of the jffs2 partition however.
  296. #ifndef CONFIG_ETRAXFS_SIM
  297. move.d __vmlinux_end, $r0
  298. #else
  299. move.d __end, $r0
  300. #endif
  301. move.d [$r0], $r1
  302. cmp.d CRAMFS_MAGIC, $r1 ; cramfs magic?
  303. beq 2f ; yes, jump
  304. nop
  305. cmp.d JHEAD_MAGIC, $r1 ; jffs2 (jhead) magic?
  306. bne 4f ; no, skip copy
  307. nop
  308. addq 4, $r0 ; location of jffs2 size
  309. move.d [$r0+], $r2 ; fetch jffs2 size -> r2
  310. ; r0 now points to start of jffs2
  311. ba 3f
  312. nop
  313. 2:
  314. addoq +4, $r0, $acr ; location of cramfs size
  315. move.d [$acr], $r2 ; fetch cramfs size -> r2
  316. ; r0 still points to start of cramfs
  317. 3:
  318. ;; Now, move the root fs to after kernel's BSS
  319. move.d _end, $r1 ; start of cramfs -> r1
  320. move.d romfs_start, $r3
  321. move.d $r1, [$r3] ; store at romfs_start (for axisflashmap)
  322. move.d romfs_length, $r3
  323. move.d $r2, [$r3] ; store size at romfs_length
  324. #ifndef CONFIG_ETRAX_VCS_SIM
  325. add.d $r2, $r0 ; copy from end and downwards
  326. add.d $r2, $r1
  327. lsrq 1, $r2 ; Size is in bytes, we copy words.
  328. addq 1, $r2
  329. 1:
  330. move.w [$r0], $r3
  331. move.w $r3, [$r1]
  332. subq 2, $r0
  333. subq 2, $r1
  334. subq 1, $r2
  335. bne 1b
  336. nop
  337. #endif
  338. 4:
  339. ;; BSS move done.
  340. ;; Clear romfs_in_flash flag, as we now know romfs is in DRAM
  341. ;; Also clear nand_boot flag; if we got here, we know we've not
  342. ;; booted from NAND flash.
  343. moveq 0, $r0
  344. move.d romfs_in_flash, $r1
  345. move.d $r0, [$r1]
  346. moveq 0, $r0
  347. move.d nand_boot, $r1
  348. move.d $r0, [$r1]
  349. jump _start_it ; Jump to cached code.
  350. nop
  351. _start_it:
  352. ;; Check if kernel command line is supplied
  353. cmp.d COMMAND_LINE_MAGIC, $r10
  354. bne no_command_line
  355. nop
  356. move.d 256, $r13
  357. move.d cris_command_line, $r10
  358. or.d 0x80000000, $r11 ; Make it virtual
  359. 1:
  360. move.b [$r11+], $r1
  361. move.b $r1, [$r10+]
  362. subq 1, $r13
  363. bne 1b
  364. nop
  365. no_command_line:
  366. ;; The kernel stack contains a task structure for each task. This
  367. ;; the initial kernel stack is in the same page as the init_task,
  368. ;; but starts at the top of the page, i.e. + 8192 bytes.
  369. move.d init_thread_union + 8192, $sp
  370. move.d ebp_start, $r0 ; Defined in linker-script.
  371. move $r0, $ebp
  372. move.d etrax_irv, $r1 ; Set the exception base register and pointer.
  373. move.d $r0, [$r1]
  374. #ifndef CONFIG_ETRAX_VCS_SIM
  375. ;; Clear the BSS region from _bss_start to _end.
  376. move.d __bss_start, $r0
  377. move.d _end, $r1
  378. 1: clear.d [$r0+]
  379. cmp.d $r1, $r0
  380. blo 1b
  381. nop
  382. #endif
  383. #ifdef CONFIG_ETRAX_VCS_SIM
  384. /* Set the watchdog timeout to something big. Will be removed when */
  385. /* watchdog can be disabled with command line option */
  386. move.d 0x7fffffff, $r10
  387. jsr CPU_WATCHDOG_TIMEOUT
  388. nop
  389. #endif
  390. ; Initialize registers to increase determinism
  391. move.d __bss_start, $r0
  392. movem [$r0], $r13
  393. #ifdef CONFIG_ETRAX_L2CACHE
  394. jsr l2cache_init
  395. nop
  396. #endif
  397. jump start_kernel ; Jump to start_kernel() in init/main.c.
  398. nop
  399. .data
  400. etrax_irv:
  401. .dword 0
  402. ; Variables for communication with the Axis flash map driver (axisflashmap),
  403. ; and for setting up memory in arch/cris/kernel/setup.c .
  404. ; romfs_start is set to the start of the root file system, if it exists
  405. ; in directly accessible memory (i.e. NOR Flash when booting from Flash,
  406. ; or RAM when booting directly from a network-downloaded RAM image)
  407. romfs_start:
  408. .dword 0
  409. ; romfs_length is set to the size of the root file system image, if it exists
  410. ; in directly accessible memory (see romfs_start). Otherwise it is set to 0.
  411. romfs_length:
  412. .dword 0
  413. ; romfs_in_flash is set to 1 if the root file system resides in directly
  414. ; accessible flash memory (i.e. NOR flash). It is set to 0 for RAM boot
  415. ; or NAND flash boot.
  416. romfs_in_flash:
  417. .dword 0
  418. ; nand_boot is set to 1 when the kernel has been booted from NAND flash
  419. nand_boot:
  420. .dword 0
  421. swapper_pg_dir = 0xc0002000
  422. .section ".init.data", "aw"
  423. #if defined CONFIG_ETRAXFS
  424. #include "../mach-fs/hw_settings.S"
  425. #elif defined CONFIG_CRIS_MACH_ARTPEC3
  426. #include "../mach-a3/hw_settings.S"
  427. #else
  428. #error Only ETRAXFS and ARTPEC-3 supported!
  429. #endif