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