xref: /netbsd-src/sys/arch/or1k/include/mcontext.h (revision 16543c49052c820334cffc5c69b2afde18f02458)
1 /* $NetBSD: mcontext.h,v 1.5 2024/11/30 01:04:13 christos Exp $ */
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Matt Thomas of 3am Software Foundry.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 #ifndef _OR1K_MCONTEXT_H_
32 #define _OR1K_MCONTEXT_H_
33 
34 /*
35  */
36 
37 #define	_NGREG	33		/* GR1-31, FPCSR */
38 
39 typedef	__int64_t	__greg_t;
40 typedef	__greg_t	__gregset_t[_NGREG];
41 
42 #define	_REG_R1		0
43 #define	_REG_R2		1
44 #define	_REG_R3		2
45 #define	_REG_R4		3
46 #define	_REG_R5		4
47 #define	_REG_R6		5
48 #define	_REG_R7		6
49 #define	_REG_R8		7
50 #define	_REG_R9		8
51 #define	_REG_R10	9
52 #define	_REG_R11	10
53 #define	_REG_R12	11
54 #define	_REG_R13	12
55 #define	_REG_R14	13
56 #define	_REG_R15	14
57 #define	_REG_R16	15
58 #define	_REG_R17	16
59 #define	_REG_R18	17
60 #define	_REG_R19	18
61 #define	_REG_R20	19
62 #define	_REG_R21	20
63 #define	_REG_R22	21
64 #define	_REG_R23	22
65 #define	_REG_R24	23
66 #define	_REG_R25	24
67 #define	_REG_R26	25
68 #define	_REG_R27	26
69 #define	_REG_R28	27
70 #define	_REG_R29	28
71 #define	_REG_R30	29
72 #define	_REG_R31	30
73 #define	_REG_PC		31
74 #define	_REG_FPCSR	32
75 
76 #define	_REG_SP		_REG_R1
77 #define	_REG_LR		_REG_R9
78 #define	_REG_TP		_REG_R10
79 #define	_REG_RV		_REG_R11
80 #define	_REG_GP		_REG_R16
81 
82 typedef struct {
83 	__gregset_t	__gregs;	/* General Purpose Register set */
84 	__greg_t	__spare[8];	/* future proof */
85 } mcontext_t;
86 
87 /* Machine-dependent uc_flags */
88 #define	_UC_TLSBASE	0x00080000	/* see <sys/ucontext.h> */
89 
90 #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_SP])
91 #define _UC_MACHINE_FP(uc)	((uc)->uc_mcontext.__gregs[_REG_R2])
92 #define _UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_PC])
93 #define _UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[_REG_RV])
94 
95 #define	_UC_MACHINE_SET_PC(uc, pc)	_UC_MACHINE_PC(uc) = (pc)
96 
97 #endif /* !_OR1K_MCONTEXT_H_ */
98