• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H22-Oct-2021-9188

.travis/H22-Oct-2021-194114

CMakeModules/H22-Oct-2021-7361

docs/H22-Oct-2021-3,0222,293

externals/H03-May-2022-135,45099,744

include/dynarmic/H22-Oct-2021-891360

src/H03-May-2022-71,69554,689

tests/H03-May-2022-31,61630,604

.appveyor.ymlH A D22-Oct-2021599 3325

.gitignoreH A D22-Oct-202179 76

.travis.ymlH A D22-Oct-20212.1 KiB8178

README.mdH A D22-Oct-202113.8 KiB353269

README.md

1Dynarmic
2========
3
4[![Travis CI Build Status](https://api.travis-ci.org/MerryMage/dynarmic.svg?branch=master)](https://travis-ci.org/MerryMage/dynarmic/branches) [![Appveyor CI Build status](https://ci.appveyor.com/api/projects/status/maeiqr41rgm1innm/branch/master?svg=true)](https://ci.appveyor.com/project/MerryMage/dynarmic/branch/master)
5
6A dynamic recompiler for ARM.
7
8### Supported guest architectures
9
10* ARMv6K
11* 64-bit ARMv8
12
13### Supported host architectures
14
15* x86-64
16
17There are no plans to support x86-32.
18
19Alternatives to Dynarmic
20------------------------
21
22If you are looking at a recompiler which you can use with minimal effort to run ARM executables on non-native platforms, we would strongly recommend looking at qemu-user-static ([description of qemu-user-static](https://wiki.debian.org/QemuUserEmulation), [using qemu-user-static in combination with Docker to provide a complete emulated environment](https://github.com/multiarch/qemu-user-static)). Having a complete plug-and-play solution is out-of-scope of this project.
23
24Here are some projects with the same goals as dynarmic:
25
26* [ChocolArm64 from Ryujinx](https://github.com/Ryujinx/Ryujinx/tree/master/ChocolArm64) - ARMv8 recompiler on top of RyuJIT
27* [Unicorn](https://www.unicorn-engine.org/) - Recompiling multi-architecture CPU emulator, based on QEMU
28* [SkyEye](http://skyeye.sourceforge.net) - Cached interpreter for ARM
29
30More general alternatives:
31
32* [tARMac](https://davidsharp.com/tarmac/) - Tarmac's use of armlets was initial inspiration for us to use an intermediate representation
33* [QEMU](https://www.qemu.org/) - Recompiling multi-architecture system emulator
34* [VisUAL](https://salmanarif.bitbucket.io/visual/index.html) - Visual ARM UAL emulator intended for education
35* A wide variety of other recompilers, interpreters and emulators can be found embedded in other projects, here are some we would recommend looking at:
36  * [firebird's recompiler](https://github.com/nspire-emus/firebird) - Takes more of a call-threaded approach to recompilation
37  * [higan's arm7tdmi emulator](https://gitlab.com/higan/higan/tree/master/higan/component/processor/arm7tdmi) - Very clean code-style
38  * [arm-js by ozaki-r](https://github.com/ozaki-r/arm-js) - Emulates ARMv7A and some peripherals of Versatile Express, in the browser
39
40Disadvantages of Dynarmic
41-------------------------
42
43In the pursuit of speed, some behavior not commonly depended upon is elided. Therefore this emulator does not match spec.
44
45Known examples:
46
47* Only user-mode is emulated, there is no emulation of any other privilege levels.
48* FPSR state is approximate.
49* Misaligned loads/stores are not appropriately trapped in certain cases.
50* Exclusive monitor behavior may not match any known physical processor.
51
52As with most other hobby ARM emulation projects, no formal verification has been done. Use this code base at your own risk.
53
54Documentation
55-------------
56
57Design documentation can be found at [docs/Design.md](docs/Design.md).
58
59Plans
60-----
61
62### Near-term
63
64* Complete ARMv8 support
65
66### Medium-term
67
68* Optimizations
69
70### Long-term
71
72* ARMv7A guest support
73* ARMv5 guest support
74* ARMv8 host support
75
76Usage Example
77-------------
78
79The below is a minimal example. Bring-your-own memory system.
80
81```cpp
82#include <array>
83#include <cstdint>
84#include <cstdio>
85#include <exception>
86
87#include <dynarmic/A32/a32.h>
88#include <dynarmic/A32/config.h>
89
90using u8 = std::uint8_t;
91using u16 = std::uint16_t;
92using u32 = std::uint32_t;
93using u64 = std::uint64_t;
94
95class MyEnvironment final : public Dynarmic::A32::UserCallbacks {
96public:
97    u64 ticks_left = 0;
98    std::array<u8, 2048> memory{};
99
100    u8 MemoryRead8(u32 vaddr) override {
101        if (vaddr >= memory.size()) {
102            return 0;
103        }
104        return memory[vaddr];
105    }
106
107    u16 MemoryRead16(u32 vaddr) override {
108        return u16(MemoryRead8(vaddr)) | u16(MemoryRead8(vaddr + 1)) << 8;
109    }
110
111    u32 MemoryRead32(u32 vaddr) override {
112        return u32(MemoryRead16(vaddr)) | u32(MemoryRead16(vaddr + 2)) << 16;
113    }
114
115    u64 MemoryRead64(u32 vaddr) override {
116        return u64(MemoryRead32(vaddr)) | u64(MemoryRead32(vaddr + 4)) << 32;
117    }
118
119    void MemoryWrite8(u32 vaddr, u8 value) override {
120        if (vaddr >= memory.size()) {
121            return;
122        }
123        memory[vaddr] = value;
124    }
125
126    void MemoryWrite16(u32 vaddr, u16 value) override {
127        MemoryWrite8(vaddr, u8(value));
128        MemoryWrite8(vaddr + 1, u8(value >> 8));
129    }
130
131    void MemoryWrite32(u32 vaddr, u32 value) override {
132        MemoryWrite16(vaddr, u16(value));
133        MemoryWrite16(vaddr + 2, u16(value >> 16));
134    }
135
136    void MemoryWrite64(u32 vaddr, u64 value) override {
137        MemoryWrite32(vaddr, u32(value));
138        MemoryWrite32(vaddr + 4, u32(value >> 32));
139    }
140
141    void InterpreterFallback(u32 pc, size_t num_instructions) override {
142        // This is never called in practice.
143        std::terminate();
144    }
145
146    void CallSVC(u32 swi) override {
147        // Do something.
148    }
149
150    void ExceptionRaised(u32 pc, Dynarmic::A32::Exception exception) override {
151        // Do something.
152    }
153
154    void AddTicks(u64 ticks) override {
155        if (ticks > ticks_left) {
156            ticks_left = 0;
157            return;
158        }
159        ticks_left -= ticks;
160    }
161
162    u64 GetTicksRemaining() override {
163        return ticks_left;
164    }
165};
166
167int main(int argc, char** argv) {
168    MyEnvironment env;
169    Dynarmic::A32::UserConfig user_config;
170    user_config.callbacks = &env;
171    Dynarmic::A32::Jit cpu{user_config};
172
173    // Execute at least 1 instruction.
174    // (Note: More than one instruction may be executed.)
175    env.ticks_left = 1;
176
177    // Write some code to memory.
178    env.MemoryWrite16(0, 0x0088); // lsls r0, r1, #2
179    env.MemoryWrite16(2, 0xE7FE); // b +#0 (infinite loop)
180
181    // Setup registers.
182    cpu.Regs()[0] = 1;
183    cpu.Regs()[1] = 2;
184    cpu.Regs()[15] = 0; // PC = 0
185    cpu.SetCpsr(0x00000030); // Thumb mode
186
187    // Execute!
188    cpu.Run();
189
190    // Here we would expect cpu.Regs()[0] == 8
191    printf("R0: %u\n", cpu.Regs()[0]);
192
193    return 0;
194}
195```
196
197Legal
198-----
199
200dynarmic is under a 0BSD license. See LICENSE.txt for more details.
201
202dynarmic uses several other libraries, whose licenes are included below:
203
204### catch
205
206```
207Boost Software License - Version 1.0 - August 17th, 2003
208
209Permission is hereby granted, free of charge, to any person or organization
210obtaining a copy of the software and accompanying documentation covered by
211this license (the "Software") to use, reproduce, display, distribute,
212execute, and transmit the Software, and to prepare derivative works of the
213Software, and to permit third-parties to whom the Software is furnished to
214do so, all subject to the following:
215
216The copyright notices in the Software and this entire statement, including
217the above license grant, this restriction and the following disclaimer,
218must be included in all copies of the Software, in whole or in part, and
219all derivative works of the Software, unless such copies or derivative
220works are solely in the form of machine-executable object code generated by
221a source language processor.
222
223THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
224IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
225FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
226SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
227FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
228ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
229DEALINGS IN THE SOFTWARE.
230```
231
232### fmt
233
234```
235Copyright (c) 2012 - 2016, Victor Zverovich
236
237All rights reserved.
238
239Redistribution and use in source and binary forms, with or without
240modification, are permitted provided that the following conditions are met:
241
2421. Redistributions of source code must retain the above copyright notice, this
243   list of conditions and the following disclaimer.
2442. Redistributions in binary form must reproduce the above copyright notice,
245   this list of conditions and the following disclaimer in the documentation
246   and/or other materials provided with the distribution.
247
248THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
249ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
250WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
251DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
252ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
253(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
254LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
255ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
257SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
258```
259
260### mp
261
262```
263Copyright (C) 2017 MerryMage
264
265Permission to use, copy, modify, and/or distribute this software for
266any purpose with or without fee is hereby granted.
267
268THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
269WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
270MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
271ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
272WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
273AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
274OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
275```
276
277### robin-map
278
279```
280MIT License
281
282Copyright (c) 2017 Thibaut Goetghebuer-Planchon <tessil@gmx.com>
283
284Permission is hereby granted, free of charge, to any person obtaining a copy
285of this software and associated documentation files (the "Software"), to deal
286in the Software without restriction, including without limitation the rights
287to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
288copies of the Software, and to permit persons to whom the Software is
289furnished to do so, subject to the following conditions:
290
291The above copyright notice and this permission notice shall be included in all
292copies or substantial portions of the Software.
293
294THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
295IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
296FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
297AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
298LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
299OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
300SOFTWARE.
301```
302
303### xbyak
304
305```
306Copyright (c) 2007 MITSUNARI Shigeo
307All rights reserved.
308
309Redistribution and use in source and binary forms, with or without
310modification, are permitted provided that the following conditions are met:
311
312Redistributions of source code must retain the above copyright notice, this
313list of conditions and the following disclaimer.
314Redistributions in binary form must reproduce the above copyright notice,
315this list of conditions and the following disclaimer in the documentation
316and/or other materials provided with the distribution.
317Neither the name of the copyright owner nor the names of its contributors may
318be used to endorse or promote products derived from this software without
319specific prior written permission.
320
321THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
322AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
323IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
324ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
325LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
326CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
327SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
328INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
329CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
330ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
331THE POSSIBILITY OF SUCH DAMAGE.
332-----------------------------------------------------------------------------
333ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満た
334す場合に限り、再頒布および使用が許可されます。
335
336ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項
337を含めること。
338バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作
339権表示、本条件一覧、および下記免責条項を含めること。
340書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進
341に、著作権者の名前またはコントリビューターの名前を使用してはならない。
342本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供さ
343れており、明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性
344に関する暗黙の保証も含め、またそれに限定されない、いかなる保証もありません。
345著作権者もコントリビューターも、事由のいかんを問わず、 損害発生の原因いかんを
346問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その他の)不法行為で
347あるかを問わず、仮にそのような損害が発生する可能性を知らされていたとしても、
348本ソフトウェアの使用によって発生した(代替品または代用サービスの調達、使用の
349喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定されない)直接
350損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害について、
351一切責任を負わないものとします。
352```
353