aboutsummaryrefslogtreecommitdiff
path: root/arch/cris/arch-v32/boot/compressed/head.S
blob: a4a65c5c669ecea7ac9aede58aacd71e3b402388 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 *  Code that sets up the DRAM registers, calls the
 *  decompressor to unpack the piggybacked kernel, and jumps.
 *
 *  Copyright (C) 1999 - 2006, Axis Communications AB
 */

#define ASSEMBLER_MACROS_ONLY
#include <hwregs/asm/reg_map_asm.h>
#include <mach/startup.inc>

#define RAM_INIT_MAGIC 0x56902387
#define COMMAND_LINE_MAGIC 0x87109563

	;; Exported symbols

	.globl	input_data

	.text
_start:
	di

	;; Start clocks for used blocks.
	START_CLOCKS

	;; Initialize the DRAM registers.
	cmp.d	RAM_INIT_MAGIC, $r8	; Already initialized?
	beq	dram_init_finished
	nop

#if defined CONFIG_ETRAXFS
#include "../../mach-fs/dram_init.S"
#elif defined CONFIG_CRIS_MACH_ARTPEC3
#include "../../mach-a3/dram_init.S"
#else
#error Only ETRAXFS and ARTPEC-3 supported!
#endif

dram_init_finished:

	GIO_INIT
	;; Setup the stack to a suitably high address.
	;; We assume 8 MB is the minimum DRAM and put
	;; the SP at the top for now.

	move.d	0x40800000, $sp

	;; Figure out where the compressed piggyback image is.
	;; It is either in [NOR] flash (we don't want to copy it
	;; to DRAM before unpacking), or copied to DRAM
	;; by the [NAND] flash boot loader.
	;; The piggyback image is at _edata, but relative to where the
	;; image is actually located in memory, not where it is linked
	;; (the decompressor is linked at 0x40700000+ and runs there).
	;; Use (_edata - herami) as offset to the current PC.

hereami:
	lapcq	., $r5		; get PC
	and.d	0x7fffffff, $r5	; strip any non-cache bit
	move.d	$r5, $r0	; source address of 'herami'
	add.d	_edata, $r5
	sub.d	hereami, $r5	; r5 = flash address of '_edata'
	move.d	hereami, $r1	; destination

	;; Copy text+data to DRAM

	move.d	_edata, $r2	; end destination
1:	move.w	[$r0+], $r3	; from herami+ source
	move.w	$r3, [$r1+]	; to hereami+ destination (linked address)
	cmp.d	$r2, $r1	; finish when destination == _edata
	bcs	1b
	nop
	move.d	input_data, $r0 ; for the decompressor
	move.d	$r5, [$r0]	; for the decompressor

	;; Clear the decompressors BSS (between _edata and _end)

	moveq	0, $r0
	move.d	_edata, $r1
	move.d	_end, $r2
1:	move.w	$r0, [$r1+]
	cmp.d	$r2, $r1
	bcs	1b
	nop

	;;  Save command line magic and address.
	move.d	_cmd_line_magic, $r0
	move.d  $r10, [$r0]
	move.d	_cmd_line_addr, $r0
	move.d  $r11, [$r0]

	;;  Save boot source indicator
	move.d	_boot_source, $r0
	move.d	$r12, [$r0]

	;; Do the decompression and save compressed size in _inptr

	jsr	decompress_kernel
	nop

	;; Restore boot source indicator
	move.d	_boot_source, $r12
	move.d	[$r12], $r12

	;; Restore command line magic and address.
	move.d  _cmd_line_magic, $r10
	move.d  [$r10], $r10
	move.d  _cmd_line_addr, $r11
	move.d  [$r11], $r11

	;; Put start address of root partition in r9 so the kernel can use it
	;; when mounting from flash
	move.d  input_data, $r0
	move.d	[$r0], $r9		; flash address of compressed kernel
	move.d  inptr, $r0
	add.d	[$r0], $r9		; size of compressed kernel
	cmp.d   0x40000000, $r9		; image in DRAM ?
	blo	enter_kernel		; no, must be [NOR] flash, jump
	nop				; delay slot
	and.d   0x001fffff, $r9		; assume compressed kernel was < 2M

enter_kernel:
	;; Enter the decompressed kernel
	move.d	RAM_INIT_MAGIC, $r8	; Tell kernel that DRAM is initialized
	jump	0x40004000	; kernel is linked to this address
	nop

	.data

input_data:
	.dword	0		; used by the decompressor
_cmd_line_magic:
	.dword 0
_cmd_line_addr:
	.dword 0
_boot_source:
	.dword 0

#if defined CONFIG_ETRAXFS
#include "../../mach-fs/hw_settings.S"
#elif defined CONFIG_CRIS_MACH_ARTPEC3
#include "../../mach-a3/hw_settings.S"
#else
#error Only ETRAXFS and ARTPEC-3 supported!
#endif