Merge branch 'master' of /home/sam/kernel/linux-2.6/
[pandora-kernel.git] / arch / cris / arch-v32 / boot / compressed / head.S
1 /*
2  *  Code that sets up the DRAM registers, calls the
3  *  decompressor to unpack the piggybacked kernel, and jumps.
4  *
5  *  Copyright (C) 1999 - 2003, Axis Communications AB
6  */
7
8 #define ASSEMBLER_MACROS_ONLY
9 #include <asm/arch/hwregs/asm/reg_map_asm.h>
10 #include <asm/arch/hwregs/asm/gio_defs_asm.h>
11 #include <asm/arch/hwregs/asm/config_defs_asm.h>
12
13 #define RAM_INIT_MAGIC 0x56902387
14 #define COMMAND_LINE_MAGIC 0x87109563
15
16         ;; Exported symbols
17
18         .globl  input_data
19
20         .text
21 start:
22         di
23
24         ;; Start clocks for used blocks.
25         move.d REG_ADDR(config, regi_config, rw_clk_ctrl), $r1
26         move.d [$r1], $r0
27         or.d   REG_STATE(config, rw_clk_ctrl, cpu, yes) | \
28                REG_STATE(config, rw_clk_ctrl, bif, yes) | \
29                REG_STATE(config, rw_clk_ctrl, fix_io, yes), $r0
30         move.d $r0, [$r1]
31
32         ;; If booting from NAND flash we first have to copy some
33         ;; data from NAND flash to internal RAM to get the code
34         ;; that initializes the SDRAM. Lets copy 20 KB. This
35         ;; code executes at 0x38010000 if booting from NAND and
36         ;; we are guaranted that at least 0x200 bytes are good so
37         ;; lets start from there. The first 8192 bytes in the nand
38         ;; flash is spliced with zeroes and is thus 16384 bytes.
39         move.d 0x38010200, $r10
40         move.d 0x14200, $r11    ; Start offset in NAND flash 0x10200 + 16384
41         move.d 0x5000, $r12     ; Length of copy
42
43         ;; Before this code the tools add a partitiontable so the PC
44         ;; has an offset from the linked address.
45 offset1:
46         lapcq  ., $r13          ; get PC
47         add.d   first_copy_complete-offset1, $r13
48
49 #include "../../lib/nand_init.S"
50
51 first_copy_complete:
52         ;; Initialze the DRAM registers.
53         cmp.d   RAM_INIT_MAGIC, $r8     ; Already initialized?
54         beq     dram_init_finished
55         nop
56
57 #include "../../lib/dram_init.S"
58
59 dram_init_finished:
60         lapcq  ., $r13          ; get PC
61         add.d   second_copy_complete-dram_init_finished, $r13
62
63         move.d REG_ADDR(config, regi_config, r_bootsel), $r0
64         move.d [$r0], $r0
65         and.d  REG_MASK(config, r_bootsel, boot_mode), $r0
66         cmp.d  REG_STATE(config, r_bootsel, boot_mode, nand), $r0
67         bne second_copy_complete ; No NAND boot
68         nop
69
70         ;; Copy 2MB from NAND flash to SDRAM (at 2-4MB into the SDRAM)
71         move.d 0x40204000, $r10
72         move.d 0x8000, $r11
73         move.d 0x200000, $r12
74         ba copy_nand_to_ram
75         nop
76 second_copy_complete:
77
78         ;; Initiate the PA port.
79         move.d  CONFIG_ETRAX_DEF_GIO_PA_OUT, $r0
80         move.d  REG_ADDR(gio, regi_gio, rw_pa_dout), $r1
81         move.d  $r0, [$r1]
82
83         move.d  CONFIG_ETRAX_DEF_GIO_PA_OE, $r0
84         move.d  REG_ADDR(gio, regi_gio, rw_pa_oe), $r1
85         move.d  $r0, [$r1]
86
87         ;; Setup the stack to a suitably high address.
88         ;; We assume 8 MB is the minimum DRAM and put
89         ;; the SP at the top for now.
90
91         move.d  0x40800000, $sp
92
93         ;; Figure out where the compressed piggyback image is
94         ;; in the flash (since we wont try to copy it to DRAM
95         ;; before unpacking). It is at _edata, but in flash.
96         ;; Use (_edata - herami) as offset to the current PC.
97
98         move.d REG_ADDR(config, regi_config, r_bootsel), $r0
99         move.d [$r0], $r0
100         and.d  REG_MASK(config, r_bootsel, boot_mode), $r0
101         cmp.d  REG_STATE(config, r_bootsel, boot_mode, nand), $r0
102         beq hereami2
103         nop
104 hereami:
105         lapcq   ., $r5          ; get PC
106         and.d   0x7fffffff, $r5 ; strip any non-cache bit
107         move.d  $r5, $r0        ; save for later - flash address of 'herami'
108         add.d   _edata, $r5
109         sub.d   hereami, $r5    ; r5 = flash address of '_edata'
110         move.d  hereami, $r1    ; destination
111         ba 2f
112         nop
113 hereami2:
114         lapcq   ., $r5          ; get PC
115         and.d   0x00ffffff, $r5 ; strip any non-cache bit
116         move.d  $r5, $r6
117         or.d    0x40200000, $r6
118         move.d  $r6, $r0        ; save for later - flash address of 'herami'
119         add.d   _edata, $r5
120         sub.d   hereami2, $r5   ; r5 = flash address of '_edata'
121         add.d   0x40200000, $r5
122         move.d  hereami2, $r1   ; destination
123 2:
124         ;; Copy text+data to DRAM
125
126         move.d  _edata, $r2     ; end destination
127 1:      move.w  [$r0+], $r3
128         move.w  $r3, [$r1+]
129         cmp.d   $r2, $r1
130         bcs     1b
131         nop
132
133         move.d  input_data, $r0 ; for the decompressor
134         move.d  $r5, [$r0]      ; for the decompressor
135
136         ;; Clear the decompressors BSS (between _edata and _end)
137
138         moveq   0, $r0
139         move.d  _edata, $r1
140         move.d  _end, $r2
141 1:      move.w  $r0, [$r1+]
142         cmp.d   $r2, $r1
143         bcs     1b
144         nop
145
146         ;;  Save command line magic and address.
147         move.d  _cmd_line_magic, $r12
148         move.d  $r10, [$r12]
149         move.d  _cmd_line_addr, $r12
150         move.d  $r11, [$r12]
151
152         ;; Do the decompression and save compressed size in _inptr
153
154         jsr     decompress_kernel
155         nop
156
157         ;; Restore command line magic and address.
158         move.d  _cmd_line_magic, $r10
159         move.d  [$r10], $r10
160         move.d  _cmd_line_addr, $r11
161         move.d  [$r11], $r11
162
163         ;; Put start address of root partition in r9 so the kernel can use it
164         ;; when mounting from flash
165         move.d  input_data, $r0
166         move.d  [$r0], $r9              ; flash address of compressed kernel
167         move.d  inptr, $r0
168         add.d   [$r0], $r9              ; size of compressed kernel
169         cmp.d   0x40200000, $r9
170         blo     enter_kernel
171         nop
172         sub.d   0x40200000, $r9
173         add.d   0x4000, $r9
174
175 enter_kernel:
176         ;; Enter the decompressed kernel
177         move.d  RAM_INIT_MAGIC, $r8     ; Tell kernel that DRAM is initialized
178         jump    0x40004000      ; kernel is linked to this address
179         nop
180
181         .data
182
183 input_data:
184         .dword  0               ; used by the decompressor
185 _cmd_line_magic:
186         .dword 0
187 _cmd_line_addr:
188         .dword 0
189 is_nand_boot:
190         .dword  0
191
192 #include "../../lib/hw_settings.S"