]> git.saurik.com Git - apple/xnu.git/blame_incremental - osfmk/ppc/vmachmon.h
xnu-201.tar.gz
[apple/xnu.git] / osfmk / ppc / vmachmon.h
... / ...
CommitLineData
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
42typedef 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
48typedef 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
55typedef 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
84typedef unsigned long vmm_return_code_t;
85
86typedef unsigned long vmm_thread_index_t;
87
88enum {
89 kVmmCurMajorVersion = 0x0001,
90 kVmmCurMinorVersion = 0x0002,
91 kVmmMinMajorVersion = 0x0001,
92};
93#define kVmmCurrentVersion ((kVmmCurMajorVersion << 16) | kVmmCurMinorVersion)
94
95typedef unsigned long vmm_features_t;
96enum {
97 kVmmFeature_LittleEndian = 0x00000001,
98 kVmmFeature_Stop = 0x00000002,
99 kVmmFeature_ExtendedMapping = 0x00000004,
100};
101#define kVmmCurrentFeatures (kVmmFeature_LittleEndian | kVmmFeature_Stop | kVmmFeature_ExtendedMapping)
102
103typedef unsigned long vmm_version_t;
104
105typedef 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
119#define vmmXStart 0x08000000
120#define vmmXStartb 4
121#define vmmKey 0x04000000
122#define vmmKeyb 5
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
132enum {
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,
148 kVmmExecuteVM,
149 kVmmProtectPage,
150 kVmmMapExecute,
151 kVmmProtectExecute,
152};
153
154#define kVmmReturnNull 0
155#define kVmmBogusContext 1
156#define kVmmStopped 2
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
164#define kVmmInvalidAddress 4096
165
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)
187
188/*************************************************************************************
189 Internal Emulation Types
190**************************************************************************************/
191
192#define kVmmMaxContextsPerThread 32
193
194typedef 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
206#define vmmXStop 0x00800000
207#define vmmXStopb 8
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 */
217 uint64_t vmmTimer; /* Last set timer value. Zero means unset */
218 vm_offset_t vmmLastMap; /* Last vaddr mapping into virtual machine */
219} vmmCntrlEntry;
220
221typedef 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... */
226extern void vmm_execute_vm(thread_act_t act, vmm_thread_index_t index);
227extern vmmCntrlEntry *vmm_get_entry(thread_act_t act, vmm_thread_index_t index);
228extern kern_return_t vmm_tear_down_context(thread_act_t act, vmm_thread_index_t index);
229extern kern_return_t vmm_get_float_state(thread_act_t act, vmm_thread_index_t index);
230extern kern_return_t vmm_get_vector_state(thread_act_t act, vmm_thread_index_t index);
231extern kern_return_t vmm_set_timer(thread_act_t act, vmm_thread_index_t index, unsigned int timerhi, unsigned int timerlo);
232extern kern_return_t vmm_get_timer(thread_act_t act, vmm_thread_index_t index);
233extern void vmm_tear_down_all(thread_act_t act);
234extern 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);
236extern 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);
238extern kern_return_t vmm_protect_page(thread_act_t act, vmm_thread_index_t hindex, vm_offset_t va,
239 vm_prot_t prot);
240extern 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);
242extern vm_offset_t vmm_get_page_mapping(thread_act_t act, vmm_thread_index_t index,
243 vm_offset_t va);
244extern kern_return_t vmm_unmap_page(thread_act_t act, vmm_thread_index_t index, vm_offset_t va);
245extern void vmm_unmap_all_pages(thread_act_t act, vmm_thread_index_t index);
246extern boolean_t vmm_get_page_dirty_flag(thread_act_t act, vmm_thread_index_t index,
247 vm_offset_t va, unsigned int reset);
248extern int vmm_get_features(struct savearea *);
249extern int vmm_get_version(struct savearea *);
250extern int vmm_init_context(struct savearea *);
251extern int vmm_dispatch(struct savearea *);
252extern int vmm_exit(thread_act_t act, struct savearea *);
253extern void vmm_force_exit(thread_act_t act, struct savearea *);
254extern int vmm_stop_vm(struct savearea *save);
255extern void vmm_timer_pop(thread_act_t act);
256extern void vmm_interrupt(ReturnHandler *rh, thread_act_t act);
257
258#endif
259