head.S 13 KB

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