head.S 12 KB

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