head.S 12 KB

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