2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
33 * File: machine/thread.h
35 * This file contains the structure definitions for the thread
36 * state as applied to PPC processors.
39 #ifndef _PPC_THREAD_H_
40 #define _PPC_THREAD_H_
42 #include <mach/boolean.h>
43 #include <mach/ppc/vm_types.h>
44 #include <mach/thread_status.h>
45 #include <kern/lock.h>
46 #include <kern/clock.h>
47 #include <ppc/savearea.h>
50 * Kernel state structure
52 * This holds the kernel state that is saved and restored across context
57 * PPC process control block
59 * The PCB holds normal context. It does not contain vector or floating point
64 typedef struct savearea pcb
;
65 typedef struct savearea
*pcb_t
;
67 struct facility_context
{
69 savearea_fpu
*FPUsave
; /* The floating point savearea */
70 savearea
*FPUlevel
; /* The floating point context level */
71 unsigned int FPUcpu
; /* The last processor to enable floating point */
72 unsigned int FPUsync
; /* Sync lock */
73 savearea_vec
*VMXsave
; /* The VMX savearea */
74 savearea
*VMXlevel
; /* The VMX context level */
75 unsigned int VMXcpu
; /* The last processor to enable vector */
76 unsigned int VMXsync
; /* Sync lock */
77 struct thread
*facAct
;
80 typedef struct facility_context facility_context
;
83 * Maps state flavor to number of words in the state:
85 __private_extern__
unsigned int _MachineStateCount
[];
87 #define USER_REGS(ThrAct) ((ThrAct)->machine.pcb)
89 #define user_pc(ThrAct) ((ThrAct)->machine.pcb->save_srr0)
91 #define act_machine_state_ptr(ThrAct) (thread_state_t)USER_REGS(ThrAct)
93 struct machine_thread
{
95 * pointer to process control block control blocks. Potentially
96 * one for each active facility context. They may point to the
99 savearea
*pcb
; /* The "normal" savearea */
100 savearea
*upcb
; /* The "normal" user savearea */
101 facility_context
*curctx
; /* Current facility context */
102 facility_context
*deferctx
; /* Deferred facility context */
103 facility_context facctx
; /* "Normal" facility context */
104 struct vmmCntrlEntry
*vmmCEntry
; /* Pointer current emulation context or 0 */
105 struct vmmCntrlTable
*vmmControl
; /* Pointer to virtual machine monitor control table */
106 uint64_t qactTimer
; /* Time thread needs to interrupt. This is a single-shot timer. Zero is unset */
107 unsigned int umwSpace
; /* Address space ID for user memory window */
108 #define umwSwitchAway 0x80000000 /* Context switched away from thread since MapUserAddressWindow */
109 #define umwSwitchAwayb 0
110 addr64_t umwRelo
; /* Relocation value for user memory window */
111 unsigned int ksp
; /* points to TOP OF STACK or zero */
112 unsigned int preemption_count
; /* preemption count */
113 struct per_proc_info
*PerProc
; /* current per processor data */
114 unsigned int bbDescAddr
; /* Points to Blue Box Trap descriptor area in kernel (page aligned) */
115 unsigned int bbUserDA
; /* Points to Blue Box Trap descriptor area in user (page aligned) */
116 unsigned int bbTableStart
; /* Points to Blue Box Trap dispatch area in user */
117 unsigned int emPendRupts
; /* Number of pending emulated interruptions */
118 unsigned int bbTaskID
; /* Opaque task ID for Blue Box threads */
119 unsigned int bbTaskEnv
; /* Opaque task data reference for Blue Box threads */
120 unsigned int specFlags
; /* Special flags */
121 unsigned int pmcovfl
[8]; /* PMC overflow count */
122 unsigned int perfmonFlags
; /* Perfmon facility flags */
123 unsigned int bbTrap
; /* Blue Box trap vector */
124 unsigned int bbSysCall
; /* Blue Box syscall vector */
125 unsigned int bbInterrupt
; /* Blue Box interrupt vector */
126 unsigned int bbPending
; /* Blue Box pending interrupt vector */
128 /* special flags bits */
130 #define ignoreZeroFaultbit 0
131 #define floatUsedbit 1
132 #define vectorUsedbit 2
133 #define runningVMbit 4
134 #define floatCngbit 5
135 #define vectorCngbit 6
136 #define timerPopbit 7
137 #define userProtKeybit 8
138 #define FamVMenabit 11
139 #define FamVMmodebit 12
140 #define perfMonitorbit 13
142 /* NOTE: Do not move or assign bit 31 without changing exception vector ultra fast path code */
143 #define bbThreadbit 28
144 #define bbNoMachSCbit 29
145 #define bbPreemptivebit 30
146 #define spfReserved1 31 /* See note above */
148 #define ignoreZeroFault 0x80000000 /* (1<<(31-ignoreZeroFaultbit)) */
149 #define floatUsed 0x40000000 /* (1<<(31-floatUsedbit)) */
150 #define vectorUsed 0x20000000 /* (1<<(31-vectorUsedbit)) */
152 #define runningVM 0x08000000 /* (1<<(31-runningVMbit)) */
153 #define floatCng 0x04000000 /* (1<<(31-floatCngbit)) */
154 #define vectorCng 0x02000000 /* (1<<(31-vectorCngbit)) */
155 #define timerPop 0x01000000 /* (1<<(31-timerPopbit)) */
157 #define userProtKey 0x00800000 /* (1<<(31-userProtKeybit)) */
159 #define FamVMena 0x00100000 /* (1<<(31-FamVMenabit)) */
160 #define FamVMmode 0x00080000 /* (1<<(31-FamVMmodebit)) */
161 #define perfMonitor 0x00040000 /* (1<<(31-perfMonitorbit)) */
162 #define OnProc 0x00020000 /* (1<<(31-OnProcbit)) */
164 #define bbThread 0x00000008 /* (1<<(31-bbThreadbit)) */
165 #define bbNoMachSC 0x00000004 /* (1<<(31-bbNoMachSCbit)) */
166 #define bbPreemptive 0x00000002 /* (1<<(31-bbPreemptivebit)) */
169 #define fvChk 0x80000000
172 uint64_t cthread_self
; /* for use of cthread package */
177 extern struct savearea
*find_user_regs(thread_t
);
178 extern struct savearea
*get_user_regs(thread_t
);
179 extern struct savearea_fpu
*find_user_fpu(thread_t
);
180 extern struct savearea_vec
*find_user_vec(thread_t
);
181 extern struct savearea_vec
*find_user_vec_curr(void);
182 extern int thread_enable_fpe(thread_t act
, int onoff
);
184 extern struct savearea
*find_kern_regs(thread_t
);
186 extern void *act_thread_csave(void);
187 extern void act_thread_catt(void *ctx
);
188 extern void act_thread_cfree(void *ctx
);
191 * Return address of the function that called current function, given
192 * address of the first parameter of current function. We can't
193 * do it this way, since parameter was copied from a register
194 * into a local variable. Call an assembly sub-function to
198 extern vm_offset_t
getrpc(void);
199 #define GET_RETURN_PC(addr) getrpc()
201 #define STACK_IKS(stack) \
202 ((vm_offset_t)(((vm_offset_t)stack)+KERNEL_STACK_SIZE)-FM_SIZE)
205 * Defining this indicates that MD code will supply an exception()
206 * routine, conformant with kern/exception.c (dependency alert!)
207 * but which does wonderfully fast, machine-dependent magic.
210 #define MACHINE_FAST_EXCEPTION 1
212 #endif /* _PPC_THREAD_H_ */