2 * Copyright (c) 2000 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@
22 /*-----------------------------------------------------------------------
25 ** C routines that we are adding to the MacOS X kernel.
27 ** Wierd Apple PSL stuff goes here...
29 ** Until then, Copyright 2000, Connectix
31 -----------------------------------------------------------------------*/
33 #include <ppc/exception.h>
35 #ifndef _VEMULATION_H_
36 #define _VEMULATION_H_
38 /*************************************************************************************
39 External Emulation Types
40 **************************************************************************************/
42 typedef union vmm_vector_register_t
{
46 } vmm_vector_register_t
;
48 typedef union vmm_fp_register_t
{
55 typedef struct vmm_processor_state_t
{
60 unsigned long ppcGPRs
[32];
66 unsigned long ppcMQ
; /* Obsolete */
67 unsigned long ppcVRSave
;
69 vmm_vector_register_t ppcVSCR
;
70 vmm_fp_register_t ppcFPSCR
;
72 unsigned long ppcReserved1
[34]; /* Future processor state can go here */
74 /* We must be 16-byte aligned here */
76 vmm_vector_register_t ppcVRs
[32];
77 vmm_vector_register_t ppcVSCRshadow
;
79 /* We must be 8-byte aligned here */
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
;
86 typedef unsigned long vmm_return_code_t
;
88 typedef unsigned long vmm_thread_index_t
;
91 kVmmCurMajorVersion
= 0x0001,
92 kVmmCurMinorVersion
= 0x0004,
93 kVmmMinMajorVersion
= 0x0001,
95 #define kVmmCurrentVersion ((kVmmCurMajorVersion << 16) | kVmmCurMinorVersion)
97 typedef unsigned long vmm_features_t
;
99 kVmmFeature_LittleEndian
= 0x00000001,
100 kVmmFeature_Stop
= 0x00000002,
101 kVmmFeature_ExtendedMapping
= 0x00000004,
102 kVmmFeature_ListMapping
= 0x00000008,
104 #define kVmmCurrentFeatures (kVmmFeature_LittleEndian | kVmmFeature_Stop | kVmmFeature_ExtendedMapping | kVmmFeature_ListMapping)
106 typedef unsigned long vmm_version_t
;
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
124 #define vmmKey 0x04000000
126 vmm_return_code_t return_code
;
127 unsigned long return_params
[4];
128 unsigned long gas
[7]; /* For alignment */
130 /* The next portion of the structure must remain 32-byte aligned */
131 vmm_processor_state_t vmm_proc_state
;
135 typedef struct vmm_comm_page_t
{
137 vmm_state_page_t vmcpState
; /* Reserve area for state */
138 unsigned int vmcpPad
[768]; /* Reserve space for 3/4 page state area */
140 unsigned int vmcpComm
[256]; /* Define last 1024 bytes as a communications area - function specific */
144 /* Function Indices (passed in r3) */
154 kVmmGetPageDirtyFlag
,
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
180 * Storage Extended Protection modes
182 * To keep compatibility, vmmKey and the PPC key have reversed meanings,
183 * i.e., vmmKey 0 is PPC key 1 and vice versa.
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
195 #define kVmmProtXtnd 0x00000008
196 #define kVmmProtNARW (kVmmProtXtnd | 0x00000000)
197 #define kVmmProtRORW (kVmmProtXtnd | 0x00000001)
198 #define kVmmProtRWRW (kVmmProtXtnd | 0x00000002)
199 #define kVmmProtRORO (kVmmProtXtnd | 0x00000003)
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 */
213 /*************************************************************************************
214 Internal Emulation Types
215 **************************************************************************************/
217 #define kVmmMaxContextsPerThread 32
218 #define kVmmMaxUnmapPages 64
219 #define kVmmMaxMapPages 64
221 typedef struct vmmCntrlEntry
{ /* Virtual Machine Monitor control table entry */
222 unsigned int vmmFlags
; /* Assorted control flags */
223 #define vmmInUse 0x80000000
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
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 */
245 typedef struct vmmCntrlTable
{ /* Virtual Machine Monitor Control table */
246 vmmCntrlEntry vmmc
[kVmmMaxContextsPerThread
]; /* One entry for each possible Virtual Machine Monitor context */
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
,
264 extern vmm_return_code_t
vmm_protect_execute(thread_act_t act
, vmm_thread_index_t hindex
, vm_offset_t va
,
266 extern vm_offset_t
vmm_get_page_mapping(thread_act_t act
, vmm_thread_index_t index
,
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
);