summaryrefslogtreecommitdiffstats
path: root/src/occBootLoader/bootInit.S
blob: 9f4c104f3b6c661221b008b9909b4766c9d24e61 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# *****************************************************************************
# @file bootInit.S
# @brief OCC boot loader initialization
#

# *****************************************************************************
#
#       @page ChangeLogs Change Logs
#       @section bootInit.S BOOTINIT.S
#       @verbatim
#
#   Flag    Def/Fea    Userid    Date        Description
#   ------- ---------- --------  ----------  ----------------------------------
#   @pb000             pbavari   06/21/2011  Created
#   @pb007             pbavari   09/29/2011  Added trap if reset was due to
#                                            watchdog timer
#   @rc003             rickylie  02/03/2012  Verify & Clean Up OCC Headers & Comments
#   @th00c             thallet   03/02/2012  DCCR was getting loaded with incorret imm
#
#  @endverbatim
#
# *****************************************************************************

/*****************************************************************************/
// Includes
/*****************************************************************************/
#include "bootMain.h"
#include "ppc32_asm.h"
#include "ppc405_spr.h"
/*****************************************************************************/

/*****************************************************************************/
// Functions
/*****************************************************************************/
# Function Specification ******************************************************
#
#  Name: boot_low_level_init
#
#  Description: Low level boot initialization
#
#  Flow: 06/22/2011     FN= ??
#
# End Function Specification **************************************************

.global_function __boot_low_level_init

__boot_low_level_init:


#enable machine check exception
# initialize exception vector prefix to zero
# enable machine check (19th bit)

li      %r3, 0
mtevpr  %r3
_liwa   %r4, MACHINE_CHECK_ENABLE
mtmsr   %r4

// Check if TSR[WSR] indicates that reset was due to watchdog,
// then initialize external debug event and trap(halt). Otherwise
// continue normally. Setting up external debug event will set FIR bits on halt
mftsr   %r3
_liwa   %r4, ( TSR_WRS_CHIP | TSR_WRS_CORE | TSR_WRS_SYSTEM )
AND     %r5, %r3, %r4
li      %r4, 0
cmp     0, 0, %r4, %r5
beq     skip_wd_reset_trap

// Initialize external debug event before doing trap
_liwa   %r3, (DBCR0_EDM | DBCR0_TDE | DBCR0_FT )
mtdbcr0 %r3
tw 31,0,0

skip_wd_reset_trap:

# enable write back data cache and instruction cache
# enable write back data for 0x80000000. Note:write-back=0,write-through=1
# Data cache enabled for 0x80000000. Bit 16 going left-right. 1=enable,0=disable
# enable instruction cache for 0x80000000. Bit 16 going left-right.
#      1= enable, 0 = disable

li       %r3, 0
mtdcwr   %r3
_liw     %r3, DATA_CACHE_BLOCK_ENABLE
mtdccr   %r3
mticcr   %r3

dcache_invalidate:
	## We loop through addresses 0 ... (DCACHE_SIZE / DCACHE_WAYS) - 1
	## invalidating the D-Cache.  The dccci instruction on the 405
	## invalidates both ways.  Added: @th00c

	li	%r3, 0
	_liwa	%r4, (DATA_CACHE_LINES / 2)
	mtctr	%r4

1:	
	dccci	%r0, %r3
	addi	%r3, %r3, CACHE_LINE_SIZE
	bdnz	1b
	
	sync

# fill in 16K with zero for the data cache
# set counter to loop for number of data cache lines

_liw    %r3, 0
_liwa   %r5, DATA_CACHE_BLOCK_ADDR
_liwa   %r4, DATA_CACHE_LINES
mtctr   %r4

dcbz_loop:

    dcbz    %r5, %r3
    addi    %r3, %r3, CACHE_LINE_SIZE
    bdnz    dcbz_loop


# calculate writable data section start address
# start_addr + readonly_size = writable data section address
# load start address into r5
# load readonly size address into r4
# add contents of r5 and r4 and put into r3
# r3 now has source address
# load address of size of the data to be copied into r4
# load destination address into r5
# store number of word trasfers in r4
# set counter to r4 content
# NOTE: (-4) for the source and destination address is done because
#       in the loop 4 is added to get to the correct address.

_liw    %r5, (__START_ADDR__ - 4)
_liw    %r4, __READ_ONLY_DATA_LEN__
add     %r3, %r5, %r4
_liw    %r4, __WRITEABLE_DATA_LEN__
_liw    %r5, (__WRITEABLE_DATA_ADDR__ - 4)
_liw    %r6, 2
srw     %r4, %r4, %r6

# Compare r4 and r6. If equal then skip_loop. Else execute copy_loop
_liw    %r6, 0
cmp     0, 0, %r4, %r6
beq     skip_loop
mtctr   %r4
copy_loop:

    lwzu    %r4, 4(%r3)
    stwu    %r4, 4(%r5)
    bdnz    copy_loop

skip_loop:

# set up EABI constant registers r2,r13

_liw    %r2, _SDA2_BASE_
_liw    %r13, _SDA_BASE_

# set up stack pointer - register r1

_liwa    %r1, STACK_POINTER_ADDR

# jump to main

b main

# function clean up and return

.epilogue  __boot_low_level_init

# vector section

.section .vectors_0000, "a", @progbits
    .global __vectors_0000

__vectors_0000:


    .section .vectors_0100, "ax", @progbits
    .global __vectors_0100

__vectors_0100:

# Trap instruction
tw 31,0,0

    .section .vectors_0200, "ax", @progbits
    .global __vectors_0200

__vectors_0200:

# Trap instruction
tw 31,0,0

    .section .vectors_0300, "ax", @progbits
    .global __vectors_0300

__vectors_0300:

# Trap instruction
tw 31,0,0

    .section .vectors_0400, "ax", @progbits
    .global __vectors_0400

__vectors_0400:

# Trap instruction
tw 31,0,0

    .section .vectors_0500, "ax", @progbits
    .global __vectors_0500

__vectors_0500:

# Trap instruction
tw 31,0,0

    .section .vectors_0600, "ax", @progbits
    .global __vectors_0600

__vectors_0600:

# Trap instruction
tw 31,0,0


    .section .vectors_0700, "ax", @progbits
    .global __vectors_0700

__vectors_0700:

# Trap instruction
tw 31,0,0

OpenPOWER on IntegriCloud