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