ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / parisc / kernel / head.S
1 /*
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (C) 1999 by Helge Deller
8  * Copyright 1999 SuSE GmbH (Philipp Rumpf)
9  * Copyright 1999 Philipp Rumpf (prumpf@tux.org)
10  *
11  * Initial Version 04-23-1999 by Helge Deller <deller@gmx.de>
12  */
13
14 #include <linux/autoconf.h>     /* for CONFIG_SMP */
15
16 #include <asm/offsets.h>
17 #include <asm/psw.h>
18
19 #include <asm/assembly.h>
20 #include <asm/pgtable.h>
21
22
23         .level 1.1
24
25         .data
26
27         .export boot_args
28 boot_args:
29         .word 0 /* arg0 */
30         .word 0 /* arg1 */
31         .word 0 /* arg2 */
32         .word 0 /* arg3 */
33
34         .text
35         .align  4       
36         .import init_thread_union,data
37         .import $global$                /* forward declaration */
38         .import fault_vector_11,code    /* IVA parisc 1.1 32 bit */
39         .import fault_vector_20,code    /* IVA parisc 2.0 32 bit */
40
41         .export stext
42         .export _stext,data             /* Kernel want it this way! */
43 _stext:
44 stext:
45         .proc
46         .callinfo
47
48         /* Make sure sr4-sr7 are set to zero for the kernel address space */
49         mtsp    %r0,%sr4
50         mtsp    %r0,%sr5
51         mtsp    %r0,%sr6
52         mtsp    %r0,%sr7
53
54         /* Clear BSS (shouldn't the boot loader do this?) */
55
56         .import __bss_start,data
57         .import __bss_stop,data
58
59         ldil            L%PA(__bss_start),%r3
60         ldo             R%PA(__bss_start)(%r3),%r3
61         ldil            L%PA(__bss_stop),%r4
62         ldo             R%PA(__bss_stop)(%r4),%r4
63 $bss_loop:
64         cmpb,<<,n       %r3,%r4,$bss_loop
65         stw,ma          %r0,4(%r3)
66
67         /* Save away the arguments the boot loader passed in (32 bit args) */
68
69         ldil            L%PA(boot_args),%r1
70         ldo             R%PA(boot_args)(%r1),%r1
71         stw,ma          %arg0,4(%r1)
72         stw,ma          %arg1,4(%r1)
73         stw,ma          %arg2,4(%r1)
74         stw,ma          %arg3,4(%r1)
75
76         /* Initialize startup VM. Just map first 8 MB of memory */
77         ldil            L%PA(pg0),%r1
78         ldo             R%PA(pg0)(%r1),%r1
79         ldo             _PAGE_TABLE(%r1),%r3
80
81         ldil            L%PA(swapper_pg_dir),%r4
82         ldo             R%PA(swapper_pg_dir)(%r4),%r4
83         mtctl           %r4,%cr24       /* Initialize kernel root pointer */
84         mtctl           %r4,%cr25       /* Initialize user root pointer */
85
86 #if (__PAGE_OFFSET != 0x10000000UL)
87 Error! Code below (the next two stw's) needs to be changed
88 #endif
89
90         stw             %r3,0x100(%r4)  /* Hardwired 0x1... kernel Vaddr start*/
91         ldo             0x1000(%r3),%r3
92         stw             %r3,0x104(%r4)
93         ldo             _PAGE_KERNEL(%r0),%r3 /* Hardwired 0 phys addr start */
94 $pgt_fill_loop:
95         stwm            %r3,4(%r1)
96         ldo             0x1000(%r3),%r3
97         bb,>=           %r3,8,$pgt_fill_loop
98         nop
99
100
101         /* Load the return address...er...crash 'n burn */
102         copy            %r0,%r2
103
104         /* And the RFI Target address too */
105         ldil            L%start_kernel,%r11
106         ldo             R%start_kernel(%r11),%r11
107
108         /* And the initial task pointer */
109
110         ldil            L%init_thread_union,%r6
111         ldo             R%init_thread_union(%r6),%r6
112         mtctl           %r6,%cr30
113
114         /* And the stack pointer too */
115
116         ldo             THREAD_SZ_ALGN(%r6),%sp
117
118         /* And the interrupt stack */
119
120         ldil            L%interrupt_stack,%r6
121         ldo             R%interrupt_stack(%r6),%r6
122         mtctl           %r6,%cr31
123
124 #ifdef CONFIG_SMP
125         /* Set the smp rendevous address into page zero.
126         ** It would be safer to do this in init_smp_config() but
127         ** it's just way easier to deal with here because
128         ** of 64-bit function ptrs and the address is local to this file.
129         */
130         ldil            L%PA(smp_slave_stext),%r10
131         ldo             R%PA(smp_slave_stext)(%r10),%r10
132         stw             %r10,0x10(%r0)  /* MEM_RENDEZ */
133         stw             %r0,0x28(%r0)   /* MEM_RENDEZ_HI - assume addr < 4GB */
134
135         /* FALLTHROUGH */
136         .procend
137
138         /*
139         ** Code Common to both Monarch and Slave processors.
140         ** Entry:
141         **    %r11 must contain RFI target address.
142         **    %r25/%r26 args to pass to target function
143         **    %r2  in case rfi target decides it didn't like something
144         **
145         ** Caller must init: SR4-7, %sp, %r10, %cr24/25, 
146         */
147 common_stext:
148         .proc
149         .callinfo
150 #else
151         /* Clear PDC entry point - we won't use it */
152         stw             %r0,0x10(%r0)   /* MEM_RENDEZ */
153         stw             %r0,0x28(%r0)   /* MEM_RENDEZ_HI */
154 #endif
155
156         /* PARANOID: clear user scratch/user space SR's */
157         mtsp    %r0,%sr0
158         mtsp    %r0,%sr1
159         mtsp    %r0,%sr2
160         mtsp    %r0,%sr3
161
162         /* Initialize Protection Registers */
163         mtctl   %r0,%cr8
164         mtctl   %r0,%cr9
165         mtctl   %r0,%cr12
166         mtctl   %r0,%cr13
167
168         /* Initialize the global data pointer */
169         ldil            L%$global$,%dp
170         ldo             R%$global$(%dp),%dp
171
172         /*
173          * Set up our interrupt table.  HPMCs might not work after this! 
174          *
175          * We need to install the correct iva for PA1.1 or PA2.0. The
176          * following short sequence of instructions can determine this
177          * (without being illegal on a PA1.1 machine).
178          */
179         ldi             32,%r10
180         mtctl           %r10,%cr11
181         .level 2.0
182         mfctl,w         %cr11,%r10
183         .level 1.1
184         comib,<>,n      0,%r10,$is_pa20
185         ldil            L%PA(fault_vector_11),%r10
186         b               $install_iva
187         ldo             R%PA(fault_vector_11)(%r10),%r10
188
189 $is_pa20:
190         ldil            L%PA(fault_vector_20),%r10
191         ldo             R%PA(fault_vector_20)(%r10),%r10
192
193 $install_iva:
194         mtctl           %r10,%cr14
195
196         /* Disable Q bit so we can load the iia queue */
197         rsm            PSW_SM_Q,%r0
198
199         /* kernel PSW:
200          *  - no interruptions except HPMC and TOC (which are handled by PDC)
201          *  - Q bit set (IODC / PDC interruptions)
202          *  - big-endian
203          *  - virtually mapped
204          */
205         ldil            L%KERNEL_PSW,%r10
206         ldo             R%KERNEL_PSW(%r10),%r10
207         mtctl           %r10,%ipsw
208
209         /* Set the space pointers for the post-RFI world
210         ** Clear the two-level IIA Space Queue, effectively setting
211         ** Kernel space.
212         */
213         mtctl           %r0,%cr17       /* Clear IIASQ tail */
214         mtctl           %r0,%cr17       /* Clear IIASQ head */
215
216         /* Load RFI target into PC queue */
217         mtctl           %r11,%cr18      /* IIAOQ head */
218         ldo             4(%r11),%r11
219         mtctl           %r11,%cr18      /* IIAOQ tail */
220
221         /* Jump to hyperspace */
222         rfi
223         nop
224
225         .procend
226
227 #ifdef CONFIG_SMP
228
229         .import smp_init_current_idle_task,data
230         .import smp_callin,code
231
232 smp_callin_rtn:
233         .proc
234         .callinfo
235         break   1,1             /*  Break if returned from start_secondary */
236         nop
237         nop
238         .procend
239
240 /***************************************************************************
241 *
242 * smp_slave_stext is executed by all non-monarch Processors when the Monarch
243 * pokes the slave CPUs in smp.c:smp_boot_cpus().
244 *
245 * Once here, registers values are initialized in order to branch to virtual
246 * mode. Once all available/eligible CPUs are in virtual mode, all are
247 * released and start out by executing their own idle task.
248 *****************************************************************************/
249
250
251 smp_slave_stext:
252         .proc
253         .callinfo
254
255         /*
256         ** Initialize Space registers
257         */
258         mtsp       %r0,%sr4
259         mtsp       %r0,%sr5
260         mtsp       %r0,%sr6
261         mtsp       %r0,%sr7
262
263         /*  Initialize the SP - monarch sets up smp_init_current_idle_task */
264         ldil            L%PA(smp_init_current_idle_task),%sp
265         ldo             R%PA(smp_init_current_idle_task)(%sp),%sp
266         ldw             0(%sp),%sp      /* load task address */
267         mtctl           %sp,%cr30       /* store in cr30 */
268         addil           L%THREAD_SZ_ALGN,%sp    /* stack is above task */
269         ldo             R%THREAD_SZ_ALGN(%r1),%sp
270
271         /* point CPU to kernel page tables */
272         ldil            L%PA(swapper_pg_dir),%r4
273         ldo             R%PA(swapper_pg_dir)(%r4),%r4
274         mtctl           %r4,%cr24       /* Initialize kernel root pointer */
275         mtctl           %r4,%cr25       /* Initialize user root pointer */
276
277         /* Load RFI *return* address in case smp_callin bails */
278         ldil            L%smp_callin_rtn,%r2
279         ldo             R%smp_callin_rtn(%r2),%r2
280
281         /* Load RFI target address.  */
282         ldil            L%smp_callin,%r11
283         ldo             R%smp_callin(%r11),%r11
284         
285         /* ok...common code can handle the rest */
286         b               common_stext
287         nop
288
289         .procend
290 #endif /* CONFIG_SMP */
291
292         .data
293
294         .align  4
295         .export $global$,data
296
297         .type   $global$,@object
298         .size   $global$,4
299 $global$:       
300         .word 0