summaryrefslogtreecommitdiff
path: root/arch/ppc/boot/common/crt0.S
blob: 4d31b824bbd175c999211eafa96c10b3675cdf04 (plain) (blame)
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
/*    Copyright (c) 1997 Paul Mackerras <paulus@cs.anu.edu.au>
 *      Initial Power Macintosh COFF version.
 *    Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
 *      Modifications for IBM PowerPC 400-class processor evaluation
 *      boards.
 *
 *    Module name: crt0.S
 *
 *    Description:
 *      Boot loader execution entry point. Clears out .bss section as per
 *      ANSI C requirements. Invalidates and flushes the caches over the
 *      range covered by the boot loader's .text section. Sets up a stack
 *      below the .text section entry point.
 *
 *    This program is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU General Public License
 *    as published by the Free Software Foundation; either version
 *    2 of the License, or (at your option) any later version.
 */

#include <linux/config.h>
#include <asm/ppc_asm.h>

	.text

	.globl	_start
_start:
#ifdef XCOFF
	.long	__start,0,0

	.globl	__start
__start:
#endif

	## Flush and invalidate the caches for the range in memory covering
	## the .text section of the boot loader

	lis	r9,_start@h		# r9 = &_start
	lis	r8,_etext@ha		#
	addi	r8,r8,_etext@l		# r8 = &_etext
3:	dcbf	r0,r9			# Flush the data cache
	icbi	r0,r9			# Invalidate the instruction cache
	addi	r9,r9,0x10		# Increment by one cache line
	cmplw	cr0,r9,r8		# Are we at the end yet?
	blt	3b			# No, keep flushing and invalidating
	sync				# sync ; isync after flushing the icache
	isync

	## Clear out the BSS as per ANSI C requirements

	lis	r7,_end@ha
	addi	r7,r7,_end@l		# r7 = &_end
	lis	r8,__bss_start@ha	#
	addi	r8,r8,__bss_start@l	# r8 = &_bss_start

	## Determine how large an area, in number of words, to clear

	subf	r7,r8,r7		# r7 = &_end - &_bss_start + 1
	addi	r7,r7,3			# r7 += 3
	srwi.	r7,r7,2			# r7 = size in words.
	beq	2f			# If the size is zero, do not bother
	addi	r8,r8,-4		# r8 -= 4
	mtctr	r7			# SPRN_CTR = number of words to clear
	li	r0,0			# r0 = 0
1:	stwu	r0,4(r8)		# Clear out a word
	bdnz	1b			# If we are not done yet, keep clearing
2:

#ifdef CONFIG_40x
	## Set up the stack

	lis	r9,_start@h		# r9 = &_start (text section entry)
	ori	r9,r9,_start@l
	subi	r1,r9,64		# Start the stack 64 bytes below _start
	clrrwi	r1,r1,4			# Make sure it is aligned on 16 bytes.
	li	r0,0
	stwu	r0,-16(r1)
	mtlr	r9
#endif

	b	start			# All done, start the real work.