context.S revision 129206
1/*
2 * Copyright (c) Olivier Houchard
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. Neither the name of the author nor the names of its contributors
11 *    may be used to endorse or promote products derived from this software
12 *    without specific prior written permission.
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
27#include <machine/asm.h>
28__FBSDID("$FreeBSD: head/lib/libkse/arch/arm/arm/context.S 129206 2004-05-14 12:21:29Z cognet $");
29
30/*
31 * int thr_setcontext(mcontext_t *mcp, intptr_t val, intptr_t *loc)
32 *
33 * Restores the context in mcp.
34 *
35 * Returns 0 if there are no errors; -1 otherwise
36 */
37
38.weak _C_LABEL(_thr_setcontext)
39.set _C_LABEL(_thr_setcontext), _C_LABEL(__thr_setcontext)
40
41ENTRY(__thr_setcontext)
42/* Check for NULL pointer. */
43	cmp 	r0, #0
44	moveq 	r0, #-1
45	moveq 	pc, lr
46	add	ip, r0, #8
47	ldmia	ip, {r2-r12}
48	cmp	r2, #0
49	str	r1, [r2]
50	add	ip, r0, #4
51	str	ip, [r1] /* Restore r1. */
52	add	ip, r0, #64
53	msr	cpsr, ip
54	add	ip, r0, #52
55	mov	r0, #0 /* Return 0. */
56	ldr	sp, [ip] /* Restore stack pointer. */
57	mov	pc, lr /* Return. */
58	/* XXX: FP bits ? */
59
60/*
61 * int thr_getcontext(mcontext_t *mcp);
62 *
63 * Returns -1 if there is an error, 0 no errors; 1 upon return
64 * from a setcontext().
65 */
66.weak _C_LABEL(_thr_getcontext)
67.set _C_LABEL(_thr_getcontext), _C_LABEL(__thr_getcontext)
68
69ENTRY(__thr_getcontext)
70/* Check for NULL pointer. */
71	cmp	r0, #0
72	moveq	r0, #-1
73	moveq	pc, lr
74	stmia	r0, {r0-r13}
75	mov	r0, #0 /* Return 0. */
76	mov	pc, lr
77
78ENTRY(_arm_enter_uts)
79	add	r4, r2, r3 /* Stack addr + size. */
80	mov	lr, pc
81	mov	pc, r1
82