head.S 29 KB

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