head.S 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /* $Id: head.S,v 1.10 2005/06/20 05:12:54 starvik Exp $
  2. *
  3. * Head of the kernel - alter with care
  4. *
  5. * Copyright (C) 2000, 2001 Axis Communications AB
  6. *
  7. * Authors: Bjorn Wesen (bjornw@axis.com)
  8. *
  9. * $Log: head.S,v $
  10. * Revision 1.10 2005/06/20 05:12:54 starvik
  11. * Remove unnecessary diff to kernel.org tree
  12. *
  13. * Revision 1.9 2004/12/13 12:21:51 starvik
  14. * Added I/O and DMA allocators from Linux 2.4
  15. *
  16. * Revision 1.8 2004/11/22 11:41:14 starvik
  17. * Kernel command line may be supplied to kernel. Not used by Axis but may
  18. * be used by customers.
  19. *
  20. * Revision 1.7 2004/05/14 07:58:01 starvik
  21. * Merge of changes from 2.4
  22. *
  23. * Revision 1.6 2003/04/28 05:31:46 starvik
  24. * Added section attributes
  25. *
  26. * Revision 1.5 2002/12/11 15:42:02 starvik
  27. * Extracted v10 (ETRAX 100LX) specific stuff from arch/cris/kernel/*.c
  28. *
  29. * Revision 1.4 2002/11/07 09:00:44 starvik
  30. * Names changed for init sections
  31. * init_task_union -> init_thread_union
  32. *
  33. * Revision 1.3 2002/02/05 15:38:23 bjornw
  34. * Oops.. non-CRAMFS_MAGIC should jump over the copying, not into it...
  35. *
  36. * Revision 1.2 2001/12/18 13:35:19 bjornw
  37. * Applied the 2.4.13->2.4.16 CRIS patch to 2.5.1 (is a copy of 2.4.15).
  38. *
  39. * Revision 1.43 2001/11/08 15:09:43 starvik
  40. * Only start MII clock if Ethernet is configured
  41. *
  42. * Revision 1.42 2001/11/08 14:37:34 starvik
  43. * Start MII clock early to make sure that it is running at tranceiver reset
  44. *
  45. * Revision 1.41 2001/10/29 14:55:58 pkj
  46. * Corrected pa$r0 to par0.
  47. *
  48. * Revision 1.40 2001/10/03 14:59:57 pkj
  49. * Added support for resetting the Bluetooth hardware.
  50. *
  51. * Revision 1.39 2001/10/01 14:45:03 bjornw
  52. * Removed underscores and added register prefixes
  53. *
  54. * Revision 1.38 2001/09/21 07:14:11 jonashg
  55. * Made root filesystem (cramfs) use mtdblock driver when booting from flash.
  56. *
  57. * Revision 1.37 2001/09/11 13:44:29 orjanf
  58. * Decouple usage of serial ports for debug and kgdb.
  59. *
  60. * Revision 1.36 2001/06/29 12:39:31 pkj
  61. * Added support for mirroring the first flash to just below the
  62. * second one, to make them look consecutive to cramfs.
  63. *
  64. * Revision 1.35 2001/06/25 14:07:00 hp
  65. * Fix review comment.
  66. * * head.S: Use IO_STATE, IO_FIELD and IO_MASK constructs instead of
  67. * magic numbers. Add comment that -traditional must not be used.
  68. * * entry.S (SYMBOL_NAME): Change redefinition to use ## concatenation.
  69. * Correct and update comment.
  70. * * Makefile (.S.o): Don't use -traditional. Add comment why the
  71. * toplevel rule can't be used (now that there's a reason).
  72. *
  73. * Revision 1.34 2001/05/15 07:08:14 hp
  74. * Tweak "notice" to reflect that both r8 r9 are used
  75. *
  76. * Revision 1.33 2001/05/15 06:40:05 hp
  77. * Put bulk of code in .text.init, data in .data.init
  78. *
  79. * Revision 1.32 2001/05/15 06:18:56 hp
  80. * Execute review comment: s/bcc/bhs/g; s/bcs/blo/g
  81. *
  82. * Revision 1.31 2001/05/15 06:08:40 hp
  83. * Add sentence about autodetecting the bit31-MMU-bug
  84. *
  85. * Revision 1.30 2001/05/15 06:00:05 hp
  86. * Update comment: LOW_MAP is not forced on xsim anymore.
  87. *
  88. * Revision 1.29 2001/04/18 12:51:59 orjanf
  89. * * Reverted review change regarding the use of bcs/bcc.
  90. * * Removed non-working LED-clearing code.
  91. *
  92. * Revision 1.28 2001/04/17 13:58:39 orjanf
  93. * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
  94. *
  95. * Revision 1.27 2001/04/17 11:42:35 orjanf
  96. * Changed according to review:
  97. * * Added comment explaining memory map bug.
  98. * * Changed bcs and bcc to blo and bhs, respectively.
  99. * * Removed mentioning of Stallone and Olga boards.
  100. *
  101. * Revision 1.26 2001/04/06 12:31:07 jonashg
  102. * Check for cramfs in flash before RAM instead of RAM before flash.
  103. *
  104. * Revision 1.25 2001/04/04 06:23:53 starvik
  105. * Initialize DRAM if not already initialized
  106. *
  107. * Revision 1.24 2001/04/03 11:12:00 starvik
  108. * Removed dram init (done by rescue or etrax100boot
  109. * Corrected include
  110. *
  111. * Revision 1.23 2001/04/03 09:53:03 starvik
  112. * Include hw_settings.S
  113. *
  114. * Revision 1.22 2001/03/26 14:23:26 bjornw
  115. * Namechange of some config options
  116. *
  117. * Revision 1.21 2001/03/08 12:14:41 bjornw
  118. * * Config name for ETRAX IDE was renamed
  119. * * Removed G27 auto-setting when JULIETTE is chosen (need to make this
  120. * a new config option later)
  121. *
  122. * Revision 1.20 2001/02/23 12:47:56 bjornw
  123. * MMU regs during LOW_MAP updated to reflect a newer reality
  124. *
  125. * Revision 1.19 2001/02/19 11:12:07 bjornw
  126. * Changed comment header format
  127. *
  128. * Revision 1.18 2001/02/15 07:25:38 starvik
  129. * Added support for synchronous serial ports
  130. *
  131. * Revision 1.17 2001/02/08 15:53:13 starvik
  132. * Last commit removed some important ifdefs
  133. *
  134. * Revision 1.16 2001/02/08 15:20:38 starvik
  135. * Include dram_init.S as inline
  136. *
  137. * Revision 1.15 2001/01/29 18:12:01 bjornw
  138. * Corrected some comments
  139. *
  140. * Revision 1.14 2001/01/29 13:11:29 starvik
  141. * Include dram_init.S (with DRAM/SDRAM initialization)
  142. *
  143. * Revision 1.13 2001/01/23 14:54:57 markusl
  144. * Updated for USB
  145. * i.e. added r_gen_config settings
  146. *
  147. * Revision 1.12 2001/01/19 16:16:29 perf
  148. * Added temporary mapping of 0x0c->0x0c to avoid flash loading confusion.
  149. * Renamed serial options from ETRAX100 to ETRAX.
  150. *
  151. * Revision 1.11 2001/01/16 16:31:38 bjornw
  152. * * Changed name and semantics of running_from_flash to romfs_in_flash,
  153. * set by head.S to indicate to setup.c whether there is a cramfs image
  154. * after the kernels BSS or not. Should work for all three boot-cases
  155. * (DRAM with cramfs in DRAM, DRAM with cramfs in flash (compressed boot),
  156. * and flash with cramfs in flash)
  157. *
  158. * Revision 1.10 2001/01/16 14:12:21 bjornw
  159. * * Check for cramfs start passed in r9 from the decompressor, if all other
  160. * cramfs options fail (if we boot from DRAM but don't find a cramfs image
  161. * after the kernel in DRAM, it is probably still in the flash)
  162. * * Check magic in cramfs detection when booting from flash directly
  163. *
  164. * Revision 1.9 2001/01/15 17:17:02 bjornw
  165. * * Corrected the code that detects the cramfs lengths
  166. * * Added a comment saying that the above does not work due to other
  167. * reasons..
  168. *
  169. * Revision 1.8 2001/01/15 16:27:51 jonashg
  170. * Made boot after flashing work.
  171. * * end destination is __vmlinux_end in RAM.
  172. * * _romfs_start moved because of virtual memory.
  173. *
  174. * Revision 1.7 2000/11/21 13:55:29 bjornw
  175. * Use CONFIG_CRIS_LOW_MAP for the low VM map instead of explicit CPU type
  176. *
  177. * Revision 1.6 2000/10/06 12:36:55 bjornw
  178. * Forgot swapper_pg_dir when changing memory map..
  179. *
  180. * Revision 1.5 2000/10/04 16:49:30 bjornw
  181. * * Fixed memory mapping in LX
  182. * * Check for cramfs instead of romfs
  183. *
  184. */
  185. #define ASSEMBLER_MACROS_ONLY
  186. /* The IO_* macros use the ## token concatenation operator, so
  187. -traditional must not be used when assembling this file. */
  188. #include <asm/arch/sv_addr_ag.h>
  189. #define CRAMFS_MAGIC 0x28cd3d45
  190. #define RAM_INIT_MAGIC 0x56902387
  191. #define COMMAND_LINE_MAGIC 0x87109563
  192. #define START_ETHERNET_CLOCK IO_STATE(R_NETWORK_GEN_CONFIG, enable, on) |\
  193. IO_STATE(R_NETWORK_GEN_CONFIG, phy, mii_clk)
  194. ;; exported symbols
  195. .globl etrax_irv
  196. .globl romfs_start
  197. .globl romfs_length
  198. .globl romfs_in_flash
  199. .globl swapper_pg_dir
  200. .text
  201. ;; This is the entry point of the kernel. We are in supervisor mode.
  202. ;; 0x00000000 if Flash, 0x40004000 if DRAM
  203. ;; since etrax actually starts at address 2 when booting from flash, we
  204. ;; put a nop (2 bytes) here first so we dont accidentally skip the di
  205. ;;
  206. ;; NOTICE! The registers r8 and r9 are used as parameters carrying
  207. ;; information from the decompressor (if the kernel was compressed).
  208. ;; They should not be used in the code below until read.
  209. nop
  210. di
  211. ;; First setup the kseg_c mapping from where the kernel is linked
  212. ;; to 0x40000000 (where the actual DRAM resides) otherwise
  213. ;; we cannot do very much! See arch/cris/README.mm
  214. ;;
  215. ;; Notice that since we're potentially running at 0x00 or 0x40 right now,
  216. ;; we will get a fault as soon as we enable the MMU if we dont
  217. ;; temporarily map those segments linearily.
  218. ;;
  219. ;; Due to a bug in Etrax-100 LX version 1 we need to map the memory
  220. ;; slightly different. The bug is that you can't remap bit 31 of
  221. ;; an address. Though we can check the version register for
  222. ;; whether the bug is present, some constants would then have to
  223. ;; be variables, so we don't. The drawback is that you can "only" map
  224. ;; 1G per process with CONFIG_CRIS_LOW_MAP.
  225. #ifdef CONFIG_CRIS_LOW_MAP
  226. ; kseg mappings, temporary map of 0xc0->0x40
  227. move.d IO_FIELD (R_MMU_KBASE_HI, base_c, 4) \
  228. | IO_FIELD (R_MMU_KBASE_HI, base_b, 0xb) \
  229. | IO_FIELD (R_MMU_KBASE_HI, base_9, 9) \
  230. | IO_FIELD (R_MMU_KBASE_HI, base_8, 8), $r0
  231. move.d $r0, [R_MMU_KBASE_HI]
  232. ; temporary map of 0x40->0x40 and 0x60->0x40
  233. move.d IO_FIELD (R_MMU_KBASE_LO, base_6, 4) \
  234. | IO_FIELD (R_MMU_KBASE_LO, base_4, 4), $r0
  235. move.d $r0, [R_MMU_KBASE_LO]
  236. ; mmu enable, segs e,c,b,a,6,5,4,0 segment mapped
  237. move.d IO_STATE (R_MMU_CONFIG, mmu_enable, enable) \
  238. | IO_STATE (R_MMU_CONFIG, inv_excp, enable) \
  239. | IO_STATE (R_MMU_CONFIG, acc_excp, enable) \
  240. | IO_STATE (R_MMU_CONFIG, we_excp, enable) \
  241. | IO_STATE (R_MMU_CONFIG, seg_f, page) \
  242. | IO_STATE (R_MMU_CONFIG, seg_e, seg) \
  243. | IO_STATE (R_MMU_CONFIG, seg_d, page) \
  244. | IO_STATE (R_MMU_CONFIG, seg_c, seg) \
  245. | IO_STATE (R_MMU_CONFIG, seg_b, seg) \
  246. | IO_STATE (R_MMU_CONFIG, seg_a, seg) \
  247. | IO_STATE (R_MMU_CONFIG, seg_9, page) \
  248. | IO_STATE (R_MMU_CONFIG, seg_8, page) \
  249. | IO_STATE (R_MMU_CONFIG, seg_7, page) \
  250. | IO_STATE (R_MMU_CONFIG, seg_6, seg) \
  251. | IO_STATE (R_MMU_CONFIG, seg_5, seg) \
  252. | IO_STATE (R_MMU_CONFIG, seg_4, seg) \
  253. | IO_STATE (R_MMU_CONFIG, seg_3, page) \
  254. | IO_STATE (R_MMU_CONFIG, seg_2, page) \
  255. | IO_STATE (R_MMU_CONFIG, seg_1, page) \
  256. | IO_STATE (R_MMU_CONFIG, seg_0, seg), $r0
  257. move.d $r0, [R_MMU_CONFIG]
  258. #else
  259. ; kseg mappings
  260. move.d IO_FIELD (R_MMU_KBASE_HI, base_e, 8) \
  261. | IO_FIELD (R_MMU_KBASE_HI, base_c, 4) \
  262. | IO_FIELD (R_MMU_KBASE_HI, base_b, 0xb), $r0
  263. move.d $r0, [R_MMU_KBASE_HI]
  264. ; temporary map of 0x40->0x40 and 0x00->0x00
  265. move.d IO_FIELD (R_MMU_KBASE_LO, base_4, 4), $r0
  266. move.d $r0, [R_MMU_KBASE_LO]
  267. ; mmu enable, segs f,e,c,b,4,0 segment mapped
  268. move.d IO_STATE (R_MMU_CONFIG, mmu_enable, enable) \
  269. | IO_STATE (R_MMU_CONFIG, inv_excp, enable) \
  270. | IO_STATE (R_MMU_CONFIG, acc_excp, enable) \
  271. | IO_STATE (R_MMU_CONFIG, we_excp, enable) \
  272. | IO_STATE (R_MMU_CONFIG, seg_f, seg) \
  273. | IO_STATE (R_MMU_CONFIG, seg_e, seg) \
  274. | IO_STATE (R_MMU_CONFIG, seg_d, page) \
  275. | IO_STATE (R_MMU_CONFIG, seg_c, seg) \
  276. | IO_STATE (R_MMU_CONFIG, seg_b, seg) \
  277. | IO_STATE (R_MMU_CONFIG, seg_a, page) \
  278. | IO_STATE (R_MMU_CONFIG, seg_9, page) \
  279. | IO_STATE (R_MMU_CONFIG, seg_8, page) \
  280. | IO_STATE (R_MMU_CONFIG, seg_7, page) \
  281. | IO_STATE (R_MMU_CONFIG, seg_6, page) \
  282. | IO_STATE (R_MMU_CONFIG, seg_5, page) \
  283. | IO_STATE (R_MMU_CONFIG, seg_4, seg) \
  284. | IO_STATE (R_MMU_CONFIG, seg_3, page) \
  285. | IO_STATE (R_MMU_CONFIG, seg_2, page) \
  286. | IO_STATE (R_MMU_CONFIG, seg_1, page) \
  287. | IO_STATE (R_MMU_CONFIG, seg_0, seg), $r0
  288. move.d $r0, [R_MMU_CONFIG]
  289. #endif
  290. ;; Now we need to sort out the segments and their locations in RAM or
  291. ;; Flash. The image in the Flash (or in DRAM) consists of 3 pieces:
  292. ;; 1) kernel text, 2) kernel data, 3) ROM filesystem image
  293. ;; But the linker has linked the kernel to expect this layout in
  294. ;; DRAM memory:
  295. ;; 1) kernel text, 2) kernel data, 3) kernel BSS
  296. ;; (the location of the ROM filesystem is determined by the krom driver)
  297. ;; If we boot this from Flash, we want to keep the ROM filesystem in
  298. ;; the flash, we want to copy the text and need to copy the data to DRAM.
  299. ;; But if we boot from DRAM, we need to move the ROMFS image
  300. ;; from its position after kernel data, to after kernel BSS, BEFORE the
  301. ;; kernel starts using the BSS area (since its "overlayed" with the ROMFS)
  302. ;;
  303. ;; In both cases, we start in un-cached mode, and need to jump into a
  304. ;; cached PC after we're done fiddling around with the segments.
  305. ;;
  306. ;; arch/etrax100/etrax100.ld sets some symbols that define the start
  307. ;; and end of each segment.
  308. ;; Check if we start from DRAM or FLASH by testing PC
  309. move.d $pc,$r0
  310. and.d 0x7fffffff,$r0 ; get rid of the non-cache bit
  311. cmp.d 0x10000,$r0 ; arbitrary... just something above this code
  312. blo _inflash0
  313. nop
  314. jump _inram ; enter cached ram
  315. ;; Jumpgate for branches.
  316. _inflash0:
  317. jump _inflash
  318. ;; Put this in a suitable section where we can reclaim storage
  319. ;; after init.
  320. .section ".init.text", "ax"
  321. _inflash:
  322. #ifdef CONFIG_ETRAX_ETHERNET
  323. ;; Start MII clock to make sure it is running when tranceiver is reset
  324. move.d START_ETHERNET_CLOCK, $r0
  325. move.d $r0, [R_NETWORK_GEN_CONFIG]
  326. #endif
  327. ;; Set up waitstates etc according to kernel configuration.
  328. #ifndef CONFIG_SVINTO_SIM
  329. move.d CONFIG_ETRAX_DEF_R_WAITSTATES, $r0
  330. move.d $r0, [R_WAITSTATES]
  331. move.d CONFIG_ETRAX_DEF_R_BUS_CONFIG, $r0
  332. move.d $r0, [R_BUS_CONFIG]
  333. #endif
  334. ;; We need to initialze DRAM registers before we start using the DRAM
  335. cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?
  336. beq _dram_init_finished
  337. nop
  338. #include "../lib/dram_init.S"
  339. _dram_init_finished:
  340. ;; Copy text+data to DRAM
  341. ;; This is fragile - the calculation of r4 as the image size depends
  342. ;; on that the labels below actually are the first and last positions
  343. ;; in the linker-script.
  344. ;;
  345. ;; Then the locating of the cramfs image depends on the aforementioned
  346. ;; image being located in the flash at 0. This is most often not true,
  347. ;; thus the following does not work (normally there is a rescue-block
  348. ;; between the physical start of the flash and the flash-image start,
  349. ;; and when run with compression, the kernel is actually unpacked to
  350. ;; DRAM and we never get here in the first place :))
  351. moveq 0, $r0 ; source
  352. move.d text_start, $r1 ; destination
  353. move.d __vmlinux_end, $r2 ; end destination
  354. move.d $r2, $r4
  355. sub.d $r1, $r4 ; r4=__vmlinux_end in flash, used below
  356. 1: move.w [$r0+], $r3
  357. move.w $r3, [$r1+]
  358. cmp.d $r2, $r1
  359. blo 1b
  360. nop
  361. ;; We keep the cramfs in the flash.
  362. ;; There might be none, but that does not matter because
  363. ;; we don't do anything than read some bytes here.
  364. moveq 0, $r0
  365. move.d $r0, [romfs_length] ; default if there is no cramfs
  366. move.d [$r4], $r0 ; cramfs_super.magic
  367. cmp.d CRAMFS_MAGIC, $r0
  368. bne 1f
  369. nop
  370. move.d [$r4 + 4], $r0 ; cramfs_super.size
  371. move.d $r0, [romfs_length]
  372. #ifdef CONFIG_CRIS_LOW_MAP
  373. add.d 0x50000000, $r4 ; add flash start in virtual memory (cached)
  374. #else
  375. add.d 0xf0000000, $r4 ; add flash start in virtual memory (cached)
  376. #endif
  377. move.d $r4, [romfs_start]
  378. 1:
  379. moveq 1, $r0
  380. move.d $r0, [romfs_in_flash]
  381. jump _start_it ; enter code, cached this time
  382. _inram:
  383. ;; Move the ROM fs to after BSS end. This assumes that the cramfs
  384. ;; second longword contains the length of the cramfs
  385. moveq 0, $r0
  386. move.d $r0, [romfs_length] ; default if there is no cramfs
  387. ;; The kernel could have been unpacked to DRAM by the loader, but
  388. ;; the cramfs image could still be in the Flash directly after the
  389. ;; compressed kernel image. The loader passes the address of the
  390. ;; byte succeeding the last compressed byte in the flash in the
  391. ;; register r9 when starting the kernel. Check if r9 points to a
  392. ;; decent cramfs image!
  393. ;; (Notice that if this is not booted from the loader, r9 will be
  394. ;; garbage but we do sanity checks on it, the chance that it points
  395. ;; to a cramfs magic is small.. )
  396. cmp.d 0x0ffffff8, $r9
  397. bhs _no_romfs_in_flash ; r9 points outside the flash area
  398. nop
  399. move.d [$r9], $r0 ; cramfs_super.magic
  400. cmp.d CRAMFS_MAGIC, $r0
  401. bne _no_romfs_in_flash
  402. nop
  403. move.d [$r9+4], $r0 ; cramfs_super.length
  404. move.d $r0, [romfs_length]
  405. #ifdef CONFIG_CRIS_LOW_MAP
  406. add.d 0x50000000, $r9 ; add flash start in virtual memory (cached)
  407. #else
  408. add.d 0xf0000000, $r9 ; add flash start in virtual memory (cached)
  409. #endif
  410. move.d $r9, [romfs_start]
  411. moveq 1, $r0
  412. move.d $r0, [romfs_in_flash]
  413. jump _start_it ; enter code, cached this time
  414. _no_romfs_in_flash:
  415. ;; Check if there is a cramfs (magic value).
  416. ;; Notice that we check for cramfs magic value - which is
  417. ;; the "rom fs" we'll possibly use in 2.4 if not JFFS (which does
  418. ;; not need this mechanism anyway)
  419. move.d __vmlinux_end, $r0; the image will be after the vmlinux end address
  420. move.d [$r0], $r1 ; cramfs assumes same endian on host/target
  421. cmp.d CRAMFS_MAGIC, $r1; magic value in cramfs superblock
  422. bne 2f
  423. nop
  424. ;; Ok. What is its size ?
  425. move.d [$r0 + 4], $r2 ; cramfs_super.size (again, no need to swapwb)
  426. ;; We want to copy it to the end of the BSS
  427. move.d _end, $r1
  428. ;; Remember values so cramfs and setup can find this info
  429. move.d $r1, [romfs_start] ; new romfs location
  430. move.d $r2, [romfs_length]
  431. ;; We need to copy it backwards, since they can be overlapping
  432. add.d $r2, $r0
  433. add.d $r2, $r1
  434. ;; Go ahead. Make my loop.
  435. lsrq 1, $r2 ; size is in bytes, we copy words
  436. 1: move.w [$r0=$r0-2],$r3
  437. move.w $r3,[$r1=$r1-2]
  438. subq 1, $r2
  439. bne 1b
  440. nop
  441. 2:
  442. ;; Dont worry that the BSS is tainted. It will be cleared later.
  443. moveq 0, $r0
  444. move.d $r0, [romfs_in_flash]
  445. jump _start_it ; better skip the additional cramfs check below
  446. _start_it:
  447. ;; Check if kernel command line is supplied
  448. cmp.d COMMAND_LINE_MAGIC, $r10
  449. bne no_command_line
  450. nop
  451. move.d 256, $r13
  452. move.d cris_command_line, $r10
  453. or.d 0x80000000, $r11 ; Make it virtual
  454. 1:
  455. move.b [$r11+], $r12
  456. move.b $r12, [$r10+]
  457. subq 1, $r13
  458. bne 1b
  459. nop
  460. no_command_line:
  461. ;; the kernel stack is overlayed with the task structure for each
  462. ;; task. thus the initial kernel stack is in the same page as the
  463. ;; init_task (but starts in the top of the page, size 8192)
  464. move.d init_thread_union + 8192, $sp
  465. move.d ibr_start,$r0 ; this symbol is set by the linker script
  466. move $r0,$ibr
  467. move.d $r0,[etrax_irv] ; set the interrupt base register and pointer
  468. ;; Clear BSS region, from _bss_start to _end
  469. move.d __bss_start, $r0
  470. move.d _end, $r1
  471. 1: clear.d [$r0+]
  472. cmp.d $r1, $r0
  473. blo 1b
  474. nop
  475. #ifdef CONFIG_BLK_DEV_ETRAXIDE
  476. ;; disable ATA before enabling it in genconfig below
  477. moveq 0,$r0
  478. move.d $r0,[R_ATA_CTRL_DATA]
  479. move.d $r0,[R_ATA_TRANSFER_CNT]
  480. move.d $r0,[R_ATA_CONFIG]
  481. #if 0
  482. move.d R_PORT_G_DATA, $r1
  483. move.d $r0, [$r1]; assert ATA bus-reset
  484. nop
  485. nop
  486. nop
  487. nop
  488. nop
  489. nop
  490. move.d 0x08000000,$r0
  491. move.d $r0,[$r1]
  492. #endif
  493. #endif
  494. #ifdef CONFIG_JULIETTE
  495. ;; configure external DMA channel 0 before enabling it in genconfig
  496. moveq 0,$r0
  497. move.d $r0,[R_EXT_DMA_0_ADDR]
  498. ; cnt enable, word size, output, stop, size 0
  499. move.d IO_STATE (R_EXT_DMA_0_CMD, cnt, enable) \
  500. | IO_STATE (R_EXT_DMA_0_CMD, rqpol, ahigh) \
  501. | IO_STATE (R_EXT_DMA_0_CMD, apol, ahigh) \
  502. | IO_STATE (R_EXT_DMA_0_CMD, rq_ack, burst) \
  503. | IO_STATE (R_EXT_DMA_0_CMD, wid, word) \
  504. | IO_STATE (R_EXT_DMA_0_CMD, dir, output) \
  505. | IO_STATE (R_EXT_DMA_0_CMD, run, stop) \
  506. | IO_FIELD (R_EXT_DMA_0_CMD, trf_count, 0),$r0
  507. move.d $r0,[R_EXT_DMA_0_CMD]
  508. ;; reset dma4 and wait for completion
  509. moveq IO_STATE (R_DMA_CH4_CMD, cmd, reset),$r0
  510. move.b $r0,[R_DMA_CH4_CMD]
  511. 1: move.b [R_DMA_CH4_CMD],$r0
  512. and.b IO_MASK (R_DMA_CH4_CMD, cmd),$r0
  513. cmp.b IO_STATE (R_DMA_CH4_CMD, cmd, reset),$r0
  514. beq 1b
  515. nop
  516. ;; reset dma5 and wait for completion
  517. moveq IO_STATE (R_DMA_CH5_CMD, cmd, reset),$r0
  518. move.b $r0,[R_DMA_CH5_CMD]
  519. 1: move.b [R_DMA_CH5_CMD],$r0
  520. and.b IO_MASK (R_DMA_CH5_CMD, cmd),$r0
  521. cmp.b IO_STATE (R_DMA_CH5_CMD, cmd, reset),$r0
  522. beq 1b
  523. nop
  524. #endif
  525. ;; Etrax product HW genconfig setup
  526. moveq 0,$r0
  527. ;; Init interfaces (disable them).
  528. or.d IO_STATE (R_GEN_CONFIG, scsi0, disable) \
  529. | IO_STATE (R_GEN_CONFIG, ata, disable) \
  530. | IO_STATE (R_GEN_CONFIG, par0, disable) \
  531. | IO_STATE (R_GEN_CONFIG, ser2, disable) \
  532. | IO_STATE (R_GEN_CONFIG, mio, disable) \
  533. | IO_STATE (R_GEN_CONFIG, scsi1, disable) \
  534. | IO_STATE (R_GEN_CONFIG, scsi0w, disable) \
  535. | IO_STATE (R_GEN_CONFIG, par1, disable) \
  536. | IO_STATE (R_GEN_CONFIG, ser3, disable) \
  537. | IO_STATE (R_GEN_CONFIG, mio_w, disable) \
  538. | IO_STATE (R_GEN_CONFIG, usb1, disable) \
  539. | IO_STATE (R_GEN_CONFIG, usb2, disable) \
  540. | IO_STATE (R_GEN_CONFIG, par_w, disable),$r0
  541. ;; Init DMA channel muxing (set to unused clients).
  542. or.d IO_STATE (R_GEN_CONFIG, dma2, ata) \
  543. | IO_STATE (R_GEN_CONFIG, dma3, ata) \
  544. | IO_STATE (R_GEN_CONFIG, dma4, scsi1) \
  545. | IO_STATE (R_GEN_CONFIG, dma5, scsi1) \
  546. | IO_STATE (R_GEN_CONFIG, dma6, unused) \
  547. | IO_STATE (R_GEN_CONFIG, dma7, unused) \
  548. | IO_STATE (R_GEN_CONFIG, dma8, usb) \
  549. | IO_STATE (R_GEN_CONFIG, dma9, usb),$r0
  550. #if defined(CONFIG_ETRAX_DEF_R_PORT_G0_DIR_OUT)
  551. or.d IO_STATE (R_GEN_CONFIG, g0dir, out),$r0
  552. #endif
  553. #if defined(CONFIG_ETRAX_DEF_R_PORT_G8_15_DIR_OUT)
  554. or.d IO_STATE (R_GEN_CONFIG, g8_15dir, out),$r0
  555. #endif
  556. #if defined(CONFIG_ETRAX_DEF_R_PORT_G16_23_DIR_OUT)
  557. or.d IO_STATE (R_GEN_CONFIG, g16_23dir, out),$r0
  558. #endif
  559. #if defined(CONFIG_ETRAX_DEF_R_PORT_G24_DIR_OUT)
  560. or.d IO_STATE (R_GEN_CONFIG, g24dir, out),$r0
  561. #endif
  562. move.d $r0,[genconfig_shadow] ; init a shadow register of R_GEN_CONFIG
  563. #ifndef CONFIG_SVINTO_SIM
  564. move.d $r0,[R_GEN_CONFIG]
  565. #if 0
  566. moveq 4,$r0
  567. move.b $r0,[R_DMA_CH6_CMD] ; reset (ser0 dma out)
  568. move.b $r0,[R_DMA_CH7_CMD] ; reset (ser0 dma in)
  569. 1: move.b [R_DMA_CH6_CMD],$r0 ; wait for reset cycle to finish
  570. and.b 7,$r0
  571. cmp.b 4,$r0
  572. beq 1b
  573. nop
  574. 1: move.b [R_DMA_CH7_CMD],$r0 ; wait for reset cycle to finish
  575. and.b 7,$r0
  576. cmp.b 4,$r0
  577. beq 1b
  578. nop
  579. #endif
  580. moveq IO_STATE (R_DMA_CH8_CMD, cmd, reset),$r0
  581. move.b $r0,[R_DMA_CH8_CMD] ; reset (ser1 dma out)
  582. move.b $r0,[R_DMA_CH9_CMD] ; reset (ser1 dma in)
  583. 1: move.b [R_DMA_CH8_CMD],$r0 ; wait for reset cycle to finish
  584. andq IO_MASK (R_DMA_CH8_CMD, cmd),$r0
  585. cmpq IO_STATE (R_DMA_CH8_CMD, cmd, reset),$r0
  586. beq 1b
  587. nop
  588. 1: move.b [R_DMA_CH9_CMD],$r0 ; wait for reset cycle to finish
  589. andq IO_MASK (R_DMA_CH9_CMD, cmd),$r0
  590. cmpq IO_STATE (R_DMA_CH9_CMD, cmd, reset),$r0
  591. beq 1b
  592. nop
  593. ;; setup port PA and PB default initial directions and data
  594. ;; including their shadow registers
  595. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DIR,$r0
  596. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_PA7)
  597. or.b IO_STATE (R_PORT_PA_DIR, dir7, output),$r0
  598. #endif
  599. move.b $r0,[port_pa_dir_shadow]
  600. move.b $r0,[R_PORT_PA_DIR]
  601. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA,$r0
  602. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_PA7)
  603. #if defined(CONFIG_BLUETOOTH_RESET_ACTIVE_HIGH)
  604. and.b ~(1 << 7),$r0
  605. #else
  606. or.b (1 << 7),$r0
  607. #endif
  608. #endif
  609. move.b $r0,[port_pa_data_shadow]
  610. move.b $r0,[R_PORT_PA_DATA]
  611. move.b CONFIG_ETRAX_DEF_R_PORT_PB_CONFIG,$r0
  612. move.b $r0,[port_pb_config_shadow]
  613. move.b $r0,[R_PORT_PB_CONFIG]
  614. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DIR,$r0
  615. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_PB5)
  616. or.b IO_STATE (R_PORT_PB_DIR, dir5, output),$r0
  617. #endif
  618. move.b $r0,[port_pb_dir_shadow]
  619. move.b $r0,[R_PORT_PB_DIR]
  620. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA,$r0
  621. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_PB5)
  622. #if defined(CONFIG_BLUETOOTH_RESET_ACTIVE_HIGH)
  623. and.b ~(1 << 5),$r0
  624. #else
  625. or.b (1 << 5),$r0
  626. #endif
  627. #endif
  628. move.b $r0,[port_pb_data_shadow]
  629. move.b $r0,[R_PORT_PB_DATA]
  630. moveq 0, $r0
  631. move.d $r0,[port_pb_i2c_shadow]
  632. move.d $r0, [R_PORT_PB_I2C]
  633. moveq 0,$r0
  634. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_G10)
  635. #if defined(CONFIG_BLUETOOTH_RESET_ACTIVE_HIGH)
  636. and.d ~(1 << 10),$r0
  637. #else
  638. or.d (1 << 10),$r0
  639. #endif
  640. #endif
  641. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_G11)
  642. #if defined(CONFIG_BLUETOOTH_RESET_ACTIVE_HIGH)
  643. and.d ~(1 << 11),$r0
  644. #else
  645. or.d (1 << 11),$r0
  646. #endif
  647. #endif
  648. move.d $r0,[port_g_data_shadow]
  649. move.d $r0,[R_PORT_G_DATA]
  650. ;; setup the serial port 0 at 115200 baud for debug purposes
  651. moveq IO_STATE (R_SERIAL0_XOFF, tx_stop, enable) \
  652. | IO_STATE (R_SERIAL0_XOFF, auto_xoff, disable) \
  653. | IO_FIELD (R_SERIAL0_XOFF, xoff_char, 0),$r0
  654. move.d $r0,[R_SERIAL0_XOFF]
  655. ; 115.2kbaud for both transmit and receive
  656. move.b IO_STATE (R_SERIAL0_BAUD, tr_baud, c115k2Hz) \
  657. | IO_STATE (R_SERIAL0_BAUD, rec_baud, c115k2Hz),$r0
  658. move.b $r0,[R_SERIAL0_BAUD]
  659. ; Set up and enable the serial0 receiver.
  660. move.b IO_STATE (R_SERIAL0_REC_CTRL, dma_err, stop) \
  661. | IO_STATE (R_SERIAL0_REC_CTRL, rec_enable, enable) \
  662. | IO_STATE (R_SERIAL0_REC_CTRL, rts_, active) \
  663. | IO_STATE (R_SERIAL0_REC_CTRL, sampling, middle) \
  664. | IO_STATE (R_SERIAL0_REC_CTRL, rec_stick_par, normal) \
  665. | IO_STATE (R_SERIAL0_REC_CTRL, rec_par, even) \
  666. | IO_STATE (R_SERIAL0_REC_CTRL, rec_par_en, disable) \
  667. | IO_STATE (R_SERIAL0_REC_CTRL, rec_bitnr, rec_8bit),$r0
  668. move.b $r0,[R_SERIAL0_REC_CTRL]
  669. ; Set up and enable the serial0 transmitter.
  670. move.b IO_FIELD (R_SERIAL0_TR_CTRL, txd, 0) \
  671. | IO_STATE (R_SERIAL0_TR_CTRL, tr_enable, enable) \
  672. | IO_STATE (R_SERIAL0_TR_CTRL, auto_cts, disabled) \
  673. | IO_STATE (R_SERIAL0_TR_CTRL, stop_bits, one_bit) \
  674. | IO_STATE (R_SERIAL0_TR_CTRL, tr_stick_par, normal) \
  675. | IO_STATE (R_SERIAL0_TR_CTRL, tr_par, even) \
  676. | IO_STATE (R_SERIAL0_TR_CTRL, tr_par_en, disable) \
  677. | IO_STATE (R_SERIAL0_TR_CTRL, tr_bitnr, tr_8bit),$r0
  678. move.b $r0,[R_SERIAL0_TR_CTRL]
  679. ;; setup the serial port 1 at 115200 baud for debug purposes
  680. moveq IO_STATE (R_SERIAL1_XOFF, tx_stop, enable) \
  681. | IO_STATE (R_SERIAL1_XOFF, auto_xoff, disable) \
  682. | IO_FIELD (R_SERIAL1_XOFF, xoff_char, 0),$r0
  683. move.d $r0,[R_SERIAL1_XOFF]
  684. ; 115.2kbaud for both transmit and receive
  685. move.b IO_STATE (R_SERIAL1_BAUD, tr_baud, c115k2Hz) \
  686. | IO_STATE (R_SERIAL1_BAUD, rec_baud, c115k2Hz),$r0
  687. move.b $r0,[R_SERIAL1_BAUD]
  688. ; Set up and enable the serial1 receiver.
  689. move.b IO_STATE (R_SERIAL1_REC_CTRL, dma_err, stop) \
  690. | IO_STATE (R_SERIAL1_REC_CTRL, rec_enable, enable) \
  691. | IO_STATE (R_SERIAL1_REC_CTRL, rts_, active) \
  692. | IO_STATE (R_SERIAL1_REC_CTRL, sampling, middle) \
  693. | IO_STATE (R_SERIAL1_REC_CTRL, rec_stick_par, normal) \
  694. | IO_STATE (R_SERIAL1_REC_CTRL, rec_par, even) \
  695. | IO_STATE (R_SERIAL1_REC_CTRL, rec_par_en, disable) \
  696. | IO_STATE (R_SERIAL1_REC_CTRL, rec_bitnr, rec_8bit),$r0
  697. move.b $r0,[R_SERIAL1_REC_CTRL]
  698. ; Set up and enable the serial1 transmitter.
  699. move.b IO_FIELD (R_SERIAL1_TR_CTRL, txd, 0) \
  700. | IO_STATE (R_SERIAL1_TR_CTRL, tr_enable, enable) \
  701. | IO_STATE (R_SERIAL1_TR_CTRL, auto_cts, disabled) \
  702. | IO_STATE (R_SERIAL1_TR_CTRL, stop_bits, one_bit) \
  703. | IO_STATE (R_SERIAL1_TR_CTRL, tr_stick_par, normal) \
  704. | IO_STATE (R_SERIAL1_TR_CTRL, tr_par, even) \
  705. | IO_STATE (R_SERIAL1_TR_CTRL, tr_par_en, disable) \
  706. | IO_STATE (R_SERIAL1_TR_CTRL, tr_bitnr, tr_8bit),$r0
  707. move.b $r0,[R_SERIAL1_TR_CTRL]
  708. #ifdef CONFIG_ETRAX_SERIAL_PORT3
  709. ;; setup the serial port 3 at 115200 baud for debug purposes
  710. moveq IO_STATE (R_SERIAL3_XOFF, tx_stop, enable) \
  711. | IO_STATE (R_SERIAL3_XOFF, auto_xoff, disable) \
  712. | IO_FIELD (R_SERIAL3_XOFF, xoff_char, 0),$r0
  713. move.d $r0,[R_SERIAL3_XOFF]
  714. ; 115.2kbaud for both transmit and receive
  715. move.b IO_STATE (R_SERIAL3_BAUD, tr_baud, c115k2Hz) \
  716. | IO_STATE (R_SERIAL3_BAUD, rec_baud, c115k2Hz),$r0
  717. move.b $r0,[R_SERIAL3_BAUD]
  718. ; Set up and enable the serial3 receiver.
  719. move.b IO_STATE (R_SERIAL3_REC_CTRL, dma_err, stop) \
  720. | IO_STATE (R_SERIAL3_REC_CTRL, rec_enable, enable) \
  721. | IO_STATE (R_SERIAL3_REC_CTRL, rts_, active) \
  722. | IO_STATE (R_SERIAL3_REC_CTRL, sampling, middle) \
  723. | IO_STATE (R_SERIAL3_REC_CTRL, rec_stick_par, normal) \
  724. | IO_STATE (R_SERIAL3_REC_CTRL, rec_par, even) \
  725. | IO_STATE (R_SERIAL3_REC_CTRL, rec_par_en, disable) \
  726. | IO_STATE (R_SERIAL3_REC_CTRL, rec_bitnr, rec_8bit),$r0
  727. move.b $r0,[R_SERIAL3_REC_CTRL]
  728. ; Set up and enable the serial3 transmitter.
  729. move.b IO_FIELD (R_SERIAL3_TR_CTRL, txd, 0) \
  730. | IO_STATE (R_SERIAL3_TR_CTRL, tr_enable, enable) \
  731. | IO_STATE (R_SERIAL3_TR_CTRL, auto_cts, disabled) \
  732. | IO_STATE (R_SERIAL3_TR_CTRL, stop_bits, one_bit) \
  733. | IO_STATE (R_SERIAL3_TR_CTRL, tr_stick_par, normal) \
  734. | IO_STATE (R_SERIAL3_TR_CTRL, tr_par, even) \
  735. | IO_STATE (R_SERIAL3_TR_CTRL, tr_par_en, disable) \
  736. | IO_STATE (R_SERIAL3_TR_CTRL, tr_bitnr, tr_8bit),$r0
  737. move.b $r0,[R_SERIAL3_TR_CTRL]
  738. #endif
  739. #endif /* CONFIG_SVINTO_SIM */
  740. jump start_kernel ; jump into the C-function start_kernel in init/main.c
  741. .data
  742. etrax_irv:
  743. .dword 0
  744. romfs_start:
  745. .dword 0
  746. romfs_length:
  747. .dword 0
  748. romfs_in_flash:
  749. .dword 0
  750. ;; put some special pages at the beginning of the kernel aligned
  751. ;; to page boundaries - the kernel cannot start until after this
  752. #ifdef CONFIG_CRIS_LOW_MAP
  753. swapper_pg_dir = 0x60002000
  754. #else
  755. swapper_pg_dir = 0xc0002000
  756. #endif
  757. .section ".init.data", "aw"
  758. #include "../lib/hw_settings.S"