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
{
57 * NOTE: The general context needs to correspond to the order of the savearea for quick swaps
62 unsigned long ppcGPRs
[32];
68 unsigned long ppcMQ
; /* Obsolete */
69 unsigned long ppcVRSave
;
70 unsigned long ppcReserved1
[40]; /* Future processor state can go here */
72 /* We must be 16-byte aligned here */
74 vmm_vector_register_t ppcVRs
[32];
75 vmm_vector_register_t ppcVSCR
;
77 /* We must be 8-byte aligned here */
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
;
84 typedef unsigned long vmm_return_code_t
;
86 typedef unsigned long vmm_thread_index_t
;
88 kVmmCurrentVersion
= 0x00010000
91 typedef unsigned long vmm_features_t
;
93 kVmmFeature_LittleEndian
= 0x00000001
96 typedef unsigned long vmm_version_t
;
98 typedef struct vmm_state_page_t
{
99 /* This structure must remain below 4Kb (one page) in size */
100 vmm_version_t interface_version
;
101 vmm_thread_index_t thread_index
;
102 unsigned int vmmStat
; /* Note: this field is identical to vmmFlags in vmmCntrlEntry */
103 unsigned int vmmCntrl
;
104 #define vmmFloatLoad 0x80000000
105 #define vmmFloatLoadb 0
106 #define vmmVectLoad 0x40000000
107 #define vmmVectLoadb 1
108 #define vmmVectVRall 0x20000000
109 #define vmmVectVRallb 2
110 #define vmmVectVAss 0x10000000
111 #define vmmVectVAssb 3
112 vmm_return_code_t return_code
;
113 unsigned long return_params
[4];
114 unsigned long gas
[7]; /* For alignment */
116 /* The next portion of the structure must remain 32-byte aligned */
117 vmm_processor_state_t vmm_proc_state
;
122 /* Function Indices (passed in r3) */
132 kVmmGetPageDirtyFlag
,
140 #define kVmmReturnNull 0
141 #define kVmmBogusContext 1
142 #define kVmmReturnDataPageFault 3
143 #define kVmmReturnInstrPageFault 4
144 #define kVmmReturnAlignmentFault 6
145 #define kVmmReturnProgramException 7
146 #define kVmmReturnSystemCall 12
147 #define kVmmReturnTraceException 13
148 #define kVmmAltivecAssist 22
151 /*************************************************************************************
152 Internal Emulation Types
153 **************************************************************************************/
155 #define kVmmMaxContextsPerThread 32
158 kVmmCurrentFeatures
= kVmmFeature_LittleEndian
161 typedef struct vmmCntrlEntry
{ /* Virtual Machine Monitor control table entry */
162 unsigned int vmmFlags
; /* Assorted control flags */
163 #define vmmInUse 0x80000000
165 #define vmmFloatCngd 0x40000000
166 #define vmmFloatCngdb 1
167 #define vmmVectCngd 0x20000000
168 #define vmmVectCngdb 2
169 #define vmmTimerPop 0x10000000
170 #define vmmTimerPopb 3
171 #define vmmMapDone 0x08000000
172 #define vmmMapDoneb 4
173 #define vmmSpfSave 0x000000FF
174 #define vmmSpfSaveb 24
175 pmap_t vmmPmap
; /* pmap for alternate context's view of task memory */
176 vmm_state_page_t
*vmmContextKern
; /* Kernel address of context communications area */
177 vmm_state_page_t
*vmmContextUser
; /* User address of context communications area */
178 pcb_t vmmFPU_pcb
; /* Saved floating point context */
179 unsigned int vmmFPU_cpu
; /* CPU saved fp context is valid on */
180 pcb_t vmmVMX_pcb
; /* Saved vector context */
181 unsigned int vmmVMX_cpu
; /* CPU saved vector context is valid on */
182 AbsoluteTime vmmTimer
; /* Last set timer value. Zero means unset */
183 vm_offset_t vmmLastMap
; /* Last vaddr mapping into virtual machine */
186 typedef struct vmmCntrlTable
{ /* Virtual Machine Monitor Control table */
187 vmmCntrlEntry vmmc
[kVmmMaxContextsPerThread
]; /* One entry for each possible Virtual Machine Monitor context */
190 /* function decls for kernel level routines... */
191 extern vmmCntrlEntry
*vmm_get_entry(thread_act_t act
, vmm_thread_index_t index
);
192 extern kern_return_t
vmm_tear_down_context(thread_act_t act
, vmm_thread_index_t index
);
193 extern kern_return_t
vmm_get_float_state(thread_act_t act
, vmm_thread_index_t index
);
194 extern kern_return_t
vmm_get_vector_state(thread_act_t act
, vmm_thread_index_t index
);
195 extern kern_return_t
vmm_set_timer(thread_act_t act
, vmm_thread_index_t index
, unsigned int timerhi
, unsigned int timerlo
);
196 extern kern_return_t
vmm_get_timer(thread_act_t act
, vmm_thread_index_t index
);
197 extern void vmm_tear_down_all(thread_act_t act
);
198 extern kern_return_t
vmm_map_page(thread_act_t act
, vmm_thread_index_t hindex
, vm_offset_t cva
,
199 vm_offset_t ava
, vm_prot_t prot
);
200 extern vm_offset_t
vmm_get_page_mapping(thread_act_t act
, vmm_thread_index_t index
,
202 extern kern_return_t
vmm_unmap_page(thread_act_t act
, vmm_thread_index_t index
, vm_offset_t va
);
203 extern void vmm_unmap_all_pages(thread_act_t act
, vmm_thread_index_t index
);
204 extern boolean_t
vmm_get_page_dirty_flag(thread_act_t act
, vmm_thread_index_t index
,
205 vm_offset_t va
, unsigned int reset
);
206 extern int vmm_get_features(struct savearea
*);
207 extern int vmm_get_version(struct savearea
*);
208 extern int vmm_init_context(struct savearea
*);
209 extern int vmm_dispatch(struct savearea
*);
210 extern int vmm_exit(thread_act_t act
, struct savearea
*);
211 extern void vmm_force_exit(thread_act_t act
, struct savearea
*);
212 void vmm_timer_pop(thread_act_t act
);