1129198Scognet/*	$NetBSD: setstack.S,v 1.1 2001/07/28 13:28:03 chris Exp $	*/
2129198Scognet
3139735Simp/*-
4129198Scognet * Copyright (c) 1994 Mark Brinicombe.
5129198Scognet * Copyright (c) 1994 Brini.
6129198Scognet * All rights reserved.
7129198Scognet *
8129198Scognet * This code is derived from software written for Brini by Mark Brinicombe
9129198Scognet *
10129198Scognet * Redistribution and use in source and binary forms, with or without
11129198Scognet * modification, are permitted provided that the following conditions
12129198Scognet * are met:
13129198Scognet * 1. Redistributions of source code must retain the above copyright
14129198Scognet *    notice, this list of conditions and the following disclaimer.
15129198Scognet * 2. Redistributions in binary form must reproduce the above copyright
16129198Scognet *    notice, this list of conditions and the following disclaimer in the
17129198Scognet *    documentation and/or other materials provided with the distribution.
18129198Scognet * 3. All advertising materials mentioning features or use of this software
19129198Scognet *    must display the following acknowledgement:
20129198Scognet *	This product includes software developed by Brini.
21129198Scognet * 4. The name of the company nor the name of the author may be used to
22129198Scognet *    endorse or promote products derived from this software without specific
23129198Scognet *    prior written permission.
24129198Scognet *
25129198Scognet * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26129198Scognet * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27129198Scognet * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28129198Scognet * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29129198Scognet * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30129198Scognet * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31129198Scognet * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32129198Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33129198Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34129198Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35129198Scognet * SUCH DAMAGE.
36129198Scognet *
37129198Scognet * RiscBSD kernel project
38129198Scognet *
39129198Scognet * setstack.S
40129198Scognet *
41129198Scognet * Miscellaneous routine to play with the stack pointer in different CPU modes
42129198Scognet *
43129198Scognet * Eventually this routine can be inline assembly.
44129198Scognet *
45129198Scognet * Created      : 17/09/94
46129198Scognet *
47129198Scognet * Based of kate/display/setstack.s
48129198Scognet *
49129198Scognet */
50129198Scognet
51129198Scognet#include <machine/armreg.h>
52129198Scognet#include <machine/asm.h>
53129198Scognet__FBSDID("$FreeBSD$");
54129198Scognet
55129198Scognet/* To set the stack pointer for a particular mode we must switch
56129198Scognet * to that mode update the banked r13 and then switch back.
57129198Scognet * This routine provides an easy way of doing this for any mode
58129198Scognet *
59129198Scognet * r0 = CPU mode
60129198Scognet * r1 = stackptr
61129198Scognet */
62129198Scognet
63129198ScognetENTRY(set_stackptr)
64129198Scognet        mrs	r3, cpsr_all		/* Switch to the appropriate mode */
65129198Scognet	bic	r2, r3, #(PSR_MODE)
66129198Scognet	orr	r2, r2, r0
67129198Scognet        msr	cpsr_all, r2
68129198Scognet
69129198Scognet	mov	sp, r1			/* Set the stack pointer */
70129198Scognet
71129198Scognet        msr	cpsr_all, r3		/* Restore the old mode */
72129198Scognet
73129198Scognet	mov	pc, lr			/* Exit */
74129198Scognet
75129198Scognet/* To get the stack pointer for a particular mode we must switch
76129198Scognet * to that mode copy the banked r13 and then switch back.
77129198Scognet * This routine provides an easy way of doing this for any mode
78129198Scognet *
79129198Scognet * r0 = CPU mode
80129198Scognet */
81129198Scognet
82129198ScognetENTRY(get_stackptr)
83129198Scognet        mrs	r3, cpsr_all		/* Switch to the appropriate mode */
84129198Scognet	bic	r2, r3, #(PSR_MODE)
85129198Scognet	orr	r2, r2, r0
86129198Scognet        msr	cpsr_all, r2
87129198Scognet
88129198Scognet	mov	r0, sp			/* Set the stack pointer */
89129198Scognet
90129198Scognet        msr	cpsr_all, r3		/* Restore the old mode */
91129198Scognet
92129198Scognet	mov	pc, lr			/* Exit */
93129198Scognet
94129198Scognet/* End of setstack.S */
95