]> Pileus Git - ~andy/linux/blob - arch/sparc/kernel/head_32.S
sparc32: simpler cputype check in head_32.S
[~andy/linux] / arch / sparc / kernel / head_32.S
1 /*
2  * head.S: The initial boot code for the Sparc port of Linux.
3  *
4  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5  * Copyright (C) 1995,1999 Pete Zaitcev   (zaitcev@yahoo.com)
6  * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
7  * Copyright (C) 1997 Jakub Jelinek   (jj@sunsite.mff.cuni.cz)
8  * Copyright (C) 1997 Michael A. Griffith (grif@acm.org)
9  *
10  * CompactPCI platform by Eric Brower, 1999.
11  */
12
13 #include <linux/version.h>
14 #include <linux/init.h>
15
16 #include <asm/head.h>
17 #include <asm/asi.h>
18 #include <asm/contregs.h>
19 #include <asm/ptrace.h>
20 #include <asm/psr.h>
21 #include <asm/page.h>
22 #include <asm/kdebug.h>
23 #include <asm/winmacro.h>
24 #include <asm/thread_info.h>    /* TI_UWINMASK */
25 #include <asm/errno.h>
26 #include <asm/pgtsrmmu.h>       /* SRMMU_PGDIR_SHIFT */
27
28         .data
29 /* The following are used with the prom_vector node-ops to figure out
30  * the cpu-type
31  */
32         .align 4
33 cputyp:
34         .word   1
35
36         .align 4
37         .globl cputypval
38 cputypval:
39         .asciz "sun4m"
40         .ascii "     "
41
42 /* Tested on SS-5, SS-10 */
43         .align 4
44 cputypvar:
45         .asciz "compatible"
46
47         .align 4
48
49 sun4c_notsup:
50         .asciz  "Sparc-Linux sun4/sun4c support does no longer exist.\n\n"
51         .align 4
52
53 sun4e_notsup:
54         .asciz  "Sparc-Linux sun4e support does not exist\n\n"
55         .align 4
56
57         /* The Sparc trap table, bootloader gives us control at _start. */
58         __HEAD
59         .globl  _stext, _start, __stext
60         .globl  trapbase
61 _start:   /* danger danger */
62 __stext:
63 _stext:
64 trapbase:
65 #ifdef CONFIG_SMP
66 trapbase_cpu0:
67 #endif
68 /* We get control passed to us here at t_zero. */
69 t_zero: b gokernel; nop; nop; nop;
70 t_tflt: SRMMU_TFAULT                        /* Inst. Access Exception        */
71 t_bins: TRAP_ENTRY(0x2, bad_instruction)    /* Illegal Instruction           */
72 t_pins: TRAP_ENTRY(0x3, priv_instruction)   /* Privileged Instruction        */
73 t_fpd:  TRAP_ENTRY(0x4, fpd_trap_handler)   /* Floating Point Disabled       */
74 t_wovf: WINDOW_SPILL                        /* Window Overflow               */
75 t_wunf: WINDOW_FILL                         /* Window Underflow              */
76 t_mna:  TRAP_ENTRY(0x7, mna_handler)        /* Memory Address Not Aligned    */
77 t_fpe:  TRAP_ENTRY(0x8, fpe_trap_handler)   /* Floating Point Exception      */
78 t_dflt: SRMMU_DFAULT                        /* Data Miss Exception           */
79 t_tio:  TRAP_ENTRY(0xa, do_tag_overflow)    /* Tagged Instruction Ovrflw     */
80 t_wpt:  TRAP_ENTRY(0xb, do_watchpoint)      /* Watchpoint Detected           */
81 t_badc: BAD_TRAP(0xc) BAD_TRAP(0xd) BAD_TRAP(0xe) BAD_TRAP(0xf) BAD_TRAP(0x10)
82 t_irq1: TRAP_ENTRY_INTERRUPT(1)             /* IRQ Software/SBUS Level 1     */
83 t_irq2: TRAP_ENTRY_INTERRUPT(2)             /* IRQ SBUS Level 2              */
84 t_irq3: TRAP_ENTRY_INTERRUPT(3)             /* IRQ SCSI/DMA/SBUS Level 3     */
85 t_irq4: TRAP_ENTRY_INTERRUPT(4)             /* IRQ Software Level 4          */
86 t_irq5: TRAP_ENTRY_INTERRUPT(5)             /* IRQ SBUS/Ethernet Level 5     */
87 t_irq6: TRAP_ENTRY_INTERRUPT(6)             /* IRQ Software Level 6          */
88 t_irq7: TRAP_ENTRY_INTERRUPT(7)             /* IRQ Video/SBUS Level 5        */
89 t_irq8: TRAP_ENTRY_INTERRUPT(8)             /* IRQ SBUS Level 6              */
90 t_irq9: TRAP_ENTRY_INTERRUPT(9)             /* IRQ SBUS Level 7              */
91 t_irq10:TRAP_ENTRY_INTERRUPT(10)            /* IRQ Timer #1 (one we use)     */
92 t_irq11:TRAP_ENTRY_INTERRUPT(11)            /* IRQ Floppy Intr.              */
93 t_irq12:TRAP_ENTRY_INTERRUPT(12)            /* IRQ Zilog serial chip         */
94 t_irq13:TRAP_ENTRY_INTERRUPT(13)            /* IRQ Audio Intr.               */
95 t_irq14:TRAP_ENTRY_INTERRUPT(14)            /* IRQ Timer #2                  */
96         .globl  t_nmi
97 t_nmi:  TRAP_ENTRY(0x1f, linux_trap_ipi15_sun4m)
98
99 t_racc: TRAP_ENTRY(0x20, do_reg_access)     /* General Register Access Error */
100 t_iacce:BAD_TRAP(0x21)                      /* Instr Access Error            */
101 t_bad22:BAD_TRAP(0x22) BAD_TRAP(0x23)
102 t_cpdis:TRAP_ENTRY(0x24, do_cp_disabled)    /* Co-Processor Disabled         */
103 t_uflsh:SKIP_TRAP(0x25, unimp_flush)        /* Unimplemented FLUSH inst.     */
104 t_bad26:BAD_TRAP(0x26) BAD_TRAP(0x27)
105 t_cpexc:TRAP_ENTRY(0x28, do_cp_exception)   /* Co-Processor Exception        */
106 t_dacce:SRMMU_DFAULT                        /* Data Access Error             */
107 t_hwdz: TRAP_ENTRY(0x2a, do_hw_divzero)     /* Division by zero, you lose... */
108 t_dserr:BAD_TRAP(0x2b)                      /* Data Store Error              */
109 t_daccm:BAD_TRAP(0x2c)                      /* Data Access MMU-Miss          */
110 t_bad2d:BAD_TRAP(0x2d) BAD_TRAP(0x2e) BAD_TRAP(0x2f) BAD_TRAP(0x30) BAD_TRAP(0x31)
111 t_bad32:BAD_TRAP(0x32) BAD_TRAP(0x33) BAD_TRAP(0x34) BAD_TRAP(0x35) BAD_TRAP(0x36)
112 t_bad37:BAD_TRAP(0x37) BAD_TRAP(0x38) BAD_TRAP(0x39) BAD_TRAP(0x3a) BAD_TRAP(0x3b)
113 t_iaccm:BAD_TRAP(0x3c)                      /* Instr Access MMU-Miss         */
114 t_bad3d:BAD_TRAP(0x3d) BAD_TRAP(0x3e) BAD_TRAP(0x3f) BAD_TRAP(0x40) BAD_TRAP(0x41)
115 t_bad42:BAD_TRAP(0x42) BAD_TRAP(0x43) BAD_TRAP(0x44) BAD_TRAP(0x45) BAD_TRAP(0x46)
116 t_bad47:BAD_TRAP(0x47) BAD_TRAP(0x48) BAD_TRAP(0x49) BAD_TRAP(0x4a) BAD_TRAP(0x4b)
117 t_bad4c:BAD_TRAP(0x4c) BAD_TRAP(0x4d) BAD_TRAP(0x4e) BAD_TRAP(0x4f) BAD_TRAP(0x50)
118 t_bad51:BAD_TRAP(0x51) BAD_TRAP(0x52) BAD_TRAP(0x53) BAD_TRAP(0x54) BAD_TRAP(0x55)
119 t_bad56:BAD_TRAP(0x56) BAD_TRAP(0x57) BAD_TRAP(0x58) BAD_TRAP(0x59) BAD_TRAP(0x5a)
120 t_bad5b:BAD_TRAP(0x5b) BAD_TRAP(0x5c) BAD_TRAP(0x5d) BAD_TRAP(0x5e) BAD_TRAP(0x5f)
121 t_bad60:BAD_TRAP(0x60) BAD_TRAP(0x61) BAD_TRAP(0x62) BAD_TRAP(0x63) BAD_TRAP(0x64)
122 t_bad65:BAD_TRAP(0x65) BAD_TRAP(0x66) BAD_TRAP(0x67) BAD_TRAP(0x68) BAD_TRAP(0x69)
123 t_bad6a:BAD_TRAP(0x6a) BAD_TRAP(0x6b) BAD_TRAP(0x6c) BAD_TRAP(0x6d) BAD_TRAP(0x6e)
124 t_bad6f:BAD_TRAP(0x6f) BAD_TRAP(0x70) BAD_TRAP(0x71) BAD_TRAP(0x72) BAD_TRAP(0x73)
125 t_bad74:BAD_TRAP(0x74) BAD_TRAP(0x75) BAD_TRAP(0x76) BAD_TRAP(0x77) BAD_TRAP(0x78)
126 t_bad79:BAD_TRAP(0x79) BAD_TRAP(0x7a) BAD_TRAP(0x7b) BAD_TRAP(0x7c) BAD_TRAP(0x7d)
127 t_bad7e:BAD_TRAP(0x7e) BAD_TRAP(0x7f)
128 t_bad80:BAD_TRAP(0x80)                      /* SunOS System Call             */
129 t_sbkpt:BREAKPOINT_TRAP                     /* Software Breakpoint/KGDB      */
130 t_divz: TRAP_ENTRY(0x82, do_hw_divzero)     /* Divide by zero trap           */
131 t_flwin:TRAP_ENTRY(0x83, do_flush_windows)  /* Flush Windows Trap            */
132 t_clwin:BAD_TRAP(0x84)                      /* Clean Windows Trap            */
133 t_rchk: BAD_TRAP(0x85)                      /* Range Check                   */
134 t_funal:BAD_TRAP(0x86)                      /* Fix Unaligned Access Trap     */
135 t_iovf: BAD_TRAP(0x87)                      /* Integer Overflow Trap         */
136 t_bad88:BAD_TRAP(0x88)                      /* Slowaris System Call          */
137 t_bad89:BAD_TRAP(0x89)                      /* Net-B.S. System Call          */
138 t_bad8a:BAD_TRAP(0x8a) BAD_TRAP(0x8b) BAD_TRAP(0x8c) BAD_TRAP(0x8d) BAD_TRAP(0x8e)
139 t_bad8f:BAD_TRAP(0x8f)
140 t_linux:LINUX_SYSCALL_TRAP                  /* Linux System Call             */
141 t_bad91:BAD_TRAP(0x91) BAD_TRAP(0x92) BAD_TRAP(0x93) BAD_TRAP(0x94) BAD_TRAP(0x95)
142 t_bad96:BAD_TRAP(0x96) BAD_TRAP(0x97) BAD_TRAP(0x98) BAD_TRAP(0x99) BAD_TRAP(0x9a)
143 t_bad9b:BAD_TRAP(0x9b) BAD_TRAP(0x9c) BAD_TRAP(0x9d) BAD_TRAP(0x9e) BAD_TRAP(0x9f)
144 t_getcc:GETCC_TRAP                          /* Get Condition Codes           */
145 t_setcc:SETCC_TRAP                          /* Set Condition Codes           */
146 t_getpsr:GETPSR_TRAP                        /* Get PSR Register              */
147 t_bada3:BAD_TRAP(0xa3) BAD_TRAP(0xa4) BAD_TRAP(0xa5) BAD_TRAP(0xa6)
148 t_bada7:BAD_TRAP(0xa7)
149 t_bada8:BAD_TRAP(0xa8) BAD_TRAP(0xa9) BAD_TRAP(0xaa) BAD_TRAP(0xab)
150 t_badac:BAD_TRAP(0xac) BAD_TRAP(0xad) BAD_TRAP(0xae) BAD_TRAP(0xaf) BAD_TRAP(0xb0)
151 t_badb1:BAD_TRAP(0xb1) BAD_TRAP(0xb2) BAD_TRAP(0xb3) BAD_TRAP(0xb4) BAD_TRAP(0xb5)
152 t_badb6:BAD_TRAP(0xb6) BAD_TRAP(0xb7) BAD_TRAP(0xb8) BAD_TRAP(0xb9) BAD_TRAP(0xba)
153 t_badbb:BAD_TRAP(0xbb) BAD_TRAP(0xbc) BAD_TRAP(0xbd) BAD_TRAP(0xbe) BAD_TRAP(0xbf)
154 t_badc0:BAD_TRAP(0xc0) BAD_TRAP(0xc1) BAD_TRAP(0xc2) BAD_TRAP(0xc3) BAD_TRAP(0xc4)
155 t_badc5:BAD_TRAP(0xc5) BAD_TRAP(0xc6) BAD_TRAP(0xc7) BAD_TRAP(0xc8) BAD_TRAP(0xc9)
156 t_badca:BAD_TRAP(0xca) BAD_TRAP(0xcb) BAD_TRAP(0xcc) BAD_TRAP(0xcd) BAD_TRAP(0xce)
157 t_badcf:BAD_TRAP(0xcf) BAD_TRAP(0xd0) BAD_TRAP(0xd1) BAD_TRAP(0xd2) BAD_TRAP(0xd3)
158 t_badd4:BAD_TRAP(0xd4) BAD_TRAP(0xd5) BAD_TRAP(0xd6) BAD_TRAP(0xd7) BAD_TRAP(0xd8)
159 t_badd9:BAD_TRAP(0xd9) BAD_TRAP(0xda) BAD_TRAP(0xdb) BAD_TRAP(0xdc) BAD_TRAP(0xdd)
160 t_badde:BAD_TRAP(0xde) BAD_TRAP(0xdf) BAD_TRAP(0xe0) BAD_TRAP(0xe1) BAD_TRAP(0xe2)
161 t_bade3:BAD_TRAP(0xe3) BAD_TRAP(0xe4) BAD_TRAP(0xe5) BAD_TRAP(0xe6) BAD_TRAP(0xe7)
162 t_bade8:BAD_TRAP(0xe8) BAD_TRAP(0xe9) BAD_TRAP(0xea) BAD_TRAP(0xeb) BAD_TRAP(0xec)
163 t_baded:BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1)
164 t_badf2:BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6)
165 t_badf7:BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb)
166 t_badfc:BAD_TRAP(0xfc)
167 t_kgdb: KGDB_TRAP(0xfd)
168 dbtrap: BAD_TRAP(0xfe)                      /* Debugger/PROM breakpoint #1   */
169 dbtrap2:BAD_TRAP(0xff)                      /* Debugger/PROM breakpoint #2   */ 
170
171         .globl  end_traptable
172 end_traptable:
173
174 #ifdef CONFIG_SMP
175         /* Trap tables for the other cpus. */
176         .globl  trapbase_cpu1, trapbase_cpu2, trapbase_cpu3
177 trapbase_cpu1:
178         BAD_TRAP(0x0) SRMMU_TFAULT TRAP_ENTRY(0x2, bad_instruction)
179         TRAP_ENTRY(0x3, priv_instruction) TRAP_ENTRY(0x4, fpd_trap_handler)
180         WINDOW_SPILL WINDOW_FILL TRAP_ENTRY(0x7, mna_handler)
181         TRAP_ENTRY(0x8, fpe_trap_handler) SRMMU_DFAULT
182         TRAP_ENTRY(0xa, do_tag_overflow) TRAP_ENTRY(0xb, do_watchpoint)
183         BAD_TRAP(0xc) BAD_TRAP(0xd) BAD_TRAP(0xe) BAD_TRAP(0xf) BAD_TRAP(0x10)
184         TRAP_ENTRY_INTERRUPT(1) TRAP_ENTRY_INTERRUPT(2)
185         TRAP_ENTRY_INTERRUPT(3) TRAP_ENTRY_INTERRUPT(4)
186         TRAP_ENTRY_INTERRUPT(5) TRAP_ENTRY_INTERRUPT(6)
187         TRAP_ENTRY_INTERRUPT(7) TRAP_ENTRY_INTERRUPT(8)
188         TRAP_ENTRY_INTERRUPT(9) TRAP_ENTRY_INTERRUPT(10)
189         TRAP_ENTRY_INTERRUPT(11) TRAP_ENTRY_INTERRUPT(12)
190         TRAP_ENTRY_INTERRUPT(13) TRAP_ENTRY_INTERRUPT(14)
191         TRAP_ENTRY(0x1f, linux_trap_ipi15_sun4m)
192         TRAP_ENTRY(0x20, do_reg_access) BAD_TRAP(0x21) BAD_TRAP(0x22)
193         BAD_TRAP(0x23) TRAP_ENTRY(0x24, do_cp_disabled) SKIP_TRAP(0x25, unimp_flush)
194         BAD_TRAP(0x26) BAD_TRAP(0x27) TRAP_ENTRY(0x28, do_cp_exception)
195         SRMMU_DFAULT TRAP_ENTRY(0x2a, do_hw_divzero) BAD_TRAP(0x2b) BAD_TRAP(0x2c)
196         BAD_TRAP(0x2d) BAD_TRAP(0x2e) BAD_TRAP(0x2f) BAD_TRAP(0x30) BAD_TRAP(0x31)
197         BAD_TRAP(0x32) BAD_TRAP(0x33) BAD_TRAP(0x34) BAD_TRAP(0x35) BAD_TRAP(0x36)
198         BAD_TRAP(0x37) BAD_TRAP(0x38) BAD_TRAP(0x39) BAD_TRAP(0x3a) BAD_TRAP(0x3b)
199         BAD_TRAP(0x3c) BAD_TRAP(0x3d) BAD_TRAP(0x3e) BAD_TRAP(0x3f) BAD_TRAP(0x40)
200         BAD_TRAP(0x41) BAD_TRAP(0x42) BAD_TRAP(0x43) BAD_TRAP(0x44) BAD_TRAP(0x45)
201         BAD_TRAP(0x46) BAD_TRAP(0x47) BAD_TRAP(0x48) BAD_TRAP(0x49) BAD_TRAP(0x4a)
202         BAD_TRAP(0x4b) BAD_TRAP(0x4c) BAD_TRAP(0x4d) BAD_TRAP(0x4e) BAD_TRAP(0x4f)
203         BAD_TRAP(0x50)
204         BAD_TRAP(0x51) BAD_TRAP(0x52) BAD_TRAP(0x53) BAD_TRAP(0x54) BAD_TRAP(0x55)
205         BAD_TRAP(0x56) BAD_TRAP(0x57) BAD_TRAP(0x58) BAD_TRAP(0x59) BAD_TRAP(0x5a)
206         BAD_TRAP(0x5b) BAD_TRAP(0x5c) BAD_TRAP(0x5d) BAD_TRAP(0x5e) BAD_TRAP(0x5f)
207         BAD_TRAP(0x60) BAD_TRAP(0x61) BAD_TRAP(0x62) BAD_TRAP(0x63) BAD_TRAP(0x64)
208         BAD_TRAP(0x65) BAD_TRAP(0x66) BAD_TRAP(0x67) BAD_TRAP(0x68) BAD_TRAP(0x69)
209         BAD_TRAP(0x6a) BAD_TRAP(0x6b) BAD_TRAP(0x6c) BAD_TRAP(0x6d) BAD_TRAP(0x6e)
210         BAD_TRAP(0x6f) BAD_TRAP(0x70) BAD_TRAP(0x71) BAD_TRAP(0x72) BAD_TRAP(0x73)
211         BAD_TRAP(0x74) BAD_TRAP(0x75) BAD_TRAP(0x76) BAD_TRAP(0x77) BAD_TRAP(0x78)
212         BAD_TRAP(0x79) BAD_TRAP(0x7a) BAD_TRAP(0x7b) BAD_TRAP(0x7c) BAD_TRAP(0x7d)
213         BAD_TRAP(0x7e) BAD_TRAP(0x7f)
214         BAD_TRAP(0x80)
215         BREAKPOINT_TRAP
216         TRAP_ENTRY(0x82, do_hw_divzero)
217         TRAP_ENTRY(0x83, do_flush_windows) BAD_TRAP(0x84) BAD_TRAP(0x85)
218         BAD_TRAP(0x86) BAD_TRAP(0x87) BAD_TRAP(0x88)
219         BAD_TRAP(0x89) BAD_TRAP(0x8a) BAD_TRAP(0x8b) BAD_TRAP(0x8c)
220         BAD_TRAP(0x8d) BAD_TRAP(0x8e) BAD_TRAP(0x8f)
221         LINUX_SYSCALL_TRAP BAD_TRAP(0x91) BAD_TRAP(0x92) BAD_TRAP(0x93) BAD_TRAP(0x94)
222         BAD_TRAP(0x95) BAD_TRAP(0x96) BAD_TRAP(0x97) BAD_TRAP(0x98) BAD_TRAP(0x99)
223         BAD_TRAP(0x9a) BAD_TRAP(0x9b) BAD_TRAP(0x9c) BAD_TRAP(0x9d) BAD_TRAP(0x9e)
224         BAD_TRAP(0x9f) GETCC_TRAP SETCC_TRAP GETPSR_TRAP
225         BAD_TRAP(0xa3) BAD_TRAP(0xa4) BAD_TRAP(0xa5) BAD_TRAP(0xa6)
226         BAD_TRAP(0xa7) BAD_TRAP(0xa8) BAD_TRAP(0xa9) BAD_TRAP(0xaa) BAD_TRAP(0xab)
227         BAD_TRAP(0xac) BAD_TRAP(0xad) BAD_TRAP(0xae) BAD_TRAP(0xaf) BAD_TRAP(0xb0)
228         BAD_TRAP(0xb1) BAD_TRAP(0xb2) BAD_TRAP(0xb3) BAD_TRAP(0xb4) BAD_TRAP(0xb5)
229         BAD_TRAP(0xb6) BAD_TRAP(0xb7) BAD_TRAP(0xb8) BAD_TRAP(0xb9) BAD_TRAP(0xba)
230         BAD_TRAP(0xbb) BAD_TRAP(0xbc) BAD_TRAP(0xbd) BAD_TRAP(0xbe) BAD_TRAP(0xbf)
231         BAD_TRAP(0xc0) BAD_TRAP(0xc1) BAD_TRAP(0xc2) BAD_TRAP(0xc3) BAD_TRAP(0xc4)
232         BAD_TRAP(0xc5) BAD_TRAP(0xc6) BAD_TRAP(0xc7) BAD_TRAP(0xc8) BAD_TRAP(0xc9)
233         BAD_TRAP(0xca) BAD_TRAP(0xcb) BAD_TRAP(0xcc) BAD_TRAP(0xcd) BAD_TRAP(0xce)
234         BAD_TRAP(0xcf) BAD_TRAP(0xd0) BAD_TRAP(0xd1) BAD_TRAP(0xd2) BAD_TRAP(0xd3)
235         BAD_TRAP(0xd4) BAD_TRAP(0xd5) BAD_TRAP(0xd6) BAD_TRAP(0xd7) BAD_TRAP(0xd8)
236         BAD_TRAP(0xd9) BAD_TRAP(0xda) BAD_TRAP(0xdb) BAD_TRAP(0xdc) BAD_TRAP(0xdd)
237         BAD_TRAP(0xde) BAD_TRAP(0xdf) BAD_TRAP(0xe0) BAD_TRAP(0xe1) BAD_TRAP(0xe2)
238         BAD_TRAP(0xe3) BAD_TRAP(0xe4) BAD_TRAP(0xe5) BAD_TRAP(0xe6) BAD_TRAP(0xe7)
239         BAD_TRAP(0xe8) BAD_TRAP(0xe9) BAD_TRAP(0xea) BAD_TRAP(0xeb) BAD_TRAP(0xec)
240         BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1)
241         BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6)
242         BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb)
243         BAD_TRAP(0xfc) KGDB_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff)
244
245 trapbase_cpu2:
246         BAD_TRAP(0x0) SRMMU_TFAULT TRAP_ENTRY(0x2, bad_instruction)
247         TRAP_ENTRY(0x3, priv_instruction) TRAP_ENTRY(0x4, fpd_trap_handler)
248         WINDOW_SPILL WINDOW_FILL TRAP_ENTRY(0x7, mna_handler)
249         TRAP_ENTRY(0x8, fpe_trap_handler) SRMMU_DFAULT
250         TRAP_ENTRY(0xa, do_tag_overflow) TRAP_ENTRY(0xb, do_watchpoint)
251         BAD_TRAP(0xc) BAD_TRAP(0xd) BAD_TRAP(0xe) BAD_TRAP(0xf) BAD_TRAP(0x10)
252         TRAP_ENTRY_INTERRUPT(1) TRAP_ENTRY_INTERRUPT(2)
253         TRAP_ENTRY_INTERRUPT(3) TRAP_ENTRY_INTERRUPT(4)
254         TRAP_ENTRY_INTERRUPT(5) TRAP_ENTRY_INTERRUPT(6)
255         TRAP_ENTRY_INTERRUPT(7) TRAP_ENTRY_INTERRUPT(8)
256         TRAP_ENTRY_INTERRUPT(9) TRAP_ENTRY_INTERRUPT(10)
257         TRAP_ENTRY_INTERRUPT(11) TRAP_ENTRY_INTERRUPT(12)
258         TRAP_ENTRY_INTERRUPT(13) TRAP_ENTRY_INTERRUPT(14)
259         TRAP_ENTRY(0x1f, linux_trap_ipi15_sun4m)
260         TRAP_ENTRY(0x20, do_reg_access) BAD_TRAP(0x21) BAD_TRAP(0x22)
261         BAD_TRAP(0x23) TRAP_ENTRY(0x24, do_cp_disabled) SKIP_TRAP(0x25, unimp_flush)
262         BAD_TRAP(0x26) BAD_TRAP(0x27) TRAP_ENTRY(0x28, do_cp_exception)
263         SRMMU_DFAULT TRAP_ENTRY(0x2a, do_hw_divzero) BAD_TRAP(0x2b) BAD_TRAP(0x2c)
264         BAD_TRAP(0x2d) BAD_TRAP(0x2e) BAD_TRAP(0x2f) BAD_TRAP(0x30) BAD_TRAP(0x31)
265         BAD_TRAP(0x32) BAD_TRAP(0x33) BAD_TRAP(0x34) BAD_TRAP(0x35) BAD_TRAP(0x36)
266         BAD_TRAP(0x37) BAD_TRAP(0x38) BAD_TRAP(0x39) BAD_TRAP(0x3a) BAD_TRAP(0x3b)
267         BAD_TRAP(0x3c) BAD_TRAP(0x3d) BAD_TRAP(0x3e) BAD_TRAP(0x3f) BAD_TRAP(0x40)
268         BAD_TRAP(0x41) BAD_TRAP(0x42) BAD_TRAP(0x43) BAD_TRAP(0x44) BAD_TRAP(0x45)
269         BAD_TRAP(0x46) BAD_TRAP(0x47) BAD_TRAP(0x48) BAD_TRAP(0x49) BAD_TRAP(0x4a)
270         BAD_TRAP(0x4b) BAD_TRAP(0x4c) BAD_TRAP(0x4d) BAD_TRAP(0x4e) BAD_TRAP(0x4f)
271         BAD_TRAP(0x50)
272         BAD_TRAP(0x51) BAD_TRAP(0x52) BAD_TRAP(0x53) BAD_TRAP(0x54) BAD_TRAP(0x55)
273         BAD_TRAP(0x56) BAD_TRAP(0x57) BAD_TRAP(0x58) BAD_TRAP(0x59) BAD_TRAP(0x5a)
274         BAD_TRAP(0x5b) BAD_TRAP(0x5c) BAD_TRAP(0x5d) BAD_TRAP(0x5e) BAD_TRAP(0x5f)
275         BAD_TRAP(0x60) BAD_TRAP(0x61) BAD_TRAP(0x62) BAD_TRAP(0x63) BAD_TRAP(0x64)
276         BAD_TRAP(0x65) BAD_TRAP(0x66) BAD_TRAP(0x67) BAD_TRAP(0x68) BAD_TRAP(0x69)
277         BAD_TRAP(0x6a) BAD_TRAP(0x6b) BAD_TRAP(0x6c) BAD_TRAP(0x6d) BAD_TRAP(0x6e)
278         BAD_TRAP(0x6f) BAD_TRAP(0x70) BAD_TRAP(0x71) BAD_TRAP(0x72) BAD_TRAP(0x73)
279         BAD_TRAP(0x74) BAD_TRAP(0x75) BAD_TRAP(0x76) BAD_TRAP(0x77) BAD_TRAP(0x78)
280         BAD_TRAP(0x79) BAD_TRAP(0x7a) BAD_TRAP(0x7b) BAD_TRAP(0x7c) BAD_TRAP(0x7d)
281         BAD_TRAP(0x7e) BAD_TRAP(0x7f)
282         BAD_TRAP(0x80)
283         BREAKPOINT_TRAP
284         TRAP_ENTRY(0x82, do_hw_divzero)
285         TRAP_ENTRY(0x83, do_flush_windows) BAD_TRAP(0x84) BAD_TRAP(0x85)
286         BAD_TRAP(0x86) BAD_TRAP(0x87) BAD_TRAP(0x88)
287         BAD_TRAP(0x89) BAD_TRAP(0x8a) BAD_TRAP(0x8b) BAD_TRAP(0x8c)
288         BAD_TRAP(0x8d) BAD_TRAP(0x8e) BAD_TRAP(0x8f)
289         LINUX_SYSCALL_TRAP BAD_TRAP(0x91) BAD_TRAP(0x92) BAD_TRAP(0x93) BAD_TRAP(0x94)
290         BAD_TRAP(0x95) BAD_TRAP(0x96) BAD_TRAP(0x97) BAD_TRAP(0x98) BAD_TRAP(0x99)
291         BAD_TRAP(0x9a) BAD_TRAP(0x9b) BAD_TRAP(0x9c) BAD_TRAP(0x9d) BAD_TRAP(0x9e)
292         BAD_TRAP(0x9f) GETCC_TRAP SETCC_TRAP GETPSR_TRAP
293         BAD_TRAP(0xa3) BAD_TRAP(0xa4) BAD_TRAP(0xa5) BAD_TRAP(0xa6)
294         BAD_TRAP(0xa7) BAD_TRAP(0xa8) BAD_TRAP(0xa9) BAD_TRAP(0xaa) BAD_TRAP(0xab)
295         BAD_TRAP(0xac) BAD_TRAP(0xad) BAD_TRAP(0xae) BAD_TRAP(0xaf) BAD_TRAP(0xb0)
296         BAD_TRAP(0xb1) BAD_TRAP(0xb2) BAD_TRAP(0xb3) BAD_TRAP(0xb4) BAD_TRAP(0xb5)
297         BAD_TRAP(0xb6) BAD_TRAP(0xb7) BAD_TRAP(0xb8) BAD_TRAP(0xb9) BAD_TRAP(0xba)
298         BAD_TRAP(0xbb) BAD_TRAP(0xbc) BAD_TRAP(0xbd) BAD_TRAP(0xbe) BAD_TRAP(0xbf)
299         BAD_TRAP(0xc0) BAD_TRAP(0xc1) BAD_TRAP(0xc2) BAD_TRAP(0xc3) BAD_TRAP(0xc4)
300         BAD_TRAP(0xc5) BAD_TRAP(0xc6) BAD_TRAP(0xc7) BAD_TRAP(0xc8) BAD_TRAP(0xc9)
301         BAD_TRAP(0xca) BAD_TRAP(0xcb) BAD_TRAP(0xcc) BAD_TRAP(0xcd) BAD_TRAP(0xce)
302         BAD_TRAP(0xcf) BAD_TRAP(0xd0) BAD_TRAP(0xd1) BAD_TRAP(0xd2) BAD_TRAP(0xd3)
303         BAD_TRAP(0xd4) BAD_TRAP(0xd5) BAD_TRAP(0xd6) BAD_TRAP(0xd7) BAD_TRAP(0xd8)
304         BAD_TRAP(0xd9) BAD_TRAP(0xda) BAD_TRAP(0xdb) BAD_TRAP(0xdc) BAD_TRAP(0xdd)
305         BAD_TRAP(0xde) BAD_TRAP(0xdf) BAD_TRAP(0xe0) BAD_TRAP(0xe1) BAD_TRAP(0xe2)
306         BAD_TRAP(0xe3) BAD_TRAP(0xe4) BAD_TRAP(0xe5) BAD_TRAP(0xe6) BAD_TRAP(0xe7)
307         BAD_TRAP(0xe8) BAD_TRAP(0xe9) BAD_TRAP(0xea) BAD_TRAP(0xeb) BAD_TRAP(0xec)
308         BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1)
309         BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6)
310         BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb)
311         BAD_TRAP(0xfc) KGDB_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff)
312
313 trapbase_cpu3:
314         BAD_TRAP(0x0) SRMMU_TFAULT TRAP_ENTRY(0x2, bad_instruction)
315         TRAP_ENTRY(0x3, priv_instruction) TRAP_ENTRY(0x4, fpd_trap_handler)
316         WINDOW_SPILL WINDOW_FILL TRAP_ENTRY(0x7, mna_handler)
317         TRAP_ENTRY(0x8, fpe_trap_handler) SRMMU_DFAULT
318         TRAP_ENTRY(0xa, do_tag_overflow) TRAP_ENTRY(0xb, do_watchpoint)
319         BAD_TRAP(0xc) BAD_TRAP(0xd) BAD_TRAP(0xe) BAD_TRAP(0xf) BAD_TRAP(0x10)
320         TRAP_ENTRY_INTERRUPT(1) TRAP_ENTRY_INTERRUPT(2)
321         TRAP_ENTRY_INTERRUPT(3) TRAP_ENTRY_INTERRUPT(4)
322         TRAP_ENTRY_INTERRUPT(5) TRAP_ENTRY_INTERRUPT(6)
323         TRAP_ENTRY_INTERRUPT(7) TRAP_ENTRY_INTERRUPT(8)
324         TRAP_ENTRY_INTERRUPT(9) TRAP_ENTRY_INTERRUPT(10)
325         TRAP_ENTRY_INTERRUPT(11) TRAP_ENTRY_INTERRUPT(12)
326         TRAP_ENTRY_INTERRUPT(13) TRAP_ENTRY_INTERRUPT(14)
327         TRAP_ENTRY(0x1f, linux_trap_ipi15_sun4m)
328         TRAP_ENTRY(0x20, do_reg_access) BAD_TRAP(0x21) BAD_TRAP(0x22)
329         BAD_TRAP(0x23) TRAP_ENTRY(0x24, do_cp_disabled) SKIP_TRAP(0x25, unimp_flush)
330         BAD_TRAP(0x26) BAD_TRAP(0x27) TRAP_ENTRY(0x28, do_cp_exception)
331         SRMMU_DFAULT TRAP_ENTRY(0x2a, do_hw_divzero) BAD_TRAP(0x2b) BAD_TRAP(0x2c)
332         BAD_TRAP(0x2d) BAD_TRAP(0x2e) BAD_TRAP(0x2f) BAD_TRAP(0x30) BAD_TRAP(0x31)
333         BAD_TRAP(0x32) BAD_TRAP(0x33) BAD_TRAP(0x34) BAD_TRAP(0x35) BAD_TRAP(0x36)
334         BAD_TRAP(0x37) BAD_TRAP(0x38) BAD_TRAP(0x39) BAD_TRAP(0x3a) BAD_TRAP(0x3b)
335         BAD_TRAP(0x3c) BAD_TRAP(0x3d) BAD_TRAP(0x3e) BAD_TRAP(0x3f) BAD_TRAP(0x40)
336         BAD_TRAP(0x41) BAD_TRAP(0x42) BAD_TRAP(0x43) BAD_TRAP(0x44) BAD_TRAP(0x45)
337         BAD_TRAP(0x46) BAD_TRAP(0x47) BAD_TRAP(0x48) BAD_TRAP(0x49) BAD_TRAP(0x4a)
338         BAD_TRAP(0x4b) BAD_TRAP(0x4c) BAD_TRAP(0x4d) BAD_TRAP(0x4e) BAD_TRAP(0x4f)
339         BAD_TRAP(0x50)
340         BAD_TRAP(0x51) BAD_TRAP(0x52) BAD_TRAP(0x53) BAD_TRAP(0x54) BAD_TRAP(0x55)
341         BAD_TRAP(0x56) BAD_TRAP(0x57) BAD_TRAP(0x58) BAD_TRAP(0x59) BAD_TRAP(0x5a)
342         BAD_TRAP(0x5b) BAD_TRAP(0x5c) BAD_TRAP(0x5d) BAD_TRAP(0x5e) BAD_TRAP(0x5f)
343         BAD_TRAP(0x60) BAD_TRAP(0x61) BAD_TRAP(0x62) BAD_TRAP(0x63) BAD_TRAP(0x64)
344         BAD_TRAP(0x65) BAD_TRAP(0x66) BAD_TRAP(0x67) BAD_TRAP(0x68) BAD_TRAP(0x69)
345         BAD_TRAP(0x6a) BAD_TRAP(0x6b) BAD_TRAP(0x6c) BAD_TRAP(0x6d) BAD_TRAP(0x6e)
346         BAD_TRAP(0x6f) BAD_TRAP(0x70) BAD_TRAP(0x71) BAD_TRAP(0x72) BAD_TRAP(0x73)
347         BAD_TRAP(0x74) BAD_TRAP(0x75) BAD_TRAP(0x76) BAD_TRAP(0x77) BAD_TRAP(0x78)
348         BAD_TRAP(0x79) BAD_TRAP(0x7a) BAD_TRAP(0x7b) BAD_TRAP(0x7c) BAD_TRAP(0x7d)
349         BAD_TRAP(0x7e) BAD_TRAP(0x7f)
350         BAD_TRAP(0x80)
351         BREAKPOINT_TRAP
352         TRAP_ENTRY(0x82, do_hw_divzero)
353         TRAP_ENTRY(0x83, do_flush_windows) BAD_TRAP(0x84) BAD_TRAP(0x85)
354         BAD_TRAP(0x86) BAD_TRAP(0x87) BAD_TRAP(0x88)
355         BAD_TRAP(0x89) BAD_TRAP(0x8a) BAD_TRAP(0x8b) BAD_TRAP(0x8c)
356         BAD_TRAP(0x8d) BAD_TRAP(0x8e) BAD_TRAP(0x8f)
357         LINUX_SYSCALL_TRAP BAD_TRAP(0x91) BAD_TRAP(0x92) BAD_TRAP(0x93) BAD_TRAP(0x94)
358         BAD_TRAP(0x95) BAD_TRAP(0x96) BAD_TRAP(0x97) BAD_TRAP(0x98) BAD_TRAP(0x99)
359         BAD_TRAP(0x9a) BAD_TRAP(0x9b) BAD_TRAP(0x9c) BAD_TRAP(0x9d) BAD_TRAP(0x9e)
360         BAD_TRAP(0x9f) GETCC_TRAP SETCC_TRAP GETPSR_TRAP
361         BAD_TRAP(0xa3) BAD_TRAP(0xa4) BAD_TRAP(0xa5) BAD_TRAP(0xa6)
362         BAD_TRAP(0xa7) BAD_TRAP(0xa8) BAD_TRAP(0xa9) BAD_TRAP(0xaa) BAD_TRAP(0xab)
363         BAD_TRAP(0xac) BAD_TRAP(0xad) BAD_TRAP(0xae) BAD_TRAP(0xaf) BAD_TRAP(0xb0)
364         BAD_TRAP(0xb1) BAD_TRAP(0xb2) BAD_TRAP(0xb3) BAD_TRAP(0xb4) BAD_TRAP(0xb5)
365         BAD_TRAP(0xb6) BAD_TRAP(0xb7) BAD_TRAP(0xb8) BAD_TRAP(0xb9) BAD_TRAP(0xba)
366         BAD_TRAP(0xbb) BAD_TRAP(0xbc) BAD_TRAP(0xbd) BAD_TRAP(0xbe) BAD_TRAP(0xbf)
367         BAD_TRAP(0xc0) BAD_TRAP(0xc1) BAD_TRAP(0xc2) BAD_TRAP(0xc3) BAD_TRAP(0xc4)
368         BAD_TRAP(0xc5) BAD_TRAP(0xc6) BAD_TRAP(0xc7) BAD_TRAP(0xc8) BAD_TRAP(0xc9)
369         BAD_TRAP(0xca) BAD_TRAP(0xcb) BAD_TRAP(0xcc) BAD_TRAP(0xcd) BAD_TRAP(0xce)
370         BAD_TRAP(0xcf) BAD_TRAP(0xd0) BAD_TRAP(0xd1) BAD_TRAP(0xd2) BAD_TRAP(0xd3)
371         BAD_TRAP(0xd4) BAD_TRAP(0xd5) BAD_TRAP(0xd6) BAD_TRAP(0xd7) BAD_TRAP(0xd8)
372         BAD_TRAP(0xd9) BAD_TRAP(0xda) BAD_TRAP(0xdb) BAD_TRAP(0xdc) BAD_TRAP(0xdd)
373         BAD_TRAP(0xde) BAD_TRAP(0xdf) BAD_TRAP(0xe0) BAD_TRAP(0xe1) BAD_TRAP(0xe2)
374         BAD_TRAP(0xe3) BAD_TRAP(0xe4) BAD_TRAP(0xe5) BAD_TRAP(0xe6) BAD_TRAP(0xe7)
375         BAD_TRAP(0xe8) BAD_TRAP(0xe9) BAD_TRAP(0xea) BAD_TRAP(0xeb) BAD_TRAP(0xec)
376         BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1)
377         BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6)
378         BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb)
379         BAD_TRAP(0xfc) KGDB_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff)
380
381 #endif
382         .align PAGE_SIZE
383
384 /* This was the only reasonable way I could think of to properly align
385  * these page-table data structures.
386  */
387         .globl swapper_pg_dir
388 swapper_pg_dir:         .skip PAGE_SIZE
389         .globl empty_zero_page
390 empty_zero_page:        .skip PAGE_SIZE
391
392         .global root_flags
393         .global ram_flags
394         .global root_dev
395         .global sparc_ramdisk_image
396         .global sparc_ramdisk_size
397
398 /* This stuff has to be in sync with SILO and other potential boot loaders
399  * Fields should be kept upward compatible and whenever any change is made,
400  * HdrS version should be incremented.
401  */
402         .ascii  "HdrS"
403         .word   LINUX_VERSION_CODE
404         .half   0x0203          /* HdrS version */
405 root_flags:
406         .half   1
407 root_dev:
408         .half   0
409 ram_flags:
410         .half   0
411 sparc_ramdisk_image:
412         .word   0
413 sparc_ramdisk_size:
414         .word   0
415         .word   reboot_command
416         .word   0, 0, 0
417         .word   _end
418
419 /* Cool, here we go. Pick up the romvec pointer in %o0 and stash it in
420  * %g7 and at prom_vector_p. And also quickly check whether we are on
421  * a v0, v2, or v3 prom.
422  */
423 gokernel:
424                 /* Ok, it's nice to know, as early as possible, if we
425                  * are already mapped where we expect to be in virtual
426                  * memory.  The Solaris /boot elf format bootloader
427                  * will peek into our elf header and load us where
428                  * we want to be, otherwise we have to re-map.
429                  *
430                  * Some boot loaders don't place the jmp'rs address
431                  * in %o7, so we do a pc-relative call to a local
432                  * label, then see what %o7 has.
433                  */
434
435                 mov     %o7, %g4                ! Save %o7
436
437                 /* Jump to it, and pray... */
438 current_pc:
439                 call    1f
440                  nop
441
442 1:
443                 mov     %o7, %g3
444
445                 tst     %o0
446                 be      no_sun4u_here
447                  mov    %g4, %o7                /* Previous %o7. */
448         
449                 mov     %o0, %l0                ! stash away romvec
450                 mov     %o0, %g7                ! put it here too
451                 mov     %o1, %l1                ! stash away debug_vec too
452
453                 /* Ok, let's check out our run time program counter. */
454                 set     current_pc, %g5
455                 cmp     %g3, %g5
456                 be      already_mapped
457                  nop 
458
459                 /* %l6 will hold the offset we have to subtract
460                  * from absolute symbols in order to access areas
461                  * in our own image.  If already mapped this is
462                  * just plain zero, else it is KERNBASE.
463                  */
464                 set     KERNBASE, %l6
465                 b       copy_prom_lvl14
466                  nop
467
468 already_mapped:
469                 mov     0, %l6
470
471                 /* Copy over the Prom's level 14 clock handler. */
472 copy_prom_lvl14:
473 #if 1
474                 /* DJHR
475                  * preserve our linked/calculated instructions
476                  */
477                 set     lvl14_save, %g1
478                 set     t_irq14, %g3
479                 sub     %g1, %l6, %g1           ! translate to physical
480                 sub     %g3, %l6, %g3           ! translate to physical
481                 ldd     [%g3], %g4
482                 std     %g4, [%g1]
483                 ldd     [%g3+8], %g4
484                 std     %g4, [%g1+8]
485 #endif
486                 rd      %tbr, %g1
487                 andn    %g1, 0xfff, %g1         ! proms trap table base
488                 or      %g0, (0x1e<<4), %g2     ! offset to lvl14 intr
489                 or      %g1, %g2, %g2
490                 set     t_irq14, %g3
491                 sub     %g3, %l6, %g3
492                 ldd     [%g2], %g4
493                 std     %g4, [%g3]
494                 ldd     [%g2 + 0x8], %g4
495                 std     %g4, [%g3 + 0x8]        ! Copy proms handler
496
497 /* DON'T TOUCH %l0 thru %l5 in these remapping routines,
498  * we need their values afterwards!
499  */
500
501                 /* Now check whether we are already mapped, if we
502                  * are we can skip all this garbage coming up.
503                  */
504 copy_prom_done:
505                 cmp     %l6, 0
506                 be      go_to_highmem           ! this will be a nop then
507                  nop
508
509                 /* Validate that we are in fact running on an
510                  * SRMMU based cpu.
511                  */
512                 set     0x4000, %g6
513                 cmp     %g7, %g6
514                 bne     not_a_sun4
515                  nop
516
517 halt_sun4_or_sun4c:
518                 ld      [%g7 + 0x68], %o1
519                 set     sun4c_notsup, %o0
520                 sub     %o0, %l6, %o0
521                 call    %o1
522                  nop
523                 ba      halt_me
524                  nop
525
526 not_a_sun4:
527                 lda     [%g0] ASI_M_MMUREGS, %g1
528                 andcc   %g1, 1, %g0
529                 be      halt_sun4_or_sun4c
530                  nop
531
532 srmmu_remap:
533                 /* First, check for a viking (TI) module. */
534                 set     0x40000000, %g2
535                 rd      %psr, %g3
536                 and     %g2, %g3, %g3
537                 subcc   %g3, 0x0, %g0
538                 bz      srmmu_nviking
539                  nop
540
541                 /* Figure out what kind of viking we are on.
542                  * We need to know if we have to play with the
543                  * AC bit and disable traps or not.
544                  */
545
546                 /* I've only seen MicroSparc's on SparcClassics with this
547                  * bit set.
548                  */
549                 set     0x800, %g2
550                 lda     [%g0] ASI_M_MMUREGS, %g3        ! peek in the control reg
551                 and     %g2, %g3, %g3
552                 subcc   %g3, 0x0, %g0
553                 bnz     srmmu_nviking                   ! is in mbus mode
554                  nop
555                 
556                 rd      %psr, %g3                       ! DO NOT TOUCH %g3
557                 andn    %g3, PSR_ET, %g2
558                 wr      %g2, 0x0, %psr
559                 WRITE_PAUSE
560                 
561                 /* Get context table pointer, then convert to
562                  * a physical address, which is 36 bits.
563                  */
564                 set     AC_M_CTPR, %g4
565                 lda     [%g4] ASI_M_MMUREGS, %g4
566                 sll     %g4, 0x4, %g4                   ! We use this below
567                                                         ! DO NOT TOUCH %g4
568
569                 /* Set the AC bit in the Viking's MMU control reg. */
570                 lda     [%g0] ASI_M_MMUREGS, %g5        ! DO NOT TOUCH %g5
571                 set     0x8000, %g6                     ! AC bit mask
572                 or      %g5, %g6, %g6                   ! Or it in...
573                 sta     %g6, [%g0] ASI_M_MMUREGS        ! Close your eyes...
574
575                 /* Grrr, why does it seem like every other load/store
576                  * on the sun4m is in some ASI space...
577                  * Fine with me, let's get the pointer to the level 1
578                  * page table directory and fetch its entry.
579                  */
580                 lda     [%g4] ASI_M_BYPASS, %o1         ! This is a level 1 ptr
581                 srl     %o1, 0x4, %o1                   ! Clear low 4 bits
582                 sll     %o1, 0x8, %o1                   ! Make physical
583                 
584                 /* Ok, pull in the PTD. */
585                 lda     [%o1] ASI_M_BYPASS, %o2         ! This is the 0x0 16MB pgd
586
587                 /* Calculate to KERNBASE entry. */
588                 add     %o1, KERNBASE >> (SRMMU_PGDIR_SHIFT - 2), %o3           
589
590                 /* Poke the entry into the calculated address. */
591                 sta     %o2, [%o3] ASI_M_BYPASS
592
593                 /* I don't get it Sun, if you engineered all these
594                  * boot loaders and the PROM (thank you for the debugging
595                  * features btw) why did you not have them load kernel
596                  * images up in high address space, since this is necessary
597                  * for ABI compliance anyways?  Does this low-mapping provide
598                  * enhanced interoperability?
599                  *
600                  * "The PROM is the computer."
601                  */
602
603                 /* Ok, restore the MMU control register we saved in %g5 */
604                 sta     %g5, [%g0] ASI_M_MMUREGS        ! POW... ouch
605
606                 /* Turn traps back on.  We saved it in %g3 earlier. */
607                 wr      %g3, 0x0, %psr                  ! tick tock, tick tock
608
609                 /* Now we burn precious CPU cycles due to bad engineering. */
610                 WRITE_PAUSE
611
612                 /* Wow, all that just to move a 32-bit value from one
613                  * place to another...  Jump to high memory.
614                  */
615                 b       go_to_highmem
616                  nop
617
618                 /* This works on viking's in Mbus mode and all
619                  * other MBUS modules.  It is virtually the same as
620                  * the above madness sans turning traps off and flipping
621                  * the AC bit.
622                  */
623 srmmu_nviking:
624                 set     AC_M_CTPR, %g1
625                 lda     [%g1] ASI_M_MMUREGS, %g1        ! get ctx table ptr
626                 sll     %g1, 0x4, %g1                   ! make physical addr
627                 lda     [%g1] ASI_M_BYPASS, %g1         ! ptr to level 1 pg_table
628                 srl     %g1, 0x4, %g1
629                 sll     %g1, 0x8, %g1                   ! make phys addr for l1 tbl
630
631                 lda     [%g1] ASI_M_BYPASS, %g2         ! get level1 entry for 0x0
632                 add     %g1, KERNBASE >> (SRMMU_PGDIR_SHIFT - 2), %g3
633                 sta     %g2, [%g3] ASI_M_BYPASS         ! place at KERNBASE entry
634                 b       go_to_highmem
635                  nop                                    ! wheee....
636
637
638 /* Now do a non-relative jump so that PC is in high-memory */
639 go_to_highmem:
640                 set     execute_in_high_mem, %g1
641                 jmpl    %g1, %g0
642                  nop
643
644 /* The code above should be at beginning and we have to take care about
645  * short jumps, as branching to .init.text section from .text is usually
646  * impossible */
647                 __INIT
648 /* Acquire boot time privileged register values, this will help debugging.
649  * I figure out and store nwindows and nwindowsm1 later on.
650  */
651 execute_in_high_mem:
652                 mov     %l0, %o0                ! put back romvec
653                 mov     %l1, %o1                ! and debug_vec
654
655                 sethi   %hi(prom_vector_p), %g1
656                 st      %o0, [%g1 + %lo(prom_vector_p)]
657
658                 sethi   %hi(linux_dbvec), %g1
659                 st      %o1, [%g1 + %lo(linux_dbvec)]
660
661 /* Get the machine type via the mysterious romvec node operations. */
662
663                 add     %g7, 0x1c, %l1
664                 ld      [%l1], %l0
665                 ld      [%l0], %l0
666                 call    %l0
667                  or     %g0, %g0, %o0           ! next_node(0) = first_node
668                 or      %o0, %g0, %g6
669
670                 sethi   %hi(cputypvar), %o1     ! First node has cpu-arch
671                 or      %o1, %lo(cputypvar), %o1
672                 sethi   %hi(cputypval), %o2     ! information, the string
673                 or      %o2, %lo(cputypval), %o2
674                 ld      [%l1], %l0              ! 'compatible' tells
675                 ld      [%l0 + 0xc], %l0        ! that we want 'sun4x' where
676                 call    %l0                     ! x is one of 'm', 'd' or 'e'.
677                  nop                            ! %o2 holds pointer
678                                                 ! to a buf where above string
679                                                 ! will get stored by the prom.
680
681 #ifdef CONFIG_SPARC_LEON
682                 /* no cpu-type check is needed, it is a SPARC-LEON */
683
684                 sethi   %hi(boot_cpu_id), %g2   ! boot-cpu index
685
686 #ifdef CONFIG_SMP
687                 ldub    [%g2 + %lo(boot_cpu_id)], %g1
688                 cmp     %g1, 0xff               ! unset means first CPU
689                 bne     leon_smp_cpu_startup    ! continue only with master
690                  nop
691 #endif
692                 /* Get CPU-ID from most significant 4-bit of ASR17 */
693                 rd     %asr17, %g1
694                 srl    %g1, 28, %g1
695
696                 /* Update boot_cpu_id only on boot cpu */
697                 stub    %g1, [%g2 + %lo(boot_cpu_id)]
698
699                 ba continue_boot
700                  nop
701 #endif
702
703 /* Check to cputype. We may be booted on a sun4u (64 bit box),
704  * and sun4d needs special treatment.
705  */
706
707                 set     cputypval, %o2
708                 ldub    [%o2 + 0x4], %l1
709
710                 cmp     %l1, 'm'
711                 be      sun4m_init
712                  cmp    %l1, 's'
713                 be      sun4m_init
714                  cmp    %l1, 'd'
715                 be      sun4d_init
716                  cmp    %l1, 'e'
717                 be      no_sun4e_here           ! Could be a sun4e.
718                  nop
719                 b       no_sun4u_here           ! AIEEE, a V9 sun4u... Get our BIG BROTHER kernel :))
720                  nop
721
722 /* CPUID in bootbus can be found at PA 0xff0140000 */
723 #define SUN4D_BOOTBUS_CPUID     0xf0140000
724
725 sun4d_init:
726         /* Need to patch call to handler_irq */
727         set     patch_handler_irq, %g4
728         set     sun4d_handler_irq, %g5
729         sethi   %hi(0x40000000), %g3            ! call
730         sub     %g5, %g4, %g5
731         srl     %g5, 2, %g5
732         or      %g5, %g3, %g5
733         st      %g5, [%g4]
734
735 #ifdef CONFIG_SMP
736         /* Get our CPU id out of bootbus */
737         set     SUN4D_BOOTBUS_CPUID, %g3
738         lduba   [%g3] ASI_M_CTL, %g3
739         and     %g3, 0xf8, %g3
740         srl     %g3, 3, %g4
741         sta     %g4, [%g0] ASI_M_VIKING_TMP1
742         sethi   %hi(boot_cpu_id), %g5
743         stb     %g4, [%g5 + %lo(boot_cpu_id)]
744 #endif
745
746         /* Fall through to sun4m_init */
747
748 sun4m_init:
749         /* XXX Fucking Cypress... */
750         lda     [%g0] ASI_M_MMUREGS, %g5
751         srl     %g5, 28, %g4
752
753         cmp     %g4, 1
754         bne     1f
755          srl    %g5, 24, %g4
756
757         and     %g4, 0xf, %g4
758         cmp     %g4, 7          /* This would be a HyperSparc. */
759
760         bne     2f
761          nop
762
763 1:
764
765 #define PATCH_IT(dst, src)      \
766         set     (dst), %g5;     \
767         set     (src), %g4;     \
768         ld      [%g4], %g3;     \
769         st      %g3, [%g5];     \
770         ld      [%g4+0x4], %g3; \
771         st      %g3, [%g5+0x4];
772
773         /* Signed multiply. */
774         PATCH_IT(.mul, .mul_patch)
775         PATCH_IT(.mul+0x08, .mul_patch+0x08)
776
777         /* Signed remainder. */
778         PATCH_IT(.rem, .rem_patch)
779         PATCH_IT(.rem+0x08, .rem_patch+0x08)
780         PATCH_IT(.rem+0x10, .rem_patch+0x10)
781         PATCH_IT(.rem+0x18, .rem_patch+0x18)
782         PATCH_IT(.rem+0x20, .rem_patch+0x20)
783         PATCH_IT(.rem+0x28, .rem_patch+0x28)
784
785         /* Signed division. */
786         PATCH_IT(.div, .div_patch)
787         PATCH_IT(.div+0x08, .div_patch+0x08)
788         PATCH_IT(.div+0x10, .div_patch+0x10)
789         PATCH_IT(.div+0x18, .div_patch+0x18)
790         PATCH_IT(.div+0x20, .div_patch+0x20)
791
792         /* Unsigned multiply. */
793         PATCH_IT(.umul, .umul_patch)
794         PATCH_IT(.umul+0x08, .umul_patch+0x08)
795
796         /* Unsigned remainder. */
797         PATCH_IT(.urem, .urem_patch)
798         PATCH_IT(.urem+0x08, .urem_patch+0x08)
799         PATCH_IT(.urem+0x10, .urem_patch+0x10)
800         PATCH_IT(.urem+0x18, .urem_patch+0x18)
801
802         /* Unsigned division. */
803         PATCH_IT(.udiv, .udiv_patch)
804         PATCH_IT(.udiv+0x08, .udiv_patch+0x08)
805         PATCH_IT(.udiv+0x10, .udiv_patch+0x10)
806
807 #undef PATCH_IT
808
809 /* Ok, the PROM could have done funny things and apple cider could still
810  * be sitting in the fault status/address registers.  Read them all to
811  * clear them so we don't get magic faults later on.
812  */
813 /* This sucks, apparently this makes Vikings call prom panic, will fix later */
814 2:
815                 rd      %psr, %o1
816                 srl     %o1, 28, %o1            ! Get a type of the CPU
817
818                 subcc   %o1, 4, %g0             ! TI: Viking or MicroSPARC
819                 be      continue_boot
820                  nop
821
822                 set     AC_M_SFSR, %o0
823                 lda     [%o0] ASI_M_MMUREGS, %g0
824                 set     AC_M_SFAR, %o0
825                 lda     [%o0] ASI_M_MMUREGS, %g0
826
827                 /* Fujitsu MicroSPARC-II has no asynchronous flavors of FARs */
828                 subcc   %o1, 0, %g0
829                 be      continue_boot
830                  nop
831
832                 set     AC_M_AFSR, %o0
833                 lda     [%o0] ASI_M_MMUREGS, %g0
834                 set     AC_M_AFAR, %o0
835                 lda     [%o0] ASI_M_MMUREGS, %g0
836                  nop
837
838
839 continue_boot:
840
841 /* Aieee, now set PC and nPC, enable traps, give ourselves a stack and it's
842  * show-time!
843  */
844
845                 sethi   %hi(cputyp), %o0
846                 st      %g4, [%o0 + %lo(cputyp)]
847
848                 /* Turn on Supervisor, EnableFloating, and all the PIL bits.
849                  * Also puts us in register window zero with traps off.
850                  */
851                 set     (PSR_PS | PSR_S | PSR_PIL | PSR_EF), %g2
852                 wr      %g2, 0x0, %psr
853                 WRITE_PAUSE
854
855                 /* I want a kernel stack NOW! */
856                 set     init_thread_union, %g1
857                 set     (THREAD_SIZE - STACKFRAME_SZ), %g2
858                 add     %g1, %g2, %sp
859                 mov     0, %fp                  /* And for good luck */
860
861                 /* Zero out our BSS section. */
862                 set     __bss_start , %o0       ! First address of BSS
863                 set     _end , %o1              ! Last address of BSS
864                 add     %o0, 0x1, %o0
865 1:      
866                 stb     %g0, [%o0]
867                 subcc   %o0, %o1, %g0
868                 bl      1b
869                  add    %o0, 0x1, %o0
870
871                 /* If boot_cpu_id has not been setup by machine specific
872                  * init-code above we default it to zero.
873                  */
874                 sethi   %hi(boot_cpu_id), %g2
875                 ldub    [%g2 + %lo(boot_cpu_id)], %g3
876                 cmp     %g3, 0xff
877                 bne     1f
878                  nop
879                 mov     %g0, %g3
880                 stub    %g3, [%g2 + %lo(boot_cpu_id)]
881
882 1:              /* boot_cpu_id set. calculate boot_cpu_id4 = boot_cpu_id*4 */
883                 sll     %g3, 2, %g3
884                 sethi   %hi(boot_cpu_id4), %g2
885                 stub    %g3, [%g2 + %lo(boot_cpu_id4)]
886
887                 /* Initialize the uwinmask value for init task just in case.
888                  * But first make current_set[boot_cpu_id] point to something useful.
889                  */
890                 set     init_thread_union, %g6
891                 set     current_set, %g2
892 #ifdef CONFIG_SMP
893                 st      %g6, [%g2]
894                 add     %g2, %g3, %g2
895 #endif
896                 st      %g6, [%g2]
897
898                 st      %g0, [%g6 + TI_UWINMASK]
899
900 /* Compute NWINDOWS and stash it away. Now uses %wim trick explained
901  * in the V8 manual. Ok, this method seems to work, Sparc is cool...
902  * No, it doesn't work, have to play the save/readCWP/restore trick.
903  */
904
905                 wr      %g0, 0x0, %wim                  ! so we do not get a trap
906                 WRITE_PAUSE
907
908                 save
909
910                 rd      %psr, %g3
911
912                 restore
913
914                 and     %g3, 0x1f, %g3
915                 add     %g3, 0x1, %g3
916
917                 mov     2, %g1
918                 wr      %g1, 0x0, %wim                  ! make window 1 invalid
919                 WRITE_PAUSE
920
921                 cmp     %g3, 0x7
922                 bne     2f
923                  nop
924
925                 /* Adjust our window handling routines to
926                  * do things correctly on 7 window Sparcs.
927                  */
928
929 #define         PATCH_INSN(src, dest) \
930                 set     src, %g5; \
931                 set     dest, %g2; \
932                 ld      [%g5], %g4; \
933                 st      %g4, [%g2];
934         
935                 /* Patch for window spills... */
936                 PATCH_INSN(spnwin_patch1_7win, spnwin_patch1)
937                 PATCH_INSN(spnwin_patch2_7win, spnwin_patch2)
938                 PATCH_INSN(spnwin_patch3_7win, spnwin_patch3)
939
940                 /* Patch for window fills... */
941                 PATCH_INSN(fnwin_patch1_7win, fnwin_patch1)
942                 PATCH_INSN(fnwin_patch2_7win, fnwin_patch2)
943
944                 /* Patch for trap entry setup... */
945                 PATCH_INSN(tsetup_7win_patch1, tsetup_patch1)
946                 PATCH_INSN(tsetup_7win_patch2, tsetup_patch2)
947                 PATCH_INSN(tsetup_7win_patch3, tsetup_patch3)
948                 PATCH_INSN(tsetup_7win_patch4, tsetup_patch4)
949                 PATCH_INSN(tsetup_7win_patch5, tsetup_patch5)
950                 PATCH_INSN(tsetup_7win_patch6, tsetup_patch6)
951
952                 /* Patch for returning from traps... */
953                 PATCH_INSN(rtrap_7win_patch1, rtrap_patch1)
954                 PATCH_INSN(rtrap_7win_patch2, rtrap_patch2)
955                 PATCH_INSN(rtrap_7win_patch3, rtrap_patch3)
956                 PATCH_INSN(rtrap_7win_patch4, rtrap_patch4)
957                 PATCH_INSN(rtrap_7win_patch5, rtrap_patch5)
958
959                 /* Patch for killing user windows from the register file. */
960                 PATCH_INSN(kuw_patch1_7win, kuw_patch1)
961
962                 /* Now patch the kernel window flush sequences.
963                  * This saves 2 traps on every switch and fork.
964                  */
965                 set     0x01000000, %g4
966                 set     flush_patch_one, %g5
967                 st      %g4, [%g5 + 0x18]
968                 st      %g4, [%g5 + 0x1c]
969                 set     flush_patch_two, %g5
970                 st      %g4, [%g5 + 0x18]
971                 st      %g4, [%g5 + 0x1c]
972                 set     flush_patch_three, %g5
973                 st      %g4, [%g5 + 0x18]
974                 st      %g4, [%g5 + 0x1c]
975                 set     flush_patch_four, %g5
976                 st      %g4, [%g5 + 0x18]
977                 st      %g4, [%g5 + 0x1c]
978                 set     flush_patch_exception, %g5
979                 st      %g4, [%g5 + 0x18]
980                 st      %g4, [%g5 + 0x1c]
981                 set     flush_patch_switch, %g5
982                 st      %g4, [%g5 + 0x18]
983                 st      %g4, [%g5 + 0x1c]
984
985 2:              
986                 sethi   %hi(nwindows), %g4
987                 st      %g3, [%g4 + %lo(nwindows)]      ! store final value
988                 sub     %g3, 0x1, %g3
989                 sethi   %hi(nwindowsm1), %g4
990                 st      %g3, [%g4 + %lo(nwindowsm1)]
991
992                 /* Here we go, start using Linux's trap table... */
993                 set     trapbase, %g3
994                 wr      %g3, 0x0, %tbr
995                 WRITE_PAUSE
996
997                 /* Finally, turn on traps so that we can call c-code. */
998                 rd      %psr, %g3
999                 wr      %g3, 0x0, %psr
1000                 WRITE_PAUSE
1001
1002                 wr      %g3, PSR_ET, %psr
1003                 WRITE_PAUSE
1004
1005                 /* First we call prom_init() to set up PROMLIB, then
1006                  * off to start_kernel().
1007                  */
1008
1009                 sethi   %hi(prom_vector_p), %g5
1010                 ld      [%g5 + %lo(prom_vector_p)], %o0
1011                 call    prom_init
1012                  nop
1013
1014                 call    start_kernel
1015                  nop
1016         
1017                 /* We should not get here. */
1018                 call    halt_me
1019                  nop
1020
1021 no_sun4e_here:
1022                 ld      [%g7 + 0x68], %o1
1023                 set     sun4e_notsup, %o0
1024                 call    %o1
1025                  nop
1026                 b       halt_me
1027                  nop
1028
1029                 __INITDATA
1030
1031 sun4u_1:
1032                 .asciz "finddevice"
1033                 .align  4
1034 sun4u_2:
1035                 .asciz "/chosen"
1036                 .align  4
1037 sun4u_3:
1038                 .asciz "getprop"
1039                 .align  4
1040 sun4u_4:
1041                 .asciz "stdout"
1042                 .align  4
1043 sun4u_5:
1044                 .asciz "write"
1045                 .align  4
1046 sun4u_6:
1047                 .asciz  "\n\rOn sun4u you have to use UltraLinux (64bit) kernel\n\rand not a 32bit sun4[cdem] version\n\r\n\r"
1048 sun4u_6e:
1049                 .align  4
1050 sun4u_7:
1051                 .asciz "exit"
1052                 .align  8
1053 sun4u_a1:
1054                 .word   0, sun4u_1, 0, 1, 0, 1, 0, sun4u_2, 0
1055 sun4u_r1:
1056                 .word   0
1057 sun4u_a2:
1058                 .word   0, sun4u_3, 0, 4, 0, 1, 0
1059 sun4u_i2:
1060                 .word   0, 0, sun4u_4, 0, sun4u_1, 0, 8, 0
1061 sun4u_r2:
1062                 .word   0
1063 sun4u_a3:
1064                 .word   0, sun4u_5, 0, 3, 0, 1, 0
1065 sun4u_i3:
1066                 .word   0, 0, sun4u_6, 0, sun4u_6e - sun4u_6 - 1, 0
1067 sun4u_r3:
1068                 .word   0
1069 sun4u_a4:
1070                 .word   0, sun4u_7, 0, 0, 0, 0
1071 sun4u_r4:
1072
1073                 __INIT
1074 no_sun4u_here:
1075                 set     sun4u_a1, %o0
1076                 set     current_pc, %l2
1077                 cmp     %l2, %g3
1078                 be      1f
1079                  mov    %o4, %l0
1080                 sub     %g3, %l2, %l6
1081                 add     %o0, %l6, %o0
1082                 mov     %o0, %l4
1083                 mov     sun4u_r4 - sun4u_a1, %l3
1084                 ld      [%l4], %l5
1085 2:
1086                 add     %l4, 4, %l4
1087                 cmp     %l5, %l2
1088                 add     %l5, %l6, %l5
1089                 bgeu,a  3f
1090                  st     %l5, [%l4 - 4]
1091 3:
1092                 subcc   %l3, 4, %l3
1093                 bne     2b
1094                  ld     [%l4], %l5
1095 1:
1096                 call    %l0
1097                  mov    %o0, %l1
1098
1099                 ld      [%l1 + (sun4u_r1 - sun4u_a1)], %o1
1100                 add     %l1, (sun4u_a2 - sun4u_a1), %o0
1101                 call    %l0
1102                  st     %o1, [%o0 + (sun4u_i2 - sun4u_a2)]
1103
1104                 ld      [%l1 + (sun4u_1 - sun4u_a1)], %o1
1105                 add     %l1, (sun4u_a3 - sun4u_a1), %o0
1106                 call    %l0
1107                 st      %o1, [%o0 + (sun4u_i3 - sun4u_a3)]
1108
1109                 call    %l0
1110                  add    %l1, (sun4u_a4 - sun4u_a1), %o0
1111
1112                 /* Not reached */
1113 halt_me:
1114                 ld      [%g7 + 0x74], %o0
1115                 call    %o0                     ! Get us out of here...
1116                  nop                            ! Apparently Solaris is better.
1117
1118 /* Ok, now we continue in the .data/.text sections */
1119
1120         .data
1121         .align 4
1122
1123 /*
1124  * Fill up the prom vector, note in particular the kind first element,
1125  * no joke. I don't need all of them in here as the entire prom vector
1126  * gets initialized in c-code so all routines can use it.
1127  */
1128
1129 prom_vector_p:
1130                 .word 0
1131
1132 /* We calculate the following at boot time, window fills/spills and trap entry
1133  * code uses these to keep track of the register windows.
1134  */
1135
1136         .align 4
1137         .globl  nwindows
1138         .globl  nwindowsm1
1139 nwindows:
1140         .word   8
1141 nwindowsm1:
1142         .word   7
1143
1144 /* Boot time debugger vector value.  We need this later on. */
1145
1146         .align 4
1147         .globl  linux_dbvec
1148 linux_dbvec:
1149         .word   0
1150         .word   0
1151
1152         .align 8
1153
1154         .globl  lvl14_save
1155 lvl14_save:
1156         .word   0
1157         .word   0
1158         .word   0
1159         .word   0
1160         .word   t_irq14
1161
1162         .section        ".fixup",#alloc,#execinstr
1163         .globl  __ret_efault
1164 __ret_efault:
1165         ret
1166          restore %g0, -EFAULT, %o0