import uloader-2.4.17
[uloader.git] / uloader_boot.S
1 /*
2  * uloader_boot.S
3  *
4  * Copyright (C) 2006 Mihai Georgian <u-boot@linuxnotincluded.org.uk>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  *
21  * Based on: arch/ppc/boot/sandpoint/head.S
22  *           arch/ppc/kernel/head.S
23  *           http://www-106.ibm.com/developerworks/library/pa-ppccache.html
24  */
25
26 #define HID0        0x3F0       /* Hardware Implementation Register 0 */
27 #define HID0_ICE    (1<<15)     /* Instruction Cache Enable */
28 #define HID0_DCE    (1<<14)     /* Data Cache Enable */
29
30 .section ".text"
31 .globl load_uboot
32
33 load_uboot:
34         /* save parameters */
35         mr      r31,r3  /* pa_load_uboot */
36         mr      r30,r4  /* pa_uboot_buf */
37         mr      r29,r5  /* load_address */
38
39         /* disable interrupts */
40         mfmsr   r0
41         rlwinm  r0,r0,0,17,15   /* clear MSR_EE in r0 */
42         sync
43         mtmsr   r0
44         sync
45
46         /* disable cache */
47         bl      disable_cache
48
49         /* jump to after_mmu_off */
50         addi    r4,r31,after_mmu_off-load_uboot
51         li      r3,0
52         mtspr   SRR0,r4
53         mtspr   SRR1,r3
54         isync
55         sync
56         rfi
57
58 after_mmu_off:
59
60         /* copy uboot image */
61         mr      r4,r29          /* load address */
62         addi    r30,r30,4       /* skip size */
63
64 2:      li      r0,1024
65         lwz     r9,0(r30)
66
67         mtctr   r0
68 1:      lwz     r0,0(r9)
69         addi    r9,r9,4
70         stw     r0,0(r4)
71         addi    r4,r4,4
72         bdnz    1b
73
74         addi    r30,r30,4
75         lwz     r0,0(r30)
76         cmpwi   r0,0
77         bne     2b
78
79         /* jump to uboot */
80         lis     r1,0x100        /* put stack at 16M */
81         li      r3,0
82         mr      r9,r29
83         /* u-boot entry point is u-boot base + 0x100 */
84         addi    r9,r9,0x100
85         mtlr    r9
86         blr
87
88 disable_cache:
89         li      r2,1024 /* flush 16K cache */
90         mtctr   r2
91         mr      r3,r2
92         lis     r4,0xC000
93 loop1:
94         lwz     r6,0(r4)
95         addi    r4,r4,16
96         bdnz    loop1
97
98         lis     r4,0xC000
99         mtctr   r3
100 loop2:
101         dcbf    r0,r4
102         addi    r4,r4,16
103         bdnz    loop2
104
105         mfspr   r4,HID0
106         li      r3,0
107         ori     r3,r3,HID0_ICE|HID0_DCE
108         andc    r4,r4,r3
109         mtspr   HID0,r4
110         isync
111         blr