mcontext.h revision 1.1
11.1Smatt/* $NetBSD: mcontext.h,v 1.1 2014/08/10 05:47:38 matt Exp $ */ 21.1Smatt 31.1Smatt/*- 41.1Smatt * Copyright (c) 2014 The NetBSD Foundation, Inc. 51.1Smatt * All rights reserved. 61.1Smatt * 71.1Smatt * This code is derived from software contributed to The NetBSD Foundation 81.1Smatt * by Matt Thomas of 3am Software Foundry. 91.1Smatt * 101.1Smatt * Redistribution and use in source and binary forms, with or without 111.1Smatt * modification, are permitted provided that the following conditions 121.1Smatt * are met: 131.1Smatt * 1. Redistributions of source code must retain the above copyright 141.1Smatt * notice, this list of conditions and the following disclaimer. 151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright 161.1Smatt * notice, this list of conditions and the following disclaimer in the 171.1Smatt * documentation and/or other materials provided with the distribution. 181.1Smatt * 191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Smatt * POSSIBILITY OF SUCH DAMAGE. 301.1Smatt */ 311.1Smatt#ifndef _AARCH64_MCONTEXT_H_ 321.1Smatt#define _AARCH64_MCONTEXT_H_ 331.1Smatt 341.1Smatt#ifdef __aarch64__ 351.1Smatt 361.1Smatt/* 371.1Smatt * Layout of mcontext_t based on the System V Application Binary Interface, 381.1Smatt * Edition 4.1, PowerPC Processor ABI Supplement - September 1995, and 391.1Smatt * extended for the AltiVec Register File. Note that due to the increased 401.1Smatt * alignment requirements of the latter, the offset of mcontext_t within 411.1Smatt * an ucontext_t is different from System V. 421.1Smatt */ 431.1Smatt 441.1Smatt#define _NGREG 35 /* GR0-30, SP, PC, APSR, TPIDR */ 451.1Smatt 461.1Smatttypedef __int64_t __greg_t; 471.1Smatttypedef __greg_t __gregset_t[_NGREG]; 481.1Smatt 491.1Smatt#define _REG_X0 0 501.1Smatt#define _REG_X1 1 511.1Smatt#define _REG_X2 2 521.1Smatt#define _REG_X3 3 531.1Smatt#define _REG_X4 4 541.1Smatt#define _REG_X5 5 551.1Smatt#define _REG_X6 6 561.1Smatt#define _REG_X7 7 571.1Smatt#define _REG_X8 8 581.1Smatt#define _REG_X9 9 591.1Smatt#define _REG_X10 10 601.1Smatt#define _REG_X11 11 611.1Smatt#define _REG_X12 12 621.1Smatt#define _REG_X13 13 631.1Smatt#define _REG_X14 14 641.1Smatt#define _REG_X15 15 651.1Smatt#define _REG_X16 16 661.1Smatt#define _REG_X17 17 671.1Smatt#define _REG_X18 18 681.1Smatt#define _REG_X19 19 691.1Smatt#define _REG_X20 20 701.1Smatt#define _REG_X21 21 711.1Smatt#define _REG_X22 22 721.1Smatt#define _REG_X23 23 731.1Smatt#define _REG_X24 24 741.1Smatt#define _REG_X25 25 751.1Smatt#define _REG_X26 26 761.1Smatt#define _REG_X27 27 771.1Smatt#define _REG_X28 28 781.1Smatt#define _REG_X29 29 791.1Smatt#define _REG_X30 30 801.1Smatt#define _REG_SP 31 811.1Smatt#define _REG_PC 32 821.1Smatt#define _REG_SPSR 33 831.1Smatt#define _REG_TPIDR 34 841.1Smatt 851.1Smatt#define _NFREG 32 /* Number of SIMD registers */ 861.1Smatt 871.1Smatttypedef struct { 881.1Smatt union __freg { 891.1Smatt __uint8_t __b8[16]; 901.1Smatt __uint16_t __h16[8]; 911.1Smatt __uint32_t __s32[4]; 921.1Smatt __uint64_t __d64[2]; 931.1Smatt __uint128_t __q128[1]; 941.1Smatt } __qregs[_NFREG] __aligned(16); 951.1Smatt __uint32_t __fpcr; /* FPCR */ 961.1Smatt __uint32_t __fpsr; /* FPSR */ 971.1Smatt} __fregset_t; 981.1Smatt 991.1Smatttypedef struct { 1001.1Smatt __gregset_t __gregs; /* General Purpose Register set */ 1011.1Smatt __fregset_t __fregs; /* FPU/SIMD Register File */ 1021.1Smatt __greg_t __spare[8]; /* future proof */ 1031.1Smatt} mcontext_t; 1041.1Smatt 1051.1Smatt/* Machine-dependent uc_flags */ 1061.1Smatt#define _UC_TLSBASE 0x00080000 /* see <sys/ucontext.h> */ 1071.1Smatt 1081.1Smatt#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP]) 1091.1Smatt#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC]) 1101.1Smatt#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_X0]) 1111.1Smatt 1121.1Smatt#define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc) 1131.1Smatt 1141.1Smatt#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || defined(__LIBPTHREAD_SOURCE__) 1151.1Smatt#include <sys/tls.h> 1161.1Smatt 1171.1Smattstatic __inline void * 1181.1Smatt__lwp_getprivate_fast(void) 1191.1Smatt{ 1201.1Smatt void *__tpidr; 1211.1Smatt __asm __volatile("mrs\t%0, tpidr_el0" : "=r"(__tpidr)); 1221.1Smatt return __tpidr; 1231.1Smatt} 1241.1Smatt 1251.1Smattstatic __inline void * 1261.1Smatt__lwp_gettcb_fast(void) 1271.1Smatt{ 1281.1Smatt void *__tpidr; 1291.1Smatt __asm __volatile("mrs\t%0, tpidr_el0" : "=r"(__tpidr)); 1301.1Smatt return __tpidr; 1311.1Smatt} 1321.1Smatt 1331.1Smattstatic __inline void 1341.1Smatt__lwp_settcb(void *__tcb) 1351.1Smatt{ 1361.1Smatt __asm __volatile("msr\ttpidr_el0, %0" :: "r"(__tcb)); 1371.1Smatt} 1381.1Smatt#endif /* _RTLD_SOURCE || _LIBC_SOURCE || __LIBPTHREAD_SOURCE__ */ 1391.1Smatt 1401.1Smatt#elif defined(__arm__) 1411.1Smatt 1421.1Smatt#include <arm/mcontext.h> 1431.1Smatt 1441.1Smatt#endif /* __aarch64__/__arm__ */ 1451.1Smatt 1461.1Smatt#endif /* !_AARCH64_MCONTEXT_H_ */ 147