]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/vmachmon.h
xnu-344.12.2.tar.gz
[apple/xnu.git] / osfmk / ppc / vmachmon.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*-----------------------------------------------------------------------
23 ** vmachmon.h
24 **
25 ** C routines that we are adding to the MacOS X kernel.
26 **
27 ** Wierd Apple PSL stuff goes here...
28 **
29 ** Until then, Copyright 2000, Connectix
30 **
31 -----------------------------------------------------------------------*/
32
33 #include <ppc/exception.h>
34
35 #ifndef _VEMULATION_H_
36 #define _VEMULATION_H_
37
38 /*************************************************************************************
39 External Emulation Types
40 **************************************************************************************/
41
42 typedef union vmm_vector_register_t {
43 unsigned long i[4];
44 unsigned short s[8];
45 unsigned char b[16];
46 } vmm_vector_register_t;
47
48 typedef union vmm_fp_register_t {
49 double d;
50 unsigned long i[2];
51 unsigned short s[4];
52 unsigned char b[8];
53 } vmm_fp_register_t;
54
55 typedef struct vmm_processor_state_t {
56
57 unsigned long ppcPC;
58 unsigned long ppcMSR;
59
60 unsigned long ppcGPRs[32];
61
62 unsigned long ppcCR;
63 unsigned long ppcXER;
64 unsigned long ppcLR;
65 unsigned long ppcCTR;
66 unsigned long ppcMQ; /* Obsolete */
67 unsigned long ppcVRSave;
68 /* 32-byte bndry */
69 vmm_vector_register_t ppcVSCR;
70 vmm_fp_register_t ppcFPSCR;
71
72 unsigned long ppcReserved1[34]; /* Future processor state can go here */
73
74 /* We must be 16-byte aligned here */
75
76 vmm_vector_register_t ppcVRs[32];
77 vmm_vector_register_t ppcVSCRshadow;
78
79 /* We must be 8-byte aligned here */
80
81 vmm_fp_register_t ppcFPRs[32];
82 vmm_fp_register_t ppcFPSCRshadow;
83 unsigned long ppcReserved2[2]; /* Pad out to multiple of 16 bytes */
84 } vmm_processor_state_t;
85
86 typedef unsigned long vmm_return_code_t;
87
88 typedef unsigned long vmm_thread_index_t;
89
90 enum {
91 kVmmCurMajorVersion = 0x0001,
92 kVmmCurMinorVersion = 0x0004,
93 kVmmMinMajorVersion = 0x0001,
94 };
95 #define kVmmCurrentVersion ((kVmmCurMajorVersion << 16) | kVmmCurMinorVersion)
96
97 typedef unsigned long vmm_features_t;
98 enum {
99 kVmmFeature_LittleEndian = 0x00000001,
100 kVmmFeature_Stop = 0x00000002,
101 kVmmFeature_ExtendedMapping = 0x00000004,
102 kVmmFeature_ListMapping = 0x00000008,
103 };
104 #define kVmmCurrentFeatures (kVmmFeature_LittleEndian | kVmmFeature_Stop | kVmmFeature_ExtendedMapping | kVmmFeature_ListMapping)
105
106 typedef unsigned long vmm_version_t;
107
108 typedef struct vmm_state_page_t {
109 /* This structure must remain below 4Kb (one page) in size */
110 vmm_version_t interface_version;
111 vmm_thread_index_t thread_index;
112 unsigned int vmmStat; /* Note: this field is identical to vmmFlags in vmmCntrlEntry */
113 unsigned int vmmCntrl;
114 #define vmmFloatLoad 0x80000000
115 #define vmmFloatLoadb 0
116 #define vmmVectLoad 0x40000000
117 #define vmmVectLoadb 1
118 #define vmmVectVRall 0x20000000
119 #define vmmVectVRallb 2
120 #define vmmVectVAss 0x10000000
121 #define vmmVectVAssb 3
122 #define vmmXStart 0x08000000
123 #define vmmXStartb 4
124 #define vmmKey 0x04000000
125 #define vmmKeyb 5
126 vmm_return_code_t return_code;
127 unsigned long return_params[4];
128 unsigned long gas[7]; /* For alignment */
129
130 /* The next portion of the structure must remain 32-byte aligned */
131 vmm_processor_state_t vmm_proc_state;
132
133 } vmm_state_page_t;
134
135 typedef struct vmm_comm_page_t {
136 union {
137 vmm_state_page_t vmcpState; /* Reserve area for state */
138 unsigned int vmcpPad[768]; /* Reserve space for 3/4 page state area */
139 } vmcpfirst;
140 unsigned int vmcpComm[256]; /* Define last 1024 bytes as a communications area - function specific */
141 } vmm_comm_page_t;
142
143 enum {
144 /* Function Indices (passed in r3) */
145 kVmmGetVersion = 0,
146 kVmmvGetFeatures,
147 kVmmInitContext,
148 kVmmTearDownContext,
149 kVmmTearDownAll,
150 kVmmMapPage,
151 kVmmGetPageMapping,
152 kVmmUnmapPage,
153 kVmmUnmapAllPages,
154 kVmmGetPageDirtyFlag,
155 kVmmGetFloatState,
156 kVmmGetVectorState,
157 kVmmSetTimer,
158 kVmmGetTimer,
159 kVmmExecuteVM,
160 kVmmProtectPage,
161 kVmmMapExecute,
162 kVmmProtectExecute,
163 kVmmMapList,
164 kVmmUnmapList,
165 };
166
167 #define kVmmReturnNull 0
168 #define kVmmBogusContext 1
169 #define kVmmStopped 2
170 #define kVmmReturnDataPageFault 3
171 #define kVmmReturnInstrPageFault 4
172 #define kVmmReturnAlignmentFault 6
173 #define kVmmReturnProgramException 7
174 #define kVmmReturnSystemCall 12
175 #define kVmmReturnTraceException 13
176 #define kVmmAltivecAssist 22
177 #define kVmmInvalidAddress 4096
178
179 /*
180 * Storage Extended Protection modes
181 * Notes:
182 * To keep compatibility, vmmKey and the PPC key have reversed meanings,
183 * i.e., vmmKey 0 is PPC key 1 and vice versa.
184 *
185 * vmmKey Notes
186 * Mode 0 1
187 *
188 * kVmmProtNARW not accessible read/write VM_PROT_NONE (not settable via VM calls)
189 * kVmmProtRORW read only read/write
190 * kVmmProtRWRW read/write read/write VM_PROT_WRITE or (VM_PROT_WRITE | VM_PROT_READ)
191 * kVmmProtRORO read only read only VM_PROT_READ
192
193 */
194
195 #define kVmmProtXtnd 0x00000008
196 #define kVmmProtNARW (kVmmProtXtnd | 0x00000000)
197 #define kVmmProtRORW (kVmmProtXtnd | 0x00000001)
198 #define kVmmProtRWRW (kVmmProtXtnd | 0x00000002)
199 #define kVmmProtRORO (kVmmProtXtnd | 0x00000003)
200
201 /*
202 * Map list format
203 */
204
205 typedef struct vmmMapList {
206 unsigned int vmlva; /* Virtual address in emulator address space */
207 unsigned int vmlava; /* Virtual address in alternate address space */
208 #define vmlFlgs 0x00000FFF /* Flags passed in in vmlava low order 12 bits */
209 #define vmlProt 0x00000003 /* Protection flags for the page */
210 } vmmMapList;
211
212
213 /*************************************************************************************
214 Internal Emulation Types
215 **************************************************************************************/
216
217 #define kVmmMaxContextsPerThread 32
218 #define kVmmMaxUnmapPages 64
219 #define kVmmMaxMapPages 64
220
221 typedef struct vmmCntrlEntry { /* Virtual Machine Monitor control table entry */
222 unsigned int vmmFlags; /* Assorted control flags */
223 #define vmmInUse 0x80000000
224 #define vmmInUseb 0
225 #define vmmFloatCngd 0x40000000
226 #define vmmFloatCngdb 1
227 #define vmmVectCngd 0x20000000
228 #define vmmVectCngdb 2
229 #define vmmTimerPop 0x10000000
230 #define vmmTimerPopb 3
231 #define vmmMapDone 0x08000000
232 #define vmmMapDoneb 4
233 #define vmmXStop 0x00800000
234 #define vmmXStopb 8
235 #define vmmSpfSave 0x000000FF
236 #define vmmSpfSaveb 24
237 pmap_t vmmPmap; /* pmap for alternate context's view of task memory */
238 vmm_state_page_t *vmmContextKern; /* Kernel address of context communications area */
239 vmm_state_page_t *vmmContextUser; /* User address of context communications area */
240 facility_context vmmFacCtx; /* Header for vector and floating point contexts */
241 uint64_t vmmTimer; /* Last set timer value. Zero means unset */
242 vm_offset_t vmmLastMap; /* Last vaddr mapping into virtual machine */
243 } vmmCntrlEntry;
244
245 typedef struct vmmCntrlTable { /* Virtual Machine Monitor Control table */
246 vmmCntrlEntry vmmc[kVmmMaxContextsPerThread]; /* One entry for each possible Virtual Machine Monitor context */
247 } vmmCntrlTable;
248
249 /* function decls for kernel level routines... */
250 extern void vmm_execute_vm(thread_act_t act, vmm_thread_index_t index);
251 extern vmmCntrlEntry *vmm_get_entry(thread_act_t act, vmm_thread_index_t index);
252 extern kern_return_t vmm_tear_down_context(thread_act_t act, vmm_thread_index_t index);
253 extern kern_return_t vmm_get_float_state(thread_act_t act, vmm_thread_index_t index);
254 extern kern_return_t vmm_get_vector_state(thread_act_t act, vmm_thread_index_t index);
255 extern kern_return_t vmm_set_timer(thread_act_t act, vmm_thread_index_t index, unsigned int timerhi, unsigned int timerlo);
256 extern kern_return_t vmm_get_timer(thread_act_t act, vmm_thread_index_t index);
257 extern void vmm_tear_down_all(thread_act_t act);
258 extern kern_return_t vmm_map_page(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t cva,
259 vm_offset_t ava, vm_prot_t prot);
260 extern vmm_return_code_t vmm_map_execute(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t cva,
261 vm_offset_t ava, vm_prot_t prot);
262 extern kern_return_t vmm_protect_page(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t va,
263 vm_prot_t prot);
264 extern vmm_return_code_t vmm_protect_execute(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t va,
265 vm_prot_t prot);
266 extern vm_offset_t vmm_get_page_mapping(thread_act_t act, vmm_thread_index_t index,
267 vm_offset_t va);
268 extern kern_return_t vmm_unmap_page(thread_act_t act, vmm_thread_index_t index, vm_offset_t va);
269 extern void vmm_unmap_all_pages(thread_act_t act, vmm_thread_index_t index);
270 extern boolean_t vmm_get_page_dirty_flag(thread_act_t act, vmm_thread_index_t index,
271 vm_offset_t va, unsigned int reset);
272 extern int vmm_get_features(struct savearea *);
273 extern int vmm_get_version(struct savearea *);
274 extern int vmm_init_context(struct savearea *);
275 extern int vmm_dispatch(struct savearea *);
276 extern int vmm_exit(thread_act_t act, struct savearea *);
277 extern void vmm_force_exit(thread_act_t act, struct savearea *);
278 extern int vmm_stop_vm(struct savearea *save);
279 extern void vmm_timer_pop(thread_act_t act);
280 extern void vmm_interrupt(ReturnHandler *rh, thread_act_t act);
281 extern kern_return_t vmm_map_list(thread_act_t act, vmm_thread_index_t index, unsigned int cnt);
282 extern kern_return_t vmm_unmap_list(thread_act_t act, vmm_thread_index_t index, unsigned int cnt);
283
284 #endif
285