added UART init and progress while booting kernel.
[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
31 #define UART1           0xfc004500
32 #define UART1_IER       0xfc004501
33 #define UART1_FCR       0xfc004502
34 #define UART1_LCR       0xfc004503
35 #define UART1_DCR       0xfc004511
36
37 #define WM8(address,data) \
38         lis     r3, address@h; \
39         ori     r3, r3, address@l; \
40         li      r4, data; \
41         stb     r4, 0(r3); \
42         sync; \
43         isync;
44
45
46 .section ".text"
47 .globl load_uboot
48
49 load_uboot:
50         /* save parameters */
51         mr      r31,r3  /* pa_load_uboot */
52         mr      r30,r4  /* pa_uboot_buf */
53         mr      r29,r5  /* load_address */
54
55         /* Init UART for AVR */
56         WM8(UART1_LCR,0x00) /* clear LCR */
57         WM8(UART1_IER,0x00) /* disable interrupt */
58         WM8(UART1_LCR,0x80) /* set LCR[DLAB] bit */
59         WM8(UART1_DCR,0x01) /* set DUART mode */
60         WM8(UART1,    0x8B) /* set DLL(baudrate 9600bps, 100MHz) */
61         WM8(UART1_IER,0x02) /* set DLM(baudrate 9600bps, 100MHz) */
62         WM8(UART1_LCR,0x03) /* set 8data, 1stop, non parity */
63         WM8(UART1,    0x00) /* clear MCR */
64         WM8(UART1_FCR,0x07) /* clear & enable FIFO */
65
66         WM8(0xfc004500,0x41);
67
68         /* disable interrupts */
69         mfmsr   r0
70         rlwinm  r0,r0,0,17,15   /* clear MSR_EE in r0 */
71         sync
72         mtmsr   r0
73         sync
74
75         /* disable cache */
76         bl      disable_cache
77
78         /* jump to after_mmu_off */
79         addi    r4,r31,after_mmu_off-load_uboot
80         li      r3,0
81         mtspr   SRR0,r4
82         mtspr   SRR1,r3
83         isync
84         sync
85         rfi
86
87 after_mmu_off:
88
89         /* copy uboot image */
90         mr      r4,r29          /* load address */
91         addi    r30,r30,4       /* skip size */
92
93 2:
94
95         WM8(0xfc004500,0x42);
96         li      r0,1024
97         lwz     r9,0(r30)
98
99         mtctr   r0
100 1:      lwz     r0,0(r9)
101         addi    r9,r9,4
102         stw     r0,0(r4)
103         addi    r4,r4,4
104         bdnz    1b
105
106         addi    r30,r30,4
107         lwz     r0,0(r30)
108         cmpwi   r0,0
109         bne     2b
110
111         WM8(0xfc004500,0x43);
112         /* jump to uboot */
113         lis     r1,0x100        /* put stack at 16M */
114         li      r3,0
115         mr      r9,r29
116         /* u-boot entry point is u-boot base + 0x100 */
117         addi    r9,r9,0x100
118         mtlr    r9
119         blr
120
121         WM8(0xfc004500,0x44);
122 disable_cache:
123         li      r2,1024 /* flush 16K cache */
124         mtctr   r2
125         mr      r3,r2
126         lis     r4,0xC000
127 loop1:
128         lwz     r6,0(r4)
129         addi    r4,r4,16
130         bdnz    loop1
131
132         lis     r4,0xC000
133         mtctr   r3
134 loop2:
135         dcbf    r0,r4
136         addi    r4,r4,16
137         bdnz    loop2
138
139         mfspr   r4,HID0
140         li      r3,0
141         ori     r3,r3,HID0_ICE|HID0_DCE
142         andc    r4,r4,r3
143         mtspr   HID0,r4
144         isync
145         blr