xref: /netbsd-src/sys/arch/arm/arm/fiq_subr.S (revision 562b79dfcdcd0c05cc2a009681042af79ba9ae33)
1/*	$NetBSD: fiq_subr.S,v 1.8 2018/08/10 16:17:29 maxv Exp $	*/
2
3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *	This product includes software developed for the NetBSD Project by
20 *	Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 *    or promote products derived from this software without specific prior
23 *    written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include "assym.h"
39
40#include <arm/armreg.h>
41#include <arm/asm.h>
42#include <arm/cpuconf.h>
43
44#ifdef _ARM_ARCH_6
45#define	SWITCH_TO_FIQ_MODE						\
46	cps	#PSR_FIQ32_MODE
47#else
48#define	SWITCH_TO_FIQ_MODE						\
49	mrs	r2, cpsr					;	\
50	mov	r3, r2						;	\
51	bic	r2, r2, #(PSR_MODE)				;	\
52	orr	r2, r2, #(PSR_FIQ32_MODE)			;	\
53	msr	cpsr_all, r2
54#endif
55
56#ifdef _ARM_ARCH_6
57#define	BACK_TO_SVC_MODE						\
58	cps	#PSR_SVC32_MODE
59#else
60#define	BACK_TO_SVC_MODE						\
61	msr	cpsr_all, r3
62#endif
63
64/*
65 * fiq_getregs:
66 *
67 *	Fetch the FIQ mode banked registers into the fiqhandler
68 *	structure.
69 */
70ENTRY(fiq_getregs)
71	SWITCH_TO_FIQ_MODE
72
73#ifdef __thumb__
74	stmia	r0!, {r8-r12}
75	str	sp, [r0]
76#else
77	stmia	r0, {r8-r13}
78#endif
79
80	BACK_TO_SVC_MODE
81	RET
82END(fiq_getregs)
83
84/*
85 * fiq_setregs:
86 *
87 *	Load the FIQ mode banked registers from the fiqhandler
88 *	structure.
89 */
90ENTRY(fiq_setregs)
91	SWITCH_TO_FIQ_MODE
92
93#ifdef __thumb__
94	ldmia	r0!, {r8-r12}
95	ldr	sp, [r0]
96#else
97	ldmia	r0, {r8-r13}
98#endif
99
100	BACK_TO_SVC_MODE
101	RET
102END(fiq_setregs)
103
104/*
105 * fiq_nullhandler:
106 *
107 *	Null handler copied down to the FIQ vector when the last
108 *	FIQ handler is removed.
109 */
110	.global	_C_LABEL(fiq_nullhandler), _C_LABEL(fiq_nullhandler_end)
111_C_LABEL(fiq_nullhandler):
112	subs	pc, lr, #4
113_C_LABEL(fiq_nullhandler_end):
114	.size	_C_LABEL(fiq_nullhandler), . - _C_LABEL(fiq_nullhandler)
115