head.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. #ifdef CONFIG_SMP
  46. secondary_cpu_entry: /* Entry point for secondary CPUs */
  47. di
  48. #endif
  49. ;; Setup and enable the MMU. Use same configuration for both the data
  50. ;; and the instruction MMU.
  51. ;;
  52. ;; Note; 3 cycles is needed for a bank-select to take effect. Further;
  53. ;; bank 1 is the instruction MMU, bank 2 is the data MMU.
  54. #ifdef CONFIG_CRIS_MACH_ARTPEC3
  55. move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \
  56. | REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 4) \
  57. | REG_FIELD(mmu, rw_mm_kbase_hi, base_d, 5) \
  58. | REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb), $r0
  59. #else
  60. move.d REG_FIELD(mmu, rw_mm_kbase_hi, base_e, 8) \
  61. | REG_FIELD(mmu, rw_mm_kbase_hi, base_c, 4) \
  62. | REG_FIELD(mmu, rw_mm_kbase_hi, base_b, 0xb), $r0
  63. #endif
  64. ;; Temporary map of 0x40 -> 0x40 and 0x00 -> 0x00.
  65. move.d REG_FIELD(mmu, rw_mm_kbase_lo, base_4, 4) \
  66. | REG_FIELD(mmu, rw_mm_kbase_lo, base_0, 0), $r1
  67. ;; Enable certain page protections and setup linear mapping
  68. ;; for f,e,c,b,4,0.
  69. ;; ARTPEC-3:
  70. ;; c,d used for linear kernel mapping, up to 512 MB
  71. ;; e used for vmalloc
  72. ;; f unused, but page mapped to get page faults
  73. ;; ETRAX FS:
  74. ;; c used for linear kernel mapping, up to 256 MB
  75. ;; d used for vmalloc
  76. ;; e,f used for memory-mapped NOR flash
  77. #ifdef CONFIG_CRIS_MACH_ARTPEC3
  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, page) \
  83. | REG_STATE(mmu, rw_mm_cfg, seg_e, page) \
  84. | REG_STATE(mmu, rw_mm_cfg, seg_d, linear) \
  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, page) \
  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. ; Check if starting from DRAM (network->RAM boot or unpacked
  174. ; compressed kernel), or directly from flash.
  175. lapcq ., $r0
  176. and.d 0x7fffffff, $r0 ; Mask off the non-cache bit.
  177. cmp.d 0x10000, $r0 ; Arbitrary, something above this code.
  178. blo _inflash0
  179. nop
  180. jump _inram ; Jump to cached RAM.
  181. nop
  182. ;; Jumpgate.
  183. _inflash0:
  184. jump _inflash
  185. nop
  186. ;; Put the following in a section so that storage for it can be
  187. ;; reclaimed after init is finished.
  188. .section ".init.text", "ax"
  189. _inflash:
  190. ;; Initialize DRAM.
  191. cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?
  192. beq _dram_initialized
  193. nop
  194. #if defined CONFIG_ETRAXFS
  195. #include "../mach-fs/dram_init.S"
  196. #elif defined CONFIG_CRIS_MACH_ARTPEC3
  197. #include "../mach-a3/dram_init.S"
  198. #else
  199. #error Only ETRAXFS and ARTPEC-3 supported!
  200. #endif
  201. _dram_initialized:
  202. ;; Copy the text and data section to DRAM. This depends on that the
  203. ;; variables used below are correctly set up by the linker script.
  204. ;; The calculated value stored in R4 is used below.
  205. ;; Leave the cramfs file system (piggybacked after the kernel) in flash.
  206. moveq 0, $r0 ; Source.
  207. move.d text_start, $r1 ; Destination.
  208. move.d __vmlinux_end, $r2
  209. move.d $r2, $r4
  210. sub.d $r1, $r4
  211. 1: move.w [$r0+], $r3
  212. move.w $r3, [$r1+]
  213. cmp.d $r2, $r1
  214. blo 1b
  215. nop
  216. ;; Check for cramfs.
  217. moveq 0, $r0
  218. move.d romfs_length, $r1
  219. move.d $r0, [$r1]
  220. move.d [$r4], $r0 ; cramfs_super.magic
  221. cmp.d CRAMFS_MAGIC, $r0
  222. bne 1f
  223. nop
  224. ;; Set length and start of cramfs, set romfs_in_flash flag
  225. addoq +4, $r4, $acr
  226. move.d [$acr], $r0
  227. move.d romfs_length, $r1
  228. move.d $r0, [$r1]
  229. add.d 0xf0000000, $r4 ; Add cached flash start in virtual memory.
  230. move.d romfs_start, $r1
  231. move.d $r4, [$r1]
  232. 1: moveq 1, $r0
  233. move.d romfs_in_flash, $r1
  234. move.d $r0, [$r1]
  235. jump _start_it ; Jump to cached code.
  236. nop
  237. _inram:
  238. ;; Check if booting from NAND flash; if so, set appropriate flags
  239. ;; and move on.
  240. cmp.d NAND_BOOT_MAGIC, $r12
  241. bne move_cramfs ; not nand, jump
  242. moveq 1, $r0
  243. move.d nand_boot, $r1 ; tell axisflashmap we're booting from NAND
  244. move.d $r0, [$r1]
  245. moveq 0, $r0 ; tell axisflashmap romfs is not in
  246. move.d romfs_in_flash, $r1 ; (directly accessed) flash
  247. move.d $r0, [$r1]
  248. jump _start_it ; continue with boot
  249. nop
  250. move_cramfs:
  251. ;; kernel is in DRAM.
  252. ;; Must figure out if there is a piggybacked rootfs image or not.
  253. ;; Set romfs_length to 0 => no rootfs image available by default.
  254. moveq 0, $r0
  255. move.d romfs_length, $r1
  256. move.d $r0, [$r1]
  257. ;; The kernel could have been unpacked to DRAM by the loader, but
  258. ;; the cramfs image could still be in the flash immediately
  259. ;; following the compressed kernel image. The loader passes the address
  260. ;; of the byte succeeding the last compressed byte in the flash in
  261. ;; register R9 when starting the kernel.
  262. cmp.d 0x0ffffff8, $r9
  263. bhs _no_romfs_in_flash ; R9 points outside the flash area.
  264. nop
  265. ;; cramfs rootfs might to be in flash. Check for it.
  266. move.d [$r9], $r0 ; cramfs_super.magic
  267. cmp.d CRAMFS_MAGIC, $r0
  268. bne _no_romfs_in_flash
  269. nop
  270. ;; found cramfs in flash. set address and size, and romfs_in_flash flag.
  271. addoq +4, $r9, $acr
  272. move.d [$acr], $r0
  273. move.d romfs_length, $r1
  274. move.d $r0, [$r1]
  275. add.d 0xf0000000, $r9 ; Add cached flash start in virtual memory.
  276. move.d romfs_start, $r1
  277. move.d $r9, [$r1]
  278. moveq 1, $r0
  279. move.d romfs_in_flash, $r1
  280. move.d $r0, [$r1]
  281. jump _start_it ; Jump to cached code.
  282. nop
  283. _no_romfs_in_flash:
  284. ;; No romfs in flash, so look for cramfs, or jffs2 with jhead,
  285. ;; after kernel in RAM, as is the case with network->RAM boot.
  286. ;; For cramfs, partition starts with magic and length.
  287. ;; For jffs2, a jhead is prepended which contains with magic and length.
  288. ;; The jhead is not part of the jffs2 partition however.
  289. #ifndef CONFIG_ETRAXFS_SIM
  290. move.d __bss_start, $r0
  291. #else
  292. move.d __end, $r0
  293. #endif
  294. move.d [$r0], $r1
  295. cmp.d CRAMFS_MAGIC, $r1 ; cramfs magic?
  296. beq 2f ; yes, jump
  297. nop
  298. cmp.d JHEAD_MAGIC, $r1 ; jffs2 (jhead) magic?
  299. bne 4f ; no, skip copy
  300. nop
  301. addq 4, $r0 ; location of jffs2 size
  302. move.d [$r0+], $r2 ; fetch jffs2 size -> r2
  303. ; r0 now points to start of jffs2
  304. ba 3f
  305. nop
  306. 2:
  307. addoq +4, $r0, $acr ; location of cramfs size
  308. move.d [$acr], $r2 ; fetch cramfs size -> r2
  309. ; r0 still points to start of cramfs
  310. 3:
  311. ;; Now, move the root fs to after kernel's BSS
  312. move.d _end, $r1 ; start of cramfs -> r1
  313. move.d romfs_start, $r3
  314. move.d $r1, [$r3] ; store at romfs_start (for axisflashmap)
  315. move.d romfs_length, $r3
  316. move.d $r2, [$r3] ; store size at romfs_length
  317. add.d $r2, $r0 ; copy from end and downwards
  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. 4:
  330. ;; BSS move done.
  331. ;; Clear romfs_in_flash flag, as we now know romfs is in DRAM
  332. ;; Also clear nand_boot flag; if we got here, we know we've not
  333. ;; booted from NAND flash.
  334. moveq 0, $r0
  335. move.d romfs_in_flash, $r1
  336. move.d $r0, [$r1]
  337. moveq 0, $r0
  338. move.d nand_boot, $r1
  339. move.d $r0, [$r1]
  340. jump _start_it ; Jump to cached code.
  341. nop
  342. _start_it:
  343. ;; Check if kernel command line is supplied
  344. cmp.d COMMAND_LINE_MAGIC, $r10
  345. bne no_command_line
  346. nop
  347. move.d 256, $r13
  348. move.d cris_command_line, $r10
  349. or.d 0x80000000, $r11 ; Make it virtual
  350. 1:
  351. move.b [$r11+], $r1
  352. move.b $r1, [$r10+]
  353. subq 1, $r13
  354. bne 1b
  355. nop
  356. no_command_line:
  357. ;; The kernel stack contains a task structure for each task. This
  358. ;; the initial kernel stack is in the same page as the init_task,
  359. ;; but starts at the top of the page, i.e. + 8192 bytes.
  360. move.d init_thread_union + 8192, $sp
  361. move.d ebp_start, $r0 ; Defined in linker-script.
  362. move $r0, $ebp
  363. move.d etrax_irv, $r1 ; Set the exception base register and pointer.
  364. move.d $r0, [$r1]
  365. ;; Clear the BSS region from _bss_start to _end.
  366. move.d __bss_start, $r0
  367. move.d _end, $r1
  368. 1: clear.d [$r0+]
  369. cmp.d $r1, $r0
  370. blo 1b
  371. nop
  372. ; Initialize registers to increase determinism
  373. move.d __bss_start, $r0
  374. movem [$r0], $r13
  375. #ifdef CONFIG_ETRAX_L2CACHE
  376. jsr l2cache_init
  377. nop
  378. #endif
  379. jump start_kernel ; Jump to start_kernel() in init/main.c.
  380. nop
  381. .data
  382. etrax_irv:
  383. .dword 0
  384. ; Variables for communication with the Axis flash map driver (axisflashmap),
  385. ; and for setting up memory in arch/cris/kernel/setup.c .
  386. ; romfs_start is set to the start of the root file system, if it exists
  387. ; in directly accessible memory (i.e. NOR Flash when booting from Flash,
  388. ; or RAM when booting directly from a network-downloaded RAM image)
  389. romfs_start:
  390. .dword 0
  391. ; romfs_length is set to the size of the root file system image, if it exists
  392. ; in directly accessible memory (see romfs_start). Otherwise it is set to 0.
  393. romfs_length:
  394. .dword 0
  395. ; romfs_in_flash is set to 1 if the root file system resides in directly
  396. ; accessible flash memory (i.e. NOR flash). It is set to 0 for RAM boot
  397. ; or NAND flash boot.
  398. romfs_in_flash:
  399. .dword 0
  400. ; nand_boot is set to 1 when the kernel has been booted from NAND flash
  401. nand_boot:
  402. .dword 0
  403. swapper_pg_dir = 0xc0002000
  404. .section ".init.data", "aw"
  405. #if defined CONFIG_ETRAXFS
  406. #include "../mach-fs/hw_settings.S"
  407. #elif defined CONFIG_CRIS_MACH_ARTPEC3
  408. #include "../mach-a3/hw_settings.S"
  409. #else
  410. #error Only ETRAXFS and ARTPEC-3 supported!
  411. #endif