Small cleanups including deletion of two variables 4k each ...
[linux-2.6/linux-mips.git] / arch / mips / kernel / head.S
blob1cb9d6fe124b30a16907a85beb61ca37f037b429
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994, 1995 Waldorf Electronics
7  * Written by Ralf Baechle and Andreas Busse
8  * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003 Ralf Baechle
9  * Copyright (C) 1996 Paul M. Antoine
10  * Modified for DECStation and hence R3000 support by Paul M. Antoine
11  * Further modifications by David S. Miller and Harald Koerfgen
12  * Copyright (C) 1999 Silicon Graphics, Inc.
13  * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
14  * Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
15  */
16 #include <linux/config.h>
17 #include <linux/init.h>
18 #include <linux/threads.h>
20 #include <asm/asm.h>
21 #include <asm/regdef.h>
22 #include <asm/page.h>
23 #include <asm/processor.h>
24 #include <asm/mipsregs.h>
25 #include <asm/stackframe.h>
26 #ifdef CONFIG_SGI_IP27
27 #include <asm/sn/addrs.h>
28 #include <asm/sn/sn0/hubni.h>
29 #include <asm/sn/klkernvars.h>
30 #endif
32         .macro  ARC64_TWIDDLE_PC
33 #if defined(CONFIG_ARC64) || defined(CONFIG_MAPPED_KERNEL)
34         /* We get launched at a XKPHYS address but the kernel is linked to
35            run at a KSEG0 address, so jump there.  */
36         PTR_LA  t0, \@f
37         jr      t0
38 \@:
39 #endif
40         .endm
42 #ifdef CONFIG_SGI_IP27
43         /*
44          * outputs the local nasid into res.  IP27 stuff.
45          */
46         .macro GET_NASID_ASM res
47         dli     \res, LOCAL_HUB_ADDR(NI_STATUS_REV_ID)
48         ld      \res, (\res)
49         and     \res, NSRI_NODEID_MASK
50         dsrl    \res, NSRI_NODEID_SHFT
51         .endm
52 #endif /* CONFIG_SGI_IP27 */
54         /*
55          * inputs are the text nasid in t1, data nasid in t2.
56          */
57         .macro MAPPED_KERNEL_SETUP_TLB
58 #ifdef CONFIG_MAPPED_KERNEL
59         /*
60          * This needs to read the nasid - assume 0 for now.
61          * Drop in 0xffffffffc0000000 in tlbhi, 0+VG in tlblo_0,
62          * 0+DVG in tlblo_1.
63          */
64         dli     t0, 0xffffffffc0000000
65         dmtc0   t0, CP0_ENTRYHI
66         li      t0, 0x1c000             # Offset of text into node memory
67         dsll    t1, NASID_SHFT          # Shift text nasid into place
68         dsll    t2, NASID_SHFT          # Same for data nasid
69         or      t1, t1, t0              # Physical load address of kernel text
70         or      t2, t2, t0              # Physical load address of kernel data
71         dsrl    t1, 12                  # 4K pfn
72         dsrl    t2, 12                  # 4K pfn
73         dsll    t1, 6                   # Get pfn into place
74         dsll    t2, 6                   # Get pfn into place
75         li      t0, ((_PAGE_GLOBAL|_PAGE_VALID| _CACHE_CACHABLE_COW) >> 6)
76         or      t0, t0, t1
77         mtc0    t0, CP0_ENTRYLO0        # physaddr, VG, cach exlwr
78         li      t0, ((_PAGE_GLOBAL|_PAGE_VALID| _PAGE_DIRTY|_CACHE_CACHABLE_COW) >> 6)
79         or      t0, t0, t2
80         mtc0    t0, CP0_ENTRYLO1        # physaddr, DVG, cach exlwr
81         li      t0, 0x1ffe000           # MAPPED_KERN_TLBMASK, TLBPGMASK_16M
82         mtc0    t0, CP0_PAGEMASK
83         li      t0, 0                   # KMAP_INX
84         mtc0    t0, CP0_INDEX
85         li      t0, 1
86         mtc0    t0, CP0_WIRED
87         tlbwi
88 #else
89         mtc0    zero, CP0_WIRED
90 #endif
91         .endm
93         /*
94          * Reserved space for exception handlers.
95          * Necessary for machines which link their kernels at KSEG0.
96          */
97         .fill   0x400
99 EXPORT(stext)                                   # used for profiling
100 EXPORT(_stext)
102         __INIT
104 NESTED(kernel_entry, 16, sp)                    # kernel entry point
105 #ifdef CONFIG_SGI_IP27
106         GET_NASID_ASM   t1
107         move    t2, t1                          # text and data are here
108         MAPPED_KERNEL_SETUP_TLB
109 #endif /* IP27 */
111         ARC64_TWIDDLE_PC
113         CLI                                     # disable interrupts
115         PTR_LA          $28, init_thread_union
116         PTR_ADDIU       sp, $28, _THREAD_SIZE - 32
117         set_saved_sp    sp, t0, t1
118         PTR_SUBU        sp, 4 * SZREG           # init stack pointer
120         /*
121          * The firmware/bootloader passes argc/argp/envp
122          * to us as arguments.  But clear bss first because
123          * the romvec and other important info is stored there
124          * by prom_init().
125          */
126         PTR_LA          t0, __bss_start
127         LONG_S          zero, (t0)
128         PTR_LA          t1, __bss_stop - LONGSIZE
130         PTR_ADDIU       t0, LONGSIZE
131         LONG_S          zero, (t0)
132         bne             t0, t1, 1b
134         jal             init_arch
135         END(kernel_entry)
137 #ifdef CONFIG_SMP
139  * SMP slave cpus entry point.  Board specific code for bootstrap calls this
140  * function after setting up the stack and gp registers.
141  */
142 NESTED(smp_bootstrap, 16, sp)
143 #ifdef CONFIG_SGI_IP27
144         GET_NASID_ASM   t1
145         li      t0, KLDIR_OFFSET + (KLI_KERN_VARS * KLDIR_ENT_SIZE) + \
146                     KLDIR_OFF_POINTER + K0BASE
147         dsll    t1, NASID_SHFT
148         or      t0, t0, t1
149         ld      t0, 0(t0)                       # t0 points to kern_vars struct
150         lh      t1, KV_RO_NASID_OFFSET(t0)
151         lh      t2, KV_RW_NASID_OFFSET(t0)
152         MAPPED_KERNEL_SETUP_TLB
153         ARC64_TWIDDLE_PC
154 #endif /* CONFIG_SGI_IP27 */
156         CLI
158 #ifdef CONFIG_MIPS64
159         /*
160          * For the moment set ST0_KU so the CPU will not spit fire when
161          * executing 64-bit instructions.  The full initialization of the
162          * CPU's status register is done later in per_cpu_trap_init().
163          */
164         mfc0    t0, CP0_STATUS
165         or      t0, ST0_KX
166         mtc0    t0, CP0_STATUS
167 #endif
168         jal     start_secondary
169         END(smp_bootstrap)
170 #endif /* CONFIG_SMP */
172         __FINIT
174         .comm   kernelsp,    NR_CPUS * 8, 8
175         .comm   pgd_current, NR_CPUS * 8, 8
177         .macro  page name, order=0
178         .globl  \name
179 \name:  .size   \name, (_PAGE_SIZE << \order)
180         .org    . + (_PAGE_SIZE << \order)
181         .type   \name, @object
182         .endm
184         .data
185         .align  PAGE_SHIFT
187 #ifdef CONFIG_MIPS32
188         /*
189          * Here we only have a two-level pagetable structure ...
190          */
191         page    swapper_pg_dir, _PGD_ORDER
192         page    invalid_pte_table, _PTE_ORDER
193 #endif
194 #ifdef CONFIG_MIPS64
195         /*
196          * ... but on 64-bit we've got three-level pagetables with a
197          * slightly different layout ...
198          */
199         page    swapper_pg_dir, _PGD_ORDER
200         page    invalid_pmd_table, _PMD_ORDER
201         page    invalid_pte_table, _PTE_ORDER
203         /*
204          * 64-bit kernel mappings are really screwed up ...
205          */
206         page    kptbl, _PGD_ORDER
207         .globl  ekptbl
208         page    kpmdtbl, 0
209 ekptbl:
210 #endif