1 /* $NetBSD: srt0.s,v 1.4.32.1 2007/06/26 18:13:39 garbled Exp $ */
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <machine/psl.h>
35 #include <machine/param.h>
36 #include <machine/frame.h>
37 #include <machine/asm.h>
38 #include <machine/ctlreg.h>
56 _esym
: .word 0 /* end of symbol table */
62 .globl _start, _C_LABEL(kernel_text)
63 _C_LABEL
(kernel_text
) = _start
65 nop ! For some reason this is needed to fixup the text section
68 * Start by creating a stack for ourselves.
73 set CC64FSZ
, %g1
! Frame Size
(negative
)
75 set BIAS
, %g2
! Bias
(negative
)
76 andn
%sp
, 0x0f, %sp
! 16 byte align
, per ELF spec.
77 add %g1
, %g2
, %g1
! Frame
+ Bias
84 set CC64FSZ
, %g1
! Frame Size
(negative
)
89 sub %sp
, %g1
, %g1
! This is so we properly sign-extend things
95 * Set the psr into a known state:
96 * Set supervisor mode, interrupt level >= 13, traps enabled
98 wrpr
%g0
, 0, %pil
! So I lied
99 wrpr
%g0
, PSTATE_PRIV+PSTATE_IE
, %pstate
101 clr
%g4
! Point
%g4 to start of data segment
102 ! only problem is that apparently the
103 ! start of the data segment is
0
107 * main(void *openfirmware)
111 call _C_LABEL
(OF_exit
)
115 * void syncicache(void* start, int size)
117 * I$ flush. Really simple. Just flush over the whole range.
120 .globl _C_LABEL(syncicache)
121 _C_LABEL
(syncicache
):
124 brgz
,a,pt
%o1
, _C_LABEL
(syncicache
)
130 * openfirmware(cell* param);
132 * OpenFirmware entry point
134 * If we're running in 32-bit mode we need to convert to a 64-bit stack
135 * and 64-bit cells. The cells we'll allocate off the stack for simplicity.
138 .globl _C_LABEL(openfirmware)
141 _C_LABEL
(openfirmware
):
144 sethi
%hi
(_C_LABEL
(romp
)), %o1
146 LDPTR
[%o1+
%lo
(_C_LABEL
(romp
))], %o4
! v9 stack
, just load the addr
and callit
147 save
%sp
, -CC64FSZ
, %sp
148 mov
%i0
, %o0
! Copy over our parameter
158 wrpr
%g0
, PSTATE_PROM|PSTATE_IE
, %pstate
159 wrpr
%l0
, %g0
, %pstate
168 restore
%o0
, %g0
, %o0
170 1: ! v8
-- need to screw with stack
& params
171 save
%sp
, -CC64FSZ
, %sp
! Get
a new
64-bit stack frame
173 sethi
%hi
(_C_LABEL
(romp
)), %o1
175 LDPTR
[%o1+
%lo
(_C_LABEL
(romp
))], %o1
! Do the actual call
186 wrpr
%g0
, PSTATE_PROM|PSTATE_IE
, %pstate
! Enable
64-bit addresses for the prom
196 restore
%o0
, %g0
, %o0
200 * itlb_va_to_pa(vaddr_t)
202 * Find out if there is a mapping in iTLB for a given virtual address,
203 * return -1 if there is none.
206 .globl _C_LABEL(itlb_va_to_pa)
207 _C_LABEL
(itlb_va_to_pa
):
208 set _C_LABEL
(itlb_slot_max
), %o3
213 0: ldxa
[%o1
] ASI_IMMU_TLB_TAG
, %o2
217 /* return PA of matching entry */
218 ldxa
[%o1
] ASI_IMMU_TLB_DATA
, %o0
220 srlx
%o0
, PGSHIFT+
23, %o0
221 sllx
%o0
, PGSHIFT
, %o0
233 * dtlb_va_to_pa(vaddr_t)
235 * Find out if there is a mapping in dTLB for a given virtual address,
236 * return -1 if there is none.
239 .globl _C_LABEL(dtlb_va_to_pa)
240 _C_LABEL
(dtlb_va_to_pa
):
241 set _C_LABEL
(dtlb_slot_max
), %o3
246 0: ldxa
[%o1
] ASI_DMMU_TLB_TAG
, %o2
250 /* return PA of matching entry */
251 ldxa
[%o1
] ASI_DMMU_TLB_DATA
, %o0
253 srlx
%o0
, PGSHIFT+
23, %o0
254 sllx
%o0
, PGSHIFT
, %o0
266 * itlb_enter(vaddr_t vpn, uint32_t data_hi, uint32_t data_lo)
268 * Insert new mapping into iTLB. Data tag is passed in two different
269 * registers so that it works even with 32-bit compilers.
272 .globl _C_LABEL(itlb_enter)
273 _C_LABEL
(itlb_enter
):
277 wrpr
%o4
, PSTATE_IE
, %pstate
278 mov TLB_TAG_ACCESS
, %o3
279 stxa
%o0
, [%o3
] ASI_IMMU
280 stxa
%o1
, [%g0
] ASI_IMMU_DATA_IN
288 * dtlb_replace(vaddr_t vpn, uint32_t data_hi, uint32_t data_lo)
290 * Replace mapping in dTLB. Data tag is passed in two different
291 * registers so that it works even with 32-bit compilers.
294 .globl _C_LABEL(dtlb_replace)
295 _C_LABEL
(dtlb_replace
):
299 wrpr
%o4
, PSTATE_IE
, %pstate
300 /* loop over dtlb entries */
303 ldxa
[%o5
] ASI_DMMU_TLB_TAG
, %o2
307 /* found - modify entry */
308 mov TLB_TAG_ACCESS
, %o2
309 stxa
%o0
, [%o2
] ASI_DMMU
310 stxa
%o1
, [%o5
] ASI_DMMU_TLB_DATA
315 /* advance to next tlb entry */
324 * dtlb_enter(vaddr_t vpn, uint32_t data_hi, uint32_t data_lo)
326 * Insert new mapping into dTLB. Data tag is passed in two different
327 * registers so that it works even with 32-bit compilers.
330 .globl _C_LABEL(dtlb_enter)
331 _C_LABEL
(dtlb_enter
):
335 wrpr
%o4
, PSTATE_IE
, %pstate
336 mov TLB_TAG_ACCESS
, %o3
337 stxa
%o0
, [%o3
] ASI_DMMU
338 stxa
%o1
, [%g0
] ASI_DMMU_DATA_IN
347 * Return UPA identifier for the CPU we're running on.
350 .globl _C_LABEL(get_cpuid)
360 #define STACK_SIZE 0x14000
362 ebootstack
: ! end
(top
) of boot stack