├── .gitignore
├── PPCVM.sln
├── PPCVM
├── PPCVM.vcxproj
├── PPCVM.vcxproj.filters
└── src
│ ├── instructions.h
│ ├── main.cpp
│ ├── registers.h
│ ├── stdafx.h
│ ├── virtual_machine.cpp
│ └── virtual_machine.h
├── README.md
└── examples
├── example_1.asm
├── example_2.asm
└── example_3.asm
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | [Ll]og/
27 | !/Build/Release/
28 |
29 | *.dll
30 | *.out
31 | *.map
32 | *.exe
33 | *.old
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUNIT
48 | *.VisualState.xml
49 | TestResult.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # JustCode is a .NET coding add-in
131 | .JustCode
132 |
133 | # TeamCity is a build add-in
134 | _TeamCity*
135 |
136 | # DotCover is a Code Coverage Tool
137 | *.dotCover
138 |
139 | # AxoCover is a Code Coverage Tool
140 | .axoCover/*
141 | !.axoCover/settings.json
142 |
143 | # Visual Studio code coverage results
144 | *.coverage
145 | *.coveragexml
146 |
147 | # NCrunch
148 | _NCrunch_*
149 | .*crunch*.local.xml
150 | nCrunchTemp_*
151 |
152 | # MightyMoose
153 | *.mm.*
154 | AutoTest.Net/
155 |
156 | # Web workbench (sass)
157 | .sass-cache/
158 |
159 | # Installshield output folder
160 | [Ee]xpress/
161 |
162 | # DocProject is a documentation generator add-in
163 | DocProject/buildhelp/
164 | DocProject/Help/*.HxT
165 | DocProject/Help/*.HxC
166 | DocProject/Help/*.hhc
167 | DocProject/Help/*.hhk
168 | DocProject/Help/*.hhp
169 | DocProject/Help/Html2
170 | DocProject/Help/html
171 |
172 | # Click-Once directory
173 | publish/
174 |
175 | # Publish Web Output
176 | *.[Pp]ublish.xml
177 | *.azurePubxml
178 | # Note: Comment the next line if you want to checkin your web deploy settings,
179 | # but database connection strings (with potential passwords) will be unencrypted
180 | *.pubxml
181 | *.publishproj
182 |
183 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
184 | # checkin your Azure Web App publish settings, but sensitive information contained
185 | # in these scripts will be unencrypted
186 | PublishScripts/
187 |
188 | # NuGet Packages
189 | *.nupkg
190 | # The packages folder can be ignored because of Package Restore
191 | **/[Pp]ackages/*
192 | # except build/, which is used as an MSBuild target.
193 | !**/[Pp]ackages/build/
194 | # Uncomment if necessary however generally it will be regenerated when needed
195 | #!**/[Pp]ackages/repositories.config
196 | # NuGet v3's project.json files produces more ignorable files
197 | *.nuget.props
198 | *.nuget.targets
199 |
200 | # Microsoft Azure Build Output
201 | csx/
202 | *.build.csdef
203 |
204 | # Microsoft Azure Emulator
205 | ecf/
206 | rcf/
207 |
208 | # Windows Store app package directories and files
209 | AppPackages/
210 | BundleArtifacts/
211 | Package.StoreAssociation.xml
212 | _pkginfo.txt
213 | *.appx
214 |
215 | # Visual Studio cache files
216 | # files ending in .cache can be ignored
217 | *.[Cc]ache
218 | # but keep track of directories ending in .cache
219 | !*.[Cc]ache/
220 |
221 | # Others
222 | ClientBin/
223 | ~$*
224 | *~
225 | *.dbmdl
226 | *.dbproj.schemaview
227 | *.jfm
228 | *.pfx
229 | *.publishsettings
230 | orleans.codegen.cs
231 |
232 | # Including strong name files can present a security risk
233 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
234 | #*.snk
235 |
236 | # Since there are multiple workflows, uncomment next line to ignore bower_components
237 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
238 | #bower_components/
239 |
240 | # RIA/Silverlight projects
241 | Generated_Code/
242 |
243 | # Backup & report files from converting an old project file
244 | # to a newer Visual Studio version. Backup files are not needed,
245 | # because we have git ;-)
246 | _UpgradeReport_Files/
247 | Backup*/
248 | UpgradeLog*.XML
249 | UpgradeLog*.htm
250 | ServiceFabricBackup/
251 | *.rptproj.bak
252 |
253 | # SQL Server files
254 | *.mdf
255 | *.ldf
256 | *.ndf
257 |
258 | # Business Intelligence projects
259 | *.rdl.data
260 | *.bim.layout
261 | *.bim_*.settings
262 | *.rptproj.rsuser
263 |
264 | # Microsoft Fakes
265 | FakesAssemblies/
266 |
267 | # GhostDoc plugin setting file
268 | *.GhostDoc.xml
269 |
270 | # Node.js Tools for Visual Studio
271 | .ntvs_analysis.dat
272 | node_modules/
273 |
274 | # Visual Studio 6 build log
275 | *.plg
276 |
277 | # Visual Studio 6 workspace options file
278 | *.opt
279 |
280 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
281 | *.vbw
282 |
283 | # Visual Studio LightSwitch build output
284 | **/*.HTMLClient/GeneratedArtifacts
285 | **/*.DesktopClient/GeneratedArtifacts
286 | **/*.DesktopClient/ModelManifest.xml
287 | **/*.Server/GeneratedArtifacts
288 | **/*.Server/ModelManifest.xml
289 | _Pvt_Extensions
290 |
291 | # Paket dependency manager
292 | .paket/paket.exe
293 | paket-files/
294 |
295 | # FAKE - F# Make
296 | .fake/
297 |
298 | # JetBrains Rider
299 | .idea/
300 | *.sln.iml
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
--------------------------------------------------------------------------------
/PPCVM.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30114.105
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PPCVM", "PPCVM\PPCVM.vcxproj", "{24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}.Debug|x64.ActiveCfg = Debug|x64
17 | {24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}.Debug|x64.Build.0 = Debug|x64
18 | {24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}.Debug|x86.ActiveCfg = Debug|Win32
19 | {24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}.Debug|x86.Build.0 = Debug|Win32
20 | {24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}.Release|x64.ActiveCfg = Release|x64
21 | {24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}.Release|x64.Build.0 = Release|x64
22 | {24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}.Release|x86.ActiveCfg = Release|Win32
23 | {24C33DF0-4A4C-4C58-BA82-722AD2ACCF48}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {A9C6FD17-8833-4776-A0F5-8CB03618F281}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/PPCVM/PPCVM.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {24c33df0-4a4c-4c58-ba82-722ad2accf48}
25 | PPCVM
26 | 10.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v142
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v142
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v142
46 | Unicode
47 |
48 |
49 | Application
50 | false
51 | v142
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | true
75 |
76 |
77 | false
78 |
79 |
80 | true
81 |
82 |
83 | false
84 |
85 |
86 |
87 | Level3
88 | true
89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
90 | true
91 |
92 |
93 | Console
94 | true
95 |
96 |
97 |
98 |
99 | Level3
100 | true
101 | true
102 | true
103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
104 | true
105 |
106 |
107 | Console
108 | true
109 | true
110 | true
111 |
112 |
113 |
114 |
115 | Level3
116 | true
117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
118 | true
119 |
120 |
121 | Console
122 | true
123 |
124 |
125 |
126 |
127 | Level3
128 | true
129 | true
130 | true
131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
132 | true
133 | stdcpplatest
134 | $(ProjectDir)src\
135 | true
136 |
137 |
138 | Console
139 | true
140 | true
141 | true
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/PPCVM/PPCVM.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 |
32 |
33 | Source Files
34 |
35 |
36 | Source Files
37 |
38 |
39 |
--------------------------------------------------------------------------------
/PPCVM/src/instructions.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | union instruction {
5 | uint32_t value;
6 |
7 | struct {
8 | uint32_t data : 26;
9 | uint32_t opcode : 6;
10 | } bits;
11 | };
12 |
13 | union addcx {
14 | uint32_t value;
15 |
16 | struct {
17 | uint32_t rc : 1;
18 | uint32_t _ : 9;
19 | uint32_t oe : 1;
20 | uint32_t rb : 5;
21 | uint32_t ra : 5;
22 | uint32_t rt : 5;
23 | uint32_t opcode : 6;
24 | } bits;
25 |
26 | };
27 | union addex {
28 | uint32_t value;
29 |
30 | struct {
31 | uint32_t rc : 1;
32 | uint32_t _ : 9;
33 | uint32_t oe : 1;
34 | uint32_t rb : 5;
35 | uint32_t ra : 5;
36 | uint32_t rt : 5;
37 | uint32_t opcode : 6;
38 | } bits;
39 |
40 | };
41 | union addi {
42 | uint32_t value;
43 |
44 | struct {
45 | uint32_t ds : 16;
46 | uint32_t ra : 5;
47 | uint32_t rt : 5;
48 | uint32_t opcode : 6;
49 | } bits;
50 |
51 | };
52 | union addic {
53 | uint32_t value;
54 |
55 | struct {
56 | uint32_t ds : 16;
57 | uint32_t ra : 5;
58 | uint32_t rt : 5;
59 | uint32_t opcode : 6;
60 | } bits;
61 |
62 | };
63 | union addicx {
64 | uint32_t value;
65 |
66 | struct {
67 | uint32_t ds : 16;
68 | uint32_t ra : 5;
69 | uint32_t rt : 5;
70 | uint32_t opcode : 6;
71 | } bits;
72 |
73 | };
74 | union addis {
75 | uint32_t value;
76 |
77 | struct {
78 | uint32_t ds : 16;
79 | uint32_t ra : 5;
80 | uint32_t rt : 5;
81 | uint32_t opcode : 6;
82 | } bits;
83 |
84 | };
85 | union addmex {
86 | uint32_t value;
87 |
88 | struct {
89 | uint32_t rc : 1;
90 | uint32_t _ : 9;
91 | uint32_t oe : 1;
92 | uint32_t rb : 5;
93 | uint32_t ra : 5;
94 | uint32_t rt : 5;
95 | uint32_t opcode : 6;
96 | } bits;
97 |
98 | };
99 | union addx {
100 | uint32_t value;
101 |
102 | struct {
103 | uint32_t rc : 1;
104 | uint32_t _ : 9;
105 | uint32_t oe : 1;
106 | uint32_t rb : 5;
107 | uint32_t ra : 5;
108 | uint32_t rt : 5;
109 | uint32_t opcode : 6;
110 | } bits;
111 |
112 | };
113 | union addzex {
114 | uint32_t value;
115 |
116 | struct {
117 | uint32_t rc : 1;
118 | uint32_t _ : 9;
119 | uint32_t oe : 1;
120 | uint32_t rb : 5;
121 | uint32_t ra : 5;
122 | uint32_t rt : 5;
123 | uint32_t opcode : 6;
124 | } bits;
125 |
126 | };
127 | union andcx {
128 | uint32_t value;
129 |
130 | struct {
131 | uint32_t rc : 1;
132 | uint32_t _ : 10;
133 | uint32_t rb : 5;
134 | uint32_t ra : 5;
135 | uint32_t rt : 5;
136 | uint32_t opcode : 6;
137 | } bits;
138 |
139 | };
140 | union andisx {
141 | uint32_t value;
142 |
143 | struct {
144 | uint32_t ds : 16;
145 | uint32_t ra : 5;
146 | uint32_t rt : 5;
147 | uint32_t opcode : 6;
148 | } bits;
149 |
150 | };
151 | union andix {
152 | uint32_t value;
153 |
154 | struct {
155 | uint32_t ds : 16;
156 | uint32_t ra : 5;
157 | uint32_t rt : 5;
158 | uint32_t opcode : 6;
159 | } bits;
160 |
161 | };
162 | union andx {
163 | uint32_t value;
164 |
165 | struct {
166 | uint32_t rc : 1;
167 | uint32_t _ : 10;
168 | uint32_t rb : 5;
169 | uint32_t ra : 5;
170 | uint32_t rt : 5;
171 | uint32_t opcode : 6;
172 | } bits;
173 |
174 | };
175 | union bcctrx {
176 | uint32_t value;
177 |
178 | struct {
179 | uint32_t lk : 1;
180 | uint32_t _ : 10;
181 | uint32_t bb : 5;
182 | uint32_t bi : 5;
183 | uint32_t bo : 5;
184 | uint32_t opcode : 6;
185 | } bits;
186 |
187 | };
188 | union bclrx {
189 | uint32_t value;
190 |
191 | struct {
192 | uint32_t lk : 1;
193 | uint32_t _ : 10;
194 | uint32_t bb : 5;
195 | uint32_t bi : 5;
196 | uint32_t bo : 5;
197 | uint32_t opcode : 6;
198 | } bits;
199 |
200 | };
201 | union bcx {
202 | uint32_t value;
203 |
204 | struct {
205 | uint32_t lk : 1;
206 | uint32_t aa : 1;
207 | uint32_t bd : 14;
208 | uint32_t bi : 5;
209 | uint32_t bo : 5;
210 | uint32_t opcode : 6;
211 | } bits;
212 |
213 | };
214 | union bx {
215 | uint32_t value;
216 |
217 | struct {
218 | uint32_t lk : 1;
219 | uint32_t aa : 1;
220 | uint32_t li : 24;
221 | uint32_t opcode : 6;
222 | } bits;
223 |
224 | };
225 | union cmp {
226 | uint32_t value;
227 |
228 | struct {
229 | uint32_t : 1;
230 | uint32_t _ : 10;
231 | uint32_t rb : 5;
232 | uint32_t ra : 5;
233 | uint32_t l : 1;
234 | uint32_t : 1;
235 | uint32_t crfd : 3;
236 | uint32_t opcode : 6;
237 | } bits;
238 |
239 | };
240 | union cmpi {
241 | uint32_t value;
242 |
243 | struct {
244 | uint32_t ds : 16;
245 | uint32_t ra : 5;
246 | uint32_t l : 1;
247 | uint32_t : 1;
248 | uint32_t crfd : 3;
249 | uint32_t opcode : 6;
250 | } bits;
251 |
252 | };
253 | union cmpl {
254 | uint32_t value;
255 |
256 | struct {
257 | uint32_t : 1;
258 | uint32_t _ : 10;
259 | uint32_t rb : 5;
260 | uint32_t ra : 5;
261 | uint32_t l : 1;
262 | uint32_t : 1;
263 | uint32_t crfd : 3;
264 | uint32_t opcode : 6;
265 | } bits;
266 |
267 | };
268 | union cmpli {
269 | uint32_t value;
270 |
271 | struct {
272 | uint32_t ds : 16;
273 | uint32_t ra : 5;
274 | uint32_t l : 1;
275 | uint32_t : 1;
276 | uint32_t crfd : 3;
277 | uint32_t opcode : 6;
278 | } bits;
279 |
280 | };
281 | union cntlzdx {
282 | uint32_t value;
283 |
284 | struct {
285 | uint32_t rc : 1;
286 | uint32_t _ : 10;
287 | uint32_t rb : 5;
288 | uint32_t ra : 5;
289 | uint32_t rt : 5;
290 | uint32_t opcode : 6;
291 | } bits;
292 |
293 | };
294 | union cntlzwx {
295 | uint32_t value;
296 |
297 | struct {
298 | uint32_t rc : 1;
299 | uint32_t _ : 10;
300 | uint32_t rb : 5;
301 | uint32_t ra : 5;
302 | uint32_t rt : 5;
303 | uint32_t opcode : 6;
304 | } bits;
305 |
306 | };
307 | union crand {
308 | uint32_t value;
309 |
310 | struct {
311 | uint32_t lk : 1;
312 | uint32_t _ : 10;
313 | uint32_t bb : 5;
314 | uint32_t bi : 5;
315 | uint32_t bo : 5;
316 | uint32_t opcode : 6;
317 | } bits;
318 |
319 | };
320 | union crandc {
321 | uint32_t value;
322 |
323 | struct {
324 | uint32_t lk : 1;
325 | uint32_t _ : 10;
326 | uint32_t bb : 5;
327 | uint32_t bi : 5;
328 | uint32_t bo : 5;
329 | uint32_t opcode : 6;
330 | } bits;
331 |
332 | };
333 | union creqv {
334 | uint32_t value;
335 |
336 | struct {
337 | uint32_t lk : 1;
338 | uint32_t _ : 10;
339 | uint32_t bb : 5;
340 | uint32_t bi : 5;
341 | uint32_t bo : 5;
342 | uint32_t opcode : 6;
343 | } bits;
344 |
345 | };
346 | union crnand {
347 | uint32_t value;
348 |
349 | struct {
350 | uint32_t lk : 1;
351 | uint32_t _ : 10;
352 | uint32_t bb : 5;
353 | uint32_t bi : 5;
354 | uint32_t bo : 5;
355 | uint32_t opcode : 6;
356 | } bits;
357 |
358 | };
359 | union crnor {
360 | uint32_t value;
361 |
362 | struct {
363 | uint32_t lk : 1;
364 | uint32_t _ : 10;
365 | uint32_t bb : 5;
366 | uint32_t bi : 5;
367 | uint32_t bo : 5;
368 | uint32_t opcode : 6;
369 | } bits;
370 |
371 | };
372 | union cror {
373 | uint32_t value;
374 |
375 | struct {
376 | uint32_t lk : 1;
377 | uint32_t _ : 10;
378 | uint32_t bb : 5;
379 | uint32_t bi : 5;
380 | uint32_t bo : 5;
381 | uint32_t opcode : 6;
382 | } bits;
383 |
384 | };
385 | union crorc {
386 | uint32_t value;
387 |
388 | struct {
389 | uint32_t lk : 1;
390 | uint32_t _ : 10;
391 | uint32_t bb : 5;
392 | uint32_t bi : 5;
393 | uint32_t bo : 5;
394 | uint32_t opcode : 6;
395 | } bits;
396 |
397 | };
398 | union crxor {
399 | uint32_t value;
400 |
401 | struct {
402 | uint32_t lk : 1;
403 | uint32_t _ : 10;
404 | uint32_t bb : 5;
405 | uint32_t bi : 5;
406 | uint32_t bo : 5;
407 | uint32_t opcode : 6;
408 | } bits;
409 |
410 | };
411 | union dcbf {
412 | uint32_t value;
413 |
414 | struct {
415 | uint32_t rc : 1;
416 | uint32_t _ : 10;
417 | uint32_t rb : 5;
418 | uint32_t ra : 5;
419 | uint32_t rt : 5;
420 | uint32_t opcode : 6;
421 | } bits;
422 |
423 | };
424 | union dcbi {
425 | uint32_t value;
426 |
427 | struct {
428 | uint32_t rc : 1;
429 | uint32_t _ : 10;
430 | uint32_t rb : 5;
431 | uint32_t ra : 5;
432 | uint32_t rt : 5;
433 | uint32_t opcode : 6;
434 | } bits;
435 |
436 | };
437 | union dcbst {
438 | uint32_t value;
439 |
440 | struct {
441 | uint32_t rc : 1;
442 | uint32_t _ : 10;
443 | uint32_t rb : 5;
444 | uint32_t ra : 5;
445 | uint32_t rt : 5;
446 | uint32_t opcode : 6;
447 | } bits;
448 |
449 | };
450 | union dcbt {
451 | uint32_t value;
452 |
453 | struct {
454 | uint32_t rc : 1;
455 | uint32_t _ : 10;
456 | uint32_t rb : 5;
457 | uint32_t ra : 5;
458 | uint32_t rt : 5;
459 | uint32_t opcode : 6;
460 | } bits;
461 |
462 | };
463 | union dcbtst {
464 | uint32_t value;
465 |
466 | struct {
467 | uint32_t rc : 1;
468 | uint32_t _ : 10;
469 | uint32_t rb : 5;
470 | uint32_t ra : 5;
471 | uint32_t rt : 5;
472 | uint32_t opcode : 6;
473 | } bits;
474 |
475 | };
476 | union divdux {
477 | uint32_t value;
478 |
479 | struct {
480 | uint32_t rc : 1;
481 | uint32_t _ : 9;
482 | uint32_t oe : 1;
483 | uint32_t rb : 5;
484 | uint32_t ra : 5;
485 | uint32_t rt : 5;
486 | uint32_t opcode : 6;
487 | } bits;
488 |
489 | };
490 | union divdx {
491 | uint32_t value;
492 |
493 | struct {
494 | uint32_t rc : 1;
495 | uint32_t _ : 9;
496 | uint32_t oe : 1;
497 | uint32_t rb : 5;
498 | uint32_t ra : 5;
499 | uint32_t rt : 5;
500 | uint32_t opcode : 6;
501 | } bits;
502 |
503 | };
504 | union divwux {
505 | uint32_t value;
506 |
507 | struct {
508 | uint32_t rc : 1;
509 | uint32_t _ : 9;
510 | uint32_t oe : 1;
511 | uint32_t rb : 5;
512 | uint32_t ra : 5;
513 | uint32_t rt : 5;
514 | uint32_t opcode : 6;
515 | } bits;
516 |
517 | };
518 | union divwx {
519 | uint32_t value;
520 |
521 | struct {
522 | uint32_t rc : 1;
523 | uint32_t _ : 9;
524 | uint32_t oe : 1;
525 | uint32_t rb : 5;
526 | uint32_t ra : 5;
527 | uint32_t rt : 5;
528 | uint32_t opcode : 6;
529 | } bits;
530 |
531 | };
532 | union eieio {
533 | uint32_t value;
534 |
535 | struct {
536 | uint32_t rc : 1;
537 | uint32_t _ : 10;
538 | uint32_t rb : 5;
539 | uint32_t ra : 5;
540 | uint32_t rt : 5;
541 | uint32_t opcode : 6;
542 | } bits;
543 |
544 | };
545 | union eqvx {
546 | uint32_t value;
547 |
548 | struct {
549 | uint32_t rc : 1;
550 | uint32_t _ : 10;
551 | uint32_t rb : 5;
552 | uint32_t ra : 5;
553 | uint32_t rt : 5;
554 | uint32_t opcode : 6;
555 | } bits;
556 |
557 | };
558 | union extsbx {
559 | uint32_t value;
560 |
561 | struct {
562 | uint32_t rc : 1;
563 | uint32_t _ : 10;
564 | uint32_t rb : 5;
565 | uint32_t ra : 5;
566 | uint32_t rt : 5;
567 | uint32_t opcode : 6;
568 | } bits;
569 |
570 | };
571 | union extshx {
572 | uint32_t value;
573 |
574 | struct {
575 | uint32_t rc : 1;
576 | uint32_t _ : 10;
577 | uint32_t rb : 5;
578 | uint32_t ra : 5;
579 | uint32_t rt : 5;
580 | uint32_t opcode : 6;
581 | } bits;
582 |
583 | };
584 | union extswx {
585 | uint32_t value;
586 |
587 | struct {
588 | uint32_t rc : 1;
589 | uint32_t _ : 10;
590 | uint32_t rb : 5;
591 | uint32_t ra : 5;
592 | uint32_t rt : 5;
593 | uint32_t opcode : 6;
594 | } bits;
595 |
596 | };
597 | union fabsx {
598 | uint32_t value;
599 |
600 | struct {
601 | uint32_t rc : 1;
602 | uint32_t _ : 10;
603 | uint32_t rb : 5;
604 | uint32_t ra : 5;
605 | uint32_t rt : 5;
606 | uint32_t opcode : 6;
607 | } bits;
608 |
609 | };
610 | union fcfidx {
611 | uint32_t value;
612 |
613 | struct {
614 | uint32_t rc : 1;
615 | uint32_t _ : 10;
616 | uint32_t rb : 5;
617 | uint32_t ra : 5;
618 | uint32_t rt : 5;
619 | uint32_t opcode : 6;
620 | } bits;
621 |
622 | };
623 | union fcmpo {
624 | uint32_t value;
625 |
626 | struct {
627 | uint32_t rc : 1;
628 | uint32_t _ : 10;
629 | uint32_t rb : 5;
630 | uint32_t ra : 5;
631 | uint32_t rt : 5;
632 | uint32_t opcode : 6;
633 | } bits;
634 |
635 | };
636 | union fcmpu {
637 | uint32_t value;
638 |
639 | struct {
640 | uint32_t rc : 1;
641 | uint32_t _ : 10;
642 | uint32_t rb : 5;
643 | uint32_t ra : 5;
644 | uint32_t rt : 5;
645 | uint32_t opcode : 6;
646 | } bits;
647 |
648 | };
649 | union fctidx {
650 | uint32_t value;
651 |
652 | struct {
653 | uint32_t rc : 1;
654 | uint32_t _ : 10;
655 | uint32_t rb : 5;
656 | uint32_t ra : 5;
657 | uint32_t rt : 5;
658 | uint32_t opcode : 6;
659 | } bits;
660 |
661 | };
662 | union fctidzx {
663 | uint32_t value;
664 |
665 | struct {
666 | uint32_t rc : 1;
667 | uint32_t _ : 10;
668 | uint32_t rb : 5;
669 | uint32_t ra : 5;
670 | uint32_t rt : 5;
671 | uint32_t opcode : 6;
672 | } bits;
673 |
674 | };
675 | union fctiwx {
676 | uint32_t value;
677 |
678 | struct {
679 | uint32_t rc : 1;
680 | uint32_t _ : 10;
681 | uint32_t rb : 5;
682 | uint32_t ra : 5;
683 | uint32_t rt : 5;
684 | uint32_t opcode : 6;
685 | } bits;
686 |
687 | };
688 | union fctiwzx {
689 | uint32_t value;
690 |
691 | struct {
692 | uint32_t rc : 1;
693 | uint32_t _ : 10;
694 | uint32_t rb : 5;
695 | uint32_t ra : 5;
696 | uint32_t rt : 5;
697 | uint32_t opcode : 6;
698 | } bits;
699 |
700 | };
701 | union fmrx {
702 | uint32_t value;
703 |
704 | struct {
705 | uint32_t rc : 1;
706 | uint32_t _ : 10;
707 | uint32_t rb : 5;
708 | uint32_t ra : 5;
709 | uint32_t rt : 5;
710 | uint32_t opcode : 6;
711 | } bits;
712 |
713 | };
714 | union fnabsx {
715 | uint32_t value;
716 |
717 | struct {
718 | uint32_t rc : 1;
719 | uint32_t _ : 10;
720 | uint32_t rb : 5;
721 | uint32_t ra : 5;
722 | uint32_t rt : 5;
723 | uint32_t opcode : 6;
724 | } bits;
725 |
726 | };
727 | union fnegx {
728 | uint32_t value;
729 |
730 | struct {
731 | uint32_t rc : 1;
732 | uint32_t _ : 10;
733 | uint32_t rb : 5;
734 | uint32_t ra : 5;
735 | uint32_t rt : 5;
736 | uint32_t opcode : 6;
737 | } bits;
738 |
739 | };
740 | union frspx {
741 | uint32_t value;
742 |
743 | struct {
744 | uint32_t rc : 1;
745 | uint32_t _ : 10;
746 | uint32_t rb : 5;
747 | uint32_t ra : 5;
748 | uint32_t rt : 5;
749 | uint32_t opcode : 6;
750 | } bits;
751 |
752 | };
753 | union icbi {
754 | uint32_t value;
755 |
756 | struct {
757 | uint32_t rc : 1;
758 | uint32_t _ : 10;
759 | uint32_t rb : 5;
760 | uint32_t ra : 5;
761 | uint32_t rt : 5;
762 | uint32_t opcode : 6;
763 | } bits;
764 |
765 | };
766 | union isync {
767 | uint32_t value;
768 |
769 | struct {
770 | uint32_t lk : 1;
771 | uint32_t _ : 10;
772 | uint32_t bb : 5;
773 | uint32_t bi : 5;
774 | uint32_t bo : 5;
775 | uint32_t opcode : 6;
776 | } bits;
777 |
778 | };
779 | union lbz {
780 | uint32_t value;
781 |
782 | struct {
783 | uint32_t ds : 16;
784 | uint32_t ra : 5;
785 | uint32_t rt : 5;
786 | uint32_t opcode : 6;
787 | } bits;
788 |
789 | };
790 | union lbzu {
791 | uint32_t value;
792 |
793 | struct {
794 | uint32_t ds : 16;
795 | uint32_t ra : 5;
796 | uint32_t rt : 5;
797 | uint32_t opcode : 6;
798 | } bits;
799 |
800 | };
801 | union lbzux {
802 | uint32_t value;
803 |
804 | struct {
805 | uint32_t rc : 1;
806 | uint32_t _ : 10;
807 | uint32_t rb : 5;
808 | uint32_t ra : 5;
809 | uint32_t rt : 5;
810 | uint32_t opcode : 6;
811 | } bits;
812 |
813 | };
814 | union lbzx {
815 | uint32_t value;
816 |
817 | struct {
818 | uint32_t rc : 1;
819 | uint32_t _ : 10;
820 | uint32_t rb : 5;
821 | uint32_t ra : 5;
822 | uint32_t rt : 5;
823 | uint32_t opcode : 6;
824 | } bits;
825 |
826 | };
827 | union ldarx {
828 | uint32_t value;
829 |
830 | struct {
831 | uint32_t rc : 1;
832 | uint32_t _ : 10;
833 | uint32_t rb : 5;
834 | uint32_t ra : 5;
835 | uint32_t rt : 5;
836 | uint32_t opcode : 6;
837 | } bits;
838 |
839 | };
840 | union ldbrx {
841 | uint32_t value;
842 |
843 | struct {
844 | uint32_t rc : 1;
845 | uint32_t _ : 10;
846 | uint32_t rb : 5;
847 | uint32_t ra : 5;
848 | uint32_t rt : 5;
849 | uint32_t opcode : 6;
850 | } bits;
851 |
852 | };
853 | union ldux {
854 | uint32_t value;
855 |
856 | struct {
857 | uint32_t rc : 1;
858 | uint32_t _ : 10;
859 | uint32_t rb : 5;
860 | uint32_t ra : 5;
861 | uint32_t rt : 5;
862 | uint32_t opcode : 6;
863 | } bits;
864 |
865 | };
866 | union ldx {
867 | uint32_t value;
868 |
869 | struct {
870 | uint32_t rc : 1;
871 | uint32_t _ : 10;
872 | uint32_t rb : 5;
873 | uint32_t ra : 5;
874 | uint32_t rt : 5;
875 | uint32_t opcode : 6;
876 | } bits;
877 |
878 | };
879 | union lfd {
880 | uint32_t value;
881 |
882 | struct {
883 | uint32_t ds : 16;
884 | uint32_t ra : 5;
885 | uint32_t rt : 5;
886 | uint32_t opcode : 6;
887 | } bits;
888 |
889 | };
890 | union lfdu {
891 | uint32_t value;
892 |
893 | struct {
894 | uint32_t ds : 16;
895 | uint32_t ra : 5;
896 | uint32_t rt : 5;
897 | uint32_t opcode : 6;
898 | } bits;
899 |
900 | };
901 | union lfdux {
902 | uint32_t value;
903 |
904 | struct {
905 | uint32_t rc : 1;
906 | uint32_t _ : 10;
907 | uint32_t rb : 5;
908 | uint32_t ra : 5;
909 | uint32_t rt : 5;
910 | uint32_t opcode : 6;
911 | } bits;
912 |
913 | };
914 | union lfdx {
915 | uint32_t value;
916 |
917 | struct {
918 | uint32_t rc : 1;
919 | uint32_t _ : 10;
920 | uint32_t rb : 5;
921 | uint32_t ra : 5;
922 | uint32_t rt : 5;
923 | uint32_t opcode : 6;
924 | } bits;
925 |
926 | };
927 | union lfs {
928 | uint32_t value;
929 |
930 | struct {
931 | uint32_t ds : 16;
932 | uint32_t ra : 5;
933 | uint32_t rt : 5;
934 | uint32_t opcode : 6;
935 | } bits;
936 |
937 | };
938 | union lfsu {
939 | uint32_t value;
940 |
941 | struct {
942 | uint32_t ds : 16;
943 | uint32_t ra : 5;
944 | uint32_t rt : 5;
945 | uint32_t opcode : 6;
946 | } bits;
947 |
948 | };
949 | union lfsux {
950 | uint32_t value;
951 |
952 | struct {
953 | uint32_t rc : 1;
954 | uint32_t _ : 10;
955 | uint32_t rb : 5;
956 | uint32_t ra : 5;
957 | uint32_t rt : 5;
958 | uint32_t opcode : 6;
959 | } bits;
960 |
961 | };
962 | union lfsx {
963 | uint32_t value;
964 |
965 | struct {
966 | uint32_t rc : 1;
967 | uint32_t _ : 10;
968 | uint32_t rb : 5;
969 | uint32_t ra : 5;
970 | uint32_t rt : 5;
971 | uint32_t opcode : 6;
972 | } bits;
973 |
974 | };
975 | union lha {
976 | uint32_t value;
977 |
978 | struct {
979 | uint32_t ds : 16;
980 | uint32_t ra : 5;
981 | uint32_t rt : 5;
982 | uint32_t opcode : 6;
983 | } bits;
984 |
985 | };
986 | union lhau {
987 | uint32_t value;
988 |
989 | struct {
990 | uint32_t ds : 16;
991 | uint32_t ra : 5;
992 | uint32_t rt : 5;
993 | uint32_t opcode : 6;
994 | } bits;
995 |
996 | };
997 | union lhaux {
998 | uint32_t value;
999 |
1000 | struct {
1001 | uint32_t rc : 1;
1002 | uint32_t _ : 10;
1003 | uint32_t rb : 5;
1004 | uint32_t ra : 5;
1005 | uint32_t rt : 5;
1006 | uint32_t opcode : 6;
1007 | } bits;
1008 |
1009 | };
1010 | union lhax {
1011 | uint32_t value;
1012 |
1013 | struct {
1014 | uint32_t rc : 1;
1015 | uint32_t _ : 10;
1016 | uint32_t rb : 5;
1017 | uint32_t ra : 5;
1018 | uint32_t rt : 5;
1019 | uint32_t opcode : 6;
1020 | } bits;
1021 |
1022 | };
1023 | union lhbrx {
1024 | uint32_t value;
1025 |
1026 | struct {
1027 | uint32_t rc : 1;
1028 | uint32_t _ : 10;
1029 | uint32_t rb : 5;
1030 | uint32_t ra : 5;
1031 | uint32_t rt : 5;
1032 | uint32_t opcode : 6;
1033 | } bits;
1034 |
1035 | };
1036 | union lhz {
1037 | uint32_t value;
1038 |
1039 | struct {
1040 | uint32_t ds : 16;
1041 | uint32_t ra : 5;
1042 | uint32_t rt : 5;
1043 | uint32_t opcode : 6;
1044 | } bits;
1045 |
1046 | };
1047 | union lhzu {
1048 | uint32_t value;
1049 |
1050 | struct {
1051 | uint32_t ds : 16;
1052 | uint32_t ra : 5;
1053 | uint32_t rt : 5;
1054 | uint32_t opcode : 6;
1055 | } bits;
1056 |
1057 | };
1058 | union lhzux {
1059 | uint32_t value;
1060 |
1061 | struct {
1062 | uint32_t rc : 1;
1063 | uint32_t _ : 10;
1064 | uint32_t rb : 5;
1065 | uint32_t ra : 5;
1066 | uint32_t rt : 5;
1067 | uint32_t opcode : 6;
1068 | } bits;
1069 |
1070 | };
1071 | union lhzx {
1072 | uint32_t value;
1073 |
1074 | struct {
1075 | uint32_t rc : 1;
1076 | uint32_t _ : 10;
1077 | uint32_t rb : 5;
1078 | uint32_t ra : 5;
1079 | uint32_t rt : 5;
1080 | uint32_t opcode : 6;
1081 | } bits;
1082 |
1083 | };
1084 | union lmw {
1085 | uint32_t value;
1086 |
1087 | struct {
1088 | uint32_t ds : 16;
1089 | uint32_t ra : 5;
1090 | uint32_t rt : 5;
1091 | uint32_t opcode : 6;
1092 | } bits;
1093 |
1094 | };
1095 | union lswi {
1096 | uint32_t value;
1097 |
1098 | struct {
1099 | uint32_t rc : 1;
1100 | uint32_t _ : 10;
1101 | uint32_t rb : 5;
1102 | uint32_t ra : 5;
1103 | uint32_t rt : 5;
1104 | uint32_t opcode : 6;
1105 | } bits;
1106 |
1107 | };
1108 | union lswx {
1109 | uint32_t value;
1110 |
1111 | struct {
1112 | uint32_t rc : 1;
1113 | uint32_t _ : 10;
1114 | uint32_t rb : 5;
1115 | uint32_t ra : 5;
1116 | uint32_t rt : 5;
1117 | uint32_t opcode : 6;
1118 | } bits;
1119 |
1120 | };
1121 | union lwarx {
1122 | uint32_t value;
1123 |
1124 | struct {
1125 | uint32_t rc : 1;
1126 | uint32_t _ : 10;
1127 | uint32_t rb : 5;
1128 | uint32_t ra : 5;
1129 | uint32_t rt : 5;
1130 | uint32_t opcode : 6;
1131 | } bits;
1132 |
1133 | };
1134 | union lwaux {
1135 | uint32_t value;
1136 |
1137 | struct {
1138 | uint32_t rc : 1;
1139 | uint32_t _ : 10;
1140 | uint32_t rb : 5;
1141 | uint32_t ra : 5;
1142 | uint32_t rt : 5;
1143 | uint32_t opcode : 6;
1144 | } bits;
1145 |
1146 | };
1147 | union lwax {
1148 | uint32_t value;
1149 |
1150 | struct {
1151 | uint32_t rc : 1;
1152 | uint32_t _ : 10;
1153 | uint32_t rb : 5;
1154 | uint32_t ra : 5;
1155 | uint32_t rt : 5;
1156 | uint32_t opcode : 6;
1157 | } bits;
1158 |
1159 | };
1160 | union lwbrx {
1161 | uint32_t value;
1162 |
1163 | struct {
1164 | uint32_t rc : 1;
1165 | uint32_t _ : 10;
1166 | uint32_t rb : 5;
1167 | uint32_t ra : 5;
1168 | uint32_t rt : 5;
1169 | uint32_t opcode : 6;
1170 | } bits;
1171 |
1172 | };
1173 | union lwz {
1174 | uint32_t value;
1175 |
1176 | struct {
1177 | uint32_t ds : 16;
1178 | uint32_t ra : 5;
1179 | uint32_t rt : 5;
1180 | uint32_t opcode : 6;
1181 | } bits;
1182 |
1183 | };
1184 | union lwzu {
1185 | uint32_t value;
1186 |
1187 | struct {
1188 | uint32_t ds : 16;
1189 | uint32_t ra : 5;
1190 | uint32_t rt : 5;
1191 | uint32_t opcode : 6;
1192 | } bits;
1193 |
1194 | };
1195 | union lwzux {
1196 | uint32_t value;
1197 |
1198 | struct {
1199 | uint32_t rc : 1;
1200 | uint32_t _ : 10;
1201 | uint32_t rb : 5;
1202 | uint32_t ra : 5;
1203 | uint32_t rt : 5;
1204 | uint32_t opcode : 6;
1205 | } bits;
1206 |
1207 | };
1208 | union lwzx {
1209 | uint32_t value;
1210 |
1211 | struct {
1212 | uint32_t rc : 1;
1213 | uint32_t _ : 10;
1214 | uint32_t rb : 5;
1215 | uint32_t ra : 5;
1216 | uint32_t rt : 5;
1217 | uint32_t opcode : 6;
1218 | } bits;
1219 |
1220 | };
1221 | union mcrf {
1222 | uint32_t value;
1223 |
1224 | struct {
1225 | uint32_t lk : 1;
1226 | uint32_t _ : 10;
1227 | uint32_t bb : 5;
1228 | uint32_t bi : 5;
1229 | uint32_t bo : 5;
1230 | uint32_t opcode : 6;
1231 | } bits;
1232 |
1233 | };
1234 | union mcrfs {
1235 | uint32_t value;
1236 |
1237 | struct {
1238 | uint32_t rc : 1;
1239 | uint32_t _ : 10;
1240 | uint32_t rb : 5;
1241 | uint32_t ra : 5;
1242 | uint32_t rt : 5;
1243 | uint32_t opcode : 6;
1244 | } bits;
1245 |
1246 | };
1247 | union mcrxr {
1248 | uint32_t value;
1249 |
1250 | struct {
1251 | uint32_t rc : 1;
1252 | uint32_t _ : 10;
1253 | uint32_t rb : 5;
1254 | uint32_t ra : 5;
1255 | uint32_t rt : 5;
1256 | uint32_t opcode : 6;
1257 | } bits;
1258 |
1259 | };
1260 | union mfcr {
1261 | uint32_t value;
1262 |
1263 | struct {
1264 | uint32_t rc : 1;
1265 | uint32_t _ : 10;
1266 | uint32_t rb : 5;
1267 | uint32_t ra : 5;
1268 | uint32_t rt : 5;
1269 | uint32_t opcode : 6;
1270 | } bits;
1271 |
1272 | };
1273 | union mffsx {
1274 | uint32_t value;
1275 |
1276 | struct {
1277 | uint32_t rc : 1;
1278 | uint32_t _ : 10;
1279 | uint32_t rb : 5;
1280 | uint32_t ra : 5;
1281 | uint32_t rt : 5;
1282 | uint32_t opcode : 6;
1283 | } bits;
1284 |
1285 | };
1286 | union mfmsr {
1287 | uint32_t value;
1288 |
1289 | struct {
1290 | uint32_t rc : 1;
1291 | uint32_t _ : 10;
1292 | uint32_t rb : 5;
1293 | uint32_t ra : 5;
1294 | uint32_t rt : 5;
1295 | uint32_t opcode : 6;
1296 | } bits;
1297 |
1298 | };
1299 | union mfspr {
1300 | uint32_t value;
1301 |
1302 | struct {
1303 | uint32_t rc : 1;
1304 | uint32_t _ : 10;
1305 | uint32_t spr : 10;
1306 | uint32_t rt : 5;
1307 | uint32_t opcode : 6;
1308 | } bits;
1309 |
1310 | };
1311 | union mftb {
1312 | uint32_t value;
1313 |
1314 | struct {
1315 | uint32_t rc : 1;
1316 | uint32_t _ : 10;
1317 | uint32_t spr : 10;
1318 | uint32_t rt : 5;
1319 | uint32_t opcode : 6;
1320 | } bits;
1321 |
1322 | };
1323 | union mtcrf {
1324 | uint32_t value;
1325 |
1326 | struct {
1327 | uint32_t rc : 1;
1328 | uint32_t _ : 10;
1329 | uint32_t spr : 10;
1330 | uint32_t rt : 5;
1331 | uint32_t opcode : 6;
1332 | } bits;
1333 |
1334 | };
1335 | union mtfsb0x {
1336 | uint32_t value;
1337 |
1338 | struct {
1339 | uint32_t rc : 1;
1340 | uint32_t _ : 10;
1341 | uint32_t rb : 5;
1342 | uint32_t ra : 5;
1343 | uint32_t rt : 5;
1344 | uint32_t opcode : 6;
1345 | } bits;
1346 |
1347 | };
1348 | union mtfsb1x {
1349 | uint32_t value;
1350 |
1351 | struct {
1352 | uint32_t rc : 1;
1353 | uint32_t _ : 10;
1354 | uint32_t rb : 5;
1355 | uint32_t ra : 5;
1356 | uint32_t rt : 5;
1357 | uint32_t opcode : 6;
1358 | } bits;
1359 |
1360 | };
1361 | union mtfsfix {
1362 | uint32_t value;
1363 |
1364 | struct {
1365 | uint32_t rc : 1;
1366 | uint32_t _ : 10;
1367 | uint32_t rb : 5;
1368 | uint32_t ra : 5;
1369 | uint32_t rt : 5;
1370 | uint32_t opcode : 6;
1371 | } bits;
1372 |
1373 | };
1374 | union mtfsfx {
1375 | uint32_t value;
1376 |
1377 | struct {
1378 | uint32_t rc : 1;
1379 | uint32_t _ : 10;
1380 | uint32_t rb : 5;
1381 | uint32_t w : 1;
1382 | uint32_t fm : 8;
1383 | uint32_t l : 1;
1384 | uint32_t opcode : 6;
1385 | } bits;
1386 |
1387 | };
1388 | union mtmsr {
1389 | uint32_t value;
1390 |
1391 | struct {
1392 | uint32_t rc : 1;
1393 | uint32_t _ : 10;
1394 | uint32_t rb : 5;
1395 | uint32_t ra : 5;
1396 | uint32_t rt : 5;
1397 | uint32_t opcode : 6;
1398 | } bits;
1399 |
1400 | };
1401 | union mtmsrd {
1402 | uint32_t value;
1403 |
1404 | struct {
1405 | uint32_t rc : 1;
1406 | uint32_t _ : 10;
1407 | uint32_t rb : 5;
1408 | uint32_t ra : 5;
1409 | uint32_t rt : 5;
1410 | uint32_t opcode : 6;
1411 | } bits;
1412 |
1413 | };
1414 | union mtspr {
1415 | uint32_t value;
1416 |
1417 | struct {
1418 | uint32_t rc : 1;
1419 | uint32_t _ : 10;
1420 | uint32_t spr : 10;
1421 | uint32_t rt : 5;
1422 | uint32_t opcode : 6;
1423 | } bits;
1424 |
1425 | };
1426 | union mulhdux {
1427 | uint32_t value;
1428 |
1429 | struct {
1430 | uint32_t rc : 1;
1431 | uint32_t _ : 9;
1432 | uint32_t oe : 1;
1433 | uint32_t rb : 5;
1434 | uint32_t ra : 5;
1435 | uint32_t rt : 5;
1436 | uint32_t opcode : 6;
1437 | } bits;
1438 |
1439 | };
1440 | union mulhdx {
1441 | uint32_t value;
1442 |
1443 | struct {
1444 | uint32_t rc : 1;
1445 | uint32_t _ : 9;
1446 | uint32_t oe : 1;
1447 | uint32_t rb : 5;
1448 | uint32_t ra : 5;
1449 | uint32_t rt : 5;
1450 | uint32_t opcode : 6;
1451 | } bits;
1452 |
1453 | };
1454 | union mulhwux {
1455 | uint32_t value;
1456 |
1457 | struct {
1458 | uint32_t rc : 1;
1459 | uint32_t _ : 9;
1460 | uint32_t oe : 1;
1461 | uint32_t rb : 5;
1462 | uint32_t ra : 5;
1463 | uint32_t rt : 5;
1464 | uint32_t opcode : 6;
1465 | } bits;
1466 |
1467 | };
1468 | union mulhwx {
1469 | uint32_t value;
1470 |
1471 | struct {
1472 | uint32_t rc : 1;
1473 | uint32_t _ : 9;
1474 | uint32_t oe : 1;
1475 | uint32_t rb : 5;
1476 | uint32_t ra : 5;
1477 | uint32_t rt : 5;
1478 | uint32_t opcode : 6;
1479 | } bits;
1480 |
1481 | };
1482 | union mulldx {
1483 | uint32_t value;
1484 |
1485 | struct {
1486 | uint32_t rc : 1;
1487 | uint32_t _ : 9;
1488 | uint32_t oe : 1;
1489 | uint32_t rb : 5;
1490 | uint32_t ra : 5;
1491 | uint32_t rt : 5;
1492 | uint32_t opcode : 6;
1493 | } bits;
1494 |
1495 | };
1496 | union mulli {
1497 | uint32_t value;
1498 |
1499 | struct {
1500 | uint32_t ds : 16;
1501 | uint32_t ra : 5;
1502 | uint32_t rt : 5;
1503 | uint32_t opcode : 6;
1504 | } bits;
1505 |
1506 | };
1507 | union mullwx {
1508 | uint32_t value;
1509 |
1510 | struct {
1511 | uint32_t rc : 1;
1512 | uint32_t _ : 9;
1513 | uint32_t oe : 1;
1514 | uint32_t rb : 5;
1515 | uint32_t ra : 5;
1516 | uint32_t rt : 5;
1517 | uint32_t opcode : 6;
1518 | } bits;
1519 |
1520 | };
1521 | union nandx {
1522 | uint32_t value;
1523 |
1524 | struct {
1525 | uint32_t rc : 1;
1526 | uint32_t _ : 10;
1527 | uint32_t rb : 5;
1528 | uint32_t ra : 5;
1529 | uint32_t rt : 5;
1530 | uint32_t opcode : 6;
1531 | } bits;
1532 |
1533 | };
1534 | union negx {
1535 | uint32_t value;
1536 |
1537 | struct {
1538 | uint32_t rc : 1;
1539 | uint32_t _ : 9;
1540 | uint32_t oe : 1;
1541 | uint32_t rb : 5;
1542 | uint32_t ra : 5;
1543 | uint32_t rt : 5;
1544 | uint32_t opcode : 6;
1545 | } bits;
1546 |
1547 | };
1548 | union norx {
1549 | uint32_t value;
1550 |
1551 | struct {
1552 | uint32_t rc : 1;
1553 | uint32_t _ : 10;
1554 | uint32_t rb : 5;
1555 | uint32_t ra : 5;
1556 | uint32_t rt : 5;
1557 | uint32_t opcode : 6;
1558 | } bits;
1559 |
1560 | };
1561 | union orcx {
1562 | uint32_t value;
1563 |
1564 | struct {
1565 | uint32_t rc : 1;
1566 | uint32_t _ : 10;
1567 | uint32_t rb : 5;
1568 | uint32_t ra : 5;
1569 | uint32_t rt : 5;
1570 | uint32_t opcode : 6;
1571 | } bits;
1572 |
1573 | };
1574 | union ori {
1575 | uint32_t value;
1576 |
1577 | struct {
1578 | uint32_t ds : 16;
1579 | uint32_t ra : 5;
1580 | uint32_t rt : 5;
1581 | uint32_t opcode : 6;
1582 | } bits;
1583 |
1584 | };
1585 | union oris {
1586 | uint32_t value;
1587 |
1588 | struct {
1589 | uint32_t ds : 16;
1590 | uint32_t ra : 5;
1591 | uint32_t rt : 5;
1592 | uint32_t opcode : 6;
1593 | } bits;
1594 |
1595 | };
1596 | union orx {
1597 | uint32_t value;
1598 |
1599 | struct {
1600 | uint32_t rc : 1;
1601 | uint32_t _ : 10;
1602 | uint32_t rb : 5;
1603 | uint32_t ra : 5;
1604 | uint32_t rt : 5;
1605 | uint32_t opcode : 6;
1606 | } bits;
1607 |
1608 | };
1609 | union rldclx {
1610 | uint32_t value;
1611 |
1612 | struct {
1613 | uint32_t rc : 1;
1614 | uint32_t idx : 4;
1615 | uint32_t mb5 : 1;
1616 | uint32_t mb : 5;
1617 | uint32_t rb : 5;
1618 | uint32_t ra : 5;
1619 | uint32_t rt : 5;
1620 | uint32_t opcode : 6;
1621 | } bits;
1622 |
1623 | };
1624 | union rldcrx {
1625 | uint32_t value;
1626 |
1627 | struct {
1628 | uint32_t rc : 1;
1629 | uint32_t idx : 4;
1630 | uint32_t mb5 : 1;
1631 | uint32_t mb : 5;
1632 | uint32_t rb : 5;
1633 | uint32_t ra : 5;
1634 | uint32_t rt : 5;
1635 | uint32_t opcode : 6;
1636 | } bits;
1637 |
1638 | };
1639 | union rldiclx {
1640 | uint32_t value;
1641 |
1642 | struct {
1643 | uint32_t rc : 1;
1644 | uint32_t sh5 : 1;
1645 | uint32_t idx : 3;
1646 | uint32_t mb5 : 1;
1647 | uint32_t mb : 5;
1648 | uint32_t sh : 5;
1649 | uint32_t ra : 5;
1650 | uint32_t rt : 5;
1651 | uint32_t opcode : 6;
1652 | } bits;
1653 |
1654 | };
1655 | union rldicrx {
1656 | uint32_t value;
1657 |
1658 | struct {
1659 | uint32_t rc : 1;
1660 | uint32_t sh5 : 1;
1661 | uint32_t idx : 3;
1662 | uint32_t mb5 : 1;
1663 | uint32_t mb : 5;
1664 | uint32_t sh : 5;
1665 | uint32_t ra : 5;
1666 | uint32_t rt : 5;
1667 | uint32_t opcode : 6;
1668 | } bits;
1669 |
1670 | };
1671 | union rldicx {
1672 | uint32_t value;
1673 |
1674 | struct {
1675 | uint32_t rc : 1;
1676 | uint32_t sh5 : 1;
1677 | uint32_t idx : 3;
1678 | uint32_t mb5 : 1;
1679 | uint32_t mb : 5;
1680 | uint32_t sh : 5;
1681 | uint32_t ra : 5;
1682 | uint32_t rt : 5;
1683 | uint32_t opcode : 6;
1684 | } bits;
1685 |
1686 | };
1687 | union rldimix {
1688 | uint32_t value;
1689 |
1690 | struct {
1691 | uint32_t rc : 1;
1692 | uint32_t sh5 : 1;
1693 | uint32_t idx : 3;
1694 | uint32_t mb5 : 1;
1695 | uint32_t mb : 5;
1696 | uint32_t sh : 5;
1697 | uint32_t ra : 5;
1698 | uint32_t rt : 5;
1699 | uint32_t opcode : 6;
1700 | } bits;
1701 |
1702 | };
1703 | union rlwimix {
1704 | uint32_t value;
1705 |
1706 | struct {
1707 | uint32_t rc : 1;
1708 | uint32_t me : 5;
1709 | uint32_t mb : 5;
1710 | uint32_t sh : 5;
1711 | uint32_t ra : 5;
1712 | uint32_t rt : 5;
1713 | uint32_t opcode : 6;
1714 | } bits;
1715 |
1716 | };
1717 | union rlwinmx {
1718 | uint32_t value;
1719 |
1720 | struct {
1721 | uint32_t rc : 1;
1722 | uint32_t me : 5;
1723 | uint32_t mb : 5;
1724 | uint32_t sh : 5;
1725 | uint32_t ra : 5;
1726 | uint32_t rt : 5;
1727 | uint32_t opcode : 6;
1728 | } bits;
1729 |
1730 | };
1731 | union rlwnmx {
1732 | uint32_t value;
1733 |
1734 | struct {
1735 | uint32_t rc : 1;
1736 | uint32_t me : 5;
1737 | uint32_t mb : 5;
1738 | uint32_t sh : 5;
1739 | uint32_t ra : 5;
1740 | uint32_t rt : 5;
1741 | uint32_t opcode : 6;
1742 | } bits;
1743 |
1744 | };
1745 | union sc {
1746 | uint32_t value;
1747 |
1748 | struct {
1749 | uint32_t lev : 26;
1750 | uint32_t opcode : 6;
1751 | } bits;
1752 |
1753 | };
1754 | union sldx {
1755 | uint32_t value;
1756 |
1757 | struct {
1758 | uint32_t rc : 1;
1759 | uint32_t _ : 10;
1760 | uint32_t rb : 5;
1761 | uint32_t ra : 5;
1762 | uint32_t rt : 5;
1763 | uint32_t opcode : 6;
1764 | } bits;
1765 |
1766 | };
1767 | union slwx {
1768 | uint32_t value;
1769 |
1770 | struct {
1771 | uint32_t rc : 1;
1772 | uint32_t _ : 10;
1773 | uint32_t rb : 5;
1774 | uint32_t ra : 5;
1775 | uint32_t rt : 5;
1776 | uint32_t opcode : 6;
1777 | } bits;
1778 |
1779 | };
1780 | union sradix {
1781 | uint32_t value;
1782 |
1783 | struct {
1784 | uint32_t rc : 1;
1785 | uint32_t sh5 : 1;
1786 | uint32_t _ : 9;
1787 | uint32_t sh : 5;
1788 | uint32_t ra : 5;
1789 | uint32_t rt : 5;
1790 | uint32_t opcode : 6;
1791 | } bits;
1792 |
1793 | };
1794 | union sradx {
1795 | uint32_t value;
1796 |
1797 | struct {
1798 | uint32_t rc : 1;
1799 | uint32_t _ : 10;
1800 | uint32_t rb : 5;
1801 | uint32_t ra : 5;
1802 | uint32_t rt : 5;
1803 | uint32_t opcode : 6;
1804 | } bits;
1805 |
1806 | };
1807 | union srawix {
1808 | uint32_t value;
1809 |
1810 | struct {
1811 | uint32_t rc : 1;
1812 | uint32_t _ : 10;
1813 | uint32_t rb : 5;
1814 | uint32_t ra : 5;
1815 | uint32_t rt : 5;
1816 | uint32_t opcode : 6;
1817 | } bits;
1818 |
1819 | };
1820 | union srawx {
1821 | uint32_t value;
1822 |
1823 | struct {
1824 | uint32_t rc : 1;
1825 | uint32_t _ : 10;
1826 | uint32_t rb : 5;
1827 | uint32_t ra : 5;
1828 | uint32_t rt : 5;
1829 | uint32_t opcode : 6;
1830 | } bits;
1831 |
1832 | };
1833 | union srdx {
1834 | uint32_t value;
1835 |
1836 | struct {
1837 | uint32_t rc : 1;
1838 | uint32_t _ : 10;
1839 | uint32_t rb : 5;
1840 | uint32_t ra : 5;
1841 | uint32_t rt : 5;
1842 | uint32_t opcode : 6;
1843 | } bits;
1844 |
1845 | };
1846 | union srwx {
1847 | uint32_t value;
1848 |
1849 | struct {
1850 | uint32_t rc : 1;
1851 | uint32_t _ : 10;
1852 | uint32_t rb : 5;
1853 | uint32_t ra : 5;
1854 | uint32_t rt : 5;
1855 | uint32_t opcode : 6;
1856 | } bits;
1857 |
1858 | };
1859 | union stb {
1860 | uint32_t value;
1861 |
1862 | struct {
1863 | uint32_t ds : 16;
1864 | uint32_t ra : 5;
1865 | uint32_t rt : 5;
1866 | uint32_t opcode : 6;
1867 | } bits;
1868 |
1869 | };
1870 | union stbu {
1871 | uint32_t value;
1872 |
1873 | struct {
1874 | uint32_t ds : 16;
1875 | uint32_t ra : 5;
1876 | uint32_t rt : 5;
1877 | uint32_t opcode : 6;
1878 | } bits;
1879 |
1880 | };
1881 | union stbux {
1882 | uint32_t value;
1883 |
1884 | struct {
1885 | uint32_t rc : 1;
1886 | uint32_t _ : 10;
1887 | uint32_t rb : 5;
1888 | uint32_t ra : 5;
1889 | uint32_t rt : 5;
1890 | uint32_t opcode : 6;
1891 | } bits;
1892 |
1893 | };
1894 | union stbx {
1895 | uint32_t value;
1896 |
1897 | struct {
1898 | uint32_t rc : 1;
1899 | uint32_t _ : 10;
1900 | uint32_t rb : 5;
1901 | uint32_t ra : 5;
1902 | uint32_t rt : 5;
1903 | uint32_t opcode : 6;
1904 | } bits;
1905 |
1906 | };
1907 | union stdbrx {
1908 | uint32_t value;
1909 |
1910 | struct {
1911 | uint32_t rc : 1;
1912 | uint32_t _ : 10;
1913 | uint32_t rb : 5;
1914 | uint32_t ra : 5;
1915 | uint32_t rt : 5;
1916 | uint32_t opcode : 6;
1917 | } bits;
1918 |
1919 | };
1920 | union stdcx {
1921 | uint32_t value;
1922 |
1923 | struct {
1924 | uint32_t rc : 1;
1925 | uint32_t _ : 10;
1926 | uint32_t rb : 5;
1927 | uint32_t ra : 5;
1928 | uint32_t rt : 5;
1929 | uint32_t opcode : 6;
1930 | } bits;
1931 |
1932 | };
1933 | union stdux {
1934 | uint32_t value;
1935 |
1936 | struct {
1937 | uint32_t rc : 1;
1938 | uint32_t _ : 10;
1939 | uint32_t rb : 5;
1940 | uint32_t ra : 5;
1941 | uint32_t rt : 5;
1942 | uint32_t opcode : 6;
1943 | } bits;
1944 |
1945 | };
1946 | union stdx {
1947 | uint32_t value;
1948 |
1949 | struct {
1950 | uint32_t rc : 1;
1951 | uint32_t _ : 10;
1952 | uint32_t rb : 5;
1953 | uint32_t ra : 5;
1954 | uint32_t rt : 5;
1955 | uint32_t opcode : 6;
1956 | } bits;
1957 |
1958 | };
1959 | union stfd {
1960 | uint32_t value;
1961 |
1962 | struct {
1963 | uint32_t ds : 16;
1964 | uint32_t ra : 5;
1965 | uint32_t rt : 5;
1966 | uint32_t opcode : 6;
1967 | } bits;
1968 |
1969 | };
1970 | union stfdu {
1971 | uint32_t value;
1972 |
1973 | struct {
1974 | uint32_t ds : 16;
1975 | uint32_t ra : 5;
1976 | uint32_t rt : 5;
1977 | uint32_t opcode : 6;
1978 | } bits;
1979 |
1980 | };
1981 | union stfdux {
1982 | uint32_t value;
1983 |
1984 | struct {
1985 | uint32_t rc : 1;
1986 | uint32_t _ : 10;
1987 | uint32_t rb : 5;
1988 | uint32_t ra : 5;
1989 | uint32_t rt : 5;
1990 | uint32_t opcode : 6;
1991 | } bits;
1992 |
1993 | };
1994 | union stfdx {
1995 | uint32_t value;
1996 |
1997 | struct {
1998 | uint32_t rc : 1;
1999 | uint32_t _ : 10;
2000 | uint32_t rb : 5;
2001 | uint32_t ra : 5;
2002 | uint32_t rt : 5;
2003 | uint32_t opcode : 6;
2004 | } bits;
2005 |
2006 | };
2007 | union stfiwx {
2008 | uint32_t value;
2009 |
2010 | struct {
2011 | uint32_t rc : 1;
2012 | uint32_t _ : 10;
2013 | uint32_t rb : 5;
2014 | uint32_t ra : 5;
2015 | uint32_t rt : 5;
2016 | uint32_t opcode : 6;
2017 | } bits;
2018 |
2019 | };
2020 | union stfs {
2021 | uint32_t value;
2022 |
2023 | struct {
2024 | uint32_t ds : 16;
2025 | uint32_t ra : 5;
2026 | uint32_t rt : 5;
2027 | uint32_t opcode : 6;
2028 | } bits;
2029 |
2030 | };
2031 | union stfsu {
2032 | uint32_t value;
2033 |
2034 | struct {
2035 | uint32_t ds : 16;
2036 | uint32_t ra : 5;
2037 | uint32_t rt : 5;
2038 | uint32_t opcode : 6;
2039 | } bits;
2040 |
2041 | };
2042 | union stfsux {
2043 | uint32_t value;
2044 |
2045 | struct {
2046 | uint32_t rc : 1;
2047 | uint32_t _ : 10;
2048 | uint32_t rb : 5;
2049 | uint32_t ra : 5;
2050 | uint32_t rt : 5;
2051 | uint32_t opcode : 6;
2052 | } bits;
2053 |
2054 | };
2055 | union stfsx {
2056 | uint32_t value;
2057 |
2058 | struct {
2059 | uint32_t rc : 1;
2060 | uint32_t _ : 10;
2061 | uint32_t rb : 5;
2062 | uint32_t ra : 5;
2063 | uint32_t rt : 5;
2064 | uint32_t opcode : 6;
2065 | } bits;
2066 |
2067 | };
2068 | union sth {
2069 | uint32_t value;
2070 |
2071 | struct {
2072 | uint32_t ds : 16;
2073 | uint32_t ra : 5;
2074 | uint32_t rt : 5;
2075 | uint32_t opcode : 6;
2076 | } bits;
2077 |
2078 | };
2079 | union sthbrx {
2080 | uint32_t value;
2081 |
2082 | struct {
2083 | uint32_t rc : 1;
2084 | uint32_t _ : 10;
2085 | uint32_t rb : 5;
2086 | uint32_t ra : 5;
2087 | uint32_t rt : 5;
2088 | uint32_t opcode : 6;
2089 | } bits;
2090 |
2091 | };
2092 | union sthu {
2093 | uint32_t value;
2094 |
2095 | struct {
2096 | uint32_t ds : 16;
2097 | uint32_t ra : 5;
2098 | uint32_t rt : 5;
2099 | uint32_t opcode : 6;
2100 | } bits;
2101 |
2102 | };
2103 | union sthux {
2104 | uint32_t value;
2105 |
2106 | struct {
2107 | uint32_t rc : 1;
2108 | uint32_t _ : 10;
2109 | uint32_t rb : 5;
2110 | uint32_t ra : 5;
2111 | uint32_t rt : 5;
2112 | uint32_t opcode : 6;
2113 | } bits;
2114 |
2115 | };
2116 | union sthx {
2117 | uint32_t value;
2118 |
2119 | struct {
2120 | uint32_t rc : 1;
2121 | uint32_t _ : 10;
2122 | uint32_t rb : 5;
2123 | uint32_t ra : 5;
2124 | uint32_t rt : 5;
2125 | uint32_t opcode : 6;
2126 | } bits;
2127 |
2128 | };
2129 | union stmw {
2130 | uint32_t value;
2131 |
2132 | struct {
2133 | uint32_t ds : 16;
2134 | uint32_t ra : 5;
2135 | uint32_t rt : 5;
2136 | uint32_t opcode : 6;
2137 | } bits;
2138 |
2139 | };
2140 | union stswi {
2141 | uint32_t value;
2142 |
2143 | struct {
2144 | uint32_t rc : 1;
2145 | uint32_t _ : 10;
2146 | uint32_t rb : 5;
2147 | uint32_t ra : 5;
2148 | uint32_t rt : 5;
2149 | uint32_t opcode : 6;
2150 | } bits;
2151 |
2152 | };
2153 | union stswx {
2154 | uint32_t value;
2155 |
2156 | struct {
2157 | uint32_t rc : 1;
2158 | uint32_t _ : 10;
2159 | uint32_t rb : 5;
2160 | uint32_t ra : 5;
2161 | uint32_t rt : 5;
2162 | uint32_t opcode : 6;
2163 | } bits;
2164 |
2165 | };
2166 | union stw {
2167 | uint32_t value;
2168 |
2169 | struct {
2170 | uint32_t ds : 16;
2171 | uint32_t ra : 5;
2172 | uint32_t rt : 5;
2173 | uint32_t opcode : 6;
2174 | } bits;
2175 |
2176 | };
2177 | union stwbrx {
2178 | uint32_t value;
2179 |
2180 | struct {
2181 | uint32_t rc : 1;
2182 | uint32_t _ : 10;
2183 | uint32_t rb : 5;
2184 | uint32_t ra : 5;
2185 | uint32_t rt : 5;
2186 | uint32_t opcode : 6;
2187 | } bits;
2188 |
2189 | };
2190 | union stwcx {
2191 | uint32_t value;
2192 |
2193 | struct {
2194 | uint32_t rc : 1;
2195 | uint32_t _ : 10;
2196 | uint32_t rb : 5;
2197 | uint32_t ra : 5;
2198 | uint32_t rt : 5;
2199 | uint32_t opcode : 6;
2200 | } bits;
2201 |
2202 | };
2203 | union stwu {
2204 | uint32_t value;
2205 |
2206 | struct {
2207 | uint32_t ds : 16;
2208 | uint32_t ra : 5;
2209 | uint32_t rt : 5;
2210 | uint32_t opcode : 6;
2211 | } bits;
2212 |
2213 | };
2214 | union stwux {
2215 | uint32_t value;
2216 |
2217 | struct {
2218 | uint32_t rc : 1;
2219 | uint32_t _ : 10;
2220 | uint32_t rb : 5;
2221 | uint32_t ra : 5;
2222 | uint32_t rt : 5;
2223 | uint32_t opcode : 6;
2224 | } bits;
2225 |
2226 | };
2227 | union stwx {
2228 | uint32_t value;
2229 |
2230 | struct {
2231 | uint32_t rc : 1;
2232 | uint32_t _ : 10;
2233 | uint32_t rb : 5;
2234 | uint32_t ra : 5;
2235 | uint32_t rt : 5;
2236 | uint32_t opcode : 6;
2237 | } bits;
2238 |
2239 | };
2240 | union subfcx {
2241 | uint32_t value;
2242 |
2243 | struct {
2244 | uint32_t rc : 1;
2245 | uint32_t _ : 9;
2246 | uint32_t oe : 1;
2247 | uint32_t rb : 5;
2248 | uint32_t ra : 5;
2249 | uint32_t rt : 5;
2250 | uint32_t opcode : 6;
2251 | } bits;
2252 |
2253 | };
2254 | union subfex {
2255 | uint32_t value;
2256 |
2257 | struct {
2258 | uint32_t rc : 1;
2259 | uint32_t _ : 9;
2260 | uint32_t oe : 1;
2261 | uint32_t rb : 5;
2262 | uint32_t ra : 5;
2263 | uint32_t rt : 5;
2264 | uint32_t opcode : 6;
2265 | } bits;
2266 |
2267 | };
2268 | union subficx {
2269 | uint32_t value;
2270 |
2271 | struct {
2272 | uint32_t ds : 16;
2273 | uint32_t ra : 5;
2274 | uint32_t rt : 5;
2275 | uint32_t opcode : 6;
2276 | } bits;
2277 |
2278 | };
2279 | union subfmex {
2280 | uint32_t value;
2281 |
2282 | struct {
2283 | uint32_t rc : 1;
2284 | uint32_t _ : 9;
2285 | uint32_t oe : 1;
2286 | uint32_t rb : 5;
2287 | uint32_t ra : 5;
2288 | uint32_t rt : 5;
2289 | uint32_t opcode : 6;
2290 | } bits;
2291 |
2292 | };
2293 | union subfx {
2294 | uint32_t value;
2295 |
2296 | struct {
2297 | uint32_t rc : 1;
2298 | uint32_t _ : 9;
2299 | uint32_t oe : 1;
2300 | uint32_t rb : 5;
2301 | uint32_t ra : 5;
2302 | uint32_t rt : 5;
2303 | uint32_t opcode : 6;
2304 | } bits;
2305 |
2306 | };
2307 | union subfzex {
2308 | uint32_t value;
2309 |
2310 | struct {
2311 | uint32_t rc : 1;
2312 | uint32_t _ : 9;
2313 | uint32_t oe : 1;
2314 | uint32_t rb : 5;
2315 | uint32_t ra : 5;
2316 | uint32_t rt : 5;
2317 | uint32_t opcode : 6;
2318 | } bits;
2319 |
2320 | };
2321 | union sync {
2322 | uint32_t value;
2323 |
2324 | struct {
2325 | uint32_t rc : 1;
2326 | uint32_t _ : 10;
2327 | uint32_t rb : 5;
2328 | uint32_t ra : 5;
2329 | uint32_t rt : 5;
2330 | uint32_t opcode : 6;
2331 | } bits;
2332 |
2333 | };
2334 | union td {
2335 | uint32_t value;
2336 |
2337 | struct {
2338 | uint32_t rc : 1;
2339 | uint32_t _ : 10;
2340 | uint32_t rb : 5;
2341 | uint32_t ra : 5;
2342 | uint32_t rt : 5;
2343 | uint32_t opcode : 6;
2344 | } bits;
2345 |
2346 | };
2347 | union tdi {
2348 | uint32_t value;
2349 |
2350 | struct {
2351 | uint32_t ds : 16;
2352 | uint32_t ra : 5;
2353 | uint32_t rt : 5;
2354 | uint32_t opcode : 6;
2355 | } bits;
2356 |
2357 | };
2358 | union tw {
2359 | uint32_t value;
2360 |
2361 | struct {
2362 | uint32_t rc : 1;
2363 | uint32_t _ : 10;
2364 | uint32_t rb : 5;
2365 | uint32_t ra : 5;
2366 | uint32_t rt : 5;
2367 | uint32_t opcode : 6;
2368 | } bits;
2369 |
2370 | };
2371 | union twi {
2372 | uint32_t value;
2373 |
2374 | struct {
2375 | uint32_t ds : 16;
2376 | uint32_t ra : 5;
2377 | uint32_t rt : 5;
2378 | uint32_t opcode : 6;
2379 | } bits;
2380 |
2381 | };
2382 | union xori {
2383 | uint32_t value;
2384 |
2385 | struct {
2386 | uint32_t ds : 16;
2387 | uint32_t ra : 5;
2388 | uint32_t rt : 5;
2389 | uint32_t opcode : 6;
2390 | } bits;
2391 |
2392 | };
2393 | union xoris {
2394 | uint32_t value;
2395 |
2396 | struct {
2397 | uint32_t ds : 16;
2398 | uint32_t ra : 5;
2399 | uint32_t rt : 5;
2400 | uint32_t opcode : 6;
2401 | } bits;
2402 |
2403 | };
2404 | union xorx {
2405 | uint32_t value;
2406 |
2407 | struct {
2408 | uint32_t rc : 1;
2409 | uint32_t _ : 10;
2410 | uint32_t rb : 5;
2411 | uint32_t ra : 5;
2412 | uint32_t rt : 5;
2413 | uint32_t opcode : 6;
2414 | } bits;
2415 |
2416 | };
2417 |
2418 | union li {
2419 | uint32_t value;
2420 |
2421 | struct {
2422 | uint32_t si : 16;
2423 | uint32_t ra : 5;
2424 | uint32_t rt : 5;
2425 | uint32_t opcode : 6;
2426 | } bits;
2427 | };
2428 |
2429 | union _or {
2430 | uint32_t value;
2431 |
2432 | struct {
2433 | uint32_t ui : 16;
2434 | uint32_t ra : 5;
2435 | uint32_t rs : 5;
2436 | uint32_t opcode : 6;
2437 | } bits;
2438 | };
2439 |
2440 | union bundle_31 {
2441 | uint32_t value;
2442 |
2443 | struct {
2444 | uint32_t rc : 1;
2445 | uint32_t _ : 9;
2446 | uint32_t oe : 1;
2447 | uint32_t rb : 5;
2448 | uint32_t ra : 5;
2449 | uint32_t rt : 5;
2450 | uint32_t opcode : 6;
2451 | } bits;
2452 | };
2453 |
2454 | union bundle_19 {
2455 | uint32_t value;
2456 |
2457 | struct {
2458 | uint32_t lk : 1;
2459 | uint32_t _ : 10;
2460 | uint32_t bh : 2;
2461 | uint32_t reserved : 3;
2462 | uint32_t bl : 5;
2463 | uint32_t bo : 5;
2464 | uint32_t opcode : 6;
2465 | } bits;
2466 | };
2467 |
2468 | enum opcode {
2469 | op_cmpli = 10,
2470 | op_cmpi = 11,
2471 | op_li = 14, // same as addi?
2472 | op_lis = 15,
2473 | op_sc = 17,
2474 | op_b = 18,
2475 | op_bc = 16,
2476 | op_bundle_19 = 19, // branches
2477 | op_bundle_31 = 31,
2478 | op_lwz = 32,
2479 | op_stw = 36,
2480 | op_stwu = 37,
2481 | op_stb = 38
2482 | };
2483 |
2484 | enum extended_opcode {
2485 | eop_none = -1,
2486 | eop_cmp = 0,
2487 | eop_cmpl = 32,
2488 | eop_add = 266,
2489 | eop_or = 444,
2490 | eop_bclr = 16,
2491 | eop_mtspr = 467,
2492 | eop_mfspr = 339,
2493 | };
2494 |
2495 | enum iteration_reason {
2496 | it_ok,
2497 | it_continue,
2498 | it_return
2499 | };
--------------------------------------------------------------------------------
/PPCVM/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "virtual_machine.h"
3 |
4 | void setup_syscalls() {
5 | get_core()->add_syscall([](virtual_machine* vm) {
6 | // for now, only supports formatters
7 | printf("[PRINTF] %s", (const char*)(vm->get_current_context()->gpr[3]));
8 | }, 0);
9 |
10 | get_core()->add_syscall([](virtual_machine* vm) {
11 | // set r3 to the address of ram
12 | vm->get_current_context()->gpr[3] = (uint64_t)get_core()->get_ram();
13 | }, 1);
14 |
15 | get_core()->add_syscall([](virtual_machine* vm) {
16 | // print stack
17 | printf("current stack allocated: 0x%llX\n", (uint64_t)&vm->get_stack()[STACK] - vm->get_current_context()->gpr[1]);
18 | printf("last stack frame: 0x%llx\n", *(uint64_t*)vm->get_current_context()->gpr[1]);
19 | }, 2);
20 |
21 | get_core()->add_syscall([](virtual_machine* vm) {
22 | // print registers
23 | vm->print_registers();
24 | printf("\n");
25 | }, 3);
26 |
27 | get_core()->add_syscall([](virtual_machine* vm) {
28 | // memset
29 | memset((void*)vm->get_current_context()->gpr[3], (int)vm->get_current_context()->gpr[4], vm->get_current_context()->gpr[5]);
30 | }, 4);
31 |
32 | get_core()->add_syscall([](virtual_machine* vm) {
33 | // get execution address
34 | vm->get_current_context()->gpr[3] = (uint64_t)vm->get_payload();
35 | }, 5);
36 |
37 | get_core()->add_syscall([](virtual_machine* vm) {
38 | // "create thread"
39 | // r3=func, r4=arg, r5=out thread id
40 |
41 | virtual_machine* payload = get_core()->create_vm((uint32_t*)vm->get_current_context()->gpr[5]);
42 | if (payload) {
43 | payload->execute((uint8_t*)vm->get_current_context()->gpr[3], (void*)vm->get_current_context()->gpr[4]);
44 | }
45 | }, 6);
46 | }
47 |
48 | int main() {
49 | uint8_t example_1[] = {
50 | 0x7D, 0x88, 0x02, 0xA6,
51 | 0x91, 0x81, 0xFF, 0xF8,
52 | 0x94, 0x21, 0xFF, 0xD0,
53 | 0x38, 0x60, 0x00, 0x48,
54 | 0x98, 0x61, 0x00, 0x00,
55 | 0x38, 0x60, 0x00, 0x65,
56 | 0x98, 0x61, 0x00, 0x01,
57 | 0x38, 0x60, 0x00, 0x79,
58 | 0x98, 0x61, 0x00, 0x02,
59 | 0x38, 0x60, 0x00, 0x20,
60 | 0x98, 0x61, 0x00, 0x03,
61 | 0x38, 0x60, 0x00, 0x66,
62 | 0x98, 0x61, 0x00, 0x04,
63 | 0x38, 0x60, 0x00, 0x72,
64 | 0x98, 0x61, 0x00, 0x05,
65 | 0x38, 0x60, 0x00, 0x6F,
66 | 0x98, 0x61, 0x00, 0x06,
67 | 0x38, 0x60, 0x00, 0x6D,
68 | 0x98, 0x61, 0x00, 0x07,
69 | 0x38, 0x60, 0x00, 0x20,
70 | 0x98, 0x61, 0x00, 0x08,
71 | 0x38, 0x60, 0x00, 0x50,
72 | 0x98, 0x61, 0x00, 0x09,
73 | 0x38, 0x60, 0x00, 0x50,
74 | 0x98, 0x61, 0x00, 0x0A,
75 | 0x38, 0x60, 0x00, 0x43,
76 | 0x98, 0x61, 0x00, 0x0B,
77 | 0x38, 0x60, 0x00, 0x20,
78 | 0x98, 0x61, 0x00, 0x0C,
79 | 0x38, 0x60, 0x00, 0x70,
80 | 0x98, 0x61, 0x00, 0x0D,
81 | 0x38, 0x60, 0x00, 0x61,
82 | 0x98, 0x61, 0x00, 0x0E,
83 | 0x38, 0x60, 0x00, 0x79,
84 | 0x98, 0x61, 0x00, 0x0F,
85 | 0x38, 0x60, 0x00, 0x6C,
86 | 0x98, 0x61, 0x00, 0x10,
87 | 0x38, 0x60, 0x00, 0x6F,
88 | 0x98, 0x61, 0x00, 0x11,
89 | 0x38, 0x60, 0x00, 0x61,
90 | 0x98, 0x61, 0x00, 0x12,
91 | 0x38, 0x60, 0x00, 0x64,
92 | 0x98, 0x61, 0x00, 0x13,
93 | 0x38, 0x60, 0x00, 0x20,
94 | 0x98, 0x61, 0x00, 0x14,
95 | 0x38, 0x60, 0x00, 0x70,
96 | 0x98, 0x61, 0x00, 0x15,
97 | 0x38, 0x60, 0x00, 0x6F,
98 | 0x98, 0x61, 0x00, 0x16,
99 | 0x38, 0x60, 0x00, 0x67,
100 | 0x98, 0x61, 0x00, 0x17,
101 | 0x38, 0x60, 0x00, 0x20,
102 | 0x98, 0x61, 0x00, 0x18,
103 | 0x38, 0x60, 0x00, 0x70,
104 | 0x98, 0x61, 0x00, 0x19,
105 | 0x38, 0x60, 0x00, 0x6F,
106 | 0x98, 0x61, 0x00, 0x1A,
107 | 0x38, 0x60, 0x00, 0x67,
108 | 0x98, 0x61, 0x00, 0x1B,
109 | 0x38, 0x60, 0x00, 0x20,
110 | 0x98, 0x61, 0x00, 0x1C,
111 | 0x38, 0x60, 0x00, 0x70,
112 | 0x98, 0x61, 0x00, 0x1D,
113 | 0x38, 0x60, 0x00, 0x6F,
114 | 0x98, 0x61, 0x00, 0x1E,
115 | 0x38, 0x60, 0x00, 0x67,
116 | 0x98, 0x61, 0x00, 0x1F,
117 | 0x38, 0x60, 0x00, 0x21,
118 | 0x98, 0x61, 0x00, 0x20,
119 | 0x38, 0x60, 0x00, 0x0A,
120 | 0x98, 0x61, 0x00, 0x21,
121 | 0x38, 0x60, 0x00, 0x00,
122 | 0x98, 0x61, 0x00, 0x22,
123 | 0x7C, 0x23, 0x0B, 0x78,
124 | 0x38, 0x00, 0x00, 0x00,
125 | 0x44, 0x00, 0x00, 0x02,
126 | 0x38, 0x00, 0x00, 0x01,
127 | 0x44, 0x00, 0x00, 0x02,
128 | 0x38, 0x63, 0x02, 0x00,
129 | 0x38, 0x80, 0x00, 0x69,
130 | 0x38, 0xA0, 0x01, 0x00,
131 | 0x48, 0x00, 0x00, 0x19,
132 | 0x38, 0x21, 0x00, 0x30,
133 | 0x81, 0x81, 0xFF, 0xF8,
134 | 0x7D, 0x88, 0x03, 0xA6,
135 | 0xFF, 0xFF, 0xFF, 0xFF, // TEST BREAKPOINT TO CHECK RAM+0x200
136 | 0x4E, 0x80, 0x00, 0x20,
137 | 0x38, 0x00, 0x00, 0x04,
138 | 0x44, 0x00, 0x00, 0x02,
139 | 0x4E, 0x80, 0x00, 0x20
140 | };
141 |
142 | uint8_t example_2[] = {
143 | 0x38, 0x60, 0x00, 0x08,
144 | 0x38, 0x80, 0x00, 0x06,
145 | 0x7E, 0x03, 0x20, 0x00,
146 | 0x40, 0x90, 0xFF, 0xFC,
147 | 0x4E, 0x80, 0x00, 0x20
148 | };
149 |
150 | uint8_t example_3[] = {
151 | 0x7D, 0x88, 0x02, 0xA6,
152 | 0x91, 0x81, 0xFF, 0xF8,
153 | 0x94, 0x21, 0xFF, 0xF0,
154 | 0x38, 0x00, 0x00, 0x05,
155 | 0x44, 0x00, 0x00, 0x02,
156 | 0x38, 0x63, 0x00, 0x38,
157 | 0x38, 0x80, 0x00, 0x59,
158 | 0x38, 0xA0, 0x00, 0x00,
159 | 0x38, 0x00, 0x00, 0x06,
160 | 0x44, 0x00, 0x00, 0x02,
161 | 0x38, 0x21, 0x00, 0x10,
162 | 0x81, 0x81, 0xFF, 0xF8,
163 | 0x7D, 0x88, 0x03, 0xA6,
164 | 0x4E, 0x80, 0x00, 0x20,
165 | 0x38, 0x63, 0x00, 0x10,
166 | 0x38, 0x00, 0x00, 0x03,
167 | 0x44, 0x00, 0x00, 0x02,
168 | 0x4E, 0x80, 0x00, 0x20
169 | };
170 |
171 | setup_syscalls();
172 |
173 | // ** execute takes care of cleaning up the allocations.
174 |
175 | // majority test
176 | virtual_machine* payload_1 = get_core()->create_vm();
177 | if (payload_1) {
178 | payload_1->execute(example_1);
179 | }
180 |
181 | // branch condition test
182 | virtual_machine* payload_2 = get_core()->create_vm();
183 | if (payload_2) {
184 | payload_2->execute(example_2);
185 | }
186 |
187 | // threading test
188 | virtual_machine* payload_3 = get_core()->create_vm();
189 | if (payload_3) {
190 | payload_3->execute(example_3);
191 | }
192 |
193 | system("pause");
194 | return 0;
195 | }
--------------------------------------------------------------------------------
/PPCVM/src/registers.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | struct registers {
5 | uint64_t msr; // machine status register
6 | uint64_t iar; // instruction address register
7 | uint64_t lr; // link register
8 | uint64_t ctr; // count register
9 |
10 | uint64_t gpr[32]; // general registers 0 to 31
11 |
12 | // xer register
13 | union {
14 | uint32_t value;
15 | struct {
16 | uint32_t so : 1;
17 | uint32_t ov : 1;
18 | uint32_t ca : 1;
19 | } bits;
20 | } xer;
21 |
22 | // condition register - not using bits, bitset is nicer to work with
23 | enum cr_bit { lt, gt, eq, so };
24 | std::array, 8> cr; // bools instead of bits
25 |
26 | double fpscr; // floating point status/control register
27 | double fpr[32]; // floating point registers 0 to 31
28 |
29 | registers() {
30 | msr = 0; iar = 0; lr = 0; ctr = 0;
31 | memset(gpr, 0, sizeof(gpr));
32 | }
33 | };
--------------------------------------------------------------------------------
/PPCVM/src/stdafx.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #define _CRT_SECURE_NO_WARNINGS
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
--------------------------------------------------------------------------------
/PPCVM/src/virtual_machine.cpp:
--------------------------------------------------------------------------------
1 | #include "virtual_machine.h"
2 | #include "instructions.h"
3 | #include
4 | #include
5 |
6 | core_machine* get_core() {
7 | static core_machine instance;
8 | return &instance;
9 | }
10 |
11 | namespace handlers {
12 | void breakpoint(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
13 | printf("breaking\n");
14 | __debugbreak();
15 | }
16 |
17 | void cmpi(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
18 | registers* context = vm->get_current_context();
19 | ::cmpi val = { in.value };
20 |
21 | context->cr[val.bits.crfd].reset();
22 | if (val.bits.l) {
23 | int64_t ra = (int64_t)context->gpr[val.bits.ra];
24 | int64_t ds = (int64_t)val.bits.ds;
25 |
26 | context->cr[val.bits.crfd].set(registers::cr_bit::eq, ra == ds);
27 | context->cr[val.bits.crfd].set(registers::cr_bit::lt, ra < ds);
28 | context->cr[val.bits.crfd].set(registers::cr_bit::gt, ra > ds);
29 | } else {
30 | int32_t ra = (int32_t)context->gpr[val.bits.ra];
31 | int32_t ds = (int32_t)val.bits.ds;
32 |
33 | context->cr[val.bits.crfd].set(registers::cr_bit::eq, ra == ds);
34 | context->cr[val.bits.crfd].set(registers::cr_bit::lt, ra < ds);
35 | context->cr[val.bits.crfd].set(registers::cr_bit::gt, ra > ds);
36 | }
37 |
38 | context->cr[val.bits.crfd].set(registers::cr_bit::so, context->xer.bits.so);
39 |
40 | #ifdef DEBUG
41 | if (val.bits.l) {
42 | // cmpdi
43 | printf("cmpdi cr%i, r%i, 0x%x\n", val.bits.crfd, val.bits.ra, val.bits.ds);
44 | } else {
45 | // cmpwi
46 | printf("cmpwi cr%i, r%d, 0x%x\n", val.bits.crfd, val.bits.ra, val.bits.ds);
47 | }
48 | #endif
49 | }
50 |
51 | void li(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
52 | registers* context = vm->get_current_context();
53 | ::li val = { in.value };
54 |
55 | context->gpr[val.bits.rt] = val.bits.ra == 0 ? val.bits.si : context->gpr[val.bits.ra | 0] + val.bits.si;
56 |
57 | #ifdef DEBUG
58 | if (val.bits.ra == 0) {
59 | printf("li r%i, 0x%x\n", val.bits.rt, val.bits.si);
60 | } else {
61 | printf("addi r%i, r%i, 0x%x\n", val.bits.rt, val.bits.ra | 0, val.bits.si);
62 | }
63 | #endif
64 | }
65 |
66 | void lis(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
67 | registers* context = vm->get_current_context();
68 | ::li val = { in.value };
69 |
70 | context->gpr[val.bits.rt] = val.bits.ra == 0 ? (val.bits.si || 0) : (val.bits.ra | 0) + (val.bits.si || 0);
71 |
72 | #ifdef DEBUG
73 | if (val.bits.ra == 0) {
74 | printf("lis r%i, 0x%x\n", val.bits.rt, (val.bits.si || 0));
75 | } else {
76 | printf("addic r%i, r%i, 0x%x\n", val.bits.rt, val.bits.ra | 0, (val.bits.si || 0));
77 | }
78 | #endif
79 | }
80 |
81 | void sc(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
82 | registers* context = vm->get_current_context();
83 | ::sc val = { in.value };
84 |
85 | #ifdef DEBUG
86 | printf("sc\n");
87 |
88 | #endif
89 | if (val.bits.lev == 2) {
90 | // the syscall should handle setting return registers
91 | ((void(*)(virtual_machine*))get_core()->get_syscall((int)context->gpr[0]))(vm);
92 | }
93 | }
94 |
95 | void lwz(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
96 | registers* context = vm->get_current_context();
97 | ::lwz val = { in.value };
98 |
99 | context->gpr[val.bits.rt] = _byteswap_ulong(*(uint32_t*)(context->gpr[val.bits.ra] + (short)val.bits.ds));
100 |
101 | #ifdef DEBUG
102 | printf("lwz r%i, %s0x%X(r%i)\n", val.bits.rt, (short)val.bits.ds > 0 ? "" : "-", (short)val.bits.ds > 0 ? (short)val.bits.ds : abs((short)val.bits.ds), val.bits.ra);
103 | #endif
104 | }
105 |
106 | void stwu(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
107 | registers* context = vm->get_current_context();
108 | ::stwu val = { in.value };
109 |
110 | if (val.bits.ra == 1) {
111 | // if it's a stack allocation
112 | uint64_t current_stack = context->gpr[1];
113 | context->gpr[1] += (short)val.bits.ds;
114 | *(uint64_t*)(context->gpr[1]) = current_stack; // back chain
115 | } else {
116 | *(uint32_t*)(context->gpr[val.bits.ra] + (short)val.bits.ds) = _byteswap_ulong((uint32_t)context->gpr[val.bits.rt]);
117 | }
118 |
119 | #ifdef DEBUG
120 | printf("stwu r%i, %s0x%X(r%i)\n", val.bits.rt, (short)val.bits.ds > 0 ? "" : "-", (short)val.bits.ds > 0 ? (short)val.bits.ds : abs((short)val.bits.ds), val.bits.ra);
121 | #endif
122 | }
123 |
124 | void stw(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
125 | registers* context = vm->get_current_context();
126 | ::stw val = { in.value };
127 |
128 | *(uint32_t*)(context->gpr[val.bits.ra] + (short)val.bits.ds) = _byteswap_ulong((uint32_t)context->gpr[val.bits.rt]);
129 | #ifdef DEBUG
130 | printf("stw r%i, %s0x%X(r%i)\n", val.bits.rt, (short)val.bits.ds > 0 ? "" : "-", (short)val.bits.ds > 0 ? (short)val.bits.ds : abs((short)val.bits.ds), val.bits.ra);
131 | #endif
132 | }
133 |
134 | void stb(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
135 | registers* context = vm->get_current_context();
136 | ::stb val = { in.value };
137 |
138 | *(uint8_t*)(context->gpr[val.bits.ra] + (short)val.bits.ds) = (uint8_t)context->gpr[val.bits.rt];
139 | #ifdef DEBUG
140 | printf("stb r%i, %s0x%X(r%i)\n", val.bits.rt, (short)val.bits.ds > 0 ? "" : "-", (short)val.bits.ds > 0 ? (short)val.bits.ds : abs((short)val.bits.ds), val.bits.ra);
141 | #endif
142 | }
143 |
144 | void b(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
145 | registers* context = vm->get_current_context();
146 | bx val = { in.value };
147 |
148 | if (val.bits.lk) {
149 | context->lr = context->iar + 1;
150 | }
151 |
152 | uint32_t offset = val.bits.li - 1;
153 | if (val.bits.aa == 0) {
154 | context->iar += offset;
155 | } else {
156 | context->iar = offset;
157 | }
158 |
159 | #ifdef DEBUG
160 | if (val.bits.aa == 0 && val.bits.lk == 0) {
161 | // b
162 | printf("b 0x%X\n", val.bits.li * 4);
163 | } else if (val.bits.aa == 1 && val.bits.lk == 0) {
164 | // ba
165 | printf("ba 0x%X\n", val.bits.li * 4);
166 | } else if (val.bits.aa == 0 && val.bits.lk == 1) {
167 | // bl
168 | printf("bl 0x%X\n", val.bits.li * 4);
169 | } else if (val.bits.aa == 1 && val.bits.lk == 1) {
170 | // bla
171 | printf("bla 0x%X\n", val.bits.li * 4);
172 | }
173 | #endif
174 | }
175 |
176 | void bc(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
177 | registers* context = vm->get_current_context();
178 | bcx val = { in.value };
179 |
180 | uint32_t cr_field = val.bits.bi >> 2;
181 | uint32_t cr_field_bit = val.bits.bi & 3;
182 | uint32_t branch_offset = val.bits.bd << 2;
183 |
184 | bool decrement_ctr = false;
185 | if (!(val.bits.bo & 0b00100)) {
186 | context->ctr = context->ctr - 1;
187 | decrement_ctr = true;
188 | }
189 |
190 | bool should_branch = false;
191 | if (val.bits.bo & 0b10000) {
192 | if (decrement_ctr) {
193 | should_branch = true;
194 | } else if (val.bits.bo & 0b00010) {
195 | should_branch = context->ctr == 0;
196 | #ifdef DEBUG
197 | printf("bdz cr%d, %s0x%x\n", cr_field, (int16_t)branch_offset > 0 ? "" : "-", (int16_t)branch_offset > 0 ? (int16_t)branch_offset : abs((int16_t)branch_offset));
198 | #endif
199 | } else {
200 | should_branch = context->ctr != 0;
201 | #ifdef DEBUG
202 | printf("bdnz cr%d, %s0x%x\n", cr_field, (int16_t)branch_offset > 0 ? "" : "-", (int16_t)branch_offset > 0 ? (int16_t)branch_offset : abs((int16_t)branch_offset));
203 | #endif
204 | }
205 | } else {
206 | if (val.bits.bo & 0b01000) {
207 | should_branch = context->cr[cr_field].test(cr_field_bit);
208 | #ifdef DEBUG
209 | switch (cr_field_bit) {
210 | case registers::cr_bit::lt: {
211 | printf("blt cr%d, %s0x%x\n", cr_field, (int16_t)branch_offset > 0 ? "" : "-", (int16_t)branch_offset > 0 ? (int16_t)branch_offset : abs((int16_t)branch_offset));
212 | break;
213 | }
214 |
215 | case registers::cr_bit::gt: {
216 | printf("bgt cr%d, %s0x%x\n", cr_field, (int16_t)branch_offset > 0 ? "" : "-", (int16_t)branch_offset > 0 ? (int16_t)branch_offset : abs((int16_t)branch_offset));
217 | break;
218 | }
219 |
220 | case registers::cr_bit::eq: {
221 | printf("beq cr%d, %s0x%x\n", cr_field, (int16_t)branch_offset > 0 ? "" : "-", (int16_t)branch_offset > 0 ? (int16_t)branch_offset : abs((int16_t)branch_offset));
222 | break;
223 | }
224 | }
225 | #endif
226 | } else {
227 | should_branch = !context->cr[cr_field].test(cr_field_bit);
228 | #ifdef DEBUG
229 | switch (cr_field_bit) {
230 | case registers::cr_bit::lt: {
231 | printf("bge cr%d, %s0x%x\n", cr_field, (int16_t)branch_offset > 0 ? "" : "-", (int16_t)branch_offset > 0 ? (int16_t)branch_offset : abs((int16_t)branch_offset));
232 | break;
233 | }
234 |
235 | case registers::cr_bit::gt: {
236 | printf("ble cr%d, %s0x%x\n", cr_field, (int16_t)branch_offset > 0 ? "" : "-", (int16_t)branch_offset > 0 ? (int16_t)branch_offset : abs((int16_t)branch_offset));
237 | break;
238 | }
239 |
240 | case registers::cr_bit::eq: {
241 | printf("bne cr%d, %s0x%x\n", cr_field, (int16_t)branch_offset > 0 ? "" : "-", (int16_t)branch_offset > 0 ? (int16_t)branch_offset : abs((int16_t)branch_offset));
242 | break;
243 | }
244 | }
245 | #endif
246 | }
247 | }
248 |
249 | if (should_branch) {
250 | if (val.bits.lk) {
251 | context->lr = context->iar + 1;
252 | }
253 |
254 | int32_t offset = (int32_t)((int16_t)(branch_offset) / sizeof(int32_t));
255 | context->iar = val.bits.aa ? (uint32_t)(offset) : (uint32_t)(context->iar + offset);
256 | }
257 | }
258 |
259 | void cmpli(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
260 | registers* context = vm->get_current_context();
261 | ::cmpli val = { in.value };
262 |
263 | context->cr[val.bits.crfd].reset();
264 | if (val.bits.l) {
265 | uint64_t ra = (uint64_t)context->gpr[val.bits.ra];
266 | uint64_t ds = (uint64_t)val.bits.ds;
267 |
268 | context->cr[val.bits.crfd].set(registers::cr_bit::eq, ra == ds);
269 | context->cr[val.bits.crfd].set(registers::cr_bit::lt, ra < ds);
270 | context->cr[val.bits.crfd].set(registers::cr_bit::gt, ra > ds);
271 | } else {
272 | uint32_t ra = (uint32_t)context->gpr[val.bits.ra];
273 | uint32_t ds = (uint32_t)val.bits.ds;
274 |
275 | context->cr[val.bits.crfd].set(registers::cr_bit::eq, ra == ds);
276 | context->cr[val.bits.crfd].set(registers::cr_bit::lt, ra < ds);
277 | context->cr[val.bits.crfd].set(registers::cr_bit::gt, ra > ds);
278 | }
279 |
280 | context->cr[val.bits.crfd].set(registers::cr_bit::so, context->xer.bits.so);
281 |
282 | #ifdef DEBUG
283 | if (val.bits.l) {
284 | // cmpldi
285 | printf("cmpldi cr%i, r%i, 0x%x\n", val.bits.crfd, val.bits.ra, val.bits.ds);
286 | } else {
287 | // cmplwi
288 | printf("cmplwi cr%i, r%i, 0x%x\n", val.bits.crfd, val.bits.ra, val.bits.ds);
289 | }
290 | #endif
291 | }
292 |
293 | void cmp(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
294 | registers* context = vm->get_current_context();
295 | ::cmp val = { in.value };
296 |
297 | context->cr[val.bits.crfd].reset();
298 | if (val.bits.l) {
299 | int64_t ra = (int64_t)context->gpr[val.bits.ra];
300 | int64_t rb = (int64_t)context->gpr[val.bits.rb];
301 |
302 | context->cr[val.bits.crfd].set(registers::cr_bit::eq, ra == rb);
303 | context->cr[val.bits.crfd].set(registers::cr_bit::lt, ra < rb);
304 | context->cr[val.bits.crfd].set(registers::cr_bit::gt, ra > rb);
305 | } else {
306 | int32_t ra = (int32_t)context->gpr[val.bits.ra];
307 | int32_t rb = (int32_t)context->gpr[val.bits.rb];
308 |
309 | context->cr[val.bits.crfd].set(registers::cr_bit::eq, ra == rb);
310 | context->cr[val.bits.crfd].set(registers::cr_bit::lt, ra < rb);
311 | context->cr[val.bits.crfd].set(registers::cr_bit::gt, ra > rb);
312 | }
313 |
314 | context->cr[val.bits.crfd].set(registers::cr_bit::so, context->xer.bits.so);
315 |
316 | #ifdef DEBUG
317 | if (val.bits.l) {
318 | // cmpd
319 | printf("cmpd cr%i, r%i, r%i\n", val.bits.crfd, val.bits.ra, val.bits.rb);
320 | } else {
321 | // cmpw
322 | printf("cmpw cr%i, r%i, r%i\n", val.bits.crfd, val.bits.ra, val.bits.rb);
323 | }
324 | #endif
325 | }
326 |
327 | void cmpl(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
328 | registers* context = vm->get_current_context();
329 | ::cmpl val = { in.value };
330 |
331 | context->cr[val.bits.crfd].reset();
332 |
333 | if (val.bits.l) {
334 | uint64_t ra = (uint64_t)context->gpr[val.bits.ra];
335 | uint64_t rb = (uint64_t)context->gpr[val.bits.rb];
336 |
337 | context->cr[val.bits.crfd].set(registers::cr_bit::eq, ra == rb);
338 | context->cr[val.bits.crfd].set(registers::cr_bit::lt, ra < rb);
339 | context->cr[val.bits.crfd].set(registers::cr_bit::gt, ra > rb);
340 | } else {
341 | uint32_t ra = (uint32_t)context->gpr[val.bits.ra];
342 | uint32_t rb = (uint32_t)context->gpr[val.bits.rb];
343 |
344 | context->cr[val.bits.crfd].set(registers::cr_bit::eq, ra == rb);
345 | context->cr[val.bits.crfd].set(registers::cr_bit::lt, ra < rb);
346 | context->cr[val.bits.crfd].set(registers::cr_bit::gt, ra > rb);
347 | }
348 |
349 | context->cr[val.bits.crfd].set(registers::cr_bit::so, context->xer.bits.so);
350 |
351 | #ifdef DEBUG
352 | if (val.bits.l) {
353 | // cmpld
354 | printf("cmpld cr%i, r%i, r%i\n", val.bits.crfd, val.bits.ra, val.bits.rb);
355 | } else {
356 | // cmplw
357 | printf("cmplw cr%i, r%i, r%i\n", val.bits.crfd, val.bits.ra, val.bits.rb);
358 | }
359 | #endif
360 | }
361 |
362 | void _or(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
363 | registers* context = vm->get_current_context();
364 | ::_or val = { in.value };
365 |
366 | context->gpr[val.bits.ra] = (0 || val.bits.ui) == 1 ? context->gpr[val.bits.rs] : context->gpr[val.bits.rs] | (0 || val.bits.ui);
367 |
368 | #ifdef DEBUG
369 | if ((0 || val.bits.ui) == 1) {
370 | printf("mr r%i, r%i\n", val.bits.ra, val.bits.rs);
371 | }
372 | #endif
373 | }
374 |
375 | void add(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
376 | registers* context = vm->get_current_context();
377 | addx val = { in.value };
378 |
379 | uint64_t ra = (uint64_t)context->gpr[val.bits.ra];
380 | uint64_t rb = (uint64_t)context->gpr[val.bits.rb];
381 |
382 | context->gpr[val.bits.rt] = ra + rb;
383 |
384 | uint64_t rt = context->gpr[val.bits.rt];
385 |
386 | if (val.bits.oe) {
387 | if ((ra ^ ~rb) & (ra ^ rt) & 0x80000000) {
388 | context->xer.bits.so = 1;
389 | context->xer.bits.ov = 1;
390 | } else {
391 | context->xer.bits.ov = 0;
392 | }
393 | }
394 |
395 | if (val.bits.rc) {
396 | context->cr[0].reset();
397 | if (context->gpr[val.bits.rt] == 0) {
398 | context->cr[0].set(registers::cr_bit::eq, true);
399 | } else if (context->gpr[val.bits.rt] & 0x80000000) {
400 | context->cr[0].set(registers::cr_bit::lt, true);
401 | } else {
402 | context->cr[0].set(registers::cr_bit::gt, true);
403 | }
404 |
405 | context->cr[0].set(registers::cr_bit::so, context->xer.bits.so);
406 | }
407 |
408 | #ifdef DEBUG
409 | if (val.bits.oe == 0 && val.bits.rc == 0) {
410 | // add
411 | printf("add r%i, r%i, r%i\n", val.bits.rt, val.bits.ra, val.bits.rb);
412 | } else if (val.bits.oe == 0 && val.bits.rc == 1) {
413 | // add.
414 | printf("add. r%i, r%i, r%i\n", val.bits.rt, val.bits.ra, val.bits.rb);
415 | } else if (val.bits.oe == 1 && val.bits.rc == 0) {
416 | // addo
417 | printf("addo r%i, r%i, r%i\n", val.bits.rt, val.bits.ra, val.bits.rb);
418 | } else if (val.bits.oe == 1 && val.bits.rc == 1) {
419 | // addo.
420 | printf("addo. r%i, r%i, r%i\n", val.bits.rt, val.bits.ra, val.bits.rb);
421 | }
422 | #endif
423 | }
424 |
425 | void mfspr(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
426 | registers* context = vm->get_current_context();
427 | ::mfspr val = { in.value };
428 |
429 | switch (((val.bits.spr >> 5) & 0x1F) | (val.bits.spr & 0x1F)) {
430 | case 1: { // xer
431 | context->gpr[val.bits.rt] = (uint64_t)context->xer.value;
432 |
433 | #ifdef DEBUG
434 | printf("mfxer r%i\n", val.bits.rt);
435 | #endif
436 | break;
437 | }
438 |
439 | case 8: { // lr
440 | context->gpr[val.bits.rt] = context->lr;
441 |
442 | #ifdef DEBUG
443 | printf("mflr r%i\n", val.bits.rt);
444 | #endif
445 | break;
446 | }
447 |
448 | case 9: { // ctr
449 | context->gpr[val.bits.rt] = context->ctr;
450 |
451 | #ifdef DEBUG
452 | printf("mfctr r%i\n", val.bits.rt);
453 | #endif
454 | break;
455 | }
456 | }
457 | }
458 |
459 | void mtspr(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
460 | registers* context = vm->get_current_context();
461 | ::mtspr val = { in.value };
462 |
463 | switch (((val.bits.spr >> 5) & 0x1F) | (val.bits.spr & 0x1F)) {
464 | case 1: { // xer
465 | context->xer.value = (uint32_t)context->gpr[val.bits.rt];
466 |
467 | #ifdef DEBUG
468 | printf("mtxer r%i\n", val.bits.rt);
469 | #endif
470 | break;
471 | }
472 |
473 | case 8: { // lr
474 | context->lr = context->gpr[val.bits.rt];
475 | #ifdef DEBUG
476 | printf("mtlr r%i\n", val.bits.rt);
477 | #endif
478 | break;
479 | }
480 |
481 | case 9: { // ctr
482 | context->ctr = context->gpr[val.bits.rt];
483 | #ifdef DEBUG
484 | printf("mtctr r%i\n", val.bits.rt);
485 | #endif
486 | break;
487 | }
488 | }
489 | }
490 |
491 | void bundle_31(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
492 | ::bundle_31 val = { in.value };
493 |
494 | switch (val.bits._) {
495 | case eop_cmp: return cmp(in, vm, out_reason);
496 | case eop_cmpl: return cmpl(in, vm, out_reason);
497 | case eop_or: return _or(in, vm, out_reason);
498 | case eop_add: return add(in, vm, out_reason);
499 | case eop_mfspr: return mfspr(in, vm, out_reason);
500 | case eop_mtspr: return mtspr(in, vm, out_reason);
501 | }
502 | }
503 |
504 | void bclr(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
505 | registers* context = vm->get_current_context();
506 | ::bundle_19 val = { in.value };
507 |
508 | if (val.bits.bo & 0b10100) {
509 | #ifdef DEBUG
510 | printf("blr\n");
511 | #endif
512 |
513 | if (context->lr == 0) {
514 | *out_reason = it_return;
515 | return;
516 | }
517 |
518 | context->iar = context->lr;
519 | *out_reason = it_continue;
520 | return;
521 | }
522 | }
523 |
524 | void bundle_19(instruction in, virtual_machine* vm, iteration_reason* out_reason) {
525 | ::bundle_19 val = { in.value };
526 | switch (val.bits._) {
527 | case eop_bclr: return bclr(in, vm, out_reason);
528 | }
529 | }
530 | }
531 |
532 | std::unordered_map> table = {
533 | { 63, handlers::breakpoint },
534 | { op_cmpi, handlers::cmpi },
535 | { op_li, handlers::li },
536 | { op_lis, handlers::lis },
537 | { op_sc, handlers::sc },
538 | { op_lwz, handlers::lwz },
539 | { op_stwu, handlers::stwu },
540 | { op_stw, handlers::stw },
541 | { op_stb, handlers::stb },
542 | { op_b, handlers::b },
543 | { op_bc, handlers::bc },
544 | { op_cmpli, handlers::cmpli },
545 | { op_bundle_31, handlers::bundle_31 },
546 | { op_bundle_19, handlers::bundle_19 },
547 | };
548 |
549 | void virtual_machine::execute(uint8_t* payload, void* argument) {
550 | printf("\n======== EXECUTING PAYLOAD 0x%p ========\n", payload);
551 |
552 | set_payload(payload);
553 | set_argument(argument);
554 | memset(get_stack(), 0, STACK);
555 |
556 | get_current_context()->gpr[1] = (uint64_t)&get_stack()[STACK];
557 | get_current_context()->gpr[3] = (uint64_t)argument;
558 |
559 | CreateThread(0, 0, [](LPVOID param) -> DWORD {
560 | virtual_machine* _this = (virtual_machine*)param;
561 |
562 | while (true) {
563 | uint8_t* payload = _this->get_payload();
564 | instruction in = { _byteswap_ulong(*(uint32_t*)(&payload[_this->get_current_context()->iar * sizeof(uint32_t)])) };
565 | if (table[in.bits.opcode]) {
566 | iteration_reason reason = it_ok;
567 | table[in.bits.opcode](in, _this, &reason);
568 |
569 | if (reason == it_continue) continue;
570 | if (reason == it_return) return 0;
571 | } else return 0;
572 |
573 | _this->get_current_context()->iar++;
574 | };
575 |
576 | delete _this;
577 | return 0;
578 | }, this, 0, 0);
579 | }
580 |
581 | void core_machine::add_syscall(void(*function)(virtual_machine*), int id) {
582 | if (id < MAX_SYSCALLS) {
583 | syscall_table[id] = function;
584 | }
585 | }
586 |
587 | void virtual_machine::print_registers() {
588 | for (int i = 0; i < 32; i++) {
589 | printf("r%i=0x%016I64X ", i, get_current_context()->gpr[i]);
590 |
591 | if ((i + 1) % 4 == 0) {
592 | printf("\n");
593 | }
594 | }
595 |
596 | printf("msr=0x%016I64X iar=0x%016I64X lr=0x%016I64X ctr=0x%016I64X\n", get_current_context()->msr, get_current_context()->iar, get_current_context()->lr, get_current_context()->ctr);
597 | printf("cr0=0x%X cr1=0x%X cr2=0x%X cr3=0x%X\n", get_current_context()->cr[0].to_ulong(), get_current_context()->cr[1].to_ulong(), get_current_context()->cr[2].to_ulong(), get_current_context()->cr[3].to_ulong());
598 | printf("cr4=0x%X cr5=0x%X cr6=0x%X cr7=0x%X\n", get_current_context()->cr[4].to_ulong(), get_current_context()->cr[5].to_ulong(), get_current_context()->cr[6].to_ulong(), get_current_context()->cr[7].to_ulong());
599 | }
600 |
601 | virtual_machine* core_machine::create_vm(uint32_t* thread_id) {
602 | virtual_machine* vm = new virtual_machine();
603 | if (vm) {
604 | uint32_t id = ++thread_id_count;
605 | if (thread_id) *thread_id = id;
606 |
607 | context[id] = registers();
608 | vm->set_thread_id(id);
609 | }
610 |
611 | return vm;
612 | }
--------------------------------------------------------------------------------
/PPCVM/src/virtual_machine.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "registers.h"
4 | #include
5 |
6 | #define MAX_SYSCALLS 0xFF
7 | #define RAM 0xFFFF
8 | #define STACK 0xFFFF
9 | #define DEBUG
10 |
11 | class virtual_machine;
12 |
13 | class core_machine {
14 | public:
15 | virtual_machine* create_vm(uint32_t* thread_id = nullptr);
16 | void add_syscall(void(*function)(virtual_machine*), int id);
17 |
18 | uint8_t* get_ram() { return ram; }
19 | void* get_syscall(int index) { return syscall_table[index]; }
20 | registers* get_context(uint32_t thread_id) { return &context[thread_id]; }
21 | protected:
22 | std::unordered_map context;
23 | uint8_t ram[RAM];
24 | void* syscall_table[MAX_SYSCALLS];
25 | uint32_t thread_id_count;
26 | };
27 |
28 | core_machine* get_core();
29 |
30 | class virtual_machine {
31 | public:
32 | void execute(uint8_t* payload, void* argument = nullptr);
33 | void print_registers();
34 |
35 | registers* get_current_context() { return get_core()->get_context(thread_id); }
36 | uint32_t get_thread_id() { return thread_id; }
37 | uint8_t* get_stack() { return stack; }
38 | uint8_t* get_payload() { return payload; }
39 | void* get_argument() { return argument; }
40 |
41 | void set_thread_id(uint32_t id) { thread_id = id; }
42 | void set_payload(uint8_t* p) { payload = p; }
43 | void set_argument(void* p) { argument = p; }
44 | private:
45 | void* argument;
46 | uint8_t* payload;
47 | uint32_t thread_id;
48 | uint8_t stack[STACK];
49 | };
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PPC Virtual Machine
2 | PowerPC (64bit) virtual machine with support for ram, stack, syscalls, and threading.
3 |
4 | ## Brief Explanation
5 | The start of a virtual machine for emulating the PowerPC instruction set seen on Xbox360 to eventually make use of virtualization. Currently only a handful of instructions are supported. More instructions will be pushed in the future.
6 |
7 | ## Examples
8 | You can find payloads in the examples folder.
9 |
--------------------------------------------------------------------------------
/examples/example_1.asm:
--------------------------------------------------------------------------------
1 | mflr %r12
2 | stw %r12, -0x8(%r1)
3 | stwu %r1, -0x30(%r1)
4 |
5 | li %r3, 0x48 # "H"
6 | stb %r3, 0x00(%r1)
7 |
8 | li %r3, 0x65 # "e"
9 | stb %r3, 0x01(%r1)
10 |
11 | li %r3, 0x79 # "y"
12 | stb %r3, 0x02(%r1)
13 |
14 | li %r3, 0x20 # " "
15 | stb %r3, 0x03(%r1)
16 |
17 | li %r3, 0x66 # "f"
18 | stb %r3, 0x04(%r1)
19 |
20 | li %r3, 0x72 # "r"
21 | stb %r3, 0x05(%r1)
22 |
23 | li %r3, 0x6F # "o"
24 | stb %r3, 0x06(%r1)
25 |
26 | li %r3, 0x6D # "m"
27 | stb %r3, 0x07(%r1)
28 |
29 | li %r3, 0x20 # " "
30 | stb %r3, 0x08(%r1)
31 |
32 | li %r3, 0x50 # "P"
33 | stb %r3, 0x09(%r1)
34 |
35 | li %r3, 0x50 # "P"
36 | stb %r3, 0x0A(%r1)
37 |
38 | li %r3, 0x43 # "C"
39 | stb %r3, 0x0B(%r1)
40 |
41 | li %r3, 0x20 # " "
42 | stb %r3, 0x0C(%r1)
43 |
44 | li %r3, 0x70 # "p"
45 | stb %r3, 0x0D(%r1)
46 |
47 | li %r3, 0x61 # "a"
48 | stb %r3, 0x0E(%r1)
49 |
50 | li %r3, 0x79 # "y"
51 | stb %r3, 0x0F(%r1)
52 |
53 | li %r3, 0x6C # "l"
54 | stb %r3, 0x10(%r1)
55 |
56 | li %r3, 0x6F # "o"
57 | stb %r3, 0x11(%r1)
58 |
59 | li %r3, 0x61 # "a"
60 | stb %r3, 0x12(%r1)
61 |
62 | li %r3, 0x64 # "d"
63 | stb %r3, 0x13(%r1)
64 |
65 | li %r3, 0x20 # " "
66 | stb %r3, 0x14(%r1)
67 |
68 | li %r3, 0x70 # "p"
69 | stb %r3, 0x15(%r1)
70 |
71 | li %r3, 0x6F # "o"
72 | stb %r3, 0x16(%r1)
73 |
74 | li %r3, 0x67 # "g"
75 | stb %r3, 0x17(%r1)
76 |
77 | li %r3, 0x20 # " "
78 | stb %r3, 0x18(%r1)
79 |
80 | li %r3, 0x70 # "p"
81 | stb %r3, 0x19(%r1)
82 |
83 | li %r3, 0x6F # "o"
84 | stb %r3, 0x1A(%r1)
85 |
86 | li %r3, 0x67 # "g"
87 | stb %r3, 0x1B(%r1)
88 |
89 | li %r3, 0x20 # " "
90 | stb %r3, 0x1C(%r1)
91 |
92 | li %r3, 0x70 # "p"
93 | stb %r3, 0x1D(%r1)
94 |
95 | li %r3, 0x6F # "o"
96 | stb %r3, 0x1E(%r1)
97 |
98 | li %r3, 0x67 # "g"
99 | stb %r3, 0x1F(%r1)
100 |
101 | li %r3, 0x21 # "!"
102 | stb %r3, 0x20(%r1)
103 |
104 | li %r3, 0x0A # "\n"
105 | stb %r3, 0x21(%r1)
106 |
107 | li %r3, 0x00 # ""
108 | stb %r3, 0x22(%r1)
109 |
110 | mr %r3, %r1
111 | li %r0, 0x0
112 | sc
113 |
114 | li %r0, 0x1
115 | sc
116 |
117 | addi %r3, %r3, 0x200
118 | li %r4, 0x69
119 | li %r5, 0x100
120 | bl 0x18 # memset ram+0x200 to 0x69 (check in debugger)
121 |
122 | addi %r1, %r1, 0x30
123 | lwz %r12, -0x8(%r1)
124 | mtlr %r12
125 | blr
126 |
127 | # memset
128 | li %r0, 4
129 | sc
130 | blr
--------------------------------------------------------------------------------
/examples/example_2.asm:
--------------------------------------------------------------------------------
1 | li %r3, 8
2 | li %r4, 6
3 | cmpw %cr4, %r3, %r4
4 | bge %cr4, -0x4
5 | blr
--------------------------------------------------------------------------------
/examples/example_3.asm:
--------------------------------------------------------------------------------
1 | mflr %r12
2 | stw %r12, -0x8(%r1)
3 | stwu %r1, -0x10(%r1)
4 | li %r0, 5
5 | sc
6 | addi %r3, %r3, 0x3C
7 | li %r5, 0x59
8 | mr %r4, %r3
9 | li %r3, 0xFF
10 | li %r0, 6
11 | sc
12 | addi %r1, %r1, 0x10
13 | lwz %r12, -0x8(%r1)
14 | mtlr %r12
15 | blr
16 |
17 | # thread
18 | addi %r3, %r3, 0x10
19 | li %r0, 3
20 | sc
21 | blr
--------------------------------------------------------------------------------