Merge tag 'mips_fixes_4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/jhogan...
[sfrench/cifs-2.6.git] / arch / cris / boot / compressed / head_v32.S
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  Code that sets up the DRAM registers, calls the
4  *  decompressor to unpack the piggybacked kernel, and jumps.
5  *
6  *  Copyright (C) 1999 - 2006, Axis Communications AB
7  */
8
9 #define ASSEMBLER_MACROS_ONLY
10 #include <hwregs/asm/reg_map_asm.h>
11 #include <mach/startup.inc>
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         START_CLOCKS
26
27         ;; Initialize the DRAM registers.
28         cmp.d   RAM_INIT_MAGIC, $r8     ; Already initialized?
29         beq     dram_init_finished
30         nop
31
32 #if defined CONFIG_ETRAXFS
33 #include "../../arch-v32/mach-fs/dram_init.S"
34 #elif defined CONFIG_CRIS_MACH_ARTPEC3
35 #include "../../arch-v32/mach-a3/dram_init.S"
36 #else
37 #error Only ETRAXFS and ARTPEC-3 supported!
38 #endif
39
40 dram_init_finished:
41
42         GIO_INIT
43         ;; Setup the stack to a suitably high address.
44         ;; We assume 8 MB is the minimum DRAM and put
45         ;; the SP at the top for now.
46
47         move.d  0x40800000, $sp
48
49         ;; Figure out where the compressed piggyback image is.
50         ;; It is either in [NOR] flash (we don't want to copy it
51         ;; to DRAM before unpacking), or copied to DRAM
52         ;; by the [NAND] flash boot loader.
53         ;; The piggyback image is at _edata, but relative to where the
54         ;; image is actually located in memory, not where it is linked
55         ;; (the decompressor is linked at 0x40700000+ and runs there).
56         ;; Use (_edata - herami) as offset to the current PC.
57
58 hereami:
59         lapcq   ., $r5          ; get PC
60         and.d   0x7fffffff, $r5 ; strip any non-cache bit
61         move.d  $r5, $r0        ; source address of 'herami'
62         add.d   _edata, $r5
63         sub.d   hereami, $r5    ; r5 = flash address of '_edata'
64         move.d  hereami, $r1    ; destination
65
66         ;; Copy text+data to DRAM
67
68         move.d  _edata, $r2     ; end destination
69 1:      move.w  [$r0+], $r3     ; from herami+ source
70         move.w  $r3, [$r1+]     ; to hereami+ destination (linked address)
71         cmp.d   $r2, $r1        ; finish when destination == _edata
72         bcs     1b
73         nop
74         move.d  input_data, $r0 ; for the decompressor
75         move.d  $r5, [$r0]      ; for the decompressor
76
77         ;; Clear the decompressors BSS (between _edata and _end)
78
79         moveq   0, $r0
80         move.d  _edata, $r1
81         move.d  _end, $r2
82 1:      move.w  $r0, [$r1+]
83         cmp.d   $r2, $r1
84         bcs     1b
85         nop
86
87         ;;  Save command line magic and address.
88         move.d  _cmd_line_magic, $r0
89         move.d  $r10, [$r0]
90         move.d  _cmd_line_addr, $r0
91         move.d  $r11, [$r0]
92
93         ;;  Save boot source indicator
94         move.d  _boot_source, $r0
95         move.d  $r12, [$r0]
96
97         ;; Do the decompression and save compressed size in _inptr
98
99         jsr     decompress_kernel
100         nop
101
102         ;; Restore boot source indicator
103         move.d  _boot_source, $r12
104         move.d  [$r12], $r12
105
106         ;; Restore command line magic and address.
107         move.d  _cmd_line_magic, $r10
108         move.d  [$r10], $r10
109         move.d  _cmd_line_addr, $r11
110         move.d  [$r11], $r11
111
112         ;; Put start address of root partition in r9 so the kernel can use it
113         ;; when mounting from flash
114         move.d  input_data, $r0
115         move.d  [$r0], $r9              ; flash address of compressed kernel
116         move.d  inptr, $r0
117         add.d   [$r0], $r9              ; size of compressed kernel
118         cmp.d   0x40000000, $r9         ; image in DRAM ?
119         blo     enter_kernel            ; no, must be [NOR] flash, jump
120         nop                             ; delay slot
121         and.d   0x001fffff, $r9         ; assume compressed kernel was < 2M
122
123 enter_kernel:
124         ;; Enter the decompressed kernel
125         move.d  RAM_INIT_MAGIC, $r8     ; Tell kernel that DRAM is initialized
126         jump    0x40004000      ; kernel is linked to this address
127         nop
128
129         .data
130
131 input_data:
132         .dword  0               ; used by the decompressor
133 _cmd_line_magic:
134         .dword 0
135 _cmd_line_addr:
136         .dword 0
137 _boot_source:
138         .dword 0
139
140 #if defined CONFIG_ETRAXFS
141 #include "../../arch-v32/mach-fs/hw_settings.S"
142 #elif defined CONFIG_CRIS_MACH_ARTPEC3
143 #include "../../arch-v32/mach-a3/hw_settings.S"
144 #else
145 #error Only ETRAXFS and ARTPEC-3 supported!
146 #endif