sb_asm.S revision 203985
1/*-
2 * Copyright (c) 2009 Neelkanth Natu
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/mips/sibyte/sb_asm.S 203985 2010-02-17 06:43:37Z neel $
27 */
28
29#include <machine/asm.h>
30#include <machine/cpuregs.h>
31#include <machine/endian.h>
32
33/*
34 * We compile a 32-bit kernel to run on the SB-1 processor which is a 64-bit
35 * processor. It has some registers that must be accessed using 64-bit load
36 * and store instructions.
37 *
38 * So we have to resort to assembly because the compiler does not emit the
39 * 'ld' and 'sd' instructions since it thinks that it is compiling for a
40 * 32-bit mips processor.
41 */
42
43.set	mips64
44.set	noat
45.set	noreorder
46
47/*
48 * Parameters:		uint32_t ptr
49 * Return value: 	*(uint64_t *)ptr
50 */
51LEAF(sb_load64)
52	ld      v1, 0(a0)	/* result = *(uint64_t *)ptr */
53	move	v0, v1
54#if _BYTE_ORDER == _BIG_ENDIAN
55	dsll32	v1, v1, 0
56	dsrl32	v1, v1, 0	/* v1 = lower_uint32(result) */
57	jr	ra
58	dsrl32	v0, v0, 0	/* v0 = upper_uint32(result) */
59#else
60	dsll32	v0, v0, 0
61	dsrl32	v0, v0, 0	/* v0 = lower_uint32(result) */
62	jr	ra
63	dsrl32	v1, v1, 0	/* v1 = upper_uint32(result) */
64#endif
65END(sb_load64)
66
67/*
68 * Parameters:		uint32_t ptr, uint64_t val
69 * Return value:	void
70 */
71LEAF(sb_store64)
72#if _BYTE_ORDER == _BIG_ENDIAN
73	dsll32	a2, a2, 0	/* a2 = upper_uint32(val) */
74	dsll32	a3, a3, 0	/* a3 = lower_uint32(val) */
75	dsrl32	a3, a3, 0
76#else
77	dsll32	a3, a3, 0	/* a3 = upper_uint32(val) */
78	dsll32	a2, a2, 0	/* a2 = lower_uint32(val) */
79	dsrl32	a2, a2, 0
80#endif
81	or	t0, a2, a3
82	jr	ra
83	sd	t0, 0(a0)
84END(sb_store64)
85
86#ifdef SMP
87/*
88 * This function must be implemented in assembly because it is called early
89 * in AP boot without a valid stack.
90 *
91 * This cpu number is available in bits 25 to 27 of the coprocessor 0 PRID
92 * register. This is not documented in the BCM1250 user manual but can be
93 * gleaned from the CFE source code - see sb1250_altcpu.S
94 */
95LEAF(platform_processor_id)
96	mfc0	v0, MIPS_COP_0_PRID
97	srl	v0, v0, 25
98	jr	ra
99	and	v0, v0, 7
100END(platform_processor_id)
101#endif	/* SMP */
102