]>
Commit | Line | Data |
---|---|---|
1c79356b A |
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 | * NOTE: The general context needs to correspond to the order of the savearea for quick swaps | |
58 | */ | |
59 | unsigned long ppcPC; | |
60 | unsigned long ppcMSR; | |
61 | ||
62 | unsigned long ppcGPRs[32]; | |
63 | ||
64 | unsigned long ppcCR; | |
65 | unsigned long ppcXER; | |
66 | unsigned long ppcLR; | |
67 | unsigned long ppcCTR; | |
68 | unsigned long ppcMQ; /* Obsolete */ | |
69 | unsigned long ppcVRSave; | |
70 | unsigned long ppcReserved1[40]; /* Future processor state can go here */ | |
71 | ||
72 | /* We must be 16-byte aligned here */ | |
73 | ||
74 | vmm_vector_register_t ppcVRs[32]; | |
75 | vmm_vector_register_t ppcVSCR; | |
76 | ||
77 | /* We must be 8-byte aligned here */ | |
78 | ||
79 | vmm_fp_register_t ppcFPRs[32]; | |
80 | vmm_fp_register_t ppcFPSCR; | |
81 | unsigned long ppcReserved2[2]; /* Pad out to multiple of 16 bytes */ | |
82 | } vmm_processor_state_t; | |
83 | ||
84 | typedef unsigned long vmm_return_code_t; | |
85 | ||
86 | typedef unsigned long vmm_thread_index_t; | |
0b4e3aa0 | 87 | |
1c79356b | 88 | enum { |
0b4e3aa0 A |
89 | kVmmCurMajorVersion = 0x0001, |
90 | kVmmCurMinorVersion = 0x0002, | |
91 | kVmmMinMajorVersion = 0x0001, | |
1c79356b | 92 | }; |
0b4e3aa0 | 93 | #define kVmmCurrentVersion ((kVmmCurMajorVersion << 16) | kVmmCurMinorVersion) |
1c79356b A |
94 | |
95 | typedef unsigned long vmm_features_t; | |
96 | enum { | |
0b4e3aa0 A |
97 | kVmmFeature_LittleEndian = 0x00000001, |
98 | kVmmFeature_Stop = 0x00000002, | |
99 | kVmmFeature_ExtendedMapping = 0x00000004, | |
1c79356b | 100 | }; |
0b4e3aa0 | 101 | #define kVmmCurrentFeatures (kVmmFeature_LittleEndian | kVmmFeature_Stop | kVmmFeature_ExtendedMapping) |
1c79356b A |
102 | |
103 | typedef unsigned long vmm_version_t; | |
104 | ||
105 | typedef struct vmm_state_page_t { | |
106 | /* This structure must remain below 4Kb (one page) in size */ | |
107 | vmm_version_t interface_version; | |
108 | vmm_thread_index_t thread_index; | |
109 | unsigned int vmmStat; /* Note: this field is identical to vmmFlags in vmmCntrlEntry */ | |
110 | unsigned int vmmCntrl; | |
111 | #define vmmFloatLoad 0x80000000 | |
112 | #define vmmFloatLoadb 0 | |
113 | #define vmmVectLoad 0x40000000 | |
114 | #define vmmVectLoadb 1 | |
115 | #define vmmVectVRall 0x20000000 | |
116 | #define vmmVectVRallb 2 | |
117 | #define vmmVectVAss 0x10000000 | |
118 | #define vmmVectVAssb 3 | |
0b4e3aa0 A |
119 | #define vmmXStart 0x08000000 |
120 | #define vmmXStartb 4 | |
121 | #define vmmKey 0x04000000 | |
122 | #define vmmKeyb 5 | |
1c79356b A |
123 | vmm_return_code_t return_code; |
124 | unsigned long return_params[4]; | |
125 | unsigned long gas[7]; /* For alignment */ | |
126 | ||
127 | /* The next portion of the structure must remain 32-byte aligned */ | |
128 | vmm_processor_state_t vmm_proc_state; | |
129 | ||
130 | } vmm_state_page_t; | |
131 | ||
132 | enum { | |
133 | /* Function Indices (passed in r3) */ | |
134 | kVmmGetVersion = 0, | |
135 | kVmmvGetFeatures, | |
136 | kVmmInitContext, | |
137 | kVmmTearDownContext, | |
138 | kVmmTearDownAll, | |
139 | kVmmMapPage, | |
140 | kVmmGetPageMapping, | |
141 | kVmmUnmapPage, | |
142 | kVmmUnmapAllPages, | |
143 | kVmmGetPageDirtyFlag, | |
144 | kVmmGetFloatState, | |
145 | kVmmGetVectorState, | |
146 | kVmmSetTimer, | |
147 | kVmmGetTimer, | |
0b4e3aa0 A |
148 | kVmmExecuteVM, |
149 | kVmmProtectPage, | |
150 | kVmmMapExecute, | |
151 | kVmmProtectExecute, | |
1c79356b A |
152 | }; |
153 | ||
154 | #define kVmmReturnNull 0 | |
155 | #define kVmmBogusContext 1 | |
0b4e3aa0 | 156 | #define kVmmStopped 2 |
1c79356b A |
157 | #define kVmmReturnDataPageFault 3 |
158 | #define kVmmReturnInstrPageFault 4 | |
159 | #define kVmmReturnAlignmentFault 6 | |
160 | #define kVmmReturnProgramException 7 | |
161 | #define kVmmReturnSystemCall 12 | |
162 | #define kVmmReturnTraceException 13 | |
163 | #define kVmmAltivecAssist 22 | |
0b4e3aa0 | 164 | #define kVmmInvalidAddress 4096 |
1c79356b | 165 | |
0b4e3aa0 A |
166 | /* |
167 | * Storage Extended Protection modes | |
168 | * Notes: | |
169 | * To keep compatibility, vmmKey and the PPC key have reversed meanings, | |
170 | * i.e., vmmKey 0 is PPC key 1 and vice versa. | |
171 | * | |
172 | * vmmKey Notes | |
173 | * Mode 0 1 | |
174 | * | |
175 | * kVmmProtNARW not accessible read/write VM_PROT_NONE (not settable via VM calls) | |
176 | * kVmmProtRORW read only read/write | |
177 | * kVmmProtRWRW read/write read/write VM_PROT_WRITE or (VM_PROT_WRITE | VM_PROT_READ) | |
178 | * kVmmProtRORO read only read only VM_PROT_READ | |
179 | ||
180 | */ | |
181 | ||
182 | #define kVmmProtXtnd 0x00000008 | |
183 | #define kVmmProtNARW (kVmmProtXtnd | 0x00000000) | |
184 | #define kVmmProtRORW (kVmmProtXtnd | 0x00000001) | |
185 | #define kVmmProtRWRW (kVmmProtXtnd | 0x00000002) | |
186 | #define kVmmProtRORO (kVmmProtXtnd | 0x00000003) | |
1c79356b A |
187 | |
188 | /************************************************************************************* | |
189 | Internal Emulation Types | |
190 | **************************************************************************************/ | |
191 | ||
192 | #define kVmmMaxContextsPerThread 32 | |
193 | ||
1c79356b A |
194 | typedef struct vmmCntrlEntry { /* Virtual Machine Monitor control table entry */ |
195 | unsigned int vmmFlags; /* Assorted control flags */ | |
196 | #define vmmInUse 0x80000000 | |
197 | #define vmmInUseb 0 | |
198 | #define vmmFloatCngd 0x40000000 | |
199 | #define vmmFloatCngdb 1 | |
200 | #define vmmVectCngd 0x20000000 | |
201 | #define vmmVectCngdb 2 | |
202 | #define vmmTimerPop 0x10000000 | |
203 | #define vmmTimerPopb 3 | |
204 | #define vmmMapDone 0x08000000 | |
205 | #define vmmMapDoneb 4 | |
0b4e3aa0 A |
206 | #define vmmXStop 0x00800000 |
207 | #define vmmXStopb 8 | |
1c79356b A |
208 | #define vmmSpfSave 0x000000FF |
209 | #define vmmSpfSaveb 24 | |
210 | pmap_t vmmPmap; /* pmap for alternate context's view of task memory */ | |
211 | vmm_state_page_t *vmmContextKern; /* Kernel address of context communications area */ | |
212 | vmm_state_page_t *vmmContextUser; /* User address of context communications area */ | |
213 | pcb_t vmmFPU_pcb; /* Saved floating point context */ | |
214 | unsigned int vmmFPU_cpu; /* CPU saved fp context is valid on */ | |
215 | pcb_t vmmVMX_pcb; /* Saved vector context */ | |
216 | unsigned int vmmVMX_cpu; /* CPU saved vector context is valid on */ | |
0b4e3aa0 | 217 | uint64_t vmmTimer; /* Last set timer value. Zero means unset */ |
1c79356b A |
218 | vm_offset_t vmmLastMap; /* Last vaddr mapping into virtual machine */ |
219 | } vmmCntrlEntry; | |
220 | ||
221 | typedef struct vmmCntrlTable { /* Virtual Machine Monitor Control table */ | |
222 | vmmCntrlEntry vmmc[kVmmMaxContextsPerThread]; /* One entry for each possible Virtual Machine Monitor context */ | |
223 | } vmmCntrlTable; | |
224 | ||
225 | /* function decls for kernel level routines... */ | |
0b4e3aa0 | 226 | extern void vmm_execute_vm(thread_act_t act, vmm_thread_index_t index); |
1c79356b A |
227 | extern vmmCntrlEntry *vmm_get_entry(thread_act_t act, vmm_thread_index_t index); |
228 | extern kern_return_t vmm_tear_down_context(thread_act_t act, vmm_thread_index_t index); | |
229 | extern kern_return_t vmm_get_float_state(thread_act_t act, vmm_thread_index_t index); | |
230 | extern kern_return_t vmm_get_vector_state(thread_act_t act, vmm_thread_index_t index); | |
231 | extern kern_return_t vmm_set_timer(thread_act_t act, vmm_thread_index_t index, unsigned int timerhi, unsigned int timerlo); | |
232 | extern kern_return_t vmm_get_timer(thread_act_t act, vmm_thread_index_t index); | |
233 | extern void vmm_tear_down_all(thread_act_t act); | |
234 | extern kern_return_t vmm_map_page(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t cva, | |
235 | vm_offset_t ava, vm_prot_t prot); | |
0b4e3aa0 A |
236 | extern vmm_return_code_t vmm_map_execute(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t cva, |
237 | vm_offset_t ava, vm_prot_t prot); | |
238 | extern kern_return_t vmm_protect_page(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t va, | |
239 | vm_prot_t prot); | |
240 | extern vmm_return_code_t vmm_protect_execute(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t va, | |
241 | vm_prot_t prot); | |
1c79356b A |
242 | extern vm_offset_t vmm_get_page_mapping(thread_act_t act, vmm_thread_index_t index, |
243 | vm_offset_t va); | |
244 | extern kern_return_t vmm_unmap_page(thread_act_t act, vmm_thread_index_t index, vm_offset_t va); | |
245 | extern void vmm_unmap_all_pages(thread_act_t act, vmm_thread_index_t index); | |
246 | extern boolean_t vmm_get_page_dirty_flag(thread_act_t act, vmm_thread_index_t index, | |
247 | vm_offset_t va, unsigned int reset); | |
248 | extern int vmm_get_features(struct savearea *); | |
249 | extern int vmm_get_version(struct savearea *); | |
250 | extern int vmm_init_context(struct savearea *); | |
251 | extern int vmm_dispatch(struct savearea *); | |
252 | extern int vmm_exit(thread_act_t act, struct savearea *); | |
253 | extern void vmm_force_exit(thread_act_t act, struct savearea *); | |
0b4e3aa0 A |
254 | extern int vmm_stop_vm(struct savearea *save); |
255 | extern void vmm_timer_pop(thread_act_t act); | |
256 | extern void vmm_interrupt(ReturnHandler *rh, thread_act_t act); | |
1c79356b A |
257 | |
258 | #endif | |
259 |