1 /* 2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of ARM nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific 16 * prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef __CONTEXT_H__ 32 #define __CONTEXT_H__ 33 34 /******************************************************************************* 35 * Constants that allow assembler code to access members of and the 'regs' 36 * structure at their correct offsets. 37 ******************************************************************************/ 38 #define CTX_REGS_OFFSET 0x0 39 #define CTX_GPREG_R0 0x0 40 #define CTX_GPREG_R1 0x4 41 #define CTX_GPREG_R2 0x8 42 #define CTX_GPREG_R3 0xC 43 #define CTX_LR 0x10 44 #define CTX_SCR 0x14 45 #define CTX_SPSR 0x18 46 #define CTX_NS_SCTLR 0x1C 47 #define CTX_REGS_END 0x20 48 49 #ifndef __ASSEMBLY__ 50 51 #include <cassert.h> 52 #include <stdint.h> 53 54 /* 55 * Common constants to help define the 'cpu_context' structure and its 56 * members below. 57 */ 58 #define WORD_SHIFT 2 59 #define DEFINE_REG_STRUCT(name, num_regs) \ 60 typedef struct name { \ 61 uint32_t _regs[num_regs]; \ 62 } __aligned(8) name##_t 63 64 /* Constants to determine the size of individual context structures */ 65 #define CTX_REG_ALL (CTX_REGS_END >> WORD_SHIFT) 66 67 DEFINE_REG_STRUCT(regs, CTX_REG_ALL); 68 69 #undef CTX_REG_ALL 70 71 #define read_ctx_reg(ctx, offset) ((ctx)->_regs[offset >> WORD_SHIFT]) 72 #define write_ctx_reg(ctx, offset, val) (((ctx)->_regs[offset >> WORD_SHIFT]) \ 73 = val) 74 typedef struct cpu_context { 75 regs_t regs_ctx; 76 } cpu_context_t; 77 78 /* Macros to access members of the 'cpu_context_t' structure */ 79 #define get_regs_ctx(h) (&((cpu_context_t *) h)->regs_ctx) 80 81 /* 82 * Compile time assertions related to the 'cpu_context' structure to 83 * ensure that the assembler and the compiler view of the offsets of 84 * the structure members is the same. 85 */ 86 CASSERT(CTX_REGS_OFFSET == __builtin_offsetof(cpu_context_t, regs_ctx), \ 87 assert_core_context_regs_offset_mismatch); 88 89 #endif /* __ASSEMBLY__ */ 90 91 #endif /* __CONTEXT_H__ */ 92