head.S 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. * Head of the kernel - alter with care
  3. *
  4. * Copyright (C) 2000, 2001, 2010 Axis Communications AB
  5. *
  6. */
  7. #define ASSEMBLER_MACROS_ONLY
  8. /* The IO_* macros use the ## token concatenation operator, so
  9. -traditional must not be used when assembling this file. */
  10. #include <arch/sv_addr_ag.h>
  11. #define CRAMFS_MAGIC 0x28cd3d45
  12. #define RAM_INIT_MAGIC 0x56902387
  13. #define COMMAND_LINE_MAGIC 0x87109563
  14. #define START_ETHERNET_CLOCK IO_STATE(R_NETWORK_GEN_CONFIG, enable, on) |\
  15. IO_STATE(R_NETWORK_GEN_CONFIG, phy, mii_clk)
  16. ;; exported symbols
  17. .globl etrax_irv
  18. .globl romfs_start
  19. .globl romfs_length
  20. .globl romfs_in_flash
  21. .globl swapper_pg_dir
  22. .text
  23. ;; This is the entry point of the kernel. We are in supervisor mode.
  24. ;; 0x00000000 if Flash, 0x40004000 if DRAM
  25. ;; since etrax actually starts at address 2 when booting from flash, we
  26. ;; put a nop (2 bytes) here first so we dont accidentally skip the di
  27. ;;
  28. ;; NOTICE! The registers r8 and r9 are used as parameters carrying
  29. ;; information from the decompressor (if the kernel was compressed).
  30. ;; They should not be used in the code below until read.
  31. nop
  32. di
  33. ;; First setup the kseg_c mapping from where the kernel is linked
  34. ;; to 0x40000000 (where the actual DRAM resides) otherwise
  35. ;; we cannot do very much! See arch/cris/README.mm
  36. ;;
  37. ;; Notice that since we're potentially running at 0x00 or 0x40 right now,
  38. ;; we will get a fault as soon as we enable the MMU if we dont
  39. ;; temporarily map those segments linearily.
  40. ;;
  41. ;; Due to a bug in Etrax-100 LX version 1 we need to map the memory
  42. ;; slightly different. The bug is that you can't remap bit 31 of
  43. ;; an address. Though we can check the version register for
  44. ;; whether the bug is present, some constants would then have to
  45. ;; be variables, so we don't. The drawback is that you can "only" map
  46. ;; 1G per process with CONFIG_CRIS_LOW_MAP.
  47. #ifdef CONFIG_CRIS_LOW_MAP
  48. ; kseg mappings, temporary map of 0xc0->0x40
  49. move.d IO_FIELD (R_MMU_KBASE_HI, base_c, 4) \
  50. | IO_FIELD (R_MMU_KBASE_HI, base_b, 0xb) \
  51. | IO_FIELD (R_MMU_KBASE_HI, base_9, 9) \
  52. | IO_FIELD (R_MMU_KBASE_HI, base_8, 8), $r0
  53. move.d $r0, [R_MMU_KBASE_HI]
  54. ; temporary map of 0x40->0x40 and 0x60->0x40
  55. move.d IO_FIELD (R_MMU_KBASE_LO, base_6, 4) \
  56. | IO_FIELD (R_MMU_KBASE_LO, base_4, 4), $r0
  57. move.d $r0, [R_MMU_KBASE_LO]
  58. ; mmu enable, segs e,c,b,a,6,5,4,0 segment mapped
  59. move.d IO_STATE (R_MMU_CONFIG, mmu_enable, enable) \
  60. | IO_STATE (R_MMU_CONFIG, inv_excp, enable) \
  61. | IO_STATE (R_MMU_CONFIG, acc_excp, enable) \
  62. | IO_STATE (R_MMU_CONFIG, we_excp, enable) \
  63. | IO_STATE (R_MMU_CONFIG, seg_f, page) \
  64. | IO_STATE (R_MMU_CONFIG, seg_e, seg) \
  65. | IO_STATE (R_MMU_CONFIG, seg_d, page) \
  66. | IO_STATE (R_MMU_CONFIG, seg_c, seg) \
  67. | IO_STATE (R_MMU_CONFIG, seg_b, seg) \
  68. | IO_STATE (R_MMU_CONFIG, seg_a, seg) \
  69. | IO_STATE (R_MMU_CONFIG, seg_9, page) \
  70. | IO_STATE (R_MMU_CONFIG, seg_8, page) \
  71. | IO_STATE (R_MMU_CONFIG, seg_7, page) \
  72. | IO_STATE (R_MMU_CONFIG, seg_6, seg) \
  73. | IO_STATE (R_MMU_CONFIG, seg_5, seg) \
  74. | IO_STATE (R_MMU_CONFIG, seg_4, seg) \
  75. | IO_STATE (R_MMU_CONFIG, seg_3, page) \
  76. | IO_STATE (R_MMU_CONFIG, seg_2, page) \
  77. | IO_STATE (R_MMU_CONFIG, seg_1, page) \
  78. | IO_STATE (R_MMU_CONFIG, seg_0, seg), $r0
  79. move.d $r0, [R_MMU_CONFIG]
  80. #else
  81. ; kseg mappings
  82. move.d IO_FIELD (R_MMU_KBASE_HI, base_e, 8) \
  83. | IO_FIELD (R_MMU_KBASE_HI, base_c, 4) \
  84. | IO_FIELD (R_MMU_KBASE_HI, base_b, 0xb), $r0
  85. move.d $r0, [R_MMU_KBASE_HI]
  86. ; temporary map of 0x40->0x40 and 0x00->0x00
  87. move.d IO_FIELD (R_MMU_KBASE_LO, base_4, 4), $r0
  88. move.d $r0, [R_MMU_KBASE_LO]
  89. ; mmu enable, segs f,e,c,b,4,0 segment mapped
  90. move.d IO_STATE (R_MMU_CONFIG, mmu_enable, enable) \
  91. | IO_STATE (R_MMU_CONFIG, inv_excp, enable) \
  92. | IO_STATE (R_MMU_CONFIG, acc_excp, enable) \
  93. | IO_STATE (R_MMU_CONFIG, we_excp, enable) \
  94. | IO_STATE (R_MMU_CONFIG, seg_f, seg) \
  95. | IO_STATE (R_MMU_CONFIG, seg_e, seg) \
  96. | IO_STATE (R_MMU_CONFIG, seg_d, page) \
  97. | IO_STATE (R_MMU_CONFIG, seg_c, seg) \
  98. | IO_STATE (R_MMU_CONFIG, seg_b, seg) \
  99. | IO_STATE (R_MMU_CONFIG, seg_a, page) \
  100. | IO_STATE (R_MMU_CONFIG, seg_9, page) \
  101. | IO_STATE (R_MMU_CONFIG, seg_8, page) \
  102. | IO_STATE (R_MMU_CONFIG, seg_7, page) \
  103. | IO_STATE (R_MMU_CONFIG, seg_6, page) \
  104. | IO_STATE (R_MMU_CONFIG, seg_5, page) \
  105. | IO_STATE (R_MMU_CONFIG, seg_4, seg) \
  106. | IO_STATE (R_MMU_CONFIG, seg_3, page) \
  107. | IO_STATE (R_MMU_CONFIG, seg_2, page) \
  108. | IO_STATE (R_MMU_CONFIG, seg_1, page) \
  109. | IO_STATE (R_MMU_CONFIG, seg_0, seg), $r0
  110. move.d $r0, [R_MMU_CONFIG]
  111. #endif
  112. ;; Now we need to sort out the segments and their locations in RAM or
  113. ;; Flash. The image in the Flash (or in DRAM) consists of 3 pieces:
  114. ;; 1) kernel text, 2) kernel data, 3) ROM filesystem image
  115. ;; But the linker has linked the kernel to expect this layout in
  116. ;; DRAM memory:
  117. ;; 1) kernel text, 2) kernel data, 3) kernel BSS
  118. ;; (the location of the ROM filesystem is determined by the krom driver)
  119. ;; If we boot this from Flash, we want to keep the ROM filesystem in
  120. ;; the flash, we want to copy the text and need to copy the data to DRAM.
  121. ;; But if we boot from DRAM, we need to move the ROMFS image
  122. ;; from its position after kernel data, to after kernel BSS, BEFORE the
  123. ;; kernel starts using the BSS area (since its "overlayed" with the ROMFS)
  124. ;;
  125. ;; In both cases, we start in un-cached mode, and need to jump into a
  126. ;; cached PC after we're done fiddling around with the segments.
  127. ;;
  128. ;; arch/etrax100/etrax100.ld sets some symbols that define the start
  129. ;; and end of each segment.
  130. ;; Check if we start from DRAM or FLASH by testing PC
  131. move.d $pc,$r0
  132. and.d 0x7fffffff,$r0 ; get rid of the non-cache bit
  133. cmp.d 0x10000,$r0 ; arbitrary... just something above this code
  134. blo _inflash0
  135. nop
  136. jump _inram ; enter cached ram
  137. ;; Jumpgate for branches.
  138. _inflash0:
  139. jump _inflash
  140. ;; Put this in a suitable section where we can reclaim storage
  141. ;; after init.
  142. .section ".init.text", "ax"
  143. _inflash:
  144. #ifdef CONFIG_ETRAX_ETHERNET
  145. ;; Start MII clock to make sure it is running when tranceiver is reset
  146. move.d START_ETHERNET_CLOCK, $r0
  147. move.d $r0, [R_NETWORK_GEN_CONFIG]
  148. #endif
  149. ;; Set up waitstates etc according to kernel configuration.
  150. move.d CONFIG_ETRAX_DEF_R_WAITSTATES, $r0
  151. move.d $r0, [R_WAITSTATES]
  152. move.d CONFIG_ETRAX_DEF_R_BUS_CONFIG, $r0
  153. move.d $r0, [R_BUS_CONFIG]
  154. ;; We need to initialze DRAM registers before we start using the DRAM
  155. cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?
  156. beq _dram_init_finished
  157. nop
  158. #include "../lib/dram_init.S"
  159. _dram_init_finished:
  160. ;; Copy text+data to DRAM
  161. ;; This is fragile - the calculation of r4 as the image size depends
  162. ;; on that the labels below actually are the first and last positions
  163. ;; in the linker-script.
  164. ;;
  165. ;; Then the locating of the cramfs image depends on the aforementioned
  166. ;; image being located in the flash at 0. This is most often not true,
  167. ;; thus the following does not work (normally there is a rescue-block
  168. ;; between the physical start of the flash and the flash-image start,
  169. ;; and when run with compression, the kernel is actually unpacked to
  170. ;; DRAM and we never get here in the first place :))
  171. moveq 0, $r0 ; source
  172. move.d text_start, $r1 ; destination
  173. move.d __vmlinux_end, $r2 ; end destination
  174. move.d $r2, $r4
  175. sub.d $r1, $r4 ; r4=__vmlinux_end in flash, used below
  176. 1: move.w [$r0+], $r3
  177. move.w $r3, [$r1+]
  178. cmp.d $r2, $r1
  179. blo 1b
  180. nop
  181. ;; We keep the cramfs in the flash.
  182. ;; There might be none, but that does not matter because
  183. ;; we don't do anything than read some bytes here.
  184. moveq 0, $r0
  185. move.d $r0, [romfs_length] ; default if there is no cramfs
  186. move.d [$r4], $r0 ; cramfs_super.magic
  187. cmp.d CRAMFS_MAGIC, $r0
  188. bne 1f
  189. nop
  190. move.d [$r4 + 4], $r0 ; cramfs_super.size
  191. move.d $r0, [romfs_length]
  192. #ifdef CONFIG_CRIS_LOW_MAP
  193. add.d 0x50000000, $r4 ; add flash start in virtual memory (cached)
  194. #else
  195. add.d 0xf0000000, $r4 ; add flash start in virtual memory (cached)
  196. #endif
  197. move.d $r4, [romfs_start]
  198. 1:
  199. moveq 1, $r0
  200. move.d $r0, [romfs_in_flash]
  201. jump _start_it ; enter code, cached this time
  202. _inram:
  203. ;; Move the ROM fs to after BSS end. This assumes that the cramfs
  204. ;; second longword contains the length of the cramfs
  205. moveq 0, $r0
  206. move.d $r0, [romfs_length] ; default if there is no cramfs
  207. ;; The kernel could have been unpacked to DRAM by the loader, but
  208. ;; the cramfs image could still be in the Flash directly after the
  209. ;; compressed kernel image. The loader passes the address of the
  210. ;; byte succeeding the last compressed byte in the flash in the
  211. ;; register r9 when starting the kernel. Check if r9 points to a
  212. ;; decent cramfs image!
  213. ;; (Notice that if this is not booted from the loader, r9 will be
  214. ;; garbage but we do sanity checks on it, the chance that it points
  215. ;; to a cramfs magic is small.. )
  216. cmp.d 0x0ffffff8, $r9
  217. bhs _no_romfs_in_flash ; r9 points outside the flash area
  218. nop
  219. move.d [$r9], $r0 ; cramfs_super.magic
  220. cmp.d CRAMFS_MAGIC, $r0
  221. bne _no_romfs_in_flash
  222. nop
  223. move.d [$r9+4], $r0 ; cramfs_super.length
  224. move.d $r0, [romfs_length]
  225. #ifdef CONFIG_CRIS_LOW_MAP
  226. add.d 0x50000000, $r9 ; add flash start in virtual memory (cached)
  227. #else
  228. add.d 0xf0000000, $r9 ; add flash start in virtual memory (cached)
  229. #endif
  230. move.d $r9, [romfs_start]
  231. moveq 1, $r0
  232. move.d $r0, [romfs_in_flash]
  233. jump _start_it ; enter code, cached this time
  234. _no_romfs_in_flash:
  235. ;; Check if there is a cramfs (magic value).
  236. ;; Notice that we check for cramfs magic value - which is
  237. ;; the "rom fs" we'll possibly use in 2.4 if not JFFS (which does
  238. ;; not need this mechanism anyway)
  239. move.d __init_end, $r0; the image will be after the end of init
  240. move.d [$r0], $r1 ; cramfs assumes same endian on host/target
  241. cmp.d CRAMFS_MAGIC, $r1; magic value in cramfs superblock
  242. bne 2f
  243. nop
  244. ;; Ok. What is its size ?
  245. move.d [$r0 + 4], $r2 ; cramfs_super.size (again, no need to swapwb)
  246. ;; We want to copy it to the end of the BSS
  247. move.d _end, $r1
  248. ;; Remember values so cramfs and setup can find this info
  249. move.d $r1, [romfs_start] ; new romfs location
  250. move.d $r2, [romfs_length]
  251. ;; We need to copy it backwards, since they can be overlapping
  252. add.d $r2, $r0
  253. add.d $r2, $r1
  254. ;; Go ahead. Make my loop.
  255. lsrq 1, $r2 ; size is in bytes, we copy words
  256. 1: move.w [$r0=$r0-2],$r3
  257. move.w $r3,[$r1=$r1-2]
  258. subq 1, $r2
  259. bne 1b
  260. nop
  261. 2:
  262. ;; Dont worry that the BSS is tainted. It will be cleared later.
  263. moveq 0, $r0
  264. move.d $r0, [romfs_in_flash]
  265. jump _start_it ; better skip the additional cramfs check below
  266. _start_it:
  267. ;; Check if kernel command line is supplied
  268. cmp.d COMMAND_LINE_MAGIC, $r10
  269. bne no_command_line
  270. nop
  271. move.d 256, $r13
  272. move.d cris_command_line, $r10
  273. or.d 0x80000000, $r11 ; Make it virtual
  274. 1:
  275. move.b [$r11+], $r12
  276. move.b $r12, [$r10+]
  277. subq 1, $r13
  278. bne 1b
  279. nop
  280. no_command_line:
  281. ;; the kernel stack is overlayed with the task structure for each
  282. ;; task. thus the initial kernel stack is in the same page as the
  283. ;; init_task (but starts in the top of the page, size 8192)
  284. move.d init_thread_union + 8192, $sp
  285. move.d ibr_start,$r0 ; this symbol is set by the linker script
  286. move $r0,$ibr
  287. move.d $r0,[etrax_irv] ; set the interrupt base register and pointer
  288. ;; Clear BSS region, from _bss_start to _end
  289. move.d __bss_start, $r0
  290. move.d _end, $r1
  291. 1: clear.d [$r0+]
  292. cmp.d $r1, $r0
  293. blo 1b
  294. nop
  295. #ifdef CONFIG_BLK_DEV_ETRAXIDE
  296. ;; disable ATA before enabling it in genconfig below
  297. moveq 0,$r0
  298. move.d $r0,[R_ATA_CTRL_DATA]
  299. move.d $r0,[R_ATA_TRANSFER_CNT]
  300. move.d $r0,[R_ATA_CONFIG]
  301. #if 0
  302. move.d R_PORT_G_DATA, $r1
  303. move.d $r0, [$r1]; assert ATA bus-reset
  304. nop
  305. nop
  306. nop
  307. nop
  308. nop
  309. nop
  310. move.d 0x08000000,$r0
  311. move.d $r0,[$r1]
  312. #endif
  313. #endif
  314. #ifdef CONFIG_JULIETTE
  315. ;; configure external DMA channel 0 before enabling it in genconfig
  316. moveq 0,$r0
  317. move.d $r0,[R_EXT_DMA_0_ADDR]
  318. ; cnt enable, word size, output, stop, size 0
  319. move.d IO_STATE (R_EXT_DMA_0_CMD, cnt, enable) \
  320. | IO_STATE (R_EXT_DMA_0_CMD, rqpol, ahigh) \
  321. | IO_STATE (R_EXT_DMA_0_CMD, apol, ahigh) \
  322. | IO_STATE (R_EXT_DMA_0_CMD, rq_ack, burst) \
  323. | IO_STATE (R_EXT_DMA_0_CMD, wid, word) \
  324. | IO_STATE (R_EXT_DMA_0_CMD, dir, output) \
  325. | IO_STATE (R_EXT_DMA_0_CMD, run, stop) \
  326. | IO_FIELD (R_EXT_DMA_0_CMD, trf_count, 0),$r0
  327. move.d $r0,[R_EXT_DMA_0_CMD]
  328. ;; reset dma4 and wait for completion
  329. moveq IO_STATE (R_DMA_CH4_CMD, cmd, reset),$r0
  330. move.b $r0,[R_DMA_CH4_CMD]
  331. 1: move.b [R_DMA_CH4_CMD],$r0
  332. and.b IO_MASK (R_DMA_CH4_CMD, cmd),$r0
  333. cmp.b IO_STATE (R_DMA_CH4_CMD, cmd, reset),$r0
  334. beq 1b
  335. nop
  336. ;; reset dma5 and wait for completion
  337. moveq IO_STATE (R_DMA_CH5_CMD, cmd, reset),$r0
  338. move.b $r0,[R_DMA_CH5_CMD]
  339. 1: move.b [R_DMA_CH5_CMD],$r0
  340. and.b IO_MASK (R_DMA_CH5_CMD, cmd),$r0
  341. cmp.b IO_STATE (R_DMA_CH5_CMD, cmd, reset),$r0
  342. beq 1b
  343. nop
  344. #endif
  345. ;; Etrax product HW genconfig setup
  346. moveq 0,$r0
  347. ;; Select or disable serial port 2
  348. #ifdef CONFIG_ETRAX_SERIAL_PORT2
  349. or.d IO_STATE (R_GEN_CONFIG, ser2, select),$r0
  350. #else
  351. or.d IO_STATE (R_GEN_CONFIG, ser2, disable),$r0
  352. #endif
  353. ;; Init interfaces (disable them).
  354. or.d IO_STATE (R_GEN_CONFIG, scsi0, disable) \
  355. | IO_STATE (R_GEN_CONFIG, ata, disable) \
  356. | IO_STATE (R_GEN_CONFIG, par0, disable) \
  357. | IO_STATE (R_GEN_CONFIG, mio, disable) \
  358. | IO_STATE (R_GEN_CONFIG, scsi1, disable) \
  359. | IO_STATE (R_GEN_CONFIG, scsi0w, disable) \
  360. | IO_STATE (R_GEN_CONFIG, par1, disable) \
  361. | IO_STATE (R_GEN_CONFIG, ser3, disable) \
  362. | IO_STATE (R_GEN_CONFIG, mio_w, disable) \
  363. | IO_STATE (R_GEN_CONFIG, usb1, disable) \
  364. | IO_STATE (R_GEN_CONFIG, usb2, disable) \
  365. | IO_STATE (R_GEN_CONFIG, par_w, disable),$r0
  366. ;; Init DMA channel muxing (set to unused clients).
  367. or.d IO_STATE (R_GEN_CONFIG, dma2, ata) \
  368. | IO_STATE (R_GEN_CONFIG, dma3, ata) \
  369. | IO_STATE (R_GEN_CONFIG, dma4, scsi1) \
  370. | IO_STATE (R_GEN_CONFIG, dma5, scsi1) \
  371. | IO_STATE (R_GEN_CONFIG, dma6, unused) \
  372. | IO_STATE (R_GEN_CONFIG, dma7, unused) \
  373. | IO_STATE (R_GEN_CONFIG, dma8, usb) \
  374. | IO_STATE (R_GEN_CONFIG, dma9, usb),$r0
  375. #if defined(CONFIG_ETRAX_DEF_R_PORT_G0_DIR_OUT)
  376. or.d IO_STATE (R_GEN_CONFIG, g0dir, out),$r0
  377. #endif
  378. #if defined(CONFIG_ETRAX_DEF_R_PORT_G8_15_DIR_OUT)
  379. or.d IO_STATE (R_GEN_CONFIG, g8_15dir, out),$r0
  380. #endif
  381. #if defined(CONFIG_ETRAX_DEF_R_PORT_G16_23_DIR_OUT)
  382. or.d IO_STATE (R_GEN_CONFIG, g16_23dir, out),$r0
  383. #endif
  384. #if defined(CONFIG_ETRAX_DEF_R_PORT_G24_DIR_OUT)
  385. or.d IO_STATE (R_GEN_CONFIG, g24dir, out),$r0
  386. #endif
  387. move.d $r0,[genconfig_shadow] ; init a shadow register of R_GEN_CONFIG
  388. move.d $r0,[R_GEN_CONFIG]
  389. #if 0
  390. moveq 4,$r0
  391. move.b $r0,[R_DMA_CH6_CMD] ; reset (ser0 dma out)
  392. move.b $r0,[R_DMA_CH7_CMD] ; reset (ser0 dma in)
  393. 1: move.b [R_DMA_CH6_CMD],$r0 ; wait for reset cycle to finish
  394. and.b 7,$r0
  395. cmp.b 4,$r0
  396. beq 1b
  397. nop
  398. 1: move.b [R_DMA_CH7_CMD],$r0 ; wait for reset cycle to finish
  399. and.b 7,$r0
  400. cmp.b 4,$r0
  401. beq 1b
  402. nop
  403. #endif
  404. moveq IO_STATE (R_DMA_CH8_CMD, cmd, reset),$r0
  405. move.b $r0,[R_DMA_CH8_CMD] ; reset (ser1 dma out)
  406. move.b $r0,[R_DMA_CH9_CMD] ; reset (ser1 dma in)
  407. 1: move.b [R_DMA_CH8_CMD],$r0 ; wait for reset cycle to finish
  408. andq IO_MASK (R_DMA_CH8_CMD, cmd),$r0
  409. cmpq IO_STATE (R_DMA_CH8_CMD, cmd, reset),$r0
  410. beq 1b
  411. nop
  412. 1: move.b [R_DMA_CH9_CMD],$r0 ; wait for reset cycle to finish
  413. andq IO_MASK (R_DMA_CH9_CMD, cmd),$r0
  414. cmpq IO_STATE (R_DMA_CH9_CMD, cmd, reset),$r0
  415. beq 1b
  416. nop
  417. ;; setup port PA and PB default initial directions and data
  418. ;; including their shadow registers
  419. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DIR,$r0
  420. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_PA7)
  421. or.b IO_STATE (R_PORT_PA_DIR, dir7, output),$r0
  422. #endif
  423. move.b $r0,[port_pa_dir_shadow]
  424. move.b $r0,[R_PORT_PA_DIR]
  425. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA,$r0
  426. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_PA7)
  427. #if defined(CONFIG_BLUETOOTH_RESET_ACTIVE_HIGH)
  428. and.b ~(1 << 7),$r0
  429. #else
  430. or.b (1 << 7),$r0
  431. #endif
  432. #endif
  433. move.b $r0,[port_pa_data_shadow]
  434. move.b $r0,[R_PORT_PA_DATA]
  435. move.b CONFIG_ETRAX_DEF_R_PORT_PB_CONFIG,$r0
  436. move.b $r0,[port_pb_config_shadow]
  437. move.b $r0,[R_PORT_PB_CONFIG]
  438. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DIR,$r0
  439. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_PB5)
  440. or.b IO_STATE (R_PORT_PB_DIR, dir5, output),$r0
  441. #endif
  442. move.b $r0,[port_pb_dir_shadow]
  443. move.b $r0,[R_PORT_PB_DIR]
  444. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA,$r0
  445. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_PB5)
  446. #if defined(CONFIG_BLUETOOTH_RESET_ACTIVE_HIGH)
  447. and.b ~(1 << 5),$r0
  448. #else
  449. or.b (1 << 5),$r0
  450. #endif
  451. #endif
  452. move.b $r0,[port_pb_data_shadow]
  453. move.b $r0,[R_PORT_PB_DATA]
  454. moveq 0, $r0
  455. move.d $r0,[port_pb_i2c_shadow]
  456. move.d $r0, [R_PORT_PB_I2C]
  457. moveq 0,$r0
  458. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_G10)
  459. #if defined(CONFIG_BLUETOOTH_RESET_ACTIVE_HIGH)
  460. and.d ~(1 << 10),$r0
  461. #else
  462. or.d (1 << 10),$r0
  463. #endif
  464. #endif
  465. #if defined(CONFIG_BLUETOOTH) && defined(CONFIG_BLUETOOTH_RESET_G11)
  466. #if defined(CONFIG_BLUETOOTH_RESET_ACTIVE_HIGH)
  467. and.d ~(1 << 11),$r0
  468. #else
  469. or.d (1 << 11),$r0
  470. #endif
  471. #endif
  472. move.d $r0,[port_g_data_shadow]
  473. move.d $r0,[R_PORT_G_DATA]
  474. ;; setup the serial port 0 at 115200 baud for debug purposes
  475. moveq IO_STATE (R_SERIAL0_XOFF, tx_stop, enable) \
  476. | IO_STATE (R_SERIAL0_XOFF, auto_xoff, disable) \
  477. | IO_FIELD (R_SERIAL0_XOFF, xoff_char, 0),$r0
  478. move.d $r0,[R_SERIAL0_XOFF]
  479. ; 115.2kbaud for both transmit and receive
  480. move.b IO_STATE (R_SERIAL0_BAUD, tr_baud, c115k2Hz) \
  481. | IO_STATE (R_SERIAL0_BAUD, rec_baud, c115k2Hz),$r0
  482. move.b $r0,[R_SERIAL0_BAUD]
  483. ; Set up and enable the serial0 receiver.
  484. move.b IO_STATE (R_SERIAL0_REC_CTRL, dma_err, stop) \
  485. | IO_STATE (R_SERIAL0_REC_CTRL, rec_enable, enable) \
  486. | IO_STATE (R_SERIAL0_REC_CTRL, rts_, active) \
  487. | IO_STATE (R_SERIAL0_REC_CTRL, sampling, middle) \
  488. | IO_STATE (R_SERIAL0_REC_CTRL, rec_stick_par, normal) \
  489. | IO_STATE (R_SERIAL0_REC_CTRL, rec_par, even) \
  490. | IO_STATE (R_SERIAL0_REC_CTRL, rec_par_en, disable) \
  491. | IO_STATE (R_SERIAL0_REC_CTRL, rec_bitnr, rec_8bit),$r0
  492. move.b $r0,[R_SERIAL0_REC_CTRL]
  493. ; Set up and enable the serial0 transmitter.
  494. move.b IO_FIELD (R_SERIAL0_TR_CTRL, txd, 0) \
  495. | IO_STATE (R_SERIAL0_TR_CTRL, tr_enable, enable) \
  496. | IO_STATE (R_SERIAL0_TR_CTRL, auto_cts, disabled) \
  497. | IO_STATE (R_SERIAL0_TR_CTRL, stop_bits, one_bit) \
  498. | IO_STATE (R_SERIAL0_TR_CTRL, tr_stick_par, normal) \
  499. | IO_STATE (R_SERIAL0_TR_CTRL, tr_par, even) \
  500. | IO_STATE (R_SERIAL0_TR_CTRL, tr_par_en, disable) \
  501. | IO_STATE (R_SERIAL0_TR_CTRL, tr_bitnr, tr_8bit),$r0
  502. move.b $r0,[R_SERIAL0_TR_CTRL]
  503. ;; setup the serial port 1 at 115200 baud for debug purposes
  504. moveq IO_STATE (R_SERIAL1_XOFF, tx_stop, enable) \
  505. | IO_STATE (R_SERIAL1_XOFF, auto_xoff, disable) \
  506. | IO_FIELD (R_SERIAL1_XOFF, xoff_char, 0),$r0
  507. move.d $r0,[R_SERIAL1_XOFF]
  508. ; 115.2kbaud for both transmit and receive
  509. move.b IO_STATE (R_SERIAL1_BAUD, tr_baud, c115k2Hz) \
  510. | IO_STATE (R_SERIAL1_BAUD, rec_baud, c115k2Hz),$r0
  511. move.b $r0,[R_SERIAL1_BAUD]
  512. ; Set up and enable the serial1 receiver.
  513. move.b IO_STATE (R_SERIAL1_REC_CTRL, dma_err, stop) \
  514. | IO_STATE (R_SERIAL1_REC_CTRL, rec_enable, enable) \
  515. | IO_STATE (R_SERIAL1_REC_CTRL, rts_, active) \
  516. | IO_STATE (R_SERIAL1_REC_CTRL, sampling, middle) \
  517. | IO_STATE (R_SERIAL1_REC_CTRL, rec_stick_par, normal) \
  518. | IO_STATE (R_SERIAL1_REC_CTRL, rec_par, even) \
  519. | IO_STATE (R_SERIAL1_REC_CTRL, rec_par_en, disable) \
  520. | IO_STATE (R_SERIAL1_REC_CTRL, rec_bitnr, rec_8bit),$r0
  521. move.b $r0,[R_SERIAL1_REC_CTRL]
  522. ; Set up and enable the serial1 transmitter.
  523. move.b IO_FIELD (R_SERIAL1_TR_CTRL, txd, 0) \
  524. | IO_STATE (R_SERIAL1_TR_CTRL, tr_enable, enable) \
  525. | IO_STATE (R_SERIAL1_TR_CTRL, auto_cts, disabled) \
  526. | IO_STATE (R_SERIAL1_TR_CTRL, stop_bits, one_bit) \
  527. | IO_STATE (R_SERIAL1_TR_CTRL, tr_stick_par, normal) \
  528. | IO_STATE (R_SERIAL1_TR_CTRL, tr_par, even) \
  529. | IO_STATE (R_SERIAL1_TR_CTRL, tr_par_en, disable) \
  530. | IO_STATE (R_SERIAL1_TR_CTRL, tr_bitnr, tr_8bit),$r0
  531. move.b $r0,[R_SERIAL1_TR_CTRL]
  532. #ifdef CONFIG_ETRAX_SERIAL_PORT2
  533. ;; setup the serial port 2 at 115200 baud for debug purposes
  534. moveq IO_STATE (R_SERIAL2_XOFF, tx_stop, enable) \
  535. | IO_STATE (R_SERIAL2_XOFF, auto_xoff, disable) \
  536. | IO_FIELD (R_SERIAL2_XOFF, xoff_char, 0),$r0
  537. move.d $r0,[R_SERIAL2_XOFF]
  538. ; 115.2kbaud for both transmit and receive
  539. move.b IO_STATE (R_SERIAL2_BAUD, tr_baud, c115k2Hz) \
  540. | IO_STATE (R_SERIAL2_BAUD, rec_baud, c115k2Hz),$r0
  541. move.b $r0,[R_SERIAL2_BAUD]
  542. ; Set up and enable the serial2 receiver.
  543. move.b IO_STATE (R_SERIAL2_REC_CTRL, dma_err, stop) \
  544. | IO_STATE (R_SERIAL2_REC_CTRL, rec_enable, enable) \
  545. | IO_STATE (R_SERIAL2_REC_CTRL, rts_, active) \
  546. | IO_STATE (R_SERIAL2_REC_CTRL, sampling, middle) \
  547. | IO_STATE (R_SERIAL2_REC_CTRL, rec_stick_par, normal) \
  548. | IO_STATE (R_SERIAL2_REC_CTRL, rec_par, even) \
  549. | IO_STATE (R_SERIAL2_REC_CTRL, rec_par_en, disable) \
  550. | IO_STATE (R_SERIAL2_REC_CTRL, rec_bitnr, rec_8bit),$r0
  551. move.b $r0,[R_SERIAL2_REC_CTRL]
  552. ; Set up and enable the serial2 transmitter.
  553. move.b IO_FIELD (R_SERIAL2_TR_CTRL, txd, 0) \
  554. | IO_STATE (R_SERIAL2_TR_CTRL, tr_enable, enable) \
  555. | IO_STATE (R_SERIAL2_TR_CTRL, auto_cts, disabled) \
  556. | IO_STATE (R_SERIAL2_TR_CTRL, stop_bits, one_bit) \
  557. | IO_STATE (R_SERIAL2_TR_CTRL, tr_stick_par, normal) \
  558. | IO_STATE (R_SERIAL2_TR_CTRL, tr_par, even) \
  559. | IO_STATE (R_SERIAL2_TR_CTRL, tr_par_en, disable) \
  560. | IO_STATE (R_SERIAL2_TR_CTRL, tr_bitnr, tr_8bit),$r0
  561. move.b $r0,[R_SERIAL2_TR_CTRL]
  562. #endif
  563. #ifdef CONFIG_ETRAX_SERIAL_PORT3
  564. ;; setup the serial port 3 at 115200 baud for debug purposes
  565. moveq IO_STATE (R_SERIAL3_XOFF, tx_stop, enable) \
  566. | IO_STATE (R_SERIAL3_XOFF, auto_xoff, disable) \
  567. | IO_FIELD (R_SERIAL3_XOFF, xoff_char, 0),$r0
  568. move.d $r0,[R_SERIAL3_XOFF]
  569. ; 115.2kbaud for both transmit and receive
  570. move.b IO_STATE (R_SERIAL3_BAUD, tr_baud, c115k2Hz) \
  571. | IO_STATE (R_SERIAL3_BAUD, rec_baud, c115k2Hz),$r0
  572. move.b $r0,[R_SERIAL3_BAUD]
  573. ; Set up and enable the serial3 receiver.
  574. move.b IO_STATE (R_SERIAL3_REC_CTRL, dma_err, stop) \
  575. | IO_STATE (R_SERIAL3_REC_CTRL, rec_enable, enable) \
  576. | IO_STATE (R_SERIAL3_REC_CTRL, rts_, active) \
  577. | IO_STATE (R_SERIAL3_REC_CTRL, sampling, middle) \
  578. | IO_STATE (R_SERIAL3_REC_CTRL, rec_stick_par, normal) \
  579. | IO_STATE (R_SERIAL3_REC_CTRL, rec_par, even) \
  580. | IO_STATE (R_SERIAL3_REC_CTRL, rec_par_en, disable) \
  581. | IO_STATE (R_SERIAL3_REC_CTRL, rec_bitnr, rec_8bit),$r0
  582. move.b $r0,[R_SERIAL3_REC_CTRL]
  583. ; Set up and enable the serial3 transmitter.
  584. move.b IO_FIELD (R_SERIAL3_TR_CTRL, txd, 0) \
  585. | IO_STATE (R_SERIAL3_TR_CTRL, tr_enable, enable) \
  586. | IO_STATE (R_SERIAL3_TR_CTRL, auto_cts, disabled) \
  587. | IO_STATE (R_SERIAL3_TR_CTRL, stop_bits, one_bit) \
  588. | IO_STATE (R_SERIAL3_TR_CTRL, tr_stick_par, normal) \
  589. | IO_STATE (R_SERIAL3_TR_CTRL, tr_par, even) \
  590. | IO_STATE (R_SERIAL3_TR_CTRL, tr_par_en, disable) \
  591. | IO_STATE (R_SERIAL3_TR_CTRL, tr_bitnr, tr_8bit),$r0
  592. move.b $r0,[R_SERIAL3_TR_CTRL]
  593. #endif
  594. jump start_kernel ; jump into the C-function start_kernel in init/main.c
  595. .data
  596. etrax_irv:
  597. .dword 0
  598. romfs_start:
  599. .dword 0
  600. romfs_length:
  601. .dword 0
  602. romfs_in_flash:
  603. .dword 0
  604. ;; put some special pages at the beginning of the kernel aligned
  605. ;; to page boundaries - the kernel cannot start until after this
  606. #ifdef CONFIG_CRIS_LOW_MAP
  607. swapper_pg_dir = 0x60002000
  608. #else
  609. swapper_pg_dir = 0xc0002000
  610. #endif
  611. .section ".init.data", "aw"
  612. #include "../lib/hw_settings.S"