2 * (C) Copyright 2012, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 #define EXCEPTION_STACK_SIZE (4*32)
24 #define HANDLE_EXCEPTION ; \
25 l.addi r1, r1, -EXCEPTION_STACK_SIZE ; \
27 l.jal _exception_handler ; \
29 l.lwz r9, 0x1c(r1) ; \
30 l.addi r1, r1, EXCEPTION_STACK_SIZE ; \
35 .section .text, "ax", @progbits
72 l.ori r21, r0, SPR_SR_SM
73 l.mtspr r0, r21, SPR_SR
74 l.movhi r21, hi(_reset_handler)
75 l.ori r21, r21, lo(_reset_handler)
76 l.mtspr r0, r21, SPR_EVBAR
91 /* instruction page fault */
103 /* illegal instruction */
107 /* external interrupt */
141 /* Setup stack and global pointer */
142 l.movhi r1, hi(_fstack)
143 l.ori r1, r1, lo(_fstack)
146 l.movhi r21, hi(_fbss)
147 l.ori r21, r21, lo(_fbss)
148 l.movhi r3, hi(_ebss)
149 l.ori r3, r3, lo(_ebss)
194 /* Save return address */
196 /* Calculate exception vector from handler address */
199 /* Pass saved register state */
201 /* Extract exception PC */
202 l.mfspr r5, r0, SPR_EPCR_BASE
203 /* Extract exception effective address */
204 l.mfspr r6, r0, SPR_EEAR_BASE
205 /* Call exception handler with the link address as argument */
206 l.jal exception_handler
209 /* Load return address */
247 This function is to be used ONLY during reset, before main() is called.
248 TODO: Perhaps break into individual enable instruction/data cache
249 sections functions, and provide disable functions, also, all
253 /* Instruction cache enable */
254 /* Check if IC present and skip enabling otherwise */
257 l.mfspr r3,r0,SPR_UPR
258 l.andi r7,r3,SPR_UPR_ICP
266 l.xori r5,r5,SPR_SR_ICE
270 /* Establish cache block size
273 r14 contain block size
275 l.mfspr r3,r0,SPR_ICCFGR
276 l.andi r7,r3,SPR_ICCFGR_CBS
281 /* Establish number of cache sets
282 r10 contains number of cache sets
283 r8 contains log(# of cache sets)
285 l.andi r7,r3,SPR_ICCFGR_NCS
294 .L7: l.mtspr r0,r6,SPR_ICBIR
301 l.ori r6,r6,SPR_SR_ICE
311 /* Data cache enable */
312 /* Check if DC present and skip enabling otherwise */
316 l.mfspr r3,r0,SPR_UPR
317 l.andi r7,r3,SPR_UPR_DCP
324 l.xori r5,r5,SPR_SR_DCE
327 /* Establish cache block size
330 r14 contain block size
332 l.mfspr r3,r0,SPR_DCCFGR
333 l.andi r7,r3,SPR_DCCFGR_CBS
337 /* Establish number of cache sets
338 r10 contains number of cache sets
339 r8 contains log(# of cache sets)
341 l.andi r7,r3,SPR_DCCFGR_NCS
350 l.mtspr r0,r6,SPR_DCBIR
356 l.ori r6,r6,SPR_SR_DCE