├── CMakeLists.txt ├── LICENSE ├── Makefile ├── Makefile.common ├── README.md ├── deps └── virt86 │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README.md │ ├── apps │ ├── CMakeLists.txt │ └── platform-check │ │ ├── CMakeLists.txt │ │ └── src │ │ ├── main.cpp │ │ ├── pch.cpp │ │ └── pch.hpp │ ├── appveyor.yml │ ├── bintray.json │ ├── cmake │ ├── PrecompiledHeader.cmake │ └── VSHelpers.cmake │ └── modules │ ├── CMakeLists.txt │ ├── core │ ├── CMakeLists.txt │ ├── cmake │ │ └── Config.cmake.in │ ├── include │ │ └── virt86 │ │ │ ├── platform │ │ │ ├── features.hpp │ │ │ └── platform.hpp │ │ │ ├── util │ │ │ ├── bitmask_enum.hpp │ │ │ ├── bytemanip.hpp │ │ │ └── host_info.hpp │ │ │ ├── vm │ │ │ ├── io.hpp │ │ │ ├── mem.hpp │ │ │ ├── specs.hpp │ │ │ ├── status.hpp │ │ │ └── vm.hpp │ │ │ └── vp │ │ │ ├── cpuid.hpp │ │ │ ├── exception.hpp │ │ │ ├── fpregs.hpp │ │ │ ├── gdt.hpp │ │ │ ├── hwbp.hpp │ │ │ ├── idt.hpp │ │ │ ├── mode.hpp │ │ │ ├── paging.hpp │ │ │ ├── regs.hpp │ │ │ ├── status.hpp │ │ │ └── vp.hpp │ └── src │ │ ├── pch.cpp │ │ ├── pch.hpp │ │ ├── platform │ │ └── platform.cpp │ │ ├── util │ │ └── host_info.cpp │ │ ├── vm │ │ └── vm.cpp │ │ └── vp │ │ ├── gdt.cpp │ │ ├── idt.cpp │ │ └── vp.cpp │ ├── haxm │ ├── CMakeLists.txt │ ├── cmake │ │ └── Config.cmake.in │ ├── include │ │ └── virt86 │ │ │ └── haxm │ │ │ └── haxm_platform.hpp │ └── src │ │ ├── common │ │ ├── haxm_helpers.cpp │ │ ├── haxm_helpers.hpp │ │ ├── haxm_platform.cpp │ │ ├── haxm_platform_impl.cpp │ │ ├── haxm_platform_impl.hpp │ │ ├── haxm_version.hpp │ │ ├── haxm_vm.cpp │ │ ├── haxm_vm.hpp │ │ ├── haxm_vp.cpp │ │ ├── haxm_vp.hpp │ │ ├── interface │ │ │ ├── darwin │ │ │ │ ├── hax_interface_mac.hpp │ │ │ │ └── hax_types_mac.hpp │ │ │ ├── hax_interface.hpp │ │ │ ├── hax_types.hpp │ │ │ ├── linux │ │ │ │ ├── hax_interface_linux.hpp │ │ │ │ └── hax_types_linux.hpp │ │ │ ├── vcpu_state.hpp │ │ │ └── windows │ │ │ │ ├── hax_interface_windows.hpp │ │ │ │ └── hax_types_windows.hpp │ │ ├── pch.cpp │ │ └── pch.hpp │ │ ├── darwin │ │ ├── haxm_sys_platform.cpp │ │ ├── haxm_sys_platform.hpp │ │ ├── haxm_sys_vm.cpp │ │ ├── haxm_sys_vm.hpp │ │ ├── haxm_sys_vp.cpp │ │ └── haxm_sys_vp.hpp │ │ ├── linux │ │ ├── haxm_sys_platform.cpp │ │ ├── haxm_sys_platform.hpp │ │ ├── haxm_sys_vm.cpp │ │ ├── haxm_sys_vm.hpp │ │ ├── haxm_sys_vp.cpp │ │ └── haxm_sys_vp.hpp │ │ └── windows │ │ ├── haxm_sys_platform.cpp │ │ ├── haxm_sys_platform.hpp │ │ ├── haxm_sys_vm.cpp │ │ ├── haxm_sys_vm.hpp │ │ ├── haxm_sys_vp.cpp │ │ └── haxm_sys_vp.hpp │ ├── hvf │ ├── CMakeLists.txt │ ├── cmake │ │ └── Config.cmake.in │ ├── include │ │ └── virt86 │ │ │ └── hvf │ │ │ └── hvf_platform.hpp │ └── src │ │ ├── hvf_platform.cpp │ │ ├── hvf_vm.cpp │ │ ├── hvf_vm.hpp │ │ ├── hvf_vp.cpp │ │ ├── hvf_vp.hpp │ │ ├── pch.cpp │ │ └── pch.hpp │ ├── kvm │ ├── CMakeLists.txt │ ├── cmake │ │ └── Config.cmake.in │ ├── include │ │ └── virt86 │ │ │ └── kvm │ │ │ └── kvm_platform.hpp │ └── src │ │ ├── kvm_helpers.cpp │ │ ├── kvm_helpers.hpp │ │ ├── kvm_platform.cpp │ │ ├── kvm_vm.cpp │ │ ├── kvm_vm.hpp │ │ ├── kvm_vp.cpp │ │ ├── kvm_vp.hpp │ │ ├── pch.cpp │ │ └── pch.hpp │ ├── sys │ ├── darwin │ │ ├── CMakeLists.txt │ │ ├── cmake │ │ │ └── Config.cmake.in │ │ ├── include │ │ │ └── virt86 │ │ │ │ └── sys │ │ │ │ └── darwin │ │ │ │ └── kext.hpp │ │ └── src │ │ │ └── kext.cpp │ ├── linux │ │ ├── CMakeLists.txt │ │ ├── cmake │ │ │ └── Config.cmake.in │ │ ├── include │ │ │ └── virt86 │ │ │ │ └── sys │ │ │ │ └── linux │ │ │ │ ├── Elf.h │ │ │ │ └── util.h │ │ └── src │ │ │ ├── Elf.cpp │ │ │ └── util.cpp │ └── windows │ │ ├── CMakeLists.txt │ │ ├── cmake │ │ └── Config.cmake.in │ │ ├── include │ │ └── virt86 │ │ │ └── sys │ │ │ └── windows │ │ │ └── version_info.hpp │ │ └── src │ │ ├── pch.cpp │ │ ├── pch.hpp │ │ └── version_info.cpp │ ├── virt86 │ ├── CMakeLists.txt │ ├── cmake │ │ └── Config.cmake.in │ ├── include │ │ └── virt86 │ │ │ └── virt86.hpp │ └── src │ │ └── lib.cpp │ └── whpx │ ├── CMakeLists.txt │ ├── cmake │ └── Config.cmake.in │ ├── include │ └── virt86 │ │ └── whpx │ │ └── whpx_platform.hpp │ └── src │ ├── pch.cpp │ ├── pch.hpp │ ├── whpx_defs.hpp │ ├── whpx_dispatch.cpp │ ├── whpx_dispatch.hpp │ ├── whpx_platform.cpp │ ├── whpx_regs.cpp │ ├── whpx_regs.hpp │ ├── whpx_vm.cpp │ ├── whpx_vm.hpp │ ├── whpx_vp.cpp │ └── whpx_vp.hpp ├── docs └── cromwell.png ├── link.T └── src ├── CMakeLists.txt ├── devices ├── ata │ ├── ata_controller.cpp │ └── ata_controller.h ├── audio │ ├── ac97 │ │ ├── ac97.cpp │ │ └── ac97.h │ └── mcpx │ │ ├── mcpx_apu.cpp │ │ └── mcpx_apu.h ├── eeprom.cpp ├── eeprom.h ├── i8254.cpp ├── i8254.h ├── i8259.cpp ├── i8259.h ├── pci │ ├── agp_bridge.cpp │ ├── agp_bridge.h │ ├── host_bridge.cpp │ ├── host_bridge.h │ ├── pci.cpp │ ├── pci.h │ ├── pci_bridge.cpp │ ├── pci_bridge.h │ ├── pci_bus.cpp │ ├── pci_bus.h │ └── pci_regs.h ├── smbus.cpp ├── smbus.h ├── smbus_device.h ├── smc.cpp ├── smc.h └── video │ ├── nv2a │ ├── component.h │ ├── nv2a.cpp │ ├── nv2a.h │ ├── pbus.cpp │ ├── pbus.h │ ├── pcounter.cpp │ ├── pcounter.h │ ├── pcrtc.cpp │ ├── pcrtc.h │ ├── pfb.cpp │ ├── pfb.h │ ├── pfifo.cpp │ ├── pfifo.h │ ├── pgraph.cpp │ ├── pgraph.h │ ├── pmc.cpp │ ├── pmc.h │ ├── pramdac.cpp │ ├── pramdac.h │ ├── pramin.cpp │ ├── pramin.h │ ├── prma.cpp │ ├── prma.h │ ├── prmcio.cpp │ ├── prmcio.h │ ├── prmdio.cpp │ ├── prmdio.h │ ├── prmfb.cpp │ ├── prmfb.h │ ├── prmvio.cpp │ ├── prmvio.h │ ├── pstraps.cpp │ ├── pstraps.h │ ├── ptimer.cpp │ ├── ptimer.h │ ├── ptv.cpp │ ├── ptv.h │ ├── pvideo.cpp │ ├── pvideo.h │ ├── pvpe.cpp │ ├── pvpe.h │ ├── regs.h │ ├── user.cpp │ └── user.h │ └── tv │ ├── conexant.cpp │ └── conexant.h ├── libretro ├── libretro.cpp ├── libretro.h ├── libretro_core_options.h ├── libretro_core_options_intl.h └── retro_inline.h ├── util.h ├── xbox.cpp ├── xbox.h ├── xbox_database.cpp └── xbox_database.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") 3 | 4 | project(libretro-xbox) 5 | 6 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib) 7 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) 8 | 9 | enable_language(CXX) 10 | set(CMAKE_CXX_STANDARD 17) 11 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 12 | set(CMAKE_CXX_EXTENSIONS OFF) 13 | 14 | add_subdirectory(src) 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DirectXbox is an experimental work-in-progress XBox OG emulator, written from the ground up for Libretro. 2 | 3 | Currently requires the following BIOS images to be placed in the System directory: 4 | * mcpx_1.0.bin 5 | * cromwell_1024.bin 6 | 7 | # Supported platforms 8 | We currently are supporting only two platforms. We might be expanding our scope of supported platforms in the near future. 9 | * Windows 10 | * Linux 11 | 12 | # Requirements/dependencies: 13 | * Libvirt86 14 | 15 | # License 16 | GPL v2+ 17 | 18 | # How to compile 19 | Originally it was supposed to be built with CMake. 20 | 21 | However, static Makefiles have been written now, and they have been tested to compile and link on Windows and Linux. To use them, just type make in the root directory. Once complete, it will create a file called 'directxbox_libretro.{extensionname}. 22 | 23 | # Status 24 | + PCI/ISA/SMBUS devices are partially implemented 25 | + Enough of the GPU is implemented for direct framebuffer access to work 26 | - Microsoft BIOS doesn't boot yet because ATA & OCHI are missing 27 | - No hardware acceleration support yet (software rendering for now) 28 | 29 | # Compatibility 30 | Not much for now. Cromwell BIOS can boot, homebrew that theoretically only relies on basic framebuffer mode could theoretically work already. 31 | 32 | Cromwell BIOS can only boot images, but not games. 33 | 34 | Microsoft BIOS doesn't work yet (too much hardware that isn't implemented yet like ATA & OCHI) 35 | 36 | ![Cromwell](docs/cromwell.png) 37 | 38 | # Looking for contributors 39 | We are looking for contributors who would be interested in helping us carry this over the finish line. Some of the goals we are pursuing: 40 | * Ability to boot Microsoft BIOS 41 | * Commercial game compatibility 42 | * Audio implemented 43 | * OpenGL/Vulkan renderers 44 | 45 | If there's some particular thing of interest that is not addressed by the above that you'd still like to explore, don't hesitate to contact us. We can be contacted at libretro@gmail.com 46 | -------------------------------------------------------------------------------- /deps/virt86/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Top-level CMake project definitions. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | # CMake 3.12 is required for target_link_libraries with OBJECT libraries 26 | cmake_minimum_required(VERSION 3.12) 27 | 28 | project(virt86 VERSION 1.2.0) 29 | 30 | # Differentiate between Linux and macOS 31 | if(UNIX AND NOT APPLE) 32 | set(LINUX TRUE) 33 | endif() 34 | 35 | # Define properties and include helpers for Visual Studio 36 | if(MSVC) 37 | include(cmake/VSHelpers.cmake) 38 | 39 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 40 | 41 | # Configure startup project 42 | set_property(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" PROPERTY VS_STARTUP_PROJECT virt86-platform-check) 43 | endif() 44 | 45 | include(cmake/PrecompiledHeader.cmake) 46 | include(GNUInstallDirs) 47 | 48 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") 49 | 50 | # Require C++17 features 51 | set(CMAKE_CXX_STANDARD 17) 52 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 53 | set(CMAKE_CXX_EXTENSIONS ON) 54 | 55 | # Add modules and apps 56 | add_subdirectory(modules) 57 | add_subdirectory(apps) 58 | -------------------------------------------------------------------------------- /deps/virt86/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ivan Roberto de Oliveira 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /deps/virt86/apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Includes all virt86 applications. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | # Add apps 26 | add_subdirectory(platform-check) 27 | -------------------------------------------------------------------------------- /deps/virt86/apps/platform-check/src/pch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is required by Visual Studio in order to compile pch.hpp. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "pch.hpp" 27 | -------------------------------------------------------------------------------- /deps/virt86/apps/platform-check/src/pch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Precompiled header for the Platform Checker application. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include 27 | #include 28 | 29 | #ifdef _WIN32 30 | # include 31 | #endif 32 | 33 | #include "virt86/virt86.hpp" 34 | -------------------------------------------------------------------------------- /deps/virt86/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '1.2.0-b{build}' 2 | 3 | branches: 4 | only: 5 | - master 6 | - /v\d+\.\d+\.\d+/ 7 | 8 | #only_commits: 9 | # files: 10 | # - CMakeLists.txt 11 | # - appveyor.yml 12 | # - modules/ 13 | # - apps/ 14 | # - cmake/ 15 | 16 | image: 17 | - Visual Studio 2017 18 | 19 | configuration: 20 | - Release 21 | - Debug 22 | 23 | platform: 24 | - x86 25 | - x64 26 | 27 | matrix: 28 | fast_finish: true 29 | 30 | clone_folder: c:\projects\virt86 31 | 32 | init: 33 | - set ARCH= 34 | - if "%PLATFORM%"=="x64" (set ARCH= Win64) 35 | - echo %ARCH% 36 | - echo %APPVEYOR_BUILD_WORKER_IMAGE% 37 | - set generator="Visual Studio 15 2017%ARCH%" 38 | - echo CMake generator = %GENERATOR% 39 | - set VIRT86_ARTIFACT_PATH=C:\projects\virt86\build\_artifact\virt86-MSVC-%PLATFORM%-%CONFIGURATION% 40 | - echo virt86 artifact path = %VIRT86_ARTIFACT_PATH% 41 | 42 | before_build: 43 | - cmd: |- 44 | mkdir build 45 | cd build 46 | mkdir %VIRT86_ARTIFACT_PATH% 47 | cmake --version 48 | cmake .. -G %GENERATOR% -DCMAKE_INSTALL_PREFIX=%VIRT86_ARTIFACT_PATH% -DCMAKE_SYSTEM_VERSION=10.0.17763.0 49 | copy c:\projects\virt86\README.md %VIRT86_ARTIFACT_PATH% 50 | copy c:\projects\virt86\LICENSE %VIRT86_ARTIFACT_PATH% 51 | 52 | build: 53 | project: c:\projects\virt86\build\INSTALL.vcxproj 54 | verbosity: minimal 55 | parallel: true 56 | 57 | # Manually push artifacts in order to add the version to the filename 58 | after_test: 59 | - ps: |- 60 | function ZipFiles($zipfilename, $sourcedir) 61 | { 62 | [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") 63 | $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal 64 | [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, $compressionLevel, $false) 65 | } 66 | $binPath = "$($env:VIRT86_ARTIFACT_PATH)" 67 | if ($($env:APPVEYOR_REPO_TAG) -eq "true") { 68 | $tagName = $env:APPVEYOR_REPO_TAG_NAME 69 | $tagName = $tagName.Remove(0, 1) 70 | $zipName = "virt86-$($tagName)-Windows-MSVC-$($env:PLATFORM)-$($env:CONFIGURATION).zip" 71 | } else { 72 | $zipName = "virt86-$($env:APPVEYOR_BUILD_VERSION)-Windows-MSVC-$($env:PLATFORM)-$($env:CONFIGURATION).zip" 73 | } 74 | $zipFullPath = "$($binPath)$($zipName)" 75 | ZipFiles "$($zipFullPath)" "$($binPath)" | Out-Null 76 | Push-AppveyorArtifact "$($zipFullPath)" -FileName $zipName 77 | 78 | deploy: 79 | - provider: BinTray 80 | username: strikerx3 81 | api_key: 82 | secure: MBloC3yYRMJJW4YwiQr15SO89uaxGb0o1BmE0NL0AyfHnSNVr79pBH45CloK9arG 83 | subject: strikerx3 84 | repo: virt86 85 | package: virt86 86 | version: 1.2.0 87 | publish: true 88 | override: true 89 | explode: false 90 | -------------------------------------------------------------------------------- /deps/virt86/bintray.json: -------------------------------------------------------------------------------- 1 | { 2 | "package": { 3 | "name": "virt86", 4 | "repo": "virt86", 5 | "subject": "strikerx3", 6 | "vcs_url": "https://github.com/StrikerX3/virt86.git", 7 | "github_use_tag_release_notes": false, 8 | "licenses": ["MIT"], 9 | "public_download_numbers": false, 10 | "public_stats": false 11 | }, 12 | 13 | "version": { 14 | "name": "1.2.0", 15 | "desc": "virt86 1.2.0", 16 | "released": "2019-06-15", 17 | "vcs_tag": "v1.2.0", 18 | "attributes": [], 19 | "gpgSign": false 20 | }, 21 | 22 | "files": [ 23 | { 24 | "includePattern": "build/(virt86-.*.tar.gz)", 25 | "uploadPattern": "$1", 26 | "matrixParams": { 27 | "override": 1 28 | } 29 | } 30 | ], 31 | 32 | "publish": true 33 | } 34 | -------------------------------------------------------------------------------- /deps/virt86/cmake/VSHelpers.cmake: -------------------------------------------------------------------------------- 1 | # Add Visual Studio filters to better organize the code 2 | function(vs_set_filters) 3 | cmake_parse_arguments(VS_SET_FILTERS "" "FILTER_ROOT;BASE_DIR" "SOURCES" ${ARGN}) 4 | if(MSVC) 5 | foreach(FILE IN ITEMS ${VS_SET_FILTERS_SOURCES}) 6 | # Get the directory of the source file 7 | get_filename_component(PARENT_DIR "${FILE}" DIRECTORY) 8 | 9 | # Remove common directory prefix to make the group 10 | if(BASE_DIR STREQUAL "") 11 | string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" GROUP "${PARENT_DIR}") 12 | else() 13 | string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/${VS_SET_FILTERS_BASE_DIR}" "" GROUP "${PARENT_DIR}") 14 | endif() 15 | 16 | # Use Windows path separators 17 | string(REPLACE "/" "\\" GROUP "${GROUP}") 18 | 19 | # Add to filter 20 | source_group("${VS_SET_FILTERS_FILTER_ROOT}${GROUP}" FILES "${FILE}") 21 | endforeach() 22 | endif() 23 | endfunction() 24 | 25 | # Make the Debug and RelWithDebInfo targets use Program Database for Edit and Continue for easier debugging 26 | function(vs_use_edit_and_continue) 27 | if(MSVC) 28 | string(REPLACE "/Zi" "/ZI" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") 29 | string(REPLACE "/Zi" "/ZI" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") 30 | set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} PARENT_SCOPE) 31 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} PARENT_SCOPE) 32 | endif() 33 | endfunction() 34 | -------------------------------------------------------------------------------- /deps/virt86/modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Includes all virt86 modules. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | # Add modules 26 | add_subdirectory(core) 27 | 28 | if(WIN32) 29 | add_subdirectory(sys/windows) 30 | add_subdirectory(haxm) 31 | add_subdirectory(whpx) 32 | elseif(LINUX) 33 | add_subdirectory(sys/linux) 34 | add_subdirectory(haxm) 35 | add_subdirectory(kvm) 36 | elseif(APPLE) 37 | add_subdirectory(sys/darwin) 38 | add_subdirectory(haxm) 39 | # TODO: Add support for Hypervisor.Framework 40 | #add_subdirectory(hvf) 41 | endif() 42 | 43 | add_subdirectory(virt86) 44 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 27 | check_required_components("@PROJECT_NAME@") 28 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/util/bytemanip.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Byte manipulation routines. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include 29 | 30 | namespace virt86 { 31 | 32 | inline uint64_t SetLowByte(uint64_t lhs, uint8_t rhs) noexcept { 33 | return (lhs & 0xFFFFFFFF'FFFFFF00) | rhs; 34 | } 35 | 36 | inline uint64_t SetHighByte(uint64_t lhs, uint8_t rhs) noexcept { 37 | return (lhs & 0xFFFFFFFF'FFFF00FF) | ((uint64_t)rhs << 8ull); 38 | } 39 | 40 | inline uint64_t SetLowWord(uint64_t lhs, uint16_t rhs) noexcept { 41 | return (lhs & 0xFFFFFFFF'FFFF0000) | rhs; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/util/host_info.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Host information. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include 29 | 30 | #include "virt86/platform/features.hpp" 31 | 32 | namespace virt86 { 33 | 34 | /** 35 | * Information about the host environment. 36 | */ 37 | struct HostInfo { 38 | /** 39 | * Maximum extent of Guest Physical Addresses supported by the host. 40 | */ 41 | struct GPA { 42 | const uint8_t maxBits; 43 | const uint64_t maxAddress; 44 | const uint64_t mask; 45 | 46 | GPA() noexcept; 47 | } gpa; 48 | 49 | const FloatingPointExtension floatingPointExtensions; 50 | 51 | HostInfo() noexcept; 52 | }; 53 | 54 | /** 55 | * Global instance of the host information structure. 56 | */ 57 | inline struct HostInfo HostInfo; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/vm/io.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Specifies I/O callback function types. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | namespace virt86 { 32 | 33 | using IOReadFunc_t = uint32_t(*)(void *context, uint16_t port, size_t size); 34 | using IOWriteFunc_t = void(*)(void *context, uint16_t port, size_t size, uint32_t value); 35 | 36 | using MMIOReadFunc_t = uint64_t(*)(void *context, uint64_t address, size_t size); 37 | using MMIOWriteFunc_t = void(*)(void *context, uint64_t address, size_t size, uint64_t value); 38 | 39 | struct IOHandlers { 40 | IOReadFunc_t IOReadFunc; 41 | IOWriteFunc_t IOWriteFunc; 42 | 43 | MMIOReadFunc_t MMIOReadFunc; 44 | MMIOWriteFunc_t MMIOWriteFunc; 45 | 46 | uint32_t IORead(uint16_t port, size_t size) const noexcept { return IOReadFunc(context, port, size); } 47 | void IOWrite(uint16_t port, size_t size, uint32_t value) const noexcept { return IOWriteFunc(context, port, size, value); } 48 | 49 | uint64_t MMIORead(uint64_t address, size_t size) const noexcept { return MMIOReadFunc(context, address, size); } 50 | void MMIOWrite(uint64_t address, size_t size, uint64_t value) const noexcept { return MMIOWriteFunc(context, address, size, value); } 51 | 52 | void *context; 53 | }; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/vm/mem.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Specifies data structures related to memory mapping. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/util/bitmask_enum.hpp" 29 | 30 | #include 31 | 32 | namespace virt86 { 33 | 34 | // Flags for memory operations 35 | enum class MemoryFlags : uint32_t { 36 | None = 0, 37 | Read = (1 << 0), 38 | Write = (1 << 1), 39 | Execute = (1 << 2), 40 | DirtyPageTracking = (1 << 3), 41 | }; 42 | 43 | struct MemoryRegion { 44 | uint64_t baseAddress = 0; 45 | uint64_t size = 0; 46 | void *hostMemory = nullptr; 47 | 48 | MemoryRegion() = default; 49 | 50 | MemoryRegion(uint64_t baseAddress, uint64_t size, void *hostMemory) noexcept 51 | : baseAddress(baseAddress) 52 | , size(size) 53 | , hostMemory(hostMemory) 54 | {} 55 | }; 56 | 57 | } 58 | 59 | ENABLE_BITMASK_OPERATORS(virt86::MemoryFlags) 60 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/vm/specs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Defines virtual machine specifications to be used when creating a virtual 3 | machine through a Platform instance. 4 | 5 | Features not supported by a platform are ignored. 6 | ------------------------------------------------------------------------------- 7 | MIT License 8 | 9 | Copyright (c) 2019 Ivan Roberto de Oliveira 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. 28 | */ 29 | #pragma once 30 | 31 | #include "virt86/platform/features.hpp" 32 | #include "virt86/vp/cpuid.hpp" 33 | 34 | #include 35 | 36 | namespace virt86 { 37 | 38 | /** 39 | * Virtual machine specifications. 40 | */ 41 | struct VMSpecifications { 42 | /** 43 | * The number of virtual processors to create in the virtual machine. 44 | * Must be a positive number. 45 | */ 46 | size_t numProcessors; 47 | 48 | /** 49 | * The set of extended VM exits to enable in the virtual machine. 50 | */ 51 | ExtendedVMExit extendedVMExits; 52 | 53 | /** 54 | * CPUID functions to trigger a VM exit when exit on CPUID instruction is 55 | * enabled. 56 | */ 57 | std::vector vmExitCPUIDFunctions; 58 | 59 | /** 60 | * Exception codes to trigger a VM exit when exit on exceptions is enabled. 61 | */ 62 | ExceptionCode vmExitExceptions; 63 | 64 | /** 65 | * Custom CPUID results to generate. 66 | */ 67 | std::vector CPUIDResults; 68 | 69 | /** 70 | * Guest TSC frequency to use. A value of zero means no adjustment. 71 | */ 72 | uint64_t guestTSCFrequency; 73 | 74 | /** 75 | * KVM-specific parameters. Ignored by all other platforms. 76 | */ 77 | struct { 78 | /** 79 | * Specifies the base address of the identity map page, used with the 80 | * KVM_SET_IDENTITY_MAP_ADDR ioctl. If set to zero, assumes the default 81 | * value of 0xfffbc000. 82 | */ 83 | uint32_t identityMapPageAddress = 0xfffbc000; 84 | } kvm; 85 | }; 86 | 87 | } 88 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/vp/cpuid.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Defines data structures for CPUID. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include 29 | 30 | namespace virt86 { 31 | 32 | struct CPUIDResult { 33 | uint32_t function; 34 | uint32_t eax, ebx, ecx, edx; 35 | 36 | CPUIDResult() = default; 37 | CPUIDResult(uint32_t function, uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx) noexcept 38 | : function(function) 39 | , eax(eax) 40 | , ebx(ebx) 41 | , ecx(ecx) 42 | , edx(edx) 43 | {} 44 | }; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/vp/exception.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Defines the set of x86 exceptions that may be raised by the virtual processor. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/util/bitmask_enum.hpp" 29 | 30 | #include 31 | 32 | namespace virt86 { 33 | 34 | enum class ExceptionCode : uint64_t { 35 | None = 0, 36 | 37 | DivideErrorFault = (1 << 0), 38 | DebugTrapOrFault = (1 << 1), 39 | BreakpointTrap = (1 << 3), 40 | OverflowTrap = (1 << 4), 41 | BoundRangeFault = (1 << 5), 42 | InvalidOpcodeFault = (1 << 6), 43 | DeviceNotAvailableFault = (1 << 7), 44 | DoubleFaultAbort = (1 << 8), 45 | InvalidTaskStateSegmentFault = (1 << 10), 46 | SegmentNotPresentFault = (1 << 11), 47 | StackFault = (1 << 12), 48 | GeneralProtectionFault = (1 << 13), 49 | PageFault = (1 << 14), 50 | FloatingPointErrorFault = (1 << 16), 51 | AlignmentCheckFault = (1 << 17), 52 | MachineCheckAbort = (1 << 18), 53 | SimdFloatingPointFault = (1 << 19), 54 | 55 | All = (1 << 20) - 1, 56 | }; 57 | 58 | } 59 | 60 | ENABLE_BITMASK_OPERATORS(virt86::ExceptionCode) 61 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/vp/hwbp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Defines data structures for dealing with hardware breakpoints. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "regs.hpp" 29 | 30 | namespace virt86 { 31 | 32 | enum class HardwareBreakpointTrigger : uint8_t { 33 | Execution = DR7_COND_EXEC, // Breakpoint triggered when code at the specified address is executed 34 | DataWrite = DR7_COND_WRITE, // Breakpoint triggered when data is written to the specified address 35 | Width8 = DR7_COND_WIDTH8, // Indicates that the breakpoint is 8 bytes wide 36 | DataReadWrite = DR7_COND_READWRITE, // Breakpoint triggered when data is read from or written to the specified address 37 | }; 38 | 39 | enum class HardwareBreakpointLength : uint8_t { 40 | Byte = DR7_SIZE_BYTE, // Breakpoint is 1 byte wide 41 | Word = DR7_SIZE_WORD, // Breakpoint is 2 bytes wide 42 | Qword = DR7_SIZE_QWORD, // Breakpoint is 8 bytes wide 43 | Dword = DR7_SIZE_DWORD, // Breakpoint is 4 bytes wide 44 | }; 45 | 46 | struct HardwareBreakpoints { 47 | struct { 48 | uint64_t address; 49 | bool localEnable; 50 | bool globalEnable; 51 | HardwareBreakpointTrigger trigger; 52 | HardwareBreakpointLength length; 53 | } bp[4]; 54 | }; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/vp/idt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Defines the Interrupt Descriptor Table data structure. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include 29 | 30 | namespace virt86 { 31 | 32 | enum class IDTType : uint8_t { 33 | Null00 = 0x0, 34 | Task32 = 0x5, 35 | Intr32 = 0xE, 36 | Trap32 = 0xF, 37 | }; 38 | 39 | struct IDTEntry { 40 | union { 41 | struct { 42 | uint16_t offsetLow : 16; 43 | uint16_t selector: 16; 44 | uint8_t zero : 8; 45 | uint8_t type : 4; 46 | uint8_t storageSegment : 1; 47 | uint8_t privilegeLevel : 2; 48 | uint8_t present : 1; 49 | uint16_t offsetHigh : 16; 50 | } data; 51 | uint64_t descriptor; 52 | }; 53 | 54 | void Set(uint32_t offset, uint16_t selector, IDTType type, uint8_t attributes) noexcept; 55 | 56 | uint32_t GetOffset() noexcept; 57 | void SetOffset(uint32_t offset) noexcept; 58 | }; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/include/virt86/vp/mode.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Defines enumerations of CPU modes. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | namespace virt86 { 29 | 30 | /** 31 | * The CPU execution mode, based on CR0.PE, RFLAGS.VM and EFER.LMA. 32 | */ 33 | enum class CPUExecutionMode { 34 | Unknown, 35 | 36 | RealAddress, // Real-address mode (CR0.PE = 0) 37 | Virtual8086, // Virtual-8086 mode (CR0.PE = 1, RFLAGS.VM = 1) 38 | Protected, // Protected mode (CR0.PE = 1, RFLAGS.VM = 0, EFER.LMA = 0) 39 | IA32e, // IA-32e mode (CR0.PE = 1, RFLAGS.VM = 0, EFER.LMA = 1) 40 | }; 41 | 42 | /** 43 | * The CPU paging mode, based on CR0.PG, CR4.PAE and EFER.LME. 44 | */ 45 | enum class CPUPagingMode { 46 | Unknown, 47 | Invalid, // Invalid paging mode (CR0.PG = 1, CR4.PAE = 0, EFER.LME = 1) 48 | 49 | None, // No paging (CR0.PG = 0, CR4.PAE = 0, EFER.LME = 0) 50 | NoneLME, // No paging (LME enabled) (CR0.PG = 0, CR4.PAE = 0, EFER.LME = 1) 51 | NonePAE, // No paging (PAE enabled) (CR0.PG = 0, CR4.PAE = 1, EFER.LME = 0) 52 | NonePAEandLME, // No paging (PAE and LME enabled) (CR0.PG = 0, CR4.PAE = 1, EFER.LME = 1) 53 | ThirtyTwoBit, // 32-bit paging (CR0.PG = 1, CR4.PAE = 0, EFER.LME = 0) 54 | PAE, // PAE paging (CR0.PG = 1, CR4.PAE = 1, EFER.LME = 0) 55 | FourLevel, // 4-level paging (CR0.PG = 1, CR4.PAE = 1, EFER.LME = 1) 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/src/pch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is required by Visual Studio in order to compile pch.hpp. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "pch.hpp" 27 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/src/pch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Precompiled header for the virt86 core project. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "virt86/platform/platform.hpp" 36 | #include "virt86/vm/vm.hpp" 37 | #include "virt86/vp/vp.hpp" 38 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/src/platform/platform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Base implementation of the Platform interface. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "virt86/platform/platform.hpp" 27 | 28 | namespace virt86 { 29 | 30 | Platform::Platform(const char *name) noexcept 31 | : m_name(name) 32 | , m_initStatus(PlatformInitStatus::Uninitialized) 33 | { 34 | } 35 | 36 | Platform::~Platform() noexcept { 37 | } 38 | 39 | const std::optional> Platform::CreateVM(const VMSpecifications& specifications) { 40 | auto vm = CreateVMImpl(specifications); 41 | if (vm != nullptr) { 42 | return *m_vms.emplace_back(std::move(vm)); 43 | } 44 | 45 | return std::nullopt; 46 | } 47 | 48 | const bool Platform::FreeVM(VirtualMachine& vm) { 49 | for (auto it = m_vms.cbegin(); it != m_vms.cend(); it++) { 50 | if (it->get() == &vm) { 51 | m_vms.erase(it); 52 | return true; 53 | } 54 | } 55 | 56 | return false; 57 | } 58 | 59 | void Platform::DestroyVMs() noexcept { 60 | m_vms.clear(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /deps/virt86/modules/core/src/vp/idt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Interrupt Descriptor Table method implementations. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "virt86/vp/idt.hpp" 27 | 28 | namespace virt86 { 29 | 30 | void IDTEntry::Set(uint32_t offset, uint16_t selector, IDTType type, uint8_t attributes) noexcept { 31 | this->descriptor = 0ULL; 32 | 33 | this->data.offsetLow = offset & 0xFFFF; 34 | this->data.offsetHigh = (offset >> 16); 35 | 36 | this->data.selector = selector; 37 | 38 | this->data.type = static_cast(type) & 0xF; 39 | this->data.storageSegment = attributes & 0x1; 40 | this->data.privilegeLevel = (attributes >> 1) & 0x3; 41 | this->data.present = (attributes >> 3) & 0x1; 42 | } 43 | 44 | uint32_t IDTEntry::GetOffset() noexcept { 45 | return static_cast(data.offsetLow) | (static_cast(data.offsetHigh) << 16); 46 | } 47 | 48 | void IDTEntry::SetOffset(uint32_t offset) noexcept { 49 | this->data.offsetLow = offset & 0xFFFF; 50 | this->data.offsetHigh = (offset >> 16); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | find_package(virt86-core CONFIG REQUIRED) 27 | if(WIN32) 28 | find_package(virt86-sys-windows CONFIG QUIET) 29 | elseif(LINUX) 30 | find_package(virt86-sys-linux CONFIG QUIET) 31 | elseif(APPLE) 32 | find_package(virt86-sys-darwin CONFIG QUIET) 33 | endif() 34 | 35 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 36 | check_required_components("@PROJECT_NAME@") 37 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/include/virt86/haxm/haxm_platform.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares the implementation class for the HAXM hypervisor platform adapter. 3 | 4 | Include this file to use HAXM as a platform. The platform instance is exposed 5 | as a singleton: 6 | 7 | auto& instance = virt86::haxm::HaxmPlatform::Instance(); 8 | ------------------------------------------------------------------------------- 9 | MIT License 10 | 11 | Copyright (c) 2019 Ivan Roberto de Oliveira 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all 21 | copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | SOFTWARE. 30 | */ 31 | #pragma once 32 | 33 | #include "virt86/platform/platform.hpp" 34 | 35 | #include 36 | 37 | namespace virt86::haxm { 38 | 39 | class HaxmPlatform : public Platform { 40 | public: 41 | ~HaxmPlatform() noexcept final; 42 | 43 | // Prevent copy construction and copy assignment 44 | HaxmPlatform(const HaxmPlatform&) = delete; 45 | HaxmPlatform& operator=(const HaxmPlatform&) = delete; 46 | 47 | // Prevent move construction and move assignment 48 | HaxmPlatform(HaxmPlatform&&) = delete; 49 | HaxmPlatform&& operator=(HaxmPlatform&&) = delete; 50 | 51 | // Disallow taking the address 52 | HaxmPlatform *operator&() = delete; 53 | 54 | static HaxmPlatform& Instance() noexcept; 55 | 56 | bool SetGlobalMemoryLimit(bool enabled, uint64_t limitMB) noexcept; 57 | 58 | protected: 59 | std::unique_ptr CreateVMImpl(const VMSpecifications& specifications) override; 60 | 61 | private: 62 | HaxmPlatform() noexcept; 63 | 64 | struct Delegate; 65 | std::unique_ptr m_delegate; 66 | }; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/haxm_helpers.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares helper functions for translating between virt86 and HAXM data 3 | structures. 4 | ------------------------------------------------------------------------------- 5 | MIT License 6 | 7 | Copyright (c) 2019 Ivan Roberto de Oliveira 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | #pragma once 28 | 29 | #include "virt86/vp/regs.hpp" 30 | 31 | namespace virt86::haxm { 32 | 33 | void LoadSegment(RegValue& value, const segment_desc_t *segment) noexcept; 34 | void StoreSegment(const RegValue& value, segment_desc_t *segment) noexcept; 35 | 36 | void LoadTable(RegValue& value, const segment_desc_t *table) noexcept; 37 | void StoreTable(const RegValue& value, segment_desc_t *table) noexcept; 38 | 39 | void LoadSTRegister(RegValue& value, uint8_t index, const fx_layout& fpuRegs) noexcept; 40 | void StoreSTRegister(const RegValue& value, uint8_t index, fx_layout& fpuRegs) noexcept; 41 | 42 | void LoadMMRegister(RegValue& value, uint8_t index, const fx_layout& fpuRegs) noexcept; 43 | void StoreMMRegister(const RegValue& value, uint8_t index, fx_layout& fpuRegs) noexcept; 44 | 45 | bool LoadXMMRegister(RegValue& value, uint8_t index, const fx_layout& fpuRegs) noexcept; 46 | bool StoreXMMRegister(const RegValue& value, uint8_t index, fx_layout& fpuRegs) noexcept; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/haxm_platform_impl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Implementation of the HAXM Platform internal implementation class. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "haxm_platform_impl.hpp" 27 | #include "haxm_sys_platform.hpp" 28 | 29 | namespace virt86::haxm { 30 | 31 | HaxmVersion g_haxmVersion; 32 | 33 | HaxmPlatformImpl::HaxmPlatformImpl() noexcept 34 | : m_haxVer({ 0 }) 35 | , m_haxCaps({ 0 }) 36 | , m_sys(std::make_unique()) 37 | { 38 | } 39 | 40 | HaxmPlatformImpl::~HaxmPlatformImpl() noexcept { 41 | } 42 | 43 | PlatformInitStatus HaxmPlatformImpl::Initialize() noexcept { 44 | return m_sys->Initialize(&m_haxVer, &m_haxCaps); 45 | } 46 | 47 | HaxmVersion HaxmPlatformImpl::GetVersion() noexcept { 48 | return m_sys->GetVersion(); 49 | } 50 | 51 | bool HaxmPlatformImpl::SetGlobalMemoryLimit(bool enabled, uint64_t limitMB) noexcept { 52 | return m_sys->SetGlobalMemoryLimit(enabled, limitMB); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/haxm_platform_impl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares the Platform internal implementation class for HAXM. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/haxm/haxm_platform.hpp" 29 | #include "interface/hax_interface.hpp" 30 | #include "haxm_version.hpp" 31 | 32 | #include 33 | 34 | namespace virt86::haxm { 35 | 36 | extern HaxmVersion g_haxmVersion; 37 | 38 | class HaxmPlatformSysImpl; 39 | 40 | class HaxmPlatformImpl { 41 | public: 42 | HaxmPlatformImpl() noexcept; 43 | ~HaxmPlatformImpl() noexcept; 44 | 45 | // Prevent copy construction and copy assignment 46 | HaxmPlatformImpl(const HaxmPlatformImpl&) = delete; 47 | HaxmPlatformImpl& operator=(const HaxmPlatformImpl&) = delete; 48 | 49 | // Prevent move construction and move assignment 50 | HaxmPlatformImpl(HaxmPlatformImpl&&) = delete; 51 | HaxmPlatformImpl&& operator=(HaxmPlatformImpl&&) = delete; 52 | 53 | // Disallow taking the address 54 | HaxmPlatformImpl *operator&() = delete; 55 | 56 | PlatformInitStatus Initialize() noexcept; 57 | 58 | HaxmVersion GetVersion() noexcept; 59 | bool SetGlobalMemoryLimit(bool enabled, uint64_t limitMB) noexcept; 60 | 61 | hax_module_version m_haxVer; 62 | hax_capabilityinfo m_haxCaps; 63 | 64 | // OS-specific implementation 65 | std::unique_ptr m_sys; 66 | }; 67 | 68 | struct HaxmPlatform::Delegate { 69 | HaxmPlatformImpl impl; 70 | }; 71 | 72 | } 73 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/haxm_version.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares the HAXM version type. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | namespace virt86::haxm { 29 | 30 | // Undefine system-defined macros from / in Linux 31 | #ifdef major 32 | #undef major 33 | #endif 34 | 35 | #ifdef minor 36 | #undef minor 37 | #endif 38 | 39 | union HaxmVersion { 40 | struct { 41 | uint16_t major, minor, build; 42 | }; 43 | uint64_t u64; 44 | 45 | HaxmVersion() : u64(0) {} 46 | 47 | HaxmVersion(uint16_t major, uint16_t minor, uint16_t build) 48 | : major(major) 49 | , minor(minor) 50 | , build(build) { 51 | } 52 | 53 | bool operator==(const HaxmVersion& version) { return u64 == version.u64; } 54 | bool operator!=(const HaxmVersion& version) { return u64 != version.u64; } 55 | bool operator>=(const HaxmVersion& version) { return u64 >= version.u64; } 56 | bool operator<=(const HaxmVersion& version) { return u64 <= version.u64; } 57 | bool operator>(const HaxmVersion& version) { return u64 > version.u64; } 58 | bool operator<(const HaxmVersion& version) { return u64 < version.u64; } 59 | }; 60 | 61 | // Global instance of the HAXM version loaded in the system. 62 | extern HaxmVersion g_haxmVersion; 63 | 64 | } 65 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/haxm_vm.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares the VirtualMachine implementation class for HAXM. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/vm/vm.hpp" 29 | #include "virt86/haxm/haxm_platform.hpp" 30 | #include "haxm_platform_impl.hpp" 31 | #include "haxm_sys_vm.hpp" 32 | 33 | #include 34 | 35 | namespace virt86::haxm { 36 | 37 | class HaxmVirtualMachine : public VirtualMachine { 38 | public: 39 | HaxmVirtualMachine(HaxmPlatform& platform, const VMSpecifications& specifications, HaxmPlatformImpl& platformImpl); 40 | ~HaxmVirtualMachine() noexcept final; 41 | 42 | // Prevent copy construction and copy assignment 43 | HaxmVirtualMachine(const HaxmVirtualMachine&) = delete; 44 | HaxmVirtualMachine& operator=(const HaxmVirtualMachine&) = delete; 45 | 46 | // Prevent move construction and move assignment 47 | HaxmVirtualMachine(HaxmVirtualMachine&&) = delete; 48 | HaxmVirtualMachine&& operator=(HaxmVirtualMachine&&) = delete; 49 | 50 | // Disallow taking the address 51 | HaxmVirtualMachine *operator&() = delete; 52 | 53 | const bool FastMMIOEnabled() const noexcept { return m_fastMMIO; } 54 | const uint32_t ID() const noexcept { return m_vmID; } 55 | 56 | protected: 57 | MemoryMappingStatus MapGuestMemoryImpl(const uint64_t baseAddress, const uint64_t size, const MemoryFlags flags, void *memory) noexcept override; 58 | MemoryMappingStatus UnmapGuestMemoryImpl(const uint64_t baseAddress, const uint64_t size) noexcept override; 59 | MemoryMappingStatus SetGuestMemoryFlagsImpl(const uint64_t baseAddress, const uint64_t size, const MemoryFlags flags) noexcept override; 60 | 61 | private: 62 | bool Initialize(); 63 | 64 | HaxmPlatform& m_platform; 65 | HaxmPlatformImpl& m_platformImpl; 66 | std::unique_ptr m_sys; 67 | 68 | bool m_fastMMIO; 69 | uint32_t m_vmID; 70 | 71 | // Allow HaxmPlatform to access Initialize() 72 | friend class HaxmPlatform; 73 | }; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/interface/darwin/hax_types_mac.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * 3. Neither the name of the copyright holder nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef HAX_DARWIN_HAX_TYPES_MAC_H_ 32 | #define HAX_DARWIN_HAX_TYPES_MAC_H_ 33 | 34 | // Unsigned Types 35 | typedef unsigned long ulong; 36 | 37 | typedef ulong mword; 38 | 39 | #endif // HAX_DARWIN_HAX_TYPES_MAC_H_ 40 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/interface/linux/hax_types_linux.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Intel Corporation 3 | * Copyright (c) 2018 Kryptos Logic 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef HAX_LINUX_HAX_TYPES_LINUX_H_ 33 | #define HAX_LINUX_HAX_TYPES_LINUX_H_ 34 | 35 | #include 36 | 37 | // Signed Types 38 | typedef int8_t int8; 39 | typedef int16_t int16; 40 | typedef int32_t int32; 41 | typedef int64_t int64; 42 | 43 | // Unsigned Types 44 | typedef uint8_t uint8; 45 | typedef uint16_t uint16; 46 | typedef uint32_t uint32; 47 | typedef uint64_t uint64; 48 | 49 | typedef unsigned int uint; 50 | typedef unsigned long ulong; 51 | typedef unsigned long ulong_t; 52 | 53 | #if defined(__i386__) 54 | typedef uint32_t mword; 55 | #endif 56 | #if defined (__x86_64__) 57 | typedef uint64_t mword; 58 | #endif 59 | 60 | #endif // HAX_LINUX_HAX_TYPES_LINUX_H_ 61 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/interface/windows/hax_types_windows.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * 3. Neither the name of the copyright holder nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef HAX_WINDOWS_HAX_TYPES_WINDOWS_H_ 32 | #define HAX_WINDOWS_HAX_TYPES_WINDOWS_H_ 33 | 34 | #if defined(_WIN32) && !defined(__cplusplus) 35 | #define inline __inline 36 | typedef unsigned char bool; 37 | #define true 1 38 | #define false 0 39 | #endif 40 | 41 | // Signed Types 42 | typedef signed char int8_t; 43 | typedef signed short int16_t; 44 | typedef signed int int32_t; 45 | typedef signed long long int64_t; 46 | 47 | // Unsigned Types 48 | typedef unsigned char uint8_t; 49 | typedef unsigned short uint16_t; 50 | typedef unsigned int uint32_t; 51 | typedef unsigned long long uint64_t; 52 | typedef unsigned int uint; 53 | typedef unsigned long ulong; 54 | typedef unsigned long ulong_t; 55 | 56 | #if defined(_X86_) 57 | typedef uint32_t mword; 58 | #endif 59 | 60 | #if defined (_AMD64_) 61 | typedef uint64_t mword; 62 | #endif 63 | 64 | #endif // HAX_WINDOWS_HAX_TYPES_WINDOWS_H_ 65 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/pch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file instructs CMake to build the precompiled header 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "pch.hpp" 27 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/common/pch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Precompiled header for the virt86 HAXM hypervisor platform adapter. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "virt86/platform/platform.hpp" 27 | #include "virt86/vm/vm.hpp" 28 | #include "virt86/vp/vp.hpp" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef _WIN32 37 | # include 38 | #endif 39 | 40 | #include "interface/hax_interface.hpp" 41 | 42 | #include "virt86/haxm/haxm_platform.hpp" 43 | #include "haxm_vm.hpp" 44 | #include "haxm_vp.hpp" 45 | 46 | #include "haxm_helpers.hpp" 47 | #include "haxm_platform_impl.hpp" 48 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/darwin/haxm_sys_platform.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | HAXM system-based platform implementation for macOS. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/platform/platform.hpp" 29 | 30 | #include "interface/hax_interface.hpp" 31 | #include "haxm_version.hpp" 32 | 33 | namespace virt86::haxm { 34 | 35 | class HaxmPlatformSysImpl { 36 | public: 37 | HaxmPlatformSysImpl() noexcept; 38 | ~HaxmPlatformSysImpl() noexcept; 39 | 40 | // Prevent copy construction and copy assignment 41 | HaxmPlatformSysImpl(const HaxmPlatformSysImpl&) = delete; 42 | HaxmPlatformSysImpl& operator=(const HaxmPlatformSysImpl&) = delete; 43 | 44 | // Prevent move construction and move assignment 45 | HaxmPlatformSysImpl(HaxmPlatformSysImpl&&) = delete; 46 | HaxmPlatformSysImpl&& operator=(HaxmPlatformSysImpl&&) = delete; 47 | 48 | // Disallow taking the address 49 | HaxmPlatformSysImpl *operator&() = delete; 50 | 51 | PlatformInitStatus Initialize(hax_module_version *haxVer, hax_capabilityinfo *haxCaps) noexcept; 52 | 53 | HaxmVersion GetVersion() noexcept; 54 | bool SetGlobalMemoryLimit(bool enabled, uint64_t limitMB) noexcept; 55 | 56 | const int FileDescriptor() const noexcept { return m_fd; } 57 | 58 | private: 59 | int m_fd; 60 | }; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/darwin/haxm_sys_vp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | HAXM system-based virtual processor implementation for macOS. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/platform/platform.hpp" 29 | #include "haxm_vm.hpp" 30 | #include "haxm_platform_impl.hpp" 31 | #include "haxm_sys_platform.hpp" 32 | 33 | #include "interface/hax_interface.hpp" 34 | 35 | #include 36 | 37 | namespace virt86::haxm { 38 | 39 | class HaxmVirtualProcessorSysImpl { 40 | public: 41 | HaxmVirtualProcessorSysImpl(HaxmVirtualMachine& vm, HaxmVirtualMachineSysImpl& vmSys) noexcept; 42 | ~HaxmVirtualProcessorSysImpl() noexcept; 43 | 44 | // Prevent copy construction and copy assignment 45 | HaxmVirtualProcessorSysImpl(const HaxmVirtualProcessorSysImpl&) = delete; 46 | HaxmVirtualProcessorSysImpl& operator=(const HaxmVirtualProcessorSysImpl&) = delete; 47 | 48 | // Prevent move construction and move assignment 49 | HaxmVirtualProcessorSysImpl(HaxmVirtualProcessorSysImpl&&) = delete; 50 | HaxmVirtualProcessorSysImpl&& operator=(HaxmVirtualProcessorSysImpl&&) = delete; 51 | 52 | // Disallow taking the address 53 | HaxmVirtualProcessorSysImpl *operator&() = delete; 54 | 55 | bool Initialize(uint32_t vcpuID, hax_tunnel **out_tunnel, void **out_ioTunnel) noexcept; 56 | void Destroy() noexcept; 57 | 58 | bool Run() noexcept; 59 | 60 | bool InjectInterrupt(uint8_t vector) noexcept; 61 | 62 | bool GetRegisters(vcpu_state_t *registers) noexcept; 63 | bool SetRegisters(vcpu_state_t *registers) noexcept; 64 | 65 | bool GetFPURegisters(fx_layout *registers) noexcept; 66 | bool SetFPURegisters(fx_layout *registers) noexcept; 67 | 68 | bool GetMSRData(hax_msr_data *msrData) noexcept; 69 | bool SetMSRData(hax_msr_data *msrData) noexcept; 70 | 71 | bool SetDebug(hax_debug_t *debug) noexcept; 72 | 73 | private: 74 | HaxmVirtualMachine& m_vm; 75 | HaxmVirtualMachineSysImpl& m_vmSys; 76 | 77 | int m_fdVM; 78 | int m_fd; 79 | }; 80 | 81 | } 82 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/linux/haxm_sys_platform.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | HAXM system-based platform implementation for Linux 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/platform/platform.hpp" 29 | 30 | #include "interface/hax_interface.hpp" 31 | #include "haxm_version.hpp" 32 | 33 | namespace virt86::haxm { 34 | 35 | class HaxmPlatformSysImpl { 36 | public: 37 | HaxmPlatformSysImpl() noexcept; 38 | ~HaxmPlatformSysImpl() noexcept; 39 | 40 | // Prevent copy construction and copy assignment 41 | HaxmPlatformSysImpl(const HaxmPlatformSysImpl&) = delete; 42 | HaxmPlatformSysImpl& operator=(const HaxmPlatformSysImpl&) = delete; 43 | 44 | // Prevent move construction and move assignment 45 | HaxmPlatformSysImpl(HaxmPlatformSysImpl&&) = delete; 46 | HaxmPlatformSysImpl&& operator=(HaxmPlatformSysImpl&&) = delete; 47 | 48 | // Disallow taking the address 49 | HaxmPlatformSysImpl *operator&() = delete; 50 | 51 | PlatformInitStatus Initialize(hax_module_version *haxVer, hax_capabilityinfo *haxCaps) noexcept; 52 | 53 | HaxmVersion GetVersion() noexcept; 54 | bool SetGlobalMemoryLimit(bool enabled, uint64_t limitMB) noexcept; 55 | 56 | const int FileDescriptor() const noexcept { return m_fd; } 57 | 58 | private: 59 | int m_fd; 60 | }; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/linux/haxm_sys_vp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | HAXM system-based virtual processor implementation for Linux. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/platform/platform.hpp" 29 | #include "haxm_vm.hpp" 30 | #include "haxm_platform_impl.hpp" 31 | #include "haxm_sys_platform.hpp" 32 | 33 | #include "interface/hax_interface.hpp" 34 | 35 | #include 36 | 37 | namespace virt86::haxm { 38 | 39 | class HaxmVirtualProcessorSysImpl { 40 | public: 41 | HaxmVirtualProcessorSysImpl(HaxmVirtualMachine& vm, HaxmVirtualMachineSysImpl& vmSys) noexcept; 42 | ~HaxmVirtualProcessorSysImpl() noexcept; 43 | 44 | // Prevent copy construction and copy assignment 45 | HaxmVirtualProcessorSysImpl(const HaxmVirtualProcessorSysImpl&) = delete; 46 | HaxmVirtualProcessorSysImpl& operator=(const HaxmVirtualProcessorSysImpl&) = delete; 47 | 48 | // Prevent move construction and move assignment 49 | HaxmVirtualProcessorSysImpl(HaxmVirtualProcessorSysImpl&&) = delete; 50 | HaxmVirtualProcessorSysImpl&& operator=(HaxmVirtualProcessorSysImpl&&) = delete; 51 | 52 | // Disallow taking the address 53 | HaxmVirtualProcessorSysImpl *operator&() = delete; 54 | 55 | bool Initialize(uint32_t vcpuID, hax_tunnel **out_tunnel, void **out_ioTunnel) noexcept; 56 | void Destroy() noexcept; 57 | 58 | bool Run() noexcept; 59 | 60 | bool InjectInterrupt(uint8_t vector) noexcept; 61 | 62 | bool GetRegisters(vcpu_state_t *registers) noexcept; 63 | bool SetRegisters(vcpu_state_t *registers) noexcept; 64 | 65 | bool GetFPURegisters(fx_layout *registers) noexcept; 66 | bool SetFPURegisters(fx_layout *registers) noexcept; 67 | 68 | bool GetMSRData(hax_msr_data *msrData) noexcept; 69 | bool SetMSRData(hax_msr_data *msrData) noexcept; 70 | 71 | bool SetDebug(hax_debug_t *debug) noexcept; 72 | 73 | private: 74 | HaxmVirtualMachine& m_vm; 75 | HaxmVirtualMachineSysImpl& m_vmSys; 76 | 77 | int m_fdVM; 78 | int m_fd; 79 | }; 80 | 81 | } 82 | -------------------------------------------------------------------------------- /deps/virt86/modules/haxm/src/windows/haxm_sys_platform.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | HAXM system-based platform implementation for Windows. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/platform/platform.hpp" 29 | #include "virt86/sys/windows/version_info.hpp" 30 | 31 | #include "interface/hax_interface.hpp" 32 | #include "haxm_version.hpp" 33 | 34 | #include 35 | 36 | namespace virt86::haxm { 37 | 38 | class HaxmPlatformSysImpl { 39 | public: 40 | HaxmPlatformSysImpl() noexcept; 41 | ~HaxmPlatformSysImpl() noexcept; 42 | 43 | // Prevent copy construction and copy assignment 44 | HaxmPlatformSysImpl(const HaxmPlatformSysImpl&) = delete; 45 | HaxmPlatformSysImpl& operator=(const HaxmPlatformSysImpl&) = delete; 46 | 47 | // Prevent move construction and move assignment 48 | HaxmPlatformSysImpl(HaxmPlatformSysImpl&&) = delete; 49 | HaxmPlatformSysImpl&& operator=(HaxmPlatformSysImpl&&) = delete; 50 | 51 | // Disallow taking the address 52 | HaxmPlatformSysImpl *operator&() = delete; 53 | 54 | PlatformInitStatus Initialize(hax_module_version *haxVer, hax_capabilityinfo *haxCaps) noexcept; 55 | 56 | HaxmVersion GetVersion() noexcept; 57 | bool SetGlobalMemoryLimit(bool enabled, uint64_t limitMB) noexcept; 58 | 59 | const HANDLE Handle() const noexcept { return m_handle; } 60 | 61 | private: 62 | HANDLE m_handle; 63 | }; 64 | 65 | } 66 | -------------------------------------------------------------------------------- /deps/virt86/modules/hvf/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 27 | check_required_components("@PROJECT_NAME@") 28 | -------------------------------------------------------------------------------- /deps/virt86/modules/hvf/include/virt86/hvf/hvf_platform.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares the implementation class for the Hypervisor.Framework adapter. 3 | 4 | Include this file to use Hypervisor.Framework as a platform. The platform 5 | instance is exposed as a singleton: 6 | 7 | auto& instance = virt86::hvf::HvFPlatform::Instance(); 8 | ------------------------------------------------------------------------------- 9 | MIT License 10 | 11 | Copyright (c) 2019 Ivan Roberto de Oliveira 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all 21 | copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | SOFTWARE. 30 | */ 31 | #pragma once 32 | 33 | #include "virt86/platform/platform.hpp" 34 | 35 | namespace virt86::hvf { 36 | 37 | class HvFPlatform : public Platform { 38 | public: 39 | static HvFPlatform& Instance(); 40 | 41 | protected: 42 | HvFPlatform(); 43 | virtual ~HvFPlatform() override; 44 | 45 | VirtualMachine *CreateVMImpl(const VMSpecifications& specifications) override; 46 | 47 | }; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /deps/virt86/modules/hvf/src/hvf_vm.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares the VirtualMachine implementation class for the Hypervisor.Framework 3 | platform adapter. 4 | ------------------------------------------------------------------------------- 5 | MIT License 6 | 7 | Copyright (c) 2019 Ivan Roberto de Oliveira 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | #pragma once 28 | 29 | #include "virt86/vm/vm.hpp" 30 | #include "virt86/hvf/hvf_platform.hpp" 31 | 32 | namespace virt86::hvf { 33 | 34 | class HvFVirtualMachine : public VirtualMachine { 35 | protected: 36 | virtual ~HvFVirtualMachine() override; 37 | 38 | // TODO: UnmapGuestMemoryImpl, SetGuestMemoryFlagsImpl and the dirty page 39 | // tracking operations are optional and may be removed if 40 | // Hypervisor.Framework doesn't support them 41 | MemoryMappingStatus MapGuestMemoryImpl(const uint64_t baseAddress, const uint64_t size, const MemoryFlags flags, void *memory) override; 42 | MemoryMappingStatus UnmapGuestMemoryImpl(const uint64_t baseAddress, const uint64_t size) override; 43 | MemoryMappingStatus SetGuestMemoryFlagsImpl(const uint64_t baseAddress, const uint64_t size, const MemoryFlags flags) override; 44 | 45 | DirtyPageTrackingStatus QueryDirtyPagesImpl(const uint64_t baseAddress, const uint64_t size, uint64_t *bitmap, const size_t bitmapSize) override; 46 | DirtyPageTrackingStatus ClearDirtyPagesImpl(const uint64_t baseAddress, const uint64_t size) override; 47 | 48 | private: 49 | HvFVirtualMachine(HvFPlatform& platform, const VMSpecifications& specifications); // TODO: modify the constructor to pass down handles or file descriptors as needed 50 | bool Initialize(); 51 | 52 | HvFPlatform& m_platform; 53 | 54 | // Allow HvFPlatform to access the constructor and Initialize() 55 | friend class HvFPlatform; 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /deps/virt86/modules/hvf/src/pch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file instructs CMake to build the precompiled header file. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "pch.hpp" 27 | -------------------------------------------------------------------------------- /deps/virt86/modules/hvf/src/pch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Precompiled header for the virt86 Hypervisor.Framework platform adapter. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "virt86/platform/platform.hpp" 27 | #include "hvf_vm.hpp" 28 | #include "hvf_vp.hpp" 29 | -------------------------------------------------------------------------------- /deps/virt86/modules/kvm/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 27 | check_required_components("@PROJECT_NAME@") 28 | -------------------------------------------------------------------------------- /deps/virt86/modules/kvm/include/virt86/kvm/kvm_platform.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares the implementation class for the KVM hypervisor platform adapter. 3 | 4 | Include this file to use KVM as a platform. The platform instance is exposed 5 | as a singleton: 6 | 7 | auto& instance = virt86::kvm::KvmPlatform::Instance(); 8 | ------------------------------------------------------------------------------- 9 | MIT License 10 | 11 | Copyright (c) 2019 Ivan Roberto de Oliveira 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all 21 | copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | SOFTWARE. 30 | */ 31 | #pragma once 32 | 33 | #include "virt86/platform/platform.hpp" 34 | 35 | namespace virt86::kvm { 36 | 37 | class KvmPlatform : public Platform { 38 | public: 39 | ~KvmPlatform() noexcept final; 40 | 41 | // Prevent copy construction and copy assignment 42 | KvmPlatform(const KvmPlatform&) = delete; 43 | KvmPlatform& operator=(const KvmPlatform&) = delete; 44 | 45 | // Prevent move construction and move assignment 46 | KvmPlatform(KvmPlatform&&) = delete; 47 | KvmPlatform&& operator=(KvmPlatform&&) = delete; 48 | 49 | // Disallow taking the address 50 | KvmPlatform *operator&() = delete; 51 | static KvmPlatform& Instance() noexcept; 52 | 53 | protected: 54 | std::unique_ptr CreateVMImpl(const VMSpecifications& specifications) override; 55 | 56 | private: 57 | KvmPlatform() noexcept; 58 | 59 | int m_fd; 60 | }; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /deps/virt86/modules/kvm/src/kvm_helpers.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares helper functions to convert between virt86 and KVM data structures. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include "virt86/vp/regs.hpp" 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | namespace virt86::kvm { 36 | 37 | void LoadSegment(RegValue& value, const struct kvm_segment *segment) noexcept; 38 | void StoreSegment(const RegValue& value, struct kvm_segment *segment) noexcept; 39 | 40 | void LoadTable(RegValue& value, const struct kvm_dtable *table) noexcept; 41 | void StoreTable(const RegValue& value, struct kvm_dtable *table) noexcept; 42 | 43 | void LoadSTRegister(RegValue& value, uint8_t index, const struct kvm_fpu& fpuRegs) noexcept; 44 | void StoreSTRegister(const RegValue& value, uint8_t index, struct kvm_fpu& fpuRegs) noexcept; 45 | 46 | void LoadMMRegister(RegValue& value, uint8_t index, const struct kvm_fpu& fpuRegs) noexcept; 47 | void StoreMMRegister(const RegValue& value, uint8_t index, struct kvm_fpu& fpuRegs) noexcept; 48 | 49 | bool LoadXMMRegister(RegValue& value, uint8_t index, const struct kvm_fpu& fpuRegs) noexcept; 50 | bool StoreXMMRegister(const RegValue& value, uint8_t index, struct kvm_fpu& fpuRegs) noexcept; 51 | 52 | /** 53 | * Allocates memory for an object of type T that contains a variable-length 54 | * array of entries with type E. 55 | */ 56 | template 57 | T *allocVarEntry(size_t numEntries) { 58 | size_t sz = sizeof(T) + numEntries * sizeof(E); 59 | auto mem = (T *)malloc(sz); 60 | memset(mem, 0, sz); 61 | return mem; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /deps/virt86/modules/kvm/src/pch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file instructs CMake to build the precompiled header file. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "pch.hpp" 27 | -------------------------------------------------------------------------------- /deps/virt86/modules/kvm/src/pch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Precompiled header for the virt86 KVM platform adapter. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "virt86/platform/platform.hpp" 27 | #include "kvm_vm.hpp" 28 | #include "kvm_vp.hpp" 29 | #include "kvm_helpers.hpp" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/darwin/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 27 | check_required_components("@PROJECT_NAME@") 28 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/darwin/include/virt86/sys/darwin/kext.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Basic macOS kext handling functions. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | namespace virt86::sys::darwin { 29 | 30 | char *getKextVersion(const char *kextName); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/darwin/src/kext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Basic macOS kext handling functions. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "virt86/sys/darwin/kext.hpp" 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace virt86::sys::darwin { 33 | 34 | char *getKextVersion(const char *kextName) { 35 | // Cheaty version: run kextstat command and look for the desired kext 36 | char *cmd; 37 | asprintf(&cmd, "/usr/sbin/kextstat | /usr/bin/grep -F %s", kextName); 38 | FILE *fp = popen(cmd, "r"); 39 | free(cmd); 40 | 41 | // Read command output 42 | char result[256]; 43 | fread(result, sizeof(result), 1, fp); 44 | pclose(fp); 45 | 46 | // Find kext name in the line 47 | char *p = strstr(result, kextName); 48 | if (p == NULL) { 49 | return NULL; 50 | } 51 | 52 | // Extract version, which comes after the kext name in parenthesis 53 | p = strchr(p, '('); 54 | if (p == NULL) { 55 | return NULL; 56 | } 57 | p++; 58 | 59 | char *end = strchr(p, ')'); 60 | size_t verLen = end - p; 61 | 62 | // Allocate new string with a copy of the version 63 | char *ver = (char *)malloc(verLen + 1); 64 | strncpy(ver, p, verLen); 65 | ver[verLen] = '\0'; 66 | 67 | return ver; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/linux/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 27 | check_required_components("@PROJECT_NAME@") 28 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/linux/include/virt86/sys/linux/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Various utility functions for dealing with Linux files and kernel modules. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | #ifndef MODULE_DIR 32 | #define MODULE_DIR "/lib/modules" 33 | #endif 34 | 35 | inline int __attribute__ ((pure)) native_endianness() { 36 | /* Encoding the endianness enums in a string and then reading that 37 | * string as a 32-bit int, returns the correct endianness automagically. 38 | */ 39 | return (char) *((uint32_t *) ("\1\0\0\2")); 40 | } 41 | 42 | static inline void __swap_bytes(const void *src, void *dest, unsigned int size) { 43 | unsigned int i; 44 | for (i = 0; i < size; i++) { 45 | ((unsigned char *) dest)[i] = ((unsigned char *) src)[size - i - 1]; 46 | } 47 | } 48 | 49 | template 50 | inline T endianSwap(T data, bool swap) { 51 | if (swap) { 52 | T result = data; 53 | __swap_bytes(&data, &result, sizeof(T)); 54 | return result; 55 | } 56 | return data; 57 | } 58 | 59 | void getModulesPath(char **path); 60 | void *readFile(const char *filename, unsigned long *size); 61 | char *getModInfoParam(char *modinfo, size_t modinfoSize, const char *param); 62 | char *mmapKernelModuleFile(const char *name, size_t *size); 63 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/windows/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 27 | check_required_components("@PROJECT_NAME@") 28 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/windows/include/virt86/sys/windows/version_info.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #pragma comment(lib, "version.lib") 9 | 10 | namespace virt86::sys::windows { 11 | 12 | union VersionInfo { 13 | struct { 14 | uint16_t major, minor, build, revision; 15 | }; 16 | uint64_t ver; 17 | 18 | VersionInfo() : ver(0) {} 19 | 20 | VersionInfo(uint16_t major, uint16_t minor, uint16_t build, uint16_t revision) 21 | : major(major) 22 | , minor(minor) 23 | , build(build) 24 | , revision(revision) 25 | {} 26 | 27 | VersionInfo(VS_FIXEDFILEINFO& fileInfo) { 28 | major = (fileInfo.dwFileVersionMS >> 16) & 0xFFFF; 29 | minor = (fileInfo.dwFileVersionMS) & 0xFFFF; 30 | build = (fileInfo.dwFileVersionLS >> 16) & 0xFFFF; 31 | revision = (fileInfo.dwFileVersionLS) & 0xFFFF; 32 | } 33 | 34 | bool operator==(const VersionInfo& versionInfo) const { return ver == versionInfo.ver; } 35 | bool operator!=(const VersionInfo& versionInfo) const { return ver != versionInfo.ver; } 36 | bool operator>=(const VersionInfo& versionInfo) const { return ver >= versionInfo.ver; } 37 | bool operator<=(const VersionInfo& versionInfo) const { return ver <= versionInfo.ver; } 38 | bool operator>(const VersionInfo& versionInfo) const { return ver > versionInfo.ver; } 39 | bool operator<(const VersionInfo& versionInfo) const { return ver < versionInfo.ver; } 40 | }; 41 | 42 | std::optional getModuleVersion(HMODULE hModule); 43 | std::optional getDriverVersion(std::wstring driverFileName); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/windows/src/pch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is required by Visual Studio in order to compile pch.hpp. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "pch.hpp" 27 | -------------------------------------------------------------------------------- /deps/virt86/modules/sys/windows/src/pch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Precompiled header for the common Windows system code. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include 27 | #include 28 | #include 29 | #include 30 | -------------------------------------------------------------------------------- /deps/virt86/modules/virt86/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | find_package(virt86-core CONFIG REQUIRED) 27 | find_package(virt86-haxm CONFIG REQUIRED) 28 | if(WIN32) 29 | find_package(virt86-sys-windows CONFIG QUIET) 30 | find_package(virt86-whpx CONFIG QUIET) 31 | elseif(LINUX) 32 | find_package(virt86-sys-linux CONFIG QUIET) 33 | find_package(virt86-kvm CONFIG QUIET) 34 | elseif(APPLE) 35 | find_package(virt86-sys-darwin CONFIG QUIET) 36 | find_package(virt86-hvf CONFIG QUIET) 37 | endif() 38 | 39 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 40 | check_required_components("@PROJECT_NAME@") 41 | -------------------------------------------------------------------------------- /deps/virt86/modules/virt86/include/virt86/virt86.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Includes all available platforms based on the current build system 3 | configuration and availability according to operating system and SDK 4 | requirements: 5 | 6 | Windows Linux macOS 7 | HAXM yes yes yes 8 | WHPX yes[1] - - 9 | KVM - yes - 10 | HvF - - yes[2] 11 | 12 | [1] WHPX requires Windows 10 SDK version 10.0.17134.0 or later 13 | [2] Hypervisor.Framework support is currently unimplemented 14 | 15 | The header also exposes a fixed-size array of available platform factories on 16 | virt86::PlatformFactories. 17 | ------------------------------------------------------------------------------- 18 | MIT License 19 | 20 | Copyright (c) 2019 Ivan Roberto de Oliveira 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy 23 | of this software and associated documentation files (the "Software"), to deal 24 | in the Software without restriction, including without limitation the rights 25 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 26 | copies of the Software, and to permit persons to whom the Software is 27 | furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in all 30 | copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 37 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 38 | SOFTWARE. 39 | */ 40 | #pragma once 41 | 42 | #include "virt86/util/host_info.hpp" 43 | 44 | #if defined(VIRT86_HAXM_AVAILABLE) 45 | # include "virt86/haxm/haxm_platform.hpp" 46 | #endif 47 | 48 | #if defined(VIRT86_WHPX_AVAILABLE) 49 | # include "virt86/whpx/whpx_platform.hpp" 50 | #endif 51 | 52 | #if defined(VIRT86_KVM_AVAILABLE) 53 | # include "virt86/kvm/kvm_platform.hpp" 54 | #endif 55 | 56 | #if defined(VIRT86_HVF_AVAILABLE) 57 | # include "virt86/hvf/hvf_platform.hpp" 58 | #endif 59 | 60 | namespace virt86 { 61 | 62 | using PlatformFactory = Platform& (*)(); 63 | 64 | inline PlatformFactory PlatformFactories[] = { 65 | #if defined(VIRT86_HAXM_AVAILABLE) 66 | []() noexcept -> Platform& { return haxm::HaxmPlatform::Instance(); }, 67 | #endif 68 | 69 | #if defined(VIRT86_WHPX_AVAILABLE) 70 | []() noexcept -> Platform& { return whpx::WhpxPlatform::Instance(); }, 71 | #endif 72 | 73 | #if defined(VIRT86_KVM_AVAILABLE) 74 | []() noexcept -> Platform& { return kvm::KvmPlatform::Instance(); }, 75 | #endif 76 | 77 | #if defined(VIRT86_HVF_AVAILABLE) 78 | []() noexcept -> Platform& { return hvf::HvFPlatform::Instance(); }, 79 | #endif 80 | }; 81 | 82 | } 83 | -------------------------------------------------------------------------------- /deps/virt86/modules/virt86/src/lib.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is required in order to build the static library. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "virt86/virt86.hpp" -------------------------------------------------------------------------------- /deps/virt86/modules/whpx/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Template for CMake Config module. 2 | # ------------------------------------------------------------------------------- 3 | # MIT License 4 | # 5 | # Copyright (c) 2019 Ivan Roberto de Oliveira 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | @PACKAGE_INIT@ 25 | 26 | find_package(virt86-sys-windows CONFIG QUIET) 27 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 28 | check_required_components("@PROJECT_NAME@") 29 | -------------------------------------------------------------------------------- /deps/virt86/modules/whpx/include/virt86/whpx/whpx_platform.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares the implementation class for the Windows Hypervisor Platform adapter. 3 | 4 | Include this file to use WHPX as a platform. The platform instance is exposed 5 | as a singleton: 6 | 7 | auto& instance = virt86::whpx::WhpxPlatform::Instance(); 8 | ------------------------------------------------------------------------------- 9 | MIT License 10 | 11 | Copyright (c) 2019 Ivan Roberto de Oliveira 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all 21 | copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | SOFTWARE. 30 | */ 31 | #pragma once 32 | 33 | #include "virt86/platform/platform.hpp" 34 | 35 | namespace virt86::whpx { 36 | 37 | struct WhpxDispatch; 38 | 39 | class WhpxPlatform : public Platform { 40 | public: 41 | ~WhpxPlatform() noexcept final; 42 | 43 | // Prevent copy construction and copy assignment 44 | WhpxPlatform(const WhpxPlatform&) = delete; 45 | WhpxPlatform& operator=(const WhpxPlatform&) = delete; 46 | 47 | // Prevent move construction and move assignment 48 | WhpxPlatform(WhpxPlatform&&) = delete; 49 | WhpxPlatform&& operator=(WhpxPlatform&&) = delete; 50 | 51 | // Disallow taking the address 52 | WhpxPlatform *operator&() = delete; 53 | 54 | static WhpxPlatform& Instance() noexcept; 55 | 56 | protected: 57 | std::unique_ptr CreateVMImpl(const VMSpecifications& specifications) override; 58 | 59 | private: 60 | WhpxPlatform() noexcept; 61 | 62 | static WhpxDispatch *s_dispatch; 63 | }; 64 | 65 | } 66 | -------------------------------------------------------------------------------- /deps/virt86/modules/whpx/src/pch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file instructs CMake to build the precompiled header file. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include "pch.hpp" 27 | -------------------------------------------------------------------------------- /deps/virt86/modules/whpx/src/pch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Precompiled header for the Windows Hypervisor Platform adapter. 3 | ------------------------------------------------------------------------------- 4 | MIT License 5 | 6 | Copyright (c) 2019 Ivan Roberto de Oliveira 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include "virt86/platform/platform.hpp" 34 | #include "virt86/vm/vm.hpp" 35 | #include "virt86/vp/vp.hpp" 36 | 37 | #include "virt86/whpx/whpx_platform.hpp" 38 | #include "whpx_vm.hpp" 39 | #include "whpx_vp.hpp" 40 | 41 | #include "whpx_dispatch.hpp" 42 | #include "whpx_regs.hpp" 43 | #include "whpx_defs.hpp" 44 | -------------------------------------------------------------------------------- /deps/virt86/modules/whpx/src/whpx_dispatch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Loads the Windows Hypervisor Platform libraries dynamically and builds the 3 | function dispatch table. 4 | ------------------------------------------------------------------------------- 5 | MIT License 6 | 7 | Copyright (c) 2019 Ivan Roberto de Oliveira 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | #include "whpx_dispatch.hpp" 28 | 29 | namespace virt86::whpx { 30 | 31 | // The version of WHPX present in the system. 32 | VersionInfo g_whpxVersion; 33 | 34 | #define LOAD_LIB(name) do { \ 35 | m_h##name = LoadLibraryA(#name ".dll"); \ 36 | if (m_h##name == NULL) { \ 37 | goto fail; \ 38 | } \ 39 | } while (0) 40 | 41 | #define LOAD_FUNC(returnType, name, parameters) \ 42 | name = (name##_t) GetProcAddress(hmodule, #name); \ 43 | if (!name) { \ 44 | goto fail; \ 45 | } 46 | 47 | 48 | #define LOAD_OPTIONAL_FUNC(returnType, name, parameters) \ 49 | name = (name##_t) GetProcAddress(hmodule, #name); 50 | 51 | void setVersion(HMODULE hWinHvPlatform) noexcept { 52 | auto opt_ver = getModuleVersion(hWinHvPlatform); 53 | if (opt_ver) { 54 | g_whpxVersion = *opt_ver; 55 | } 56 | } 57 | 58 | bool WhpxDispatch::Load() noexcept { 59 | if (m_loaded) { 60 | return true; 61 | } 62 | 63 | LOAD_LIB(WinHvPlatform); 64 | LOAD_LIB(WinHvEmulation); 65 | 66 | // Determine WHPX version based on the loaded module 67 | setVersion(m_hWinHvPlatform); 68 | 69 | HMODULE hmodule; 70 | 71 | hmodule = m_hWinHvPlatform; WHPX_PLATFORM_FUNCTIONS(LOAD_FUNC); WHPX_OPTIONAL_PLATFORM_FUNCTIONS(LOAD_OPTIONAL_FUNC); 72 | hmodule = m_hWinHvEmulation; WHPX_EMULATION_FUNCTIONS(LOAD_FUNC); 73 | 74 | m_loaded = true; 75 | return true; 76 | 77 | fail: 78 | if (m_hWinHvPlatform) { 79 | FreeLibrary(m_hWinHvPlatform); 80 | m_hWinHvPlatform = NULL; 81 | } 82 | if (m_hWinHvEmulation) { 83 | FreeLibrary(m_hWinHvEmulation); 84 | m_hWinHvEmulation = NULL; 85 | } 86 | g_whpxVersion.ver = 0; 87 | 88 | return false; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /deps/virt86/modules/whpx/src/whpx_regs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Declares helper functions for translating between virt86 and Windows Hypervisor 3 | Platform data structures. 4 | ------------------------------------------------------------------------------- 5 | MIT License 6 | 7 | Copyright (c) 2019 Ivan Roberto de Oliveira 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | #pragma once 28 | 29 | #include "virt86/vp/regs.hpp" 30 | #include "virt86/vp/status.hpp" 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | namespace virt86::whpx { 38 | 39 | VPOperationStatus TranslateRegisterName(const Reg reg, WHV_REGISTER_NAME& name) noexcept; 40 | RegValue TranslateRegisterValue(const Reg reg, const WHV_REGISTER_VALUE& value) noexcept; 41 | void TranslateRegisterValue(const Reg reg, const RegValue& value, WHV_REGISTER_VALUE& output) noexcept; 42 | bool TranslateMSR(uint64_t msr, WHV_REGISTER_NAME& reg) noexcept; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /deps/virt86/modules/whpx/src/whpx_vp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libretro/libretro-directxbox/a157f3c1a68cb40dd74d5a664c0e39a245aaa59c/deps/virt86/modules/whpx/src/whpx_vp.cpp -------------------------------------------------------------------------------- /docs/cromwell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libretro/libretro-directxbox/a157f3c1a68cb40dd74d5a664c0e39a245aaa59c/docs/cromwell.png -------------------------------------------------------------------------------- /link.T: -------------------------------------------------------------------------------- 1 | { 2 | global: retro_*; 3 | local: *; 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | set(XBOX_SOURCE 4 | libretro/libretro.cpp 5 | xbox.cpp 6 | xbox_database.cpp 7 | 8 | devices/pci/agp_bridge.cpp 9 | devices/pci/host_bridge.cpp 10 | devices/pci/pci.cpp 11 | devices/pci/pci_bridge.cpp 12 | devices/pci/pci_bus.cpp 13 | 14 | devices/ata/ata_controller.cpp 15 | devices/smbus.cpp 16 | devices/smc.cpp 17 | devices/i8259.cpp 18 | devices/i8254.cpp 19 | devices/eeprom.cpp 20 | 21 | devices/audio/ac97/ac97.cpp 22 | devices/audio/mcpx/mcpx_apu.cpp 23 | 24 | devices/video/nv2a/nv2a.cpp 25 | devices/video/nv2a/pmc.cpp 26 | devices/video/nv2a/pbus.cpp 27 | devices/video/nv2a/pfifo.cpp 28 | devices/video/nv2a/prma.cpp 29 | devices/video/nv2a/pvideo.cpp 30 | devices/video/nv2a/ptimer.cpp 31 | devices/video/nv2a/pcounter.cpp 32 | devices/video/nv2a/pvpe.cpp 33 | devices/video/nv2a/ptv.cpp 34 | devices/video/nv2a/prmfb.cpp 35 | devices/video/nv2a/prmvio.cpp 36 | devices/video/nv2a/pfb.cpp 37 | devices/video/nv2a/pstraps.cpp 38 | devices/video/nv2a/pgraph.cpp 39 | devices/video/nv2a/pcrtc.cpp 40 | devices/video/nv2a/prmcio.cpp 41 | devices/video/nv2a/pramdac.cpp 42 | devices/video/nv2a/prmdio.cpp 43 | devices/video/nv2a/pramin.cpp 44 | devices/video/nv2a/user.cpp 45 | 46 | devices/video/tv/conexant.cpp 47 | ) 48 | 49 | find_package(virt86 CONFIG REQUIRED) 50 | add_library(libretro-xbox SHARED ${XBOX_SOURCE}) 51 | target_link_libraries(libretro-xbox PUBLIC virt86::virt86) 52 | 53 | if (MSVC) 54 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ot /Oi /arch:AVX /sdl- /GL") 55 | set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") 56 | endif() 57 | 58 | if(CMAKE_COMPILER_IS_GNUCXX) 59 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") ## Optimize 60 | endif() 61 | 62 | -------------------------------------------------------------------------------- /src/devices/ata/ata_controller.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "util.h" 3 | #include "ata_controller.h" 4 | 5 | AtaController::AtaController() : 6 | PCIDevice(PCI_HEADER_TYPE_NORMAL, PCI_VENDOR_ID_NVIDIA, 0x01BC, 0xD2, 0x01, 0x01, 0x8A) /* IDE controller */ 7 | { 8 | } 9 | 10 | AtaController::~AtaController() { 11 | } 12 | 13 | /* PCI Device functions */ 14 | 15 | void AtaController::Init() { 16 | RegisterBAR(4, 16, PCI_BAR_TYPE_IO); /* 0xFF60 - 0xFF6F */ 17 | 18 | /* Initialize configuration space */ 19 | Write16(m_configSpace, PCI_STATUS, PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ | PCI_STATUS_CAP_LIST); 20 | Write8(m_configSpace, PCI_CAPABILITY_LIST, 0x44); 21 | Write8(m_configSpace, PCI_MIN_GNT, 0x03); 22 | Write8(m_configSpace, PCI_MAX_LAT, 0x01); 23 | 24 | /* Capability list */ 25 | Write8(m_configSpace, 0x44, PCI_CAP_ID_PM); 26 | Write8(m_configSpace, 0x45, 0x00); 27 | 28 | /* Unknown registers */ 29 | Write16(m_configSpace, 0x46, 0x2); 30 | Write32(m_configSpace, 0x5c, 0xffff00ff); 31 | } 32 | 33 | void AtaController::Reset() 34 | { 35 | 36 | } 37 | 38 | uint32_t AtaController::IORead(int barIndex, uint32_t addr, unsigned size) 39 | { 40 | Log(LogLevel::Warning, "AtaController: Unimplemented IORead %X\n", addr); 41 | return 0; 42 | } 43 | 44 | void AtaController::IOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size) 45 | { 46 | Log(LogLevel::Warning, "AtaController: Unimplemented IOWrite %X\n", addr); 47 | } 48 | 49 | uint32_t AtaController::MMIORead(int barIndex, uint32_t addr, unsigned size) 50 | { 51 | 52 | Log(LogLevel::Warning, "AtaController: Unimplemented MMIORead %X\n", addr); 53 | return 0; 54 | } 55 | 56 | void AtaController::MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size) 57 | { 58 | Log(LogLevel::Warning, "AtaController: Unimplemented MMIOWrite %X\n", addr); 59 | } 60 | -------------------------------------------------------------------------------- /src/devices/ata/ata_controller.h: -------------------------------------------------------------------------------- 1 | #ifndef _ATA_H_ 2 | #define _ATA_H_ 3 | 4 | #include "devices/pci/pci.h" 5 | 6 | class AtaController : public PCIDevice 7 | { 8 | public: 9 | AtaController(); 10 | ~AtaController(); 11 | 12 | /* PCI Functions */ 13 | void Init(); 14 | void Reset(); 15 | 16 | uint32_t IORead(int barIndex, uint32_t addr, unsigned size = sizeof(uint8_t)); 17 | void IOWrite(int barIndex, uint32_t addr, uint32_t data, unsigned size = sizeof(uint8_t)); 18 | 19 | uint32_t MMIORead(int barIndex, uint32_t addr, unsigned size); 20 | void MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size); 21 | private: 22 | 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/devices/audio/ac97/ac97.cpp: -------------------------------------------------------------------------------- 1 | #include "ac97.h" 2 | #include "util.h" 3 | 4 | Ac97::Ac97() 5 | : PCIDevice(PCI_HEADER_TYPE_NORMAL, PCI_VENDOR_ID_NVIDIA, 0x01B1, 0xB1, 6 | 0x04, 0x01, 0x00) /* Multimedia Audio Controller */ 7 | { 8 | } 9 | 10 | Ac97::~Ac97() { 11 | } 12 | 13 | /* PCI Device functions */ 14 | 15 | void Ac97::Init() { 16 | RegisterBAR(0, 0x100, PCI_BAR_TYPE_IO); /* 0xD000 - 0xD0FF */ 17 | RegisterBAR(1, 0x80, PCI_BAR_TYPE_IO); /* 0xD200 - 0xD27F */ 18 | RegisterBAR(2, 0x1000, PCI_BAR_TYPE_MEMORY); /* 0xFEC00000 - 0xFEC00FFF */ 19 | 20 | /* Initialize configuration space */ 21 | Write16(m_configSpace, PCI_STATUS, PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ | PCI_STATUS_CAP_LIST); 22 | Write8(m_configSpace, PCI_CAPABILITY_LIST, 0x44); 23 | Write8(m_configSpace, PCI_MIN_GNT, 0x02); 24 | Write8(m_configSpace, PCI_MAX_LAT, 0x05); 25 | 26 | /* Capability list */ 27 | Write8(m_configSpace, 0x44, PCI_CAP_ID_PM); 28 | Write8(m_configSpace, 0x45, 0x00); 29 | 30 | /* Unknown registers */ 31 | Write16(m_configSpace, 0x46, 0x2); 32 | Write16(m_configSpace, 0x4c, 0x106); 33 | } 34 | 35 | void Ac97::Reset() 36 | { 37 | 38 | } 39 | 40 | uint32_t Ac97::IORead(int barIndex, uint32_t addr, unsigned size) 41 | { 42 | Log(LogLevel::Warning, "Ac97: Unimplemented IORead %X\n", addr); 43 | return 0; 44 | } 45 | 46 | void Ac97::IOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size) 47 | { 48 | Log(LogLevel::Warning, "Ac97: Unimplemented IOWrite %X\n", addr); 49 | } 50 | 51 | uint32_t Ac97::MMIORead(int barIndex, uint32_t addr, unsigned size) 52 | { 53 | Log(LogLevel::Warning, "Ac97: Unimplemented MMIORead %X\n", addr); 54 | return 0; 55 | } 56 | 57 | void Ac97::MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size) 58 | { 59 | Log(LogLevel::Warning, "Ac97: Unimplemented MMIOWrite %X\n", addr); 60 | } 61 | -------------------------------------------------------------------------------- /src/devices/audio/ac97/ac97.h: -------------------------------------------------------------------------------- 1 | #ifndef _AC97_H_ 2 | #define _AC97_H_ 3 | 4 | #include "devices/pci/pci.h" 5 | 6 | class Ac97 : public PCIDevice 7 | { 8 | public: 9 | Ac97(); 10 | ~Ac97(); 11 | 12 | void Init(); 13 | void Reset(); 14 | 15 | uint32_t IORead(int barIndex, uint32_t addr, unsigned size = sizeof(uint8_t)); 16 | void IOWrite(int barIndex, uint32_t addr, uint32_t data, unsigned size = sizeof(uint8_t)); 17 | 18 | uint32_t MMIORead(int barIndex, uint32_t addr, unsigned size); 19 | void MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size); 20 | private: 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/devices/audio/mcpx/mcpx_apu.h: -------------------------------------------------------------------------------- 1 | #ifndef _APU_H_ 2 | #define _APU_H_ 3 | 4 | #include "devices/pci/pci.h" 5 | 6 | class McpxApu : public PCIDevice 7 | { 8 | public: 9 | McpxApu(); 10 | ~McpxApu(); 11 | 12 | /* PCI Functions */ 13 | void Init(); 14 | void Reset(); 15 | 16 | uint32_t IORead(int barIndex, uint32_t addr, unsigned size = sizeof(uint8_t)); 17 | void IOWrite(int barIndex, uint32_t addr, uint32_t data, unsigned size = sizeof(uint8_t)); 18 | 19 | uint32_t MMIORead(int barIndex, uint32_t addr, unsigned size); 20 | void MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size); 21 | private: 22 | /* TODO: Split into child devices */ 23 | uint32_t GPRead(uint32_t addr, unsigned size); 24 | void GPWrite(uint32_t addr, uint32_t value, unsigned size); 25 | uint32_t EPRead(uint32_t addr, unsigned size); 26 | void EPWrite(uint32_t addr, uint32_t value, unsigned size); 27 | uint32_t VPRead(uint32_t addr, unsigned size); 28 | void VPWrite(uint32_t addr, uint32_t value, unsigned size); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/devices/eeprom.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "smbus_device.h" 4 | 5 | class Eeprom : public SMDevice 6 | { 7 | public: 8 | void Init(); 9 | void Reset(); 10 | 11 | void QuickCommand(bool read); 12 | uint8_t ReceiveByte(); 13 | uint8_t ReadByte(uint8_t command); 14 | uint16_t ReadWord(uint8_t command); 15 | int ReadBlock(uint8_t command, uint8_t *data); 16 | 17 | void SendByte(uint8_t data); 18 | void WriteByte(uint8_t command, uint8_t value); 19 | void WriteWord(uint8_t command, uint16_t value); 20 | void WriteBlock(uint8_t command, uint8_t* data, int length); 21 | 22 | private: 23 | uint8_t m_Data[256]; 24 | }; 25 | -------------------------------------------------------------------------------- /src/devices/i8254.cpp: -------------------------------------------------------------------------------- 1 | #include "xbox.h" 2 | #include "i8254.h" 3 | #include "i8259.h" 4 | #include 5 | #include "util.h" 6 | 7 | I8254::I8254(Xbox& xbox) : m_Xbox(xbox) 8 | { 9 | 10 | } 11 | 12 | I8254::~I8254() 13 | { 14 | m_Active = false; 15 | if (m_TimerThread.joinable()) 16 | m_TimerThread.join(); 17 | } 18 | 19 | void I8254::Reset() 20 | { 21 | m_Active = false; 22 | } 23 | 24 | uint32_t I8254::IORead(uint32_t addr) 25 | { 26 | return 0; 27 | } 28 | 29 | void I8254::IOWrite(uint32_t addr, uint32_t value) 30 | { 31 | // HACK: The xbox always inits the PIT to the same value 32 | // Timer 0, Mode 2, 1ms interrupt interval (Xbox) 33 | // Timer 1, Mode 2, 1ms interrupt interval (Cromwell) 34 | // Rather than fully implement the PIC, we just wait for the command 35 | // to start operating, and then simply issue IRQ 0 in a timer thread 36 | if (addr && 0x43 && (value == 0x34 || value == 0x54)) 37 | { 38 | //m_Active = true; 39 | //m_TimerThread = std::thread(TimerThread, this); 40 | } 41 | else 42 | { 43 | Log(LogLevel::Warning, "Unimplemented I8254::IOWrite (%X = %X)\n", addr, value); 44 | } 45 | } 46 | 47 | void I8254::TimerThread(I8254* pPIT) 48 | { 49 | auto nextInterruptTime = pPIT->GetNextInterruptTime(); 50 | 51 | while (pPIT->m_Active) 52 | { 53 | if (std::chrono::steady_clock::now() > nextInterruptTime) 54 | { 55 | pPIT->m_Xbox.GetInterruptController().RaiseIRQ(0); 56 | nextInterruptTime = pPIT->GetNextInterruptTime(); 57 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 58 | pPIT->m_Xbox.GetInterruptController().LowerIRQ(0); 59 | } 60 | } 61 | 62 | pPIT->m_Active = false; 63 | } 64 | 65 | std::chrono::time_point> I8254::GetNextInterruptTime() 66 | { 67 | using namespace std::literals::chrono_literals; 68 | return std::chrono::steady_clock::now() + 1ms; 69 | } 70 | -------------------------------------------------------------------------------- /src/devices/i8254.h: -------------------------------------------------------------------------------- 1 | #ifndef _PIT_H_ 2 | #define _PIT_H_ 3 | 4 | class Xbox; 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define PORT_PIT_DATA_0 0x40 11 | #define PORT_PIT_DATA_1 0x41 12 | #define PORT_PIT_DATA_2 0x42 13 | #define PORT_PIT_COMMAND 0x43 14 | 15 | class I8254 16 | { 17 | public: 18 | I8254(Xbox& xbox); 19 | ~I8254(); 20 | void Reset(); 21 | 22 | uint32_t IORead(uint32_t addr); 23 | void IOWrite(uint32_t addr, uint32_t value); 24 | private: 25 | Xbox& m_Xbox; 26 | bool m_Active; 27 | std::chrono::time_point> GetNextInterruptTime(); 28 | std::thread m_TimerThread; 29 | static void TimerThread(I8254* pPIT); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/devices/i8259.h: -------------------------------------------------------------------------------- 1 | #ifndef _PIC_H_ 2 | #define _PIC_H_ 3 | 4 | class Xbox; 5 | #include 6 | 7 | #define PORT_PIC_MASTER_COMMAND 0x20 8 | #define PORT_PIC_MASTER_DATA 0x21 9 | #define PORT_PIC_SLAVE_COMMAND 0xA0 10 | #define PORT_PIC_SLAVE_DATA 0xA1 11 | #define PORT_PIC_MASTER_ELCR 0x4D0 12 | #define PORT_PIC_SLAVE_ELCR 0x4D1 13 | 14 | #define PIC_MASTER 0 15 | #define PIC_SLAVE 1 16 | 17 | class I8259 18 | { 19 | public: 20 | I8259(Xbox& xbox); 21 | void Reset(); 22 | 23 | uint32_t IORead(uint32_t addr); 24 | void IOWrite(uint32_t addr, uint32_t value); 25 | 26 | void RaiseIRQ(int index); 27 | void LowerIRQ(int index); 28 | 29 | int GetCurrentIRQ(); 30 | private: 31 | Xbox& m_Xbox; 32 | 33 | uint8_t m_PreviousIRR[2]; /* used for edge-detection */ 34 | uint8_t m_IRR[2]; 35 | uint8_t m_IMR[2]; 36 | uint8_t m_ISR[2]; 37 | uint8_t m_Base[2]; 38 | uint8_t m_ReadRegisterSelect[2]; 39 | uint8_t m_SpecialMask[2]; 40 | uint8_t m_InitState[2]; 41 | uint8_t m_ELCR[2]; 42 | uint8_t m_ELCRMask[2]; 43 | uint8_t m_PriorityAdd[2]; 44 | 45 | bool m_Poll[2]; 46 | bool m_RotateOnAutoEOI[2]; 47 | bool m_Is4ByteInit[2]; 48 | bool m_InterruptOutput[2]; 49 | bool m_AutoEOI[2]; 50 | bool m_IsSpecialFullyNestedMode[2]; 51 | 52 | uint32_t CommandRead(int pic); 53 | void CommandWrite(int pic, uint32_t value); 54 | uint32_t DataRead(int pic); 55 | void DataWrite(int pic, uint32_t value); 56 | 57 | void AcknowledgeIRQ(int pic, int index); 58 | int GetIRQ(int pic); 59 | void SetIRQ(int pic, int index, bool value); 60 | int GetPriority(int pic, uint8_t mask); 61 | uint8_t Poll(int pic); 62 | void Reset(int pic); 63 | void UpdateIRQ(int pic); 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/devices/pci/agp_bridge.cpp: -------------------------------------------------------------------------------- 1 | #include "agp_bridge.h" 2 | 3 | AGPBridge::AGPBridge() : PCIBridge(PCI_VENDOR_ID_NVIDIA, 0x01B7, 0xA1) 4 | { 5 | 6 | } 7 | 8 | AGPBridge::~AGPBridge() 9 | { 10 | 11 | } 12 | 13 | void AGPBridge::Init() 14 | { 15 | uint8_t i; 16 | 17 | Write16(m_configSpace, PCI_PREF_MEMORY_BASE, PCI_PREF_RANGE_TYPE_32); 18 | Write16(m_configSpace, PCI_PREF_MEMORY_LIMIT, PCI_PREF_RANGE_TYPE_32); 19 | PCIBridge::Init(); 20 | 21 | /* Initialize configuration space */ 22 | Write16(m_configSpace, PCI_STATUS, PCI_STATUS_66MHZ | PCI_STATUS_DEVSEL_MEDIUM); 23 | Write16(m_configSpace, PCI_SEC_STATUS, PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ | PCI_STATUS_DEVSEL_MEDIUM); 24 | Write8(m_configSpace, PCI_MIN_GNT, 0x80); 25 | Write8(m_configSpace, PCI_MAX_LAT, 0x00); 26 | Write8(m_configSpace, PCI_IO_BASE, 0xf0); 27 | Write8(m_configSpace, PCI_IO_LIMIT, 0x0); 28 | Write16(m_configSpace, PCI_MEMORY_BASE, 0xfd00); 29 | Write16(m_configSpace, PCI_MEMORY_LIMIT, 0xfe70); 30 | Write16(m_configSpace, PCI_PREF_MEMORY_BASE, 0xf000); 31 | Write16(m_configSpace, PCI_PREF_MEMORY_LIMIT, 0xf3f0); 32 | Write32(m_configSpace, PCI_PREF_BASE_UPPER32, 0xff3fbfff); 33 | Write32(m_configSpace, PCI_PREF_LIMIT_UPPER32, 0xafff7fff); 34 | Write16(m_configSpace, PCI_IO_BASE_UPPER16, 0xf5fd); 35 | Write16(m_configSpace, PCI_IO_LIMIT_UPPER16, 0x3eff); 36 | Write8(m_configSpace, PCI_CAPABILITY_LIST, 0x0); 37 | 38 | /* Unknown registers */ 39 | Write16(m_configSpace, 0x44, 0x0); 40 | Write16(m_configSpace, 0x46, 0x8000); 41 | Write16(m_configSpace, 0x48, 0x14); 42 | Write16(m_configSpace, 0x4c, 0x1); 43 | Write16(m_configSpace, 0x50, 0x0); 44 | Write32(m_configSpace, 0x54, 0x10000000); 45 | for (i = 0; i < 0x100 - 0x58; i += 4) 46 | Write32(m_configSpace, 0x58 + i, 0xffffffff); 47 | } 48 | -------------------------------------------------------------------------------- /src/devices/pci/agp_bridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "pci_bridge.h" 5 | 6 | class AGPBridge : public PCIBridge 7 | { 8 | public: 9 | /* constructor */ 10 | AGPBridge(); 11 | virtual ~AGPBridge(); 12 | 13 | /* PCI Device functions */ 14 | void Init() override; 15 | }; 16 | -------------------------------------------------------------------------------- /src/devices/pci/host_bridge.cpp: -------------------------------------------------------------------------------- 1 | #include "host_bridge.h" 2 | #include "util.h" 3 | 4 | HostBridge::HostBridge() 5 | : PCIDevice(PCI_HEADER_TYPE_MULTIFUNCTION, PCI_VENDOR_ID_NVIDIA, 0x02A5, 0xA1, 6 | 0x06, 0x00, 0x00, /* Host bridge */ 7 | /*TODO: subsystemVendorID*/0x00, /*TODO: subsystemID*/0x00) 8 | { 9 | } 10 | 11 | HostBridge::~HostBridge() { 12 | } 13 | 14 | /* PCI Device functions */ 15 | 16 | void HostBridge::Init() 17 | { 18 | RegisterBAR(0, 1024 * 1024 * 1024, PCI_BAR_TYPE_MEMORY); /* 0x40000000 - 0x7FFFFFFF */ 19 | Write32(m_configSpace, PCI_BASE_ADDRESS_0, 0x40000008); 20 | 21 | /* Initialize configuration space */ 22 | Write16(m_configSpace, PCI_STATUS, PCI_STATUS_CAP_LIST); 23 | Write8(m_configSpace, PCI_CAPABILITY_LIST, 0x40); 24 | 25 | /* Capability list */ 26 | Write8(m_configSpace, 0x40, PCI_CAP_ID_AGP); 27 | Write8(m_configSpace, 0x41, 0x60); 28 | 29 | Write8(m_configSpace, 0x60, PCI_CAP_ID_HT); 30 | Write8(m_configSpace, 0x61, 0x00); 31 | 32 | /* Unknown registers */ 33 | Write16(m_configSpace, 0x42, 0x20); 34 | Write32(m_configSpace, 0x44, 0x1f000217); 35 | Write8(m_configSpace, 0x4c, 0x1); 36 | Write8(m_configSpace, 0x57, 0x10); 37 | Write32(m_configSpace, 0x58, 0xffffffff); 38 | Write32(m_configSpace, 0x5c, 0xffffffff); 39 | Write32(m_configSpace, 0x60, 0x20010008); 40 | Write32(m_configSpace, 0x64, 0x88880120); 41 | Write32(m_configSpace, 0x68, 0x10); 42 | Write32(m_configSpace, 0x6c, 0x0f0f0f21); 43 | Write32(m_configSpace, 0x70, 0xffffffff); 44 | Write32(m_configSpace, 0x74, 0xffffffff); 45 | Write32(m_configSpace, 0x78, 0xffffffff); 46 | Write32(m_configSpace, 0x7c, 0xffffffff); 47 | Write32(m_configSpace, 0x87, 3); 48 | Write32(m_configSpace, 0x88, 0x1); 49 | Write32(m_configSpace, 0x8c, 0x3ff6f417); 50 | Write32(m_configSpace, 0x94, 0xf9feffff); 51 | Write32(m_configSpace, 0xa4, 0x2001); 52 | Write32(m_configSpace, 0xb0, 0x1); 53 | Write32(m_configSpace, 0xc0, 0x33333); 54 | Write32(m_configSpace, 0xc4, 0x33333); 55 | Write32(m_configSpace, 0xc8, 0x13); 56 | Write32(m_configSpace, 0xd4, 0x1); 57 | Write32(m_configSpace, 0xd8, 0x7f0ffff); 58 | Write32(m_configSpace, 0xe0, 0x400006); 59 | Write32(m_configSpace, 0xe4, 0x1ff75b7); 60 | Write32(m_configSpace, 0xf0, 0xf0000001); 61 | } 62 | 63 | void HostBridge::Reset() { } 64 | 65 | uint32_t HostBridge::MMIORead(int barIndex, uint32_t addr, unsigned size) 66 | { 67 | Log(LogLevel::Warning, "HostBridge::MMIORead: Unimplemented! bar = %d, address = 0x%x, size = %u\n", barIndex, addr, size); 68 | 69 | return 0; 70 | } 71 | 72 | void HostBridge::MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size) 73 | { 74 | Log(LogLevel::Warning, "HostBridge::MMIOWrite: Unimplemented! bar = %d, address = 0x%x, value = 0x%x, size = %u\n", barIndex, addr, value, size); 75 | } 76 | -------------------------------------------------------------------------------- /src/devices/pci/host_bridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "pci.h" 6 | 7 | class HostBridge : public PCIDevice 8 | { 9 | public: 10 | /* constructor */ 11 | HostBridge(); 12 | ~HostBridge(); 13 | 14 | /* PCI Device functions */ 15 | void Init(); 16 | void Reset(); 17 | 18 | uint32_t MMIORead(int barIndex, uint32_t addr, unsigned size) override; 19 | void MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size) override; 20 | }; 21 | -------------------------------------------------------------------------------- /src/devices/pci/pci_bridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "pci.h" 6 | #include "pci_bus.h" 7 | 8 | class PCIBridge : public PCIDevice 9 | { 10 | public: 11 | /* constructor */ 12 | PCIBridge(); 13 | virtual ~PCIBridge(); 14 | 15 | /* PCI Device functions */ 16 | virtual void Init() override; 17 | virtual void Reset() override; 18 | 19 | void WriteConfig(uint32_t reg, uint32_t value, uint8_t size) override; 20 | 21 | inline PCIBus *GetSecondaryBus() { return m_secBus; } 22 | 23 | protected: 24 | PCIBridge(uint16_t vendorID, uint16_t deviceID, uint8_t revisionID); 25 | private: 26 | PCIBus *m_secBus; 27 | }; 28 | -------------------------------------------------------------------------------- /src/devices/pci/pci_bus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pci.h" 4 | #include 5 | 6 | #define PORT_PCI_CONFIG_ADDRESS 0xCF8 7 | #define PORT_PCI_CONFIG_DATA 0xCFC 8 | #define PCI_CONFIG_REGISTER_MASK 0xFC 9 | 10 | class PCIBus 11 | { 12 | public: 13 | PCIBus(); 14 | virtual ~PCIBus(); 15 | 16 | void ConnectDevice(uint32_t deviceId, PCIDevice *pDevice); 17 | 18 | bool IORead(uint32_t port, uint32_t *value, unsigned size); 19 | bool IOWrite(uint32_t port, uint32_t value, unsigned size); 20 | 21 | bool MMIORead(uint32_t addr, uint32_t *value, unsigned size); 22 | bool MMIOWrite(uint32_t addr, uint32_t value, unsigned size); 23 | 24 | void Reset(); 25 | private: 26 | friend class PCIDevice; 27 | friend class PCIBridge; 28 | 29 | PCIDevice *m_owner; /* The bridge that owns this bus */ 30 | std::map m_Devices; 31 | PCIConfigAddressRegister m_configAddressRegister; 32 | 33 | void IOWriteConfigAddress(uint32_t pData); 34 | void IOWriteConfigData(uint32_t pData, uint8_t size, uint8_t regOffset); 35 | uint32_t IOReadConfigData(uint8_t size, uint8_t regOffset); 36 | }; 37 | -------------------------------------------------------------------------------- /src/devices/smbus.h: -------------------------------------------------------------------------------- 1 | #ifndef _SMBUS_H_ 2 | #define _SMBUS_H_ 3 | 4 | #include "pci/pci.h" 5 | #include "smbus_device.h" 6 | class Xbox; 7 | 8 | #include 9 | 10 | #define SMB_ADDR_OFFSET 0xE0 11 | #define SMB_IOSIZE 16 12 | #define SMB_IRQ 11 13 | 14 | #define SMB_GLOBAL_STATUS 0x0 15 | #define SMB_GLOBAL_ENABLE 0x2 16 | #define SMB_HOST_ADDRESS 0x4 17 | #define SMB_HOST_DATA 0x6 18 | #define SMB_HOST_COMMAND 0x8 19 | #define SMB_HOST_BLOCK_DATA 0x9 20 | #define SMB_HAS_DATA 0xA 21 | #define SMB_HAS_DEVICE_ADDRESS 0xC 22 | #define SMB_HAS_HOST_ADDRESS 0xE 23 | #define SMB_SNOOP_ADDRESS 0xF 24 | 25 | /* AMD756 constants */ 26 | #define AMD756_QUICK 0x00 27 | #define AMD756_BYTE 0x01 28 | #define AMD756_BYTE_DATA 0x02 29 | #define AMD756_WORD_DATA 0x03 30 | #define AMD756_PROCESS_CALL 0x04 31 | #define AMD756_BLOCK_DATA 0x05 32 | 33 | /* SMB_GLOBAL_STATUS flags */ 34 | #define GS_ABRT_STS (1 << 0) 35 | #define GS_COL_STS (1 << 1) 36 | #define GS_PRERR_STS (1 << 2) 37 | #define GS_HST_STS (1 << 3) 38 | #define GS_HCYC_STS (1 << 4) 39 | #define GS_TO_STS (1 << 5) 40 | #define GS_SMB_STS (1 << 11) 41 | 42 | #define GS_CLEAR_STS (GS_ABRT_STS | GS_COL_STS | GS_PRERR_STS | GS_HCYC_STS | GS_TO_STS ) 43 | 44 | #define GE_CYC_TYPE_MASK (7) 45 | #define GE_HOST_STC (1 << 3) 46 | 47 | #define GE_HCYC_EN (1 << 4) 48 | #define GE_ABORT (1 << 5) 49 | 50 | class SMBus : public PCIDevice 51 | { 52 | public: 53 | SMBus(Xbox& xbox); 54 | ~SMBus(); 55 | 56 | /* PCI Functions */ 57 | void Init(); 58 | void Reset(); 59 | 60 | uint32_t IORead(int barIndex, uint32_t addr, unsigned size = sizeof(uint8_t)); 61 | void IOWrite(int barIndex, uint32_t addr, uint32_t data, unsigned size = sizeof(uint8_t)); 62 | 63 | uint32_t MMIORead(int barIndex, uint32_t addr, unsigned size); 64 | void MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size); 65 | 66 | /* Misc */ 67 | void ConnectDevice(uint8_t addr, SMDevice *device); 68 | 69 | private: 70 | Xbox& m_Xbox; 71 | uint8_t m_Status; 72 | uint8_t m_Control; 73 | uint8_t m_Command; 74 | uint8_t m_Address; 75 | uint8_t m_Data0; 76 | uint8_t m_Data1; 77 | uint8_t m_Data[32]; 78 | uint8_t m_Index; 79 | 80 | void ExecuteTransaction(); 81 | 82 | std::map m_Devices; 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/devices/smbus_device.h: -------------------------------------------------------------------------------- 1 | #ifndef _SMDEVICE_H_ 2 | #define _SMDEVICE_H_ 3 | 4 | #include 5 | 6 | class SMDevice 7 | { 8 | public: 9 | virtual void Init() = 0; 10 | virtual void Reset() = 0; 11 | 12 | virtual void QuickCommand(bool read) = 0; 13 | virtual uint8_t ReceiveByte() = 0; 14 | virtual uint8_t ReadByte(uint8_t command) = 0; 15 | virtual uint16_t ReadWord(uint8_t command) = 0; 16 | virtual int ReadBlock(uint8_t command, uint8_t *data) = 0; 17 | 18 | virtual void SendByte(uint8_t data) = 0; 19 | virtual void WriteByte(uint8_t command, uint8_t value) = 0; 20 | virtual void WriteWord(uint8_t command, uint16_t value) = 0; 21 | virtual void WriteBlock(uint8_t command, uint8_t* data, int length) = 0; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/devices/smc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "smbus_device.h" 4 | 5 | #define SMC_COMMAND_VERSION 0x01 6 | #define SMC_COMMAND_AV_PACK 0x04 7 | #define SMC_COMMAND_CPU_TEMP 0x09 8 | #define SMC_COMMAND_MOTHERBOARD_TEMP 0x0A 9 | #define SMC_COMMAND_POWER_FAN_READBACK 0x10 10 | #define SMC_COMMAND_SCRATCH 0x1B 11 | #define SMC_COMMAND_CHALLENGE_1C 0x1C 12 | #define SMC_COMMAND_CHALLENGE_1D 0x1D 13 | #define SMC_COMMAND_CHALLENGE_1E 0x1E 14 | #define SMC_COMMAND_CHALLENGE_1F 0x1F 15 | 16 | #define SMC_COMMAND_RESET 0x02 17 | #define SMC_COMMAND_POWER_FAN_MODE 0x05 18 | #define SMC_COMMAND_POWER_FAN_REGISTER 0x06 19 | #define SMC_COMMAND_LED_MODE 0x07 20 | #define SMC_COMMAND_LED_SEQUENCE 0x08 21 | #define SMC_COMMAND_SCRATCH 0x1B 22 | 23 | #define SMC_RESET_ASSERT_RESET 0x01 24 | #define SMC_RESET_ASSERT_POWERCYCLE 0x40 25 | #define SMC_RESET_ASSERT_SHUTDOWN 0x80 26 | 27 | #define SMC_SCRATCH_TRAY_EJECT_PENDING 0x01 28 | #define SMC_SCRATCH_DISPLAY_FATAL_ERROR 0x02 29 | #define SMC_SCRATCH_SHORT_ANIMATION 0x04 30 | #define SMC_SCRATCH_DASHBOARD_BOOT 0x08 31 | 32 | typedef enum 33 | { 34 | P01, 35 | P2L, 36 | D01, /* Seen in a debug kit */ 37 | D05, /* Seen in a earlier model chihiro */ 38 | } SCMRevision; 39 | 40 | class SMC : public SMDevice 41 | { 42 | public: 43 | /* SMDevice functions */ 44 | void Init(); 45 | void Reset(); 46 | 47 | void QuickCommand(bool read); 48 | uint8_t ReceiveByte(); 49 | uint8_t ReadByte(uint8_t command); 50 | uint16_t ReadWord(uint8_t command); 51 | int ReadBlock(uint8_t command, uint8_t *data); 52 | 53 | void SendByte(uint8_t data); 54 | void WriteByte(uint8_t command, uint8_t value); 55 | void WriteWord(uint8_t command, uint16_t value); 56 | void WriteBlock(uint8_t command, uint8_t* data, int length); 57 | 58 | private: 59 | SCMRevision m_revision = SCMRevision::P01; 60 | int m_PICVersionStringIndex = 0; 61 | uint8_t buffer[256] = {}; 62 | }; 63 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/component.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_COMPONENT_H 2 | #define _NV2A_COMPONENT_H 3 | 4 | #include 5 | class Nv2a; 6 | 7 | class Nv2aComponent 8 | { 9 | public: 10 | virtual uint32_t Read(uint32_t addr, unsigned size) = 0; 11 | virtual void Write(uint32_t addr, uint32_t value, unsigned size) = 0; 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/nv2a.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_H_ 2 | #define _NV2A_H_ 3 | 4 | class Xbox; 5 | 6 | #include "devices/pci/pci.h" 7 | #include "regs.h" 8 | 9 | #include "component.h" 10 | #include "pmc.h" 11 | #include "pbus.h" 12 | #include "pfifo.h" 13 | #include "prma.h" 14 | #include "pvideo.h" 15 | #include "ptimer.h" 16 | #include "pcounter.h" 17 | #include "pvpe.h" 18 | #include "ptv.h" 19 | #include "prmfb.h" 20 | #include "prmvio.h" 21 | #include "pfb.h" 22 | #include "pstraps.h" 23 | #include "pgraph.h" 24 | #include "pcrtc.h" 25 | #include "prmcio.h" 26 | #include "pramdac.h" 27 | #include "prmdio.h" 28 | #include "pramin.h" 29 | #include "user.h" 30 | 31 | #include 32 | 33 | struct Nv2aRegion 34 | { 35 | uint32_t addr; 36 | uint32_t size; 37 | Nv2aComponent& component; 38 | }; 39 | 40 | typedef struct { 41 | uint8_t fb_start; 42 | uint8_t width; 43 | uint8_t height; 44 | uint8_t pitch; 45 | } DisplayInfo; 46 | 47 | class Nv2a : public PCIDevice 48 | { 49 | public: 50 | Nv2a(Xbox& xbox); 51 | virtual ~Nv2a(); 52 | 53 | /* PCI Functions */ 54 | void Init(); 55 | void Reset(); 56 | 57 | uint32_t IORead(int barIndex, uint32_t addr, unsigned size); 58 | void IOWrite(int barIndex, uint32_t addr, uint32_t data, unsigned size); 59 | uint32_t MMIORead(int barIndex, uint32_t addr, unsigned size); 60 | void MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size); 61 | 62 | Nv2aPmc Pmc; 63 | Nv2aPbus Pbus; 64 | Nv2aPfifo Pfifo; 65 | Nv2aPrma Prma; 66 | Nv2aPvideo Pvideo; 67 | Nv2aPtimer Ptimer; 68 | Nv2aPcounter Pcounter; 69 | Nv2aPvpe Pvpe; 70 | Nv2aPtv Ptv; 71 | Nv2aPrmfb Prmfb; 72 | Nv2aPrmvio Prmvio; 73 | Nv2aPfb Pfb; 74 | Nv2aPstraps Pstraps; 75 | Nv2aPgraph Pgraph; 76 | Nv2aPcrtc Pcrtc; 77 | Nv2aPrmcio Prmcio; 78 | Nv2aPramdac Pramdac; 79 | Nv2aPrmdio Prmdio; 80 | Nv2aPramin Pramin; 81 | Nv2aUser User; 82 | 83 | void UpdateIrq(); 84 | private: 85 | std::vector m_MemoryRegions; 86 | Nv2aRegion* GetMemoryRegion(uint32_t addr); 87 | Xbox& m_Xbox; 88 | uint8_t* m_pRam; 89 | }; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pbus.cpp: -------------------------------------------------------------------------------- 1 | #include "pbus.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPbus::Nv2aPbus(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPbus::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) 14 | { 15 | default: 16 | Log(LogLevel::Warning, "Nv2aPbus: Unimplemented Read %X\n", addr); 17 | break; 18 | } 19 | 20 | return 0; 21 | } 22 | 23 | void Nv2aPbus::Write(uint32_t addr, uint32_t value, unsigned size) 24 | { 25 | switch (addr) 26 | { 27 | default: 28 | Log(LogLevel::Warning, "Nv2aPbus: Unimplemented Write %X = %X\n", addr, value); break; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pbus.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PBUS_H 2 | #define _NV2A_PBUS_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPbus : public Nv2aComponent { 10 | public: 11 | Nv2aPbus(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pcounter.cpp: -------------------------------------------------------------------------------- 1 | #include "pcounter.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPcounter::Nv2aPcounter(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPcounter::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) 14 | { 15 | default: 16 | Log(LogLevel::Warning, "Nv2aPcounter: Unimplemented Read %X\n", addr); break; 17 | } 18 | 19 | return 0; 20 | } 21 | 22 | void Nv2aPcounter::Write(uint32_t addr, uint32_t value, unsigned size) 23 | { 24 | switch (addr) 25 | { 26 | default: 27 | Log(LogLevel::Warning, "Nv2aPcounter: Unimplemented Write %X = %X\n", addr, value); 28 | break; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pcounter.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PCOUNTER_H 2 | #define _NV2A_PCOUNTER_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPcounter : public Nv2aComponent 10 | { 11 | public: 12 | Nv2aPcounter(Nv2a& nv2a); 13 | uint32_t Read(uint32_t addr, unsigned size); 14 | void Write(uint32_t addr, uint32_t value, unsigned size); 15 | private: 16 | Nv2a& m_Nv2a; 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pcrtc.cpp: -------------------------------------------------------------------------------- 1 | #include "pcrtc.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPcrtc::Nv2aPcrtc(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPcrtc::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | case NV_PCRTC_START: break; 15 | default: 16 | Log(LogLevel::Warning, "Nv2aPcrtc: Unimplemented Read %X\n", addr); 17 | } 18 | 19 | return m_Regs[addr]; 20 | } 21 | 22 | void Nv2aPcrtc::Write(uint32_t addr, uint32_t value, unsigned size) 23 | { 24 | switch (addr) { 25 | case NV_PCRTC_START: break; 26 | default: 27 | Log(LogLevel::Warning, "Nv2aPcrtc: Unimplemented Write %X = %X\n", addr, value); 28 | } 29 | 30 | m_Regs[addr] = value; 31 | } 32 | 33 | uint32_t Nv2aPcrtc::GetFramebufferAddr() 34 | { 35 | return m_Regs[NV_PCRTC_START]; 36 | } 37 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pcrtc.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PCRTC_H 2 | #define _NV2A_PCRTC_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | #define NV_REGION_PCRTC_ADDR 0x00600000 10 | #define NV_REGION_PCRTC_SIZE 0x001000 11 | 12 | class Nv2aPcrtc : public Nv2aComponent { 13 | public: 14 | Nv2aPcrtc(Nv2a& nv2a); 15 | uint32_t Read(uint32_t addr, unsigned size); 16 | void Write(uint32_t addr, uint32_t value, unsigned size); 17 | 18 | uint32_t GetFramebufferAddr(); 19 | private: 20 | uint32_t m_Regs[NV_REGION_PCRTC_SIZE]; 21 | Nv2a& m_Nv2a; 22 | }; 23 | 24 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/pfb.cpp: -------------------------------------------------------------------------------- 1 | #include "pfb.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPfb::Nv2aPfb(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPfb::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPfb: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPfb::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPfb: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/pfb.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PFB_H 2 | #define _NV2A_PFB_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPfb : public Nv2aComponent { 10 | public: 11 | Nv2aPfb(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/pfifo.cpp: -------------------------------------------------------------------------------- 1 | #include "pfifo.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPfifo::Nv2aPfifo(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint8_t Nv2aPfifo::GetCurrentChannelId() 12 | { 13 | return GET_MASK(m_Regs[NV_PFIFO_CACHE1_PUSH1], NV_PFIFO_CACHE1_PUSH1_CHID); 14 | } 15 | 16 | uint8_t Nv2aPfifo::GetChannelMode(uint8_t channel_id) 17 | { 18 | return m_Regs[NV_PFIFO_MODE] & (1 << channel_id) ? 1 : 0; 19 | } 20 | 21 | uint32_t Nv2aPfifo::Read(uint32_t addr, unsigned size) 22 | { 23 | if (addr == NV_PFIFO_RUNOUT_STATUS) { 24 | return NV_PFIFO_RUNOUT_STATUS_LOW_MARK; 25 | } 26 | 27 | return m_Regs[addr]; 28 | 29 | } 30 | 31 | void Nv2aPfifo::Write(uint32_t addr, uint32_t value, unsigned size) 32 | { 33 | switch (addr) { 34 | case NV_PFIFO_INTR_0: m_Regs[NV_PFIFO_INTR_0] &= ~value; m_Nv2a.UpdateIrq(); return; 35 | case NV_PFIFO_INTR_EN_0: m_Nv2a.UpdateIrq(); break; 36 | } 37 | 38 | m_Regs[addr] = value; 39 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/pfifo.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PFIFO_H 2 | #define _NV2A_PFIFO_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | #define NV_REGION_PFIFO_ADDR 0x00002000 10 | #define NV_REGION_PFIFO_SIZE 0x002000 11 | 12 | class Nv2aPfifo : public Nv2aComponent { 13 | public: 14 | Nv2aPfifo(Nv2a& nv2a); 15 | uint32_t Read(uint32_t addr, unsigned size); 16 | void Write(uint32_t addr, uint32_t value, unsigned size); 17 | 18 | uint8_t GetCurrentChannelId(); 19 | uint8_t GetChannelMode(uint8_t channel_id); 20 | private: 21 | uint32_t m_Regs[NV_REGION_PFIFO_SIZE]; 22 | Nv2a& m_Nv2a; 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/pgraph.cpp: -------------------------------------------------------------------------------- 1 | #include "pgraph.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPgraph::Nv2aPgraph(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPgraph::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPgraph: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPgraph::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPgraph: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/pgraph.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PGRAPH_H 2 | #define _NV2A_PGRAPH_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPgraph : public Nv2aComponent { 10 | public: 11 | Nv2aPgraph(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/pmc.cpp: -------------------------------------------------------------------------------- 1 | #include "pmc.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPmc::Nv2aPmc(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPmc::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPmc: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPmc::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPmc: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/pmc.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PMC_H 2 | #define _NV2A_PMC_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPmc : public Nv2aComponent { 10 | public: 11 | Nv2aPmc(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/pramdac.cpp: -------------------------------------------------------------------------------- 1 | #include "pramdac.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPramdac::Nv2aPramdac(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPramdac::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPramdac: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPramdac::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPramdac: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/pramdac.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PRAMDAC_H 2 | #define _NV2A_PRAMDAC_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPramdac : public Nv2aComponent { 10 | public: 11 | Nv2aPramdac(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/pramin.cpp: -------------------------------------------------------------------------------- 1 | #include "pramin.h" 2 | #include "nv2a.h" 3 | #include 4 | 5 | Nv2aPramin::Nv2aPramin(Nv2a& nv2a) : m_Nv2a(nv2a) 6 | { 7 | 8 | } 9 | 10 | uint32_t Nv2aPramin::Read(uint32_t addr, unsigned size) 11 | { 12 | return *((uint32_t*)&m_Data[addr]); 13 | } 14 | 15 | void Nv2aPramin::Write(uint32_t addr, uint32_t value, unsigned size) 16 | { 17 | *((uint32_t*)&m_Data[addr]) = value; 18 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/pramin.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PRAMIN_H 2 | #define _NV2A_PRAMIN_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPramin : public Nv2aComponent { 10 | public: 11 | Nv2aPramin(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | uint8_t m_Data[0x100000]; 16 | Nv2a& m_Nv2a; 17 | }; 18 | 19 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/prma.cpp: -------------------------------------------------------------------------------- 1 | #include "prma.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPrma::Nv2aPrma(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPrma::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPrma: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPrma::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPrma: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/prma.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PRMA_H 2 | #define _NV2A_PRMA_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPrma : public Nv2aComponent { 10 | public: 11 | Nv2aPrma(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/prmcio.cpp: -------------------------------------------------------------------------------- 1 | #include "prmcio.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | #define VGA_BASE 0x3C0 7 | 8 | Nv2aPrmcio::Nv2aPrmcio(Nv2a& nv2a) : m_Nv2a(nv2a) 9 | { 10 | m_Index = 0; 11 | } 12 | 13 | 14 | uint32_t Nv2aPrmcio::Read(uint32_t addr, unsigned size) 15 | { 16 | switch (addr) { 17 | case NV_PRMCIO_CRX__COLOR: return m_Index; 18 | case NV_PRMCIO_CR__COLOR: return m_Regs[m_Index]; 19 | default: 20 | Log(LogLevel::Warning, "Nv2aPrmcio: Unimplemented Read %X\n", addr); 21 | } 22 | 23 | return 0; 24 | } 25 | 26 | void Nv2aPrmcio::Write(uint32_t addr, uint32_t value, unsigned size) 27 | { 28 | switch (addr) { 29 | case NV_PRMCIO_CRX__COLOR: m_Index = value; return; 30 | case NV_PRMCIO_CR__COLOR: m_Regs[m_Index] = value; return; 31 | default: 32 | Log(LogLevel::Warning, "Nv2aPrmcio: Unimplemented Write %X = %X\n", addr, value); 33 | } 34 | } 35 | 36 | uint8_t Nv2aPrmcio::GetDisplayBpp() 37 | { 38 | uint8_t bpp[4] = { 4, 1, 2, 4 }; 39 | return bpp[m_Regs[NV_CIO_CRE_PIXEL_INDEX] & 3]; 40 | } 41 | 42 | uint16_t Nv2aPrmcio::GetDisplayWidth() 43 | { 44 | int width = ((int)m_Regs[NV_CIO_CR_OFFSET_INDEX]) 45 | | (0x700 & ((int)m_Regs[NV_CIO_CRE_RPC0_INDEX] << 3)) 46 | | (0x800 & ((int)m_Regs[NV_CIO_CRE_LSR_INDEX] << 6)); 47 | 48 | width *= 8; 49 | width /= GetDisplayBpp(); 50 | 51 | return (uint16_t)width; 52 | } 53 | 54 | uint16_t Nv2aPrmcio::GetDisplayHeight() 55 | { 56 | int height = (int)m_Regs[NV_CIO_CR_VDE_INDEX] 57 | | (((int)m_Regs[NV_CIO_CR_OVL_INDEX] & 0x02) >> 1 << 8) 58 | | (((int)m_Regs[NV_CIO_CR_OVL_INDEX] & 0x40) >> 6 << 9) 59 | | (((int)m_Regs[NV_CIO_CRE_LSR_INDEX] & 0x02) >> 1 << 10); 60 | 61 | return (uint16_t)height + 1; 62 | } 63 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/prmcio.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PRMCIO_H 2 | #define _NV2A_PRMCIO_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | #define NV_REGION_PRMCIO_ADDR 0x00601000 10 | #define NV_REGION_PRMCIO_SIZE 0x001000 11 | 12 | class Nv2aPrmcio : public Nv2aComponent { 13 | public: 14 | Nv2aPrmcio(Nv2a& nv2a); 15 | uint32_t Read(uint32_t addr, unsigned size); 16 | void Write(uint32_t addr, uint32_t value, unsigned size); 17 | 18 | uint8_t GetDisplayBpp(); 19 | uint16_t GetDisplayWidth(); 20 | uint16_t GetDisplayHeight(); 21 | // TODO: GetDisplayFormat 22 | private: 23 | Nv2a& m_Nv2a; 24 | uint16_t m_Index; 25 | uint32_t m_Regs[NV_REGION_PRMCIO_SIZE]; 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/prmdio.cpp: -------------------------------------------------------------------------------- 1 | #include "prmdio.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPrmdio::Nv2aPrmdio(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPrmdio::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPrmdio: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPrmdio::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPrmdio: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/prmdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PRMDIO_H 2 | #define _NV2A_PRMDIO_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPrmdio : public Nv2aComponent { 10 | public: 11 | Nv2aPrmdio(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/prmfb.cpp: -------------------------------------------------------------------------------- 1 | #include "prmfb.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPrmfb::Nv2aPrmfb(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPrmfb::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPrmfb: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPrmfb::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPrmfb: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/prmfb.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PRMFB_H 2 | #define _NV2A_PRMFB_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPrmfb : public Nv2aComponent { 10 | public: 11 | Nv2aPrmfb(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/prmvio.cpp: -------------------------------------------------------------------------------- 1 | #include "prmvio.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPrmvio::Nv2aPrmvio(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPrmvio::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPrmvio: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPrmvio::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPrmvio: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/prmvio.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PRMVIO_H 2 | #define _NV2A_PRMVIO_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPrmvio : public Nv2aComponent { 10 | public: 11 | Nv2aPrmvio(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/pstraps.cpp: -------------------------------------------------------------------------------- 1 | #include "pstraps.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPstraps::Nv2aPstraps(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPstraps::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) { 14 | default: 15 | Log(LogLevel::Warning, "Nv2aPstraps: Unimplemented Read %X\n", addr); break; 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | void Nv2aPstraps::Write(uint32_t addr, uint32_t value, unsigned size) 22 | { 23 | switch (addr) { 24 | default: 25 | Log(LogLevel::Warning, "Nv2aPstraps: Unimplemented Write %X = %X\n", addr, value); break; 26 | } 27 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/pstraps.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PSTRAPS_H 2 | #define _NV2A_PSTRAPS_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPstraps : public Nv2aComponent { 10 | public: 11 | Nv2aPstraps(Nv2a& nv2a); 12 | uint32_t Read(uint32_t addr, unsigned size); 13 | void Write(uint32_t addr, uint32_t value, unsigned size); 14 | private: 15 | Nv2a& m_Nv2a; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /src/devices/video/nv2a/ptimer.cpp: -------------------------------------------------------------------------------- 1 | #include "ptimer.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPtimer::Nv2aPtimer(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPtimer::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) 14 | { 15 | default: 16 | Log(LogLevel::Warning, "Nv2aPtimer: Unimplemented Read %X\n", addr); 17 | break; 18 | } 19 | 20 | return 0; 21 | } 22 | 23 | void Nv2aPtimer::Write(uint32_t addr, uint32_t value, unsigned size) 24 | { 25 | switch (addr) 26 | { 27 | default: 28 | Log(LogLevel::Warning, "Nv2aPtimer: Unimplemented Write %X = %X\n", addr, value); 29 | break; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/ptimer.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PTIMER_H 2 | #define _NV2A_PTIMER_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPtimer : public Nv2aComponent 10 | { 11 | public: 12 | Nv2aPtimer(Nv2a& nv2a); 13 | uint32_t Read(uint32_t addr, unsigned size); 14 | void Write(uint32_t addr, uint32_t value, unsigned size); 15 | private: 16 | Nv2a& m_Nv2a; 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/ptv.cpp: -------------------------------------------------------------------------------- 1 | #include "ptv.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPtv::Nv2aPtv(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPtv::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) 14 | { 15 | default: 16 | Log(LogLevel::Warning, "Nv2aPtv: Unimplemented Read %X\n", addr); 17 | break; 18 | } 19 | 20 | return 0; 21 | } 22 | 23 | void Nv2aPtv::Write(uint32_t addr, uint32_t value, unsigned size) 24 | { 25 | switch (addr) 26 | { 27 | default: 28 | Log(LogLevel::Warning, "Nv2aPtv: Unimplemented Write %X = %X\n", addr, value); 29 | break; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/ptv.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PTV_H 2 | #define _NV2A_PTV_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPtv : public Nv2aComponent 10 | { 11 | public: 12 | Nv2aPtv(Nv2a& nv2a); 13 | uint32_t Read(uint32_t addr, unsigned size); 14 | void Write(uint32_t addr, uint32_t value, unsigned size); 15 | private: 16 | Nv2a& m_Nv2a; 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pvideo.cpp: -------------------------------------------------------------------------------- 1 | #include "pvideo.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPvideo::Nv2aPvideo(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPvideo::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) 14 | { 15 | default: 16 | Log(LogLevel::Warning, "Nv2aPvideo: Unimplemented Read %X\n", addr); break; 17 | } 18 | 19 | return 0; 20 | } 21 | 22 | void Nv2aPvideo::Write(uint32_t addr, uint32_t value, unsigned size) 23 | { 24 | switch (addr) 25 | { 26 | default: 27 | Log(LogLevel::Warning, "Nv2aPvideo: Unimplemented Write %X = %X\n", addr, value); 28 | break; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pvideo.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PVIDEO_H 2 | #define _NV2A_PVIDEO_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPvideo : public Nv2aComponent 10 | { 11 | public: 12 | Nv2aPvideo(Nv2a& nv2a); 13 | uint32_t Read(uint32_t addr, unsigned size); 14 | void Write(uint32_t addr, uint32_t value, unsigned size); 15 | private: 16 | Nv2a& m_Nv2a; 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pvpe.cpp: -------------------------------------------------------------------------------- 1 | #include "pvpe.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aPvpe::Nv2aPvpe(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aPvpe::Read(uint32_t addr, unsigned size) 12 | { 13 | switch (addr) 14 | { 15 | default: 16 | Log(LogLevel::Warning, "Nv2aPvpe: Unimplemented Read %X\n", addr); break; 17 | } 18 | 19 | return 0; 20 | } 21 | 22 | void Nv2aPvpe::Write(uint32_t addr, uint32_t value, unsigned size) 23 | { 24 | switch (addr) 25 | { 26 | default: 27 | Log(LogLevel::Warning, "Nv2aPvpe: Unimplemented Write %X = %X\n", addr, value); break; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/pvpe.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_PVPE_H 2 | #define _NV2A_PVPE_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | class Nv2aPvpe : public Nv2aComponent 10 | { 11 | public: 12 | Nv2aPvpe(Nv2a& nv2a); 13 | uint32_t Read(uint32_t addr, unsigned size); 14 | void Write(uint32_t addr, uint32_t value, unsigned size); 15 | private: 16 | Nv2a& m_Nv2a; 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/devices/video/nv2a/user.cpp: -------------------------------------------------------------------------------- 1 | #include "user.h" 2 | #include "nv2a.h" 3 | #include "util.h" 4 | #include 5 | 6 | Nv2aUser::Nv2aUser(Nv2a& nv2a) : m_Nv2a(nv2a) 7 | { 8 | 9 | } 10 | 11 | uint32_t Nv2aUser::Read(uint32_t addr, unsigned size) 12 | { 13 | uint8_t channel_id = (addr >> 16) & 0xFF; 14 | 15 | // Do nothing if not accessing the currently active channel 16 | if (channel_id != m_Nv2a.Pfifo.GetCurrentChannelId()) { 17 | return 0; 18 | } 19 | 20 | // Do nothing if using PIO instead of DMA 21 | if (!m_Nv2a.Pfifo.GetChannelMode(channel_id)) { 22 | Log(LogLevel::Warning, "Nv2aUser: PIO Mode unsupported\n"); 23 | return 0; 24 | } 25 | 26 | switch (addr & 0xFFFF) { 27 | case NV_USER_DMA_PUT: return m_Nv2a.Pfifo.Read(NV_PFIFO_CACHE1_DMA_PUT, size); 28 | case NV_USER_DMA_GET: return m_Nv2a.Pfifo.Read(NV_PFIFO_CACHE1_DMA_GET, size); 29 | case NV_USER_REF: return m_Nv2a.Pfifo.Read(NV_PFIFO_CACHE1_REF, size); 30 | default: Log(LogLevel::Warning, "Nv2aUser: Unimplemented Read %X\n", addr); 31 | } 32 | 33 | return m_Regs[addr]; 34 | } 35 | 36 | void Nv2aUser::Write(uint32_t addr, uint32_t value, unsigned size) 37 | { 38 | uint8_t channel_id = (addr >> 16) & 0xFF; 39 | 40 | // Do nothing if not accessing the currently active channel 41 | if (channel_id != m_Nv2a.Pfifo.GetCurrentChannelId()) { 42 | return; 43 | } 44 | 45 | // Do nothing if using PIO instead of DMA 46 | if (!m_Nv2a.Pfifo.GetChannelMode(channel_id)) { 47 | Log(LogLevel::Warning, "Nv2aUser: PIO Mode unsupported\n"); 48 | return; 49 | } 50 | 51 | switch (addr & 0xFFFF) { 52 | case NV_USER_DMA_PUT: m_Nv2a.Pfifo.Write(NV_PFIFO_CACHE1_DMA_PUT, value, size); 53 | case NV_USER_DMA_GET: m_Nv2a.Pfifo.Write(NV_PFIFO_CACHE1_DMA_GET, value, size); 54 | case NV_USER_REF: m_Nv2a.Pfifo.Write(NV_PFIFO_CACHE1_REF, value, size); 55 | default: Log(LogLevel::Warning, "Nv2aUser: Unimplemented Write %X = %X\n", addr, value); 56 | } 57 | 58 | m_Regs[addr] = value; 59 | } -------------------------------------------------------------------------------- /src/devices/video/nv2a/user.h: -------------------------------------------------------------------------------- 1 | #ifndef _NV2A_USER_H 2 | #define _NV2A_USER_H 3 | 4 | #include 5 | #include "component.h" 6 | 7 | class Nv2a; 8 | 9 | #define NV_REGION_USER_ADDR 0x00800000 10 | #define NV_REGION_USER_SIZE 0x800000 11 | 12 | class Nv2aUser : public Nv2aComponent { 13 | public: 14 | Nv2aUser(Nv2a& nv2a); 15 | uint32_t Read(uint32_t addr, unsigned size); 16 | void Write(uint32_t addr, uint32_t value, unsigned size); 17 | private: 18 | uint32_t m_Regs[NV_REGION_USER_SIZE]; 19 | Nv2a& m_Nv2a; 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /src/devices/video/tv/conexant.cpp: -------------------------------------------------------------------------------- 1 | #include "conexant.h" 2 | #include "util.h" 3 | 4 | void ConexantTVEncoder::Init() 5 | { 6 | 7 | } 8 | 9 | void ConexantTVEncoder::Reset() 10 | { 11 | } 12 | 13 | void ConexantTVEncoder::QuickCommand(bool read) 14 | { 15 | Log(LogLevel::Warning, "ConexantTVEncoder::QuickCommand not implemented\n"); 16 | } 17 | 18 | uint8_t ConexantTVEncoder::ReceiveByte() 19 | { 20 | Log(LogLevel::Warning, "ConexantTVEncoder::ReceiveByte not implemented\n"); 21 | return 0; 22 | } 23 | 24 | uint8_t ConexantTVEncoder::ReadByte(uint8_t command) 25 | { 26 | Log(LogLevel::Warning, "ConexantTVEncoder::ReadByte not implemented\n"); 27 | return 0; 28 | } 29 | 30 | uint16_t ConexantTVEncoder::ReadWord(uint8_t command) 31 | { 32 | Log(LogLevel::Warning, "ConexantTVEncoder::ReadWord not implemented\n"); 33 | return 0; 34 | } 35 | 36 | int ConexantTVEncoder::ReadBlock(uint8_t command, uint8_t *data) 37 | { 38 | Log(LogLevel::Warning, "ConexantTVEncoder::ReadBlock not implemented\n"); 39 | return 0; 40 | } 41 | 42 | void ConexantTVEncoder::SendByte(uint8_t data) 43 | { 44 | Log(LogLevel::Warning, "ConexantTVEncoder::SendByte not implemented\n"); 45 | } 46 | 47 | void ConexantTVEncoder::WriteByte(uint8_t command, uint8_t value) 48 | { 49 | Log(LogLevel::Warning, "ConexantTVEncoder::WriteByte not implemented\n"); 50 | } 51 | 52 | void ConexantTVEncoder::WriteWord(uint8_t command, uint16_t value) 53 | { 54 | Log(LogLevel::Warning, "ConexantTVEncoder::WriteWord not implemented\n"); 55 | } 56 | 57 | void ConexantTVEncoder::WriteBlock(uint8_t command, uint8_t* data, int length) 58 | { 59 | Log(LogLevel::Warning, "ConexantTVEncoder::WriteBlock not implemented\n"); 60 | } 61 | -------------------------------------------------------------------------------- /src/devices/video/tv/conexant.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "devices/smbus_device.h" 4 | 5 | class ConexantTVEncoder : public SMDevice 6 | { 7 | public: 8 | /* SMDevice functions */ 9 | void Init(); 10 | void Reset(); 11 | 12 | void QuickCommand(bool read); 13 | uint8_t ReceiveByte(); 14 | uint8_t ReadByte(uint8_t command); 15 | uint16_t ReadWord(uint8_t command); 16 | int ReadBlock(uint8_t command, uint8_t *data); 17 | 18 | void SendByte(uint8_t data); 19 | void WriteByte(uint8_t command, uint8_t value); 20 | void WriteWord(uint8_t command, uint16_t value); 21 | void WriteBlock(uint8_t command, uint8_t* data, int length); 22 | private: 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /src/libretro/libretro_core_options_intl.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBRETRO_CORE_OPTIONS_INTL_H__ 2 | #define LIBRETRO_CORE_OPTIONS_INTL_H__ 3 | 4 | #if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1900) 5 | /* https://support.microsoft.com/en-us/kb/980263 */ 6 | #pragma execution_character_set("utf-8") 7 | #pragma warning(disable:4566) 8 | #endif 9 | 10 | #include "libretro.h" 11 | 12 | /* 13 | ******************************** 14 | * VERSION: 1.3 15 | ******************************** 16 | * 17 | * - 1.3: Move translations to libretro_core_options_intl.h 18 | * - libretro_core_options_intl.h includes BOM and utf-8 19 | * fix for MSVC 2010-2013 20 | * - Added HAVE_NO_LANGEXTRA flag to disable translations 21 | * on platforms/compilers without BOM support 22 | * - 1.2: Use core options v1 interface when 23 | * RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION is >= 1 24 | * (previously required RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION == 1) 25 | * - 1.1: Support generation of core options v0 retro_core_option_value 26 | * arrays containing options with a single value 27 | * - 1.0: First commit 28 | */ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* 35 | ******************************** 36 | * Core Option Definitions 37 | ******************************** 38 | */ 39 | 40 | /* RETRO_LANGUAGE_JAPANESE */ 41 | 42 | /* RETRO_LANGUAGE_FRENCH */ 43 | 44 | /* RETRO_LANGUAGE_SPANISH */ 45 | 46 | /* RETRO_LANGUAGE_GERMAN */ 47 | 48 | /* RETRO_LANGUAGE_ITALIAN */ 49 | 50 | /* RETRO_LANGUAGE_DUTCH */ 51 | 52 | /* RETRO_LANGUAGE_PORTUGUESE_BRAZIL */ 53 | 54 | /* RETRO_LANGUAGE_PORTUGUESE_PORTUGAL */ 55 | 56 | /* RETRO_LANGUAGE_RUSSIAN */ 57 | 58 | /* RETRO_LANGUAGE_KOREAN */ 59 | 60 | /* RETRO_LANGUAGE_CHINESE_TRADITIONAL */ 61 | 62 | /* RETRO_LANGUAGE_CHINESE_SIMPLIFIED */ 63 | 64 | /* RETRO_LANGUAGE_ESPERANTO */ 65 | 66 | /* RETRO_LANGUAGE_POLISH */ 67 | 68 | /* RETRO_LANGUAGE_VIETNAMESE */ 69 | 70 | /* RETRO_LANGUAGE_ARABIC */ 71 | 72 | /* RETRO_LANGUAGE_GREEK */ 73 | 74 | /* RETRO_LANGUAGE_TURKISH */ 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/libretro/retro_inline.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010-2018 The RetroArch team 2 | * 3 | * --------------------------------------------------------------------------------------- 4 | * The following license statement only applies to this file (retro_inline.h). 5 | * --------------------------------------------------------------------------------------- 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __LIBRETRO_SDK_INLINE_H 24 | #define __LIBRETRO_SDK_INLINE_H 25 | 26 | #ifndef INLINE 27 | 28 | #if defined(_WIN32) || defined(__INTEL_COMPILER) 29 | #define INLINE __inline 30 | #elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L 31 | #define INLINE inline 32 | #elif defined(__GNUC__) 33 | #define INLINE __inline__ 34 | #else 35 | #define INLINE 36 | #endif 37 | 38 | #endif 39 | #endif 40 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIL_H 2 | #define _UTIL_H 3 | 4 | #include 5 | #include 6 | 7 | enum class LogLevel 8 | { 9 | Info, 10 | Warning, 11 | Error 12 | }; 13 | 14 | void Log(LogLevel level, const char *fmt, ...); 15 | 16 | /* TODO: Utility include */ 17 | template 18 | constexpr size_t array_size(T(&)[N]) 19 | { 20 | return N; 21 | } 22 | 23 | #if defined(__linux__) 24 | #include 25 | #else 26 | static int ffs(int value) 27 | { 28 | int bit; 29 | 30 | if (value == 0) 31 | return 0; 32 | 33 | for (bit = 1; !(value & 1); bit++) 34 | value >>= 1; 35 | 36 | return bit; 37 | } 38 | #endif 39 | 40 | #define GET_MASK(v, mask) (((v) & (mask)) >> (ffs(mask)-1)) 41 | #define SET_MASK(v, mask, val) \ 42 | do { \ 43 | const unsigned int __val = (val); \ 44 | const unsigned int __mask = (mask); \ 45 | (v) &= ~(__mask); \ 46 | (v) |= ((__val) << (ffs(__mask) - 1)) & (__mask); \ 47 | } while (0) 48 | 49 | static inline uint64_t RangeGetLast(uint64_t offset, uint64_t len) { 50 | return offset + len - 1; 51 | } 52 | 53 | static inline int RangeCoversByte(uint64_t offset, uint64_t len, uint64_t byte) { 54 | return offset <= byte && byte <= RangeGetLast(offset, len); 55 | } 56 | 57 | static inline int RangesOverlap(uint64_t first1, uint64_t len1, uint64_t first2, uint64_t len2) { 58 | uint64_t last1 = RangeGetLast(first1, len1); 59 | uint64_t last2 = RangeGetLast(first2, len2); 60 | 61 | return !(last2 < first1 || last1 < first2); 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/xbox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "devices/pci/pci_bus.h" 7 | #include "devices/pci/agp_bridge.h" 8 | #include "devices/pci/host_bridge.h" 9 | #include "devices/pci/pci_bridge.h" 10 | #include "devices/ata/ata_controller.h" 11 | #include "devices/smbus.h" 12 | #include "devices/smc.h" 13 | #include "devices/audio/ac97/ac97.h" 14 | #include "devices/audio/mcpx/mcpx_apu.h" 15 | #include "devices/video/tv/conexant.h" 16 | #include "devices/video/nv2a/nv2a.h" 17 | #include "devices/i8259.h" 18 | #include "devices/i8254.h" 19 | #include "devices/eeprom.h" 20 | 21 | #include "util.h" 22 | 23 | class Xbox 24 | { 25 | public: 26 | Xbox(virt86::Platform& platform); 27 | bool Init(); 28 | void Shutdown(); 29 | bool LoadBootRoms(std::string flash, std::string mcpx = ""); 30 | 31 | I8259& GetInterruptController(); 32 | void Interrupt(int irq); 33 | 34 | void Reset(); 35 | void RunFrame(); 36 | 37 | uint8_t* GetRamPtr(); 38 | 39 | Nv2a& GetNv2a(); 40 | private: 41 | /* Memory */ 42 | void* m_pRam = nullptr; 43 | void* m_pFlashRegion = nullptr; 44 | void* m_pFlashRom = nullptr; 45 | void* m_pMcpxRom = nullptr; 46 | 47 | /* Bus Devices */ 48 | PCIBus m_Pci; 49 | SMBus m_Smbus; 50 | 51 | /* PCI Devices */ 52 | HostBridge m_HostBridge; 53 | PCIBridge m_PciBridge; 54 | AGPBridge m_AgpBridge; 55 | 56 | AtaController m_AtaController; 57 | Ac97 m_Ac97; 58 | McpxApu m_McpxApu; 59 | Nv2a m_Nv2a; 60 | 61 | /* SMBus Devices */ 62 | SMC m_Smc; 63 | ConexantTVEncoder m_ConexantEncoder; 64 | Eeprom m_Eeprom; 65 | 66 | /* ISA Devices */ 67 | I8259 m_I8259; 68 | I8254 m_I8254; 69 | 70 | /* Hypervisor Platform */ 71 | virt86::Platform& m_HypervisorPlatform; 72 | std::optional> m_Hypervisor; 73 | /* IO Callbacks */ 74 | static uint32_t IOReadCallback(void *context, uint16_t port, size_t size); 75 | static void IOWriteCallback(void *context, uint16_t port, size_t size, uint32_t value); 76 | static uint64_t MMIOReadCallback(void *context, uint64_t address, size_t size); 77 | static void MMIOWriteCallback(void *context, uint64_t address, size_t size, uint64_t value); 78 | 79 | /* IO Implementations */ 80 | uint32_t IORead(uint16_t port, size_t size); 81 | void IOWrite(uint16_t port, size_t size, uint32_t value); 82 | uint64_t MMIORead(uint64_t address, size_t size); 83 | void MMIOWrite(uint64_t address, size_t size, uint64_t value); 84 | }; 85 | -------------------------------------------------------------------------------- /src/xbox_database.cpp: -------------------------------------------------------------------------------- 1 | #include "xbox_database.h" 2 | #include 3 | 4 | std::vector> Machines = { 5 | std::make_pair("v1_0_retail", MachineInfo{"v1.0 (Retail)", MachineType::Retail, TvEncoderType::Conexant, McpxRevision::X3, McpxRomVersion::Mcpx1_0, }), 6 | std::make_pair("v1_1_retail", MachineInfo{"v1.1 (Retail)", MachineType::Retail, TvEncoderType::Conexant, McpxRevision::X3, McpxRomVersion::Mcpx1_1, }), 7 | std::make_pair("v1_2_retail", MachineInfo{"v1.2 (Retail)", MachineType::Retail, TvEncoderType::Conexant, McpxRevision::X3, McpxRomVersion::Mcpx1_1, }), 8 | std::make_pair("v1_3_retail", MachineInfo{"v1.3 (Retail)", MachineType::Retail, TvEncoderType::Conexant, McpxRevision::X3, McpxRomVersion::Mcpx1_1, }), 9 | std::make_pair("v1_4_retail", MachineInfo{"v1.4 (Retail)", MachineType::Retail, TvEncoderType::Focus, McpxRevision::X3, McpxRomVersion::Mcpx1_1, }), 10 | std::make_pair("v1_6_retail", MachineInfo{"v1.6 (Retail)", MachineType::Retail, TvEncoderType::XCalibur, McpxRevision::X3, McpxRomVersion::Mcpx1_1, }), 11 | std::make_pair("debug", MachineInfo{"v1.0 (Debug)", MachineType::Debug, TvEncoderType::Conexant, McpxRevision::X2, McpxRomVersion::None, }), 12 | std::make_pair("chihiro", MachineInfo{"Chihiro", MachineType::Chihiro, TvEncoderType::Conexant, McpxRevision::X2, McpxRomVersion::None, }), 13 | }; 14 | -------------------------------------------------------------------------------- /src/xbox_database.h: -------------------------------------------------------------------------------- 1 | #ifndef _BIOS_DATABASE_H 2 | #define _BIOS_DATABASE_H 3 | 4 | #include 5 | #include 6 | 7 | enum class TvEncoderType 8 | { 9 | Conexant, 10 | Focus, 11 | XCalibur 12 | }; 13 | 14 | enum class McpxRevision 15 | { 16 | X2, 17 | X3 18 | }; 19 | 20 | enum class McpxRomVersion 21 | { 22 | None, 23 | Mcpx1_0, 24 | Mcpx1_1 25 | }; 26 | 27 | enum class MachineType 28 | { 29 | Retail, 30 | Debug, 31 | Chihiro 32 | }; 33 | 34 | typedef struct 35 | { 36 | std::string name; 37 | MachineType machine; 38 | TvEncoderType tv_encoder; 39 | McpxRevision mcpx; 40 | McpxRomVersion mcpx_rom; 41 | } MachineInfo; 42 | 43 | #endif 44 | --------------------------------------------------------------------------------