1/*
2 * Copyright 2013, winocm. <winocm@icloud.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 *   Redistributions of source code must retain the above copyright notice, this
9 *   list of conditions and the following disclaimer.
10 *
11 *   Redistributions in binary form must reproduce the above copyright notice, this
12 *   list of conditions and the following disclaimer in the documentation and/or
13 *   other materials provided with the distribution.
14 *
15 *   If you are going to use this software in any form that does not involve
16 *   releasing the source to this project or improving it, let me know beforehand.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29/*
30 * ARM thread state
31 */
32
33#ifndef _ARM_THREAD_H_
34#define _ARM_THREAD_H_
35
36#include <mach/boolean.h>
37#include <mach/arm/vm_types.h>
38#include <mach/thread_status.h>
39
40#include <kern/lock.h>
41#include <machine/pal_routines.h>
42
43#include <arm/cpu_data.h>
44
45/*
46 * Maps state flavor to number of words in the state:
47 */
48__private_extern__ unsigned int _MachineStateCount[];
49
50/*
51 * Kernel stack stuff.
52 */
53#define FP_SIZE     sizeof(arm_saved_state_t)
54
55#define STACK_IKS(stack)		\
56    ((vm_offset_t)(((vm_offset_t)stack)+KERNEL_STACK_SIZE)-FP_SIZE)
57
58/*
59 * The machine-dependent thread state - registers and all platform-dependent
60 * state - is saved in the machine thread structure which is embedded in
61 * the thread data structure. For historical reasons this is also referred to
62 * as the PCB.
63 */
64struct machine_thread {
65    arm_saved_state_t *iss;
66
67    arm_saved_state_t *uss;
68    arm_vfp_state_t *uvfp;
69
70    arm_saved_state_t user_regs;
71
72    arm_exception_state_t es;
73
74    cpu_data_t *cpu_data;
75
76    int vfp_dirty;
77    int vfp_enable;
78    arm_vfp_state_t vfp_regs;
79
80    uint32_t preempt_count;
81
82#ifdef	MACH_BSD
83    uint64_t cthread_self;      /* for use of cthread package  */
84#endif
85};
86typedef struct machine_thread *pcb_t;
87
88#define	THREAD_TO_PCB(Thr)	(&(Thr)->machine)
89
90#define USER_STATE(Thr)		((Thr)->machine.iss)
91
92/*
93 * Return address of the function that called current function, given
94 *	address of the first parameter of current function.
95 */
96#define	GET_RETURN_PC(addr)	(__builtin_return_address(0))
97
98#endif
99