head.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 <hwregs/reg_rdwr.h>
  12. #include <asm/arch/memmap.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 <asm/arch/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. #include "../mach/dram_init.S"
  197. _dram_initialized:
  198. ;; Copy the text and data section to DRAM. This depends on that the
  199. ;; variables used below are correctly set up by the linker script.
  200. ;; The calculated value stored in R4 is used below.
  201. ;; Leave the cramfs file system (piggybacked after the kernel) in flash.
  202. moveq 0, $r0 ; Source.
  203. move.d text_start, $r1 ; Destination.
  204. move.d __vmlinux_end, $r2
  205. move.d $r2, $r4
  206. sub.d $r1, $r4
  207. 1: move.w [$r0+], $r3
  208. move.w $r3, [$r1+]
  209. cmp.d $r2, $r1
  210. blo 1b
  211. nop
  212. ;; Check for cramfs.
  213. moveq 0, $r0
  214. move.d romfs_length, $r1
  215. move.d $r0, [$r1]
  216. move.d [$r4], $r0 ; cramfs_super.magic
  217. cmp.d CRAMFS_MAGIC, $r0
  218. bne 1f
  219. nop
  220. ;; Set length and start of cramfs, set romfs_in_flash flag
  221. addoq +4, $r4, $acr
  222. move.d [$acr], $r0
  223. move.d romfs_length, $r1
  224. move.d $r0, [$r1]
  225. add.d 0xf0000000, $r4 ; Add cached flash start in virtual memory.
  226. move.d romfs_start, $r1
  227. move.d $r4, [$r1]
  228. 1: moveq 1, $r0
  229. move.d romfs_in_flash, $r1
  230. move.d $r0, [$r1]
  231. jump _start_it ; Jump to cached code.
  232. nop
  233. _inram:
  234. ;; Check if booting from NAND flash; if so, set appropriate flags
  235. ;; and move on.
  236. cmp.d NAND_BOOT_MAGIC, $r12
  237. bne move_cramfs ; not nand, jump
  238. moveq 1, $r0
  239. move.d nand_boot, $r1 ; tell axisflashmap we're booting from NAND
  240. move.d $r0, [$r1]
  241. moveq 0, $r0 ; tell axisflashmap romfs is not in
  242. move.d romfs_in_flash, $r1 ; (directly accessed) flash
  243. move.d $r0, [$r1]
  244. jump _start_it ; continue with boot
  245. nop
  246. move_cramfs:
  247. ;; kernel is in DRAM.
  248. ;; Must figure out if there is a piggybacked rootfs image or not.
  249. ;; Set romfs_length to 0 => no rootfs image available by default.
  250. moveq 0, $r0
  251. move.d romfs_length, $r1
  252. move.d $r0, [$r1]
  253. #ifndef CONFIG_ETRAX_VCS_SIM
  254. ;; The kernel could have been unpacked to DRAM by the loader, but
  255. ;; the cramfs image could still be in the flash immediately
  256. ;; following the compressed kernel image. The loader passes the address
  257. ;; of the byte succeeding the last compressed byte in the flash in
  258. ;; register R9 when starting the kernel.
  259. cmp.d 0x0ffffff8, $r9
  260. bhs _no_romfs_in_flash ; R9 points outside the flash area.
  261. nop
  262. #else
  263. ba _no_romfs_in_flash
  264. nop
  265. #endif
  266. ;; cramfs rootfs might to be in flash. Check for it.
  267. move.d [$r9], $r0 ; cramfs_super.magic
  268. cmp.d CRAMFS_MAGIC, $r0
  269. bne _no_romfs_in_flash
  270. nop
  271. ;; found cramfs in flash. set address and size, and romfs_in_flash flag.
  272. addoq +4, $r9, $acr
  273. move.d [$acr], $r0
  274. move.d romfs_length, $r1
  275. move.d $r0, [$r1]
  276. add.d 0xf0000000, $r9 ; Add cached flash start in virtual memory.
  277. move.d romfs_start, $r1
  278. move.d $r9, [$r1]
  279. moveq 1, $r0
  280. move.d romfs_in_flash, $r1
  281. move.d $r0, [$r1]
  282. jump _start_it ; Jump to cached code.
  283. nop
  284. _no_romfs_in_flash:
  285. ;; No romfs in flash, so look for cramfs, or jffs2 with jhead,
  286. ;; after kernel in RAM, as is the case with network->RAM boot.
  287. ;; For cramfs, partition starts with magic and length.
  288. ;; For jffs2, a jhead is prepended which contains with magic and length.
  289. ;; The jhead is not part of the jffs2 partition however.
  290. #ifndef CONFIG_ETRAXFS_SIM
  291. move.d __vmlinux_end, $r0
  292. #else
  293. move.d __end, $r0
  294. #endif
  295. move.d [$r0], $r1
  296. cmp.d CRAMFS_MAGIC, $r1 ; cramfs magic?
  297. beq 2f ; yes, jump
  298. nop
  299. cmp.d JHEAD_MAGIC, $r1 ; jffs2 (jhead) magic?
  300. bne 4f ; no, skip copy
  301. nop
  302. addq 4, $r0 ; location of jffs2 size
  303. move.d [$r0+], $r2 ; fetch jffs2 size -> r2
  304. ; r0 now points to start of jffs2
  305. ba 3f
  306. nop
  307. 2:
  308. addoq +4, $r0, $acr ; location of cramfs size
  309. move.d [$acr], $r2 ; fetch cramfs size -> r2
  310. ; r0 still points to start of cramfs
  311. 3:
  312. ;; Now, move the root fs to after kernel's BSS
  313. move.d _end, $r1 ; start of cramfs -> r1
  314. move.d romfs_start, $r3
  315. move.d $r1, [$r3] ; store at romfs_start (for axisflashmap)
  316. move.d romfs_length, $r3
  317. move.d $r2, [$r3] ; store size at romfs_length
  318. #ifndef CONFIG_ETRAX_VCS_SIM
  319. add.d $r2, $r0 ; copy from end and downwards
  320. add.d $r2, $r1
  321. lsrq 1, $r2 ; Size is in bytes, we copy words.
  322. addq 1, $r2
  323. 1:
  324. move.w [$r0], $r3
  325. move.w $r3, [$r1]
  326. subq 2, $r0
  327. subq 2, $r1
  328. subq 1, $r2
  329. bne 1b
  330. nop
  331. #endif
  332. 4:
  333. ;; BSS move done.
  334. ;; Clear romfs_in_flash flag, as we now know romfs is in DRAM
  335. ;; Also clear nand_boot flag; if we got here, we know we've not
  336. ;; booted from NAND flash.
  337. moveq 0, $r0
  338. move.d romfs_in_flash, $r1
  339. move.d $r0, [$r1]
  340. moveq 0, $r0
  341. move.d nand_boot, $r1
  342. move.d $r0, [$r1]
  343. jump _start_it ; Jump to cached code.
  344. nop
  345. _start_it:
  346. ;; Check if kernel command line is supplied
  347. cmp.d COMMAND_LINE_MAGIC, $r10
  348. bne no_command_line
  349. nop
  350. move.d 256, $r13
  351. move.d cris_command_line, $r10
  352. or.d 0x80000000, $r11 ; Make it virtual
  353. 1:
  354. move.b [$r11+], $r1
  355. move.b $r1, [$r10+]
  356. subq 1, $r13
  357. bne 1b
  358. nop
  359. no_command_line:
  360. ;; The kernel stack contains a task structure for each task. This
  361. ;; the initial kernel stack is in the same page as the init_task,
  362. ;; but starts at the top of the page, i.e. + 8192 bytes.
  363. move.d init_thread_union + 8192, $sp
  364. move.d ebp_start, $r0 ; Defined in linker-script.
  365. move $r0, $ebp
  366. move.d etrax_irv, $r1 ; Set the exception base register and pointer.
  367. move.d $r0, [$r1]
  368. #ifndef CONFIG_ETRAX_VCS_SIM
  369. ;; Clear the BSS region from _bss_start to _end.
  370. move.d __bss_start, $r0
  371. move.d _end, $r1
  372. 1: clear.d [$r0+]
  373. cmp.d $r1, $r0
  374. blo 1b
  375. nop
  376. #endif
  377. #ifdef CONFIG_ETRAX_VCS_SIM
  378. /* Set the watchdog timeout to something big. Will be removed when */
  379. /* watchdog can be disabled with command line option */
  380. move.d 0x7fffffff, $r10
  381. jsr CPU_WATCHDOG_TIMEOUT
  382. nop
  383. #endif
  384. ; Initialize registers to increase determinism
  385. move.d __bss_start, $r0
  386. movem [$r0], $r13
  387. #ifdef CONFIG_ETRAX_L2CACHE
  388. jsr l2cache_init
  389. nop
  390. #endif
  391. jump start_kernel ; Jump to start_kernel() in init/main.c.
  392. nop
  393. .data
  394. etrax_irv:
  395. .dword 0
  396. ; Variables for communication with the Axis flash map driver (axisflashmap),
  397. ; and for setting up memory in arch/cris/kernel/setup.c .
  398. ; romfs_start is set to the start of the root file system, if it exists
  399. ; in directly accessible memory (i.e. NOR Flash when booting from Flash,
  400. ; or RAM when booting directly from a network-downloaded RAM image)
  401. romfs_start:
  402. .dword 0
  403. ; romfs_length is set to the size of the root file system image, if it exists
  404. ; in directly accessible memory (see romfs_start). Otherwise it is set to 0.
  405. romfs_length:
  406. .dword 0
  407. ; romfs_in_flash is set to 1 if the root file system resides in directly
  408. ; accessible flash memory (i.e. NOR flash). It is set to 0 for RAM boot
  409. ; or NAND flash boot.
  410. romfs_in_flash:
  411. .dword 0
  412. ; nand_boot is set to 1 when the kernel has been booted from NAND flash
  413. nand_boot:
  414. .dword 0
  415. swapper_pg_dir = 0xc0002000
  416. .section ".init.data", "aw"
  417. #include "../mach/hw_settings.S"