├── .gitignore ├── .gitmodules ├── .travis.yml ├── Assets └── Screen.png ├── README.md ├── Third-Party ├── Makefile ├── include │ ├── capstone │ │ ├── arm.h │ │ ├── arm64.h │ │ ├── capstone.h │ │ ├── evm.h │ │ ├── m680x.h │ │ ├── m68k.h │ │ ├── mips.h │ │ ├── mos65xx.h │ │ ├── platform.h │ │ ├── ppc.h │ │ ├── sparc.h │ │ ├── systemz.h │ │ ├── tms320c64x.h │ │ ├── x86.h │ │ └── xcore.h │ ├── list.h │ ├── platform.h │ ├── qemu.h │ ├── uc_priv.h │ ├── unicorn │ │ ├── arm.h │ │ ├── arm64.h │ │ ├── m68k.h │ │ ├── mips.h │ │ ├── platform.h │ │ ├── sparc.h │ │ ├── unicorn.h │ │ └── x86.h │ └── windowsce │ │ ├── intrin.h │ │ └── stdint.h └── lib │ ├── libcapstone.a │ └── libunicorn.a ├── unicorn-bios.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ ├── unicorn-bios (XEOS).xcscheme │ └── unicorn-bios.xcscheme └── unicorn-bios ├── UB ├── Arguments.cpp ├── Arguments.hpp ├── BIOS │ ├── Disk.cpp │ ├── Disk.hpp │ ├── Keyboard.cpp │ ├── Keyboard.hpp │ ├── MemoryMap-Entry.cpp │ ├── MemoryMap.cpp │ ├── MemoryMap.hpp │ ├── SystemServices.cpp │ ├── SystemServices.hpp │ ├── VESAInfo.cpp │ ├── VESAInfo.hpp │ ├── Video.cpp │ └── Video.hpp ├── BinaryDataStream.cpp ├── BinaryDataStream.hpp ├── BinaryFileStream.cpp ├── BinaryFileStream.hpp ├── BinaryStream.cpp ├── BinaryStream.hpp ├── CPU │ ├── Functions.cpp │ └── Functions.hpp ├── Capstone.cpp ├── Capstone.hpp ├── Casts.hpp ├── Color.cpp ├── Color.hpp ├── Engine.cpp ├── Engine.hpp ├── FAT │ ├── DAP.cpp │ ├── DAP.hpp │ ├── Functions.cpp │ ├── Functions.hpp │ ├── Image.cpp │ ├── Image.hpp │ ├── MBR.cpp │ └── MBR.hpp ├── Interrupts.cpp ├── Interrupts.hpp ├── Machine.cpp ├── Machine.hpp ├── Registers.cpp ├── Registers.hpp ├── Screen.cpp ├── Screen.hpp ├── Signal.cpp ├── Signal.hpp ├── String.cpp ├── String.hpp ├── StringStream.cpp ├── StringStream.hpp ├── UI.cpp ├── UI.hpp ├── Window.cpp └── Window.hpp └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac Finder 2 | .DS_Store 3 | .Trashes 4 | Icon? 5 | 6 | # Thumbnails 7 | ._* 8 | 9 | # Files that might appear on external disk 10 | .Spotlight-V100 11 | .Trashes 12 | 13 | # Windows 14 | Thumbs.db 15 | 16 | # Xcode 17 | *.pbxuser 18 | *.mode1v3 19 | *.mode2v3 20 | *.perspectivev3 21 | *.xccheckout 22 | *.profraw 23 | !default.pbxuser 24 | !default.mode1v3 25 | !default.mode2v3 26 | !default.perspectivev3 27 | xcuserdata 28 | 29 | # VisualStudio 30 | *.suo 31 | *.sdf 32 | *.opensdf 33 | *.vcxproj.user 34 | *.csproj.user 35 | ipch 36 | .vs 37 | *.VC.db 38 | 39 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Submodules/xcconfig"] 2 | path = Submodules/xcconfig 3 | url = https://github.com/macmade/xcconfig.git 4 | [submodule "Submodules/unicorn"] 5 | path = Submodules/unicorn 6 | url = https://github.com/macmade/unicorn.git 7 | [submodule "Submodules/capstone"] 8 | path = Submodules/capstone 9 | url = https://github.com/macmade/capstone.git 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode10.2 3 | cache: 4 | directories: 5 | - $HOME/.ccache 6 | install: 7 | - gem install xcpretty 8 | - brew install ccache 9 | - PATH=$PATH:/usr/local/opt/ccache/libexec 10 | script: 11 | - set -o pipefail && xcodebuild -project "unicorn-bios.xcodeproj" -scheme "unicorn-bios" build analyze 12 | before_script: 13 | - ccache -s 14 | - ccache -z 15 | after_script: 16 | - ccache -s 17 | notifications: 18 | slack: xs-labs:FXh1yLXNkpcVxKZhZU6icdhI 19 | -------------------------------------------------------------------------------- /Assets/Screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/macmade/unicorn-bios/97a53ff5c8c418e79f0f5798da3d365b2ceaa7f2/Assets/Screen.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | unicorn-bios 2 | ============ 3 | 4 | [![Build Status](https://img.shields.io/travis/macmade/unicorn-bios.svg?branch=master&style=flat)](https://travis-ci.org/macmade/unicorn-bios) 5 | [![Coverage Status](https://img.shields.io/coveralls/macmade/unicorn-bios.svg?branch=master&style=flat)](https://coveralls.io/r/macmade/unicorn-bios?branch=master) 6 | [![Issues](http://img.shields.io/github/issues/macmade/unicorn-bios.svg?style=flat)](https://github.com/macmade/unicorn-bios/issues) 7 | ![Status](https://img.shields.io/badge/status-active-brightgreen.svg?style=flat) 8 | ![License](https://img.shields.io/badge/license-mit-brightgreen.svg?style=flat) 9 | [![Contact](https://img.shields.io/badge/contact-@macmade-blue.svg?style=flat)](https://twitter.com/macmade) 10 | [![Donate-Patreon](https://img.shields.io/badge/donate-patreon-yellow.svg?style=flat)](https://patreon.com/macmade) 11 | [![Donate-Gratipay](https://img.shields.io/badge/donate-gratipay-yellow.svg?style=flat)](https://www.gratipay.com/macmade) 12 | [![Donate-Paypal](https://img.shields.io/badge/donate-paypal-yellow.svg?style=flat)](https://paypal.me/xslabs) 13 | 14 | About 15 | ----- 16 | 17 | Basic BIOS emulator/debugger for Unicorn Engine. 18 | Written to debug the [XEOS Operating System](https://github.com/macmade/XEOS) boot sequence. 19 | 20 | ![Screenshot](Assets/Screen.png "Screenshot") 21 | 22 | ### Usage: 23 | 24 | Usage: unicorn-bios [OPTIONS] BOOT_IMG 25 | 26 | Options: 27 | 28 | --help / -h: Displays help. 29 | --memory / -m: The amount of memory to allocate for the virtual machine 30 | (in megabytes). Defaults to 64MB, minimum 2MB. 31 | --break / -b Breaks on a specific address. 32 | --break-int: Breaks on interrupt calls. 33 | --break-iret: Breaks on interrupt returns. 34 | --trap: Raises a trap when breaking. 35 | --debug-video: Turns on debug output for video services. 36 | --single-step: Breaks on every instruction. 37 | --no-ui: Don't start the user interface (output will be displayed to stdout, debug info to stderr). 38 | --no-colors: Don't use colors. 39 | 40 | ### Installation: 41 | 42 | brew install --HEAD macmade/tap/unicorn-bios 43 | 44 | License 45 | ------- 46 | 47 | unicorn-bios is released under the terms of the MIT license. 48 | 49 | Repository Infos 50 | ---------------- 51 | 52 | Owner: Jean-David Gadina - XS-Labs 53 | Web: www.xs-labs.com 54 | Blog: www.noxeos.com 55 | Twitter: @macmade 56 | GitHub: github.com/macmade 57 | LinkedIn: ch.linkedin.com/in/macmade/ 58 | StackOverflow: stackoverflow.com/users/182676/macmade 59 | -------------------------------------------------------------------------------- /Third-Party/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # The MIT License (MIT) 3 | # 4 | # Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in 14 | # all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | # THE SOFTWARE. 23 | ################################################################################ 24 | 25 | PATH_UNICORN := ../Submodules/unicorn 26 | PATH_CAPSTONE := ../Submodules/capstone 27 | PATH_INC := include 28 | PATH_LIB := lib 29 | 30 | all: unicorn capstone 31 | 32 | @rm -rf $(PATH_INC)/* 33 | @rm -rf $(PATH_LIB)/* 34 | @cp -r $(PATH_UNICORN)/include/* $(PATH_INC) 35 | @cp -r $(PATH_UNICORN)/libunicorn.a $(PATH_LIB) 36 | @cp -r $(PATH_CAPSTONE)/include/* $(PATH_INC) 37 | @cp -r $(PATH_CAPSTONE)/libcapstone.a $(PATH_LIB) 38 | 39 | unicorn: 40 | 41 | @cd $(PATH_UNICORN) && $(MAKE) clean && $(MAKE) 42 | 43 | capstone: 44 | 45 | @cd $(PATH_CAPSTONE) && $(MAKE) clean && $(MAKE) 46 | -------------------------------------------------------------------------------- /Third-Party/include/capstone/evm.h: -------------------------------------------------------------------------------- 1 | #ifndef CAPSTONE_EVM_H 2 | #define CAPSTONE_EVM_H 3 | 4 | /* Capstone Disassembly Engine */ 5 | /* By Nguyen Anh Quynh , 2013-2018 */ 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #include "platform.h" 12 | 13 | #ifdef _MSC_VER 14 | #pragma warning(disable:4201) 15 | #endif 16 | 17 | /// Instruction structure 18 | typedef struct cs_evm { 19 | unsigned char pop; ///< number of items popped from the stack 20 | unsigned char push; ///< number of items pushed into the stack 21 | unsigned int fee; ///< gas fee for the instruction 22 | } cs_evm; 23 | 24 | /// EVM instruction 25 | typedef enum evm_insn { 26 | EVM_INS_STOP = 0, 27 | EVM_INS_ADD = 1, 28 | EVM_INS_MUL = 2, 29 | EVM_INS_SUB = 3, 30 | EVM_INS_DIV = 4, 31 | EVM_INS_SDIV = 5, 32 | EVM_INS_MOD = 6, 33 | EVM_INS_SMOD = 7, 34 | EVM_INS_ADDMOD = 8, 35 | EVM_INS_MULMOD = 9, 36 | EVM_INS_EXP = 10, 37 | EVM_INS_SIGNEXTEND = 11, 38 | EVM_INS_LT = 16, 39 | EVM_INS_GT = 17, 40 | EVM_INS_SLT = 18, 41 | EVM_INS_SGT = 19, 42 | EVM_INS_EQ = 20, 43 | EVM_INS_ISZERO = 21, 44 | EVM_INS_AND = 22, 45 | EVM_INS_OR = 23, 46 | EVM_INS_XOR = 24, 47 | EVM_INS_NOT = 25, 48 | EVM_INS_BYTE = 26, 49 | EVM_INS_SHA3 = 32, 50 | EVM_INS_ADDRESS = 48, 51 | EVM_INS_BALANCE = 49, 52 | EVM_INS_ORIGIN = 50, 53 | EVM_INS_CALLER = 51, 54 | EVM_INS_CALLVALUE = 52, 55 | EVM_INS_CALLDATALOAD = 53, 56 | EVM_INS_CALLDATASIZE = 54, 57 | EVM_INS_CALLDATACOPY = 55, 58 | EVM_INS_CODESIZE = 56, 59 | EVM_INS_CODECOPY = 57, 60 | EVM_INS_GASPRICE = 58, 61 | EVM_INS_EXTCODESIZE = 59, 62 | EVM_INS_EXTCODECOPY = 60, 63 | EVM_INS_RETURNDATASIZE = 61, 64 | EVM_INS_RETURNDATACOPY = 62, 65 | EVM_INS_BLOCKHASH = 64, 66 | EVM_INS_COINBASE = 65, 67 | EVM_INS_TIMESTAMP = 66, 68 | EVM_INS_NUMBER = 67, 69 | EVM_INS_DIFFICULTY = 68, 70 | EVM_INS_GASLIMIT = 69, 71 | EVM_INS_POP = 80, 72 | EVM_INS_MLOAD = 81, 73 | EVM_INS_MSTORE = 82, 74 | EVM_INS_MSTORE8 = 83, 75 | EVM_INS_SLOAD = 84, 76 | EVM_INS_SSTORE = 85, 77 | EVM_INS_JUMP = 86, 78 | EVM_INS_JUMPI = 87, 79 | EVM_INS_PC = 88, 80 | EVM_INS_MSIZE = 89, 81 | EVM_INS_GAS = 90, 82 | EVM_INS_JUMPDEST = 91, 83 | EVM_INS_PUSH1 = 96, 84 | EVM_INS_PUSH2 = 97, 85 | EVM_INS_PUSH3 = 98, 86 | EVM_INS_PUSH4 = 99, 87 | EVM_INS_PUSH5 = 100, 88 | EVM_INS_PUSH6 = 101, 89 | EVM_INS_PUSH7 = 102, 90 | EVM_INS_PUSH8 = 103, 91 | EVM_INS_PUSH9 = 104, 92 | EVM_INS_PUSH10 = 105, 93 | EVM_INS_PUSH11 = 106, 94 | EVM_INS_PUSH12 = 107, 95 | EVM_INS_PUSH13 = 108, 96 | EVM_INS_PUSH14 = 109, 97 | EVM_INS_PUSH15 = 110, 98 | EVM_INS_PUSH16 = 111, 99 | EVM_INS_PUSH17 = 112, 100 | EVM_INS_PUSH18 = 113, 101 | EVM_INS_PUSH19 = 114, 102 | EVM_INS_PUSH20 = 115, 103 | EVM_INS_PUSH21 = 116, 104 | EVM_INS_PUSH22 = 117, 105 | EVM_INS_PUSH23 = 118, 106 | EVM_INS_PUSH24 = 119, 107 | EVM_INS_PUSH25 = 120, 108 | EVM_INS_PUSH26 = 121, 109 | EVM_INS_PUSH27 = 122, 110 | EVM_INS_PUSH28 = 123, 111 | EVM_INS_PUSH29 = 124, 112 | EVM_INS_PUSH30 = 125, 113 | EVM_INS_PUSH31 = 126, 114 | EVM_INS_PUSH32 = 127, 115 | EVM_INS_DUP1 = 128, 116 | EVM_INS_DUP2 = 129, 117 | EVM_INS_DUP3 = 130, 118 | EVM_INS_DUP4 = 131, 119 | EVM_INS_DUP5 = 132, 120 | EVM_INS_DUP6 = 133, 121 | EVM_INS_DUP7 = 134, 122 | EVM_INS_DUP8 = 135, 123 | EVM_INS_DUP9 = 136, 124 | EVM_INS_DUP10 = 137, 125 | EVM_INS_DUP11 = 138, 126 | EVM_INS_DUP12 = 139, 127 | EVM_INS_DUP13 = 140, 128 | EVM_INS_DUP14 = 141, 129 | EVM_INS_DUP15 = 142, 130 | EVM_INS_DUP16 = 143, 131 | EVM_INS_SWAP1 = 144, 132 | EVM_INS_SWAP2 = 145, 133 | EVM_INS_SWAP3 = 146, 134 | EVM_INS_SWAP4 = 147, 135 | EVM_INS_SWAP5 = 148, 136 | EVM_INS_SWAP6 = 149, 137 | EVM_INS_SWAP7 = 150, 138 | EVM_INS_SWAP8 = 151, 139 | EVM_INS_SWAP9 = 152, 140 | EVM_INS_SWAP10 = 153, 141 | EVM_INS_SWAP11 = 154, 142 | EVM_INS_SWAP12 = 155, 143 | EVM_INS_SWAP13 = 156, 144 | EVM_INS_SWAP14 = 157, 145 | EVM_INS_SWAP15 = 158, 146 | EVM_INS_SWAP16 = 159, 147 | EVM_INS_LOG0 = 160, 148 | EVM_INS_LOG1 = 161, 149 | EVM_INS_LOG2 = 162, 150 | EVM_INS_LOG3 = 163, 151 | EVM_INS_LOG4 = 164, 152 | EVM_INS_CREATE = 240, 153 | EVM_INS_CALL = 241, 154 | EVM_INS_CALLCODE = 242, 155 | EVM_INS_RETURN = 243, 156 | EVM_INS_DELEGATECALL = 244, 157 | EVM_INS_CALLBLACKBOX = 245, 158 | EVM_INS_STATICCALL = 250, 159 | EVM_INS_REVERT = 253, 160 | EVM_INS_SUICIDE = 255, 161 | 162 | EVM_INS_INVALID = 512, 163 | EVM_INS_ENDING, // <-- mark the end of the list of instructions 164 | } evm_insn; 165 | 166 | /// Group of EVM instructions 167 | typedef enum evm_insn_group { 168 | EVM_GRP_INVALID = 0, ///< = CS_GRP_INVALID 169 | 170 | EVM_GRP_JUMP, ///< all jump instructions 171 | 172 | EVM_GRP_MATH = 8, ///< math instructions 173 | EVM_GRP_STACK_WRITE, ///< instructions write to stack 174 | EVM_GRP_STACK_READ, ///< instructions read from stack 175 | EVM_GRP_MEM_WRITE, ///< instructions write to memory 176 | EVM_GRP_MEM_READ, ///< instructions read from memory 177 | EVM_GRP_STORE_WRITE, ///< instructions write to storage 178 | EVM_GRP_STORE_READ, ///< instructions read from storage 179 | EVM_GRP_HALT, ///< instructions halt execution 180 | 181 | EVM_GRP_ENDING, ///< <-- mark the end of the list of groups 182 | } evm_insn_group; 183 | 184 | #ifdef __cplusplus 185 | } 186 | #endif 187 | 188 | #endif 189 | -------------------------------------------------------------------------------- /Third-Party/include/capstone/mos65xx.h: -------------------------------------------------------------------------------- 1 | #ifndef CAPSTONE_MOS65XX_H 2 | #define CAPSTONE_MOS65XX_H 3 | 4 | /* Capstone Disassembly Engine */ 5 | /* By Sebastian Macke C99 is supported 23 | #include 24 | #endif // (_MSC_VER < 1800) || defined(_KERNEL_MODE) 25 | 26 | #else 27 | // not MSVC -> C99 is supported 28 | #include 29 | #endif // !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)) 30 | 31 | 32 | // handle inttypes.h / stdint.h compatibility 33 | #if defined(_WIN32_WCE) && (_WIN32_WCE < 0x800) 34 | #include "windowsce/stdint.h" 35 | #endif // defined(_WIN32_WCE) && (_WIN32_WCE < 0x800) 36 | 37 | #if defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE))) 38 | // this system does not have inttypes.h 39 | 40 | #if defined(_MSC_VER) && (_MSC_VER <= 1600 || defined(_KERNEL_MODE)) 41 | // this system does not have stdint.h 42 | typedef signed char int8_t; 43 | typedef signed short int16_t; 44 | typedef signed int int32_t; 45 | typedef unsigned char uint8_t; 46 | typedef unsigned short uint16_t; 47 | typedef unsigned int uint32_t; 48 | typedef signed long long int64_t; 49 | typedef unsigned long long uint64_t; 50 | #endif // defined(_MSC_VER) && (_MSC_VER <= 1600 || defined(_KERNEL_MODE)) 51 | 52 | #if defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE)) 53 | #define INT8_MIN (-127i8 - 1) 54 | #define INT16_MIN (-32767i16 - 1) 55 | #define INT32_MIN (-2147483647i32 - 1) 56 | #define INT64_MIN (-9223372036854775807i64 - 1) 57 | #define INT8_MAX 127i8 58 | #define INT16_MAX 32767i16 59 | #define INT32_MAX 2147483647i32 60 | #define INT64_MAX 9223372036854775807i64 61 | #define UINT8_MAX 0xffui8 62 | #define UINT16_MAX 0xffffui16 63 | #define UINT32_MAX 0xffffffffui32 64 | #define UINT64_MAX 0xffffffffffffffffui64 65 | #endif // defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE)) 66 | 67 | #ifdef CAPSTONE_HAS_OSXKERNEL 68 | // this system has stdint.h 69 | #include 70 | #endif 71 | 72 | #define __PRI_8_LENGTH_MODIFIER__ "hh" 73 | #define __PRI_64_LENGTH_MODIFIER__ "ll" 74 | 75 | #define PRId8 __PRI_8_LENGTH_MODIFIER__ "d" 76 | #define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i" 77 | #define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o" 78 | #define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u" 79 | #define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x" 80 | #define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X" 81 | 82 | #define PRId16 "hd" 83 | #define PRIi16 "hi" 84 | #define PRIo16 "ho" 85 | #define PRIu16 "hu" 86 | #define PRIx16 "hx" 87 | #define PRIX16 "hX" 88 | 89 | #if defined(_MSC_VER) && _MSC_VER <= 1700 90 | #define PRId32 "ld" 91 | #define PRIi32 "li" 92 | #define PRIo32 "lo" 93 | #define PRIu32 "lu" 94 | #define PRIx32 "lx" 95 | #define PRIX32 "lX" 96 | #else // OSX 97 | #define PRId32 "d" 98 | #define PRIi32 "i" 99 | #define PRIo32 "o" 100 | #define PRIu32 "u" 101 | #define PRIx32 "x" 102 | #define PRIX32 "X" 103 | #endif // defined(_MSC_VER) && _MSC_VER <= 1700 104 | 105 | #if defined(_MSC_VER) && _MSC_VER <= 1700 106 | // redefine functions from inttypes.h used in cstool 107 | #define strtoull _strtoui64 108 | #endif 109 | 110 | #define PRId64 __PRI_64_LENGTH_MODIFIER__ "d" 111 | #define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i" 112 | #define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o" 113 | #define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u" 114 | #define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x" 115 | #define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X" 116 | 117 | #else 118 | // this system has inttypes.h by default 119 | #include 120 | #endif // defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE))) 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /Third-Party/include/capstone/xcore.h: -------------------------------------------------------------------------------- 1 | #ifndef CAPSTONE_XCORE_H 2 | #define CAPSTONE_XCORE_H 3 | 4 | /* Capstone Disassembly Engine */ 5 | /* By Nguyen Anh Quynh , 2014-2015 */ 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #include "platform.h" 12 | 13 | #ifdef _MSC_VER 14 | #pragma warning(disable:4201) 15 | #endif 16 | 17 | /// Operand type for instruction's operands 18 | typedef enum xcore_op_type { 19 | XCORE_OP_INVALID = 0, ///< = CS_OP_INVALID (Uninitialized). 20 | XCORE_OP_REG, ///< = CS_OP_REG (Register operand). 21 | XCORE_OP_IMM, ///< = CS_OP_IMM (Immediate operand). 22 | XCORE_OP_MEM, ///< = CS_OP_MEM (Memory operand). 23 | } xcore_op_type; 24 | 25 | /// XCore registers 26 | typedef enum xcore_reg { 27 | XCORE_REG_INVALID = 0, 28 | 29 | XCORE_REG_CP, 30 | XCORE_REG_DP, 31 | XCORE_REG_LR, 32 | XCORE_REG_SP, 33 | XCORE_REG_R0, 34 | XCORE_REG_R1, 35 | XCORE_REG_R2, 36 | XCORE_REG_R3, 37 | XCORE_REG_R4, 38 | XCORE_REG_R5, 39 | XCORE_REG_R6, 40 | XCORE_REG_R7, 41 | XCORE_REG_R8, 42 | XCORE_REG_R9, 43 | XCORE_REG_R10, 44 | XCORE_REG_R11, 45 | 46 | // pseudo registers 47 | XCORE_REG_PC, ///< pc 48 | 49 | // internal thread registers 50 | // see The-XMOS-XS1-Architecture(X7879A).pdf 51 | XCORE_REG_SCP, ///< save pc 52 | XCORE_REG_SSR, //< save status 53 | XCORE_REG_ET, //< exception type 54 | XCORE_REG_ED, //< exception data 55 | XCORE_REG_SED, //< save exception data 56 | XCORE_REG_KEP, //< kernel entry pointer 57 | XCORE_REG_KSP, //< kernel stack pointer 58 | XCORE_REG_ID, //< thread ID 59 | 60 | XCORE_REG_ENDING, // <-- mark the end of the list of registers 61 | } xcore_reg; 62 | 63 | /// Instruction's operand referring to memory 64 | /// This is associated with XCORE_OP_MEM operand type above 65 | typedef struct xcore_op_mem { 66 | uint8_t base; ///< base register, can be safely interpreted as 67 | ///< a value of type `xcore_reg`, but it is only 68 | ///< one byte wide 69 | uint8_t index; ///< index register, same conditions apply here 70 | int32_t disp; ///< displacement/offset value 71 | int direct; ///< +1: forward, -1: backward 72 | } xcore_op_mem; 73 | 74 | /// Instruction operand 75 | typedef struct cs_xcore_op { 76 | xcore_op_type type; ///< operand type 77 | union { 78 | xcore_reg reg; ///< register value for REG operand 79 | int32_t imm; ///< immediate value for IMM operand 80 | xcore_op_mem mem; ///< base/disp value for MEM operand 81 | }; 82 | } cs_xcore_op; 83 | 84 | /// Instruction structure 85 | typedef struct cs_xcore { 86 | /// Number of operands of this instruction, 87 | /// or 0 when instruction has no operand. 88 | uint8_t op_count; 89 | cs_xcore_op operands[8]; ///< operands for this instruction. 90 | } cs_xcore; 91 | 92 | /// XCore instruction 93 | typedef enum xcore_insn { 94 | XCORE_INS_INVALID = 0, 95 | 96 | XCORE_INS_ADD, 97 | XCORE_INS_ANDNOT, 98 | XCORE_INS_AND, 99 | XCORE_INS_ASHR, 100 | XCORE_INS_BAU, 101 | XCORE_INS_BITREV, 102 | XCORE_INS_BLA, 103 | XCORE_INS_BLAT, 104 | XCORE_INS_BL, 105 | XCORE_INS_BF, 106 | XCORE_INS_BT, 107 | XCORE_INS_BU, 108 | XCORE_INS_BRU, 109 | XCORE_INS_BYTEREV, 110 | XCORE_INS_CHKCT, 111 | XCORE_INS_CLRE, 112 | XCORE_INS_CLRPT, 113 | XCORE_INS_CLRSR, 114 | XCORE_INS_CLZ, 115 | XCORE_INS_CRC8, 116 | XCORE_INS_CRC32, 117 | XCORE_INS_DCALL, 118 | XCORE_INS_DENTSP, 119 | XCORE_INS_DGETREG, 120 | XCORE_INS_DIVS, 121 | XCORE_INS_DIVU, 122 | XCORE_INS_DRESTSP, 123 | XCORE_INS_DRET, 124 | XCORE_INS_ECALLF, 125 | XCORE_INS_ECALLT, 126 | XCORE_INS_EDU, 127 | XCORE_INS_EEF, 128 | XCORE_INS_EET, 129 | XCORE_INS_EEU, 130 | XCORE_INS_ENDIN, 131 | XCORE_INS_ENTSP, 132 | XCORE_INS_EQ, 133 | XCORE_INS_EXTDP, 134 | XCORE_INS_EXTSP, 135 | XCORE_INS_FREER, 136 | XCORE_INS_FREET, 137 | XCORE_INS_GETD, 138 | XCORE_INS_GET, 139 | XCORE_INS_GETN, 140 | XCORE_INS_GETR, 141 | XCORE_INS_GETSR, 142 | XCORE_INS_GETST, 143 | XCORE_INS_GETTS, 144 | XCORE_INS_INCT, 145 | XCORE_INS_INIT, 146 | XCORE_INS_INPW, 147 | XCORE_INS_INSHR, 148 | XCORE_INS_INT, 149 | XCORE_INS_IN, 150 | XCORE_INS_KCALL, 151 | XCORE_INS_KENTSP, 152 | XCORE_INS_KRESTSP, 153 | XCORE_INS_KRET, 154 | XCORE_INS_LADD, 155 | XCORE_INS_LD16S, 156 | XCORE_INS_LD8U, 157 | XCORE_INS_LDA16, 158 | XCORE_INS_LDAP, 159 | XCORE_INS_LDAW, 160 | XCORE_INS_LDC, 161 | XCORE_INS_LDW, 162 | XCORE_INS_LDIVU, 163 | XCORE_INS_LMUL, 164 | XCORE_INS_LSS, 165 | XCORE_INS_LSUB, 166 | XCORE_INS_LSU, 167 | XCORE_INS_MACCS, 168 | XCORE_INS_MACCU, 169 | XCORE_INS_MJOIN, 170 | XCORE_INS_MKMSK, 171 | XCORE_INS_MSYNC, 172 | XCORE_INS_MUL, 173 | XCORE_INS_NEG, 174 | XCORE_INS_NOT, 175 | XCORE_INS_OR, 176 | XCORE_INS_OUTCT, 177 | XCORE_INS_OUTPW, 178 | XCORE_INS_OUTSHR, 179 | XCORE_INS_OUTT, 180 | XCORE_INS_OUT, 181 | XCORE_INS_PEEK, 182 | XCORE_INS_REMS, 183 | XCORE_INS_REMU, 184 | XCORE_INS_RETSP, 185 | XCORE_INS_SETCLK, 186 | XCORE_INS_SET, 187 | XCORE_INS_SETC, 188 | XCORE_INS_SETD, 189 | XCORE_INS_SETEV, 190 | XCORE_INS_SETN, 191 | XCORE_INS_SETPSC, 192 | XCORE_INS_SETPT, 193 | XCORE_INS_SETRDY, 194 | XCORE_INS_SETSR, 195 | XCORE_INS_SETTW, 196 | XCORE_INS_SETV, 197 | XCORE_INS_SEXT, 198 | XCORE_INS_SHL, 199 | XCORE_INS_SHR, 200 | XCORE_INS_SSYNC, 201 | XCORE_INS_ST16, 202 | XCORE_INS_ST8, 203 | XCORE_INS_STW, 204 | XCORE_INS_SUB, 205 | XCORE_INS_SYNCR, 206 | XCORE_INS_TESTCT, 207 | XCORE_INS_TESTLCL, 208 | XCORE_INS_TESTWCT, 209 | XCORE_INS_TSETMR, 210 | XCORE_INS_START, 211 | XCORE_INS_WAITEF, 212 | XCORE_INS_WAITET, 213 | XCORE_INS_WAITEU, 214 | XCORE_INS_XOR, 215 | XCORE_INS_ZEXT, 216 | 217 | XCORE_INS_ENDING, // <-- mark the end of the list of instructions 218 | } xcore_insn; 219 | 220 | /// Group of XCore instructions 221 | typedef enum xcore_insn_group { 222 | XCORE_GRP_INVALID = 0, ///< = CS_GRP_INVALID 223 | 224 | // Generic groups 225 | // all jump instructions (conditional+direct+indirect jumps) 226 | XCORE_GRP_JUMP, ///< = CS_GRP_JUMP 227 | 228 | XCORE_GRP_ENDING, // <-- mark the end of the list of groups 229 | } xcore_insn_group; 230 | 231 | #ifdef __cplusplus 232 | } 233 | #endif 234 | 235 | #endif 236 | -------------------------------------------------------------------------------- /Third-Party/include/list.h: -------------------------------------------------------------------------------- 1 | #ifndef UC_LLIST_H 2 | #define UC_LLIST_H 3 | 4 | #include "unicorn/platform.h" 5 | 6 | struct list_item { 7 | struct list_item *next; 8 | void *data; 9 | }; 10 | 11 | struct list { 12 | struct list_item *head, *tail; 13 | }; 14 | 15 | // create a new list 16 | struct list *list_new(void); 17 | 18 | // removed linked list nodes but does not free their content 19 | void list_clear(struct list *list); 20 | 21 | // insert a new item at the begin of the list. 22 | void *list_insert(struct list *list, void *data); 23 | 24 | // append a new item at the end of the list. 25 | void *list_append(struct list *list, void *data); 26 | 27 | // returns true if entry was removed, false otherwise 28 | bool list_remove(struct list *list, void *data); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Third-Party/include/platform.h: -------------------------------------------------------------------------------- 1 | /* Capstone Disassembly Engine */ 2 | /* By Axel Souchet & Nguyen Anh Quynh, 2014 */ 3 | 4 | #ifndef CAPSTONE_PLATFORM_H 5 | #define CAPSTONE_PLATFORM_H 6 | 7 | // handle C99 issue (for pre-2013 VisualStudio) 8 | #if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)) 9 | // MSVC 10 | 11 | // stdbool.h 12 | #if (_MSC_VER < 1800) || defined(_KERNEL_MODE) 13 | // this system does not have stdbool.h 14 | #ifndef __cplusplus 15 | typedef unsigned char bool; 16 | #define false 0 17 | #define true 1 18 | #endif 19 | 20 | #else 21 | // VisualStudio 2013+ -> C99 is supported 22 | #include 23 | #endif 24 | 25 | #else 26 | // not MSVC -> C99 is supported 27 | #include 28 | #endif 29 | 30 | 31 | // handle C99 issue (for pre-2013 VisualStudio) 32 | #if defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE))) 33 | // this system does not have inttypes.h 34 | 35 | #if defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE)) 36 | // this system does not have stdint.h 37 | typedef signed char int8_t; 38 | typedef signed short int16_t; 39 | typedef signed int int32_t; 40 | typedef unsigned char uint8_t; 41 | typedef unsigned short uint16_t; 42 | typedef unsigned int uint32_t; 43 | typedef signed long long int64_t; 44 | typedef unsigned long long uint64_t; 45 | 46 | #define INT8_MIN (-127i8 - 1) 47 | #define INT16_MIN (-32767i16 - 1) 48 | #define INT32_MIN (-2147483647i32 - 1) 49 | #define INT64_MIN (-9223372036854775807i64 - 1) 50 | #define INT8_MAX 127i8 51 | #define INT16_MAX 32767i16 52 | #define INT32_MAX 2147483647i32 53 | #define INT64_MAX 9223372036854775807i64 54 | #define UINT8_MAX 0xffui8 55 | #define UINT16_MAX 0xffffui16 56 | #define UINT32_MAX 0xffffffffui32 57 | #define UINT64_MAX 0xffffffffffffffffui64 58 | #endif 59 | 60 | #define __PRI_8_LENGTH_MODIFIER__ "hh" 61 | #define __PRI_64_LENGTH_MODIFIER__ "ll" 62 | 63 | #define PRId8 __PRI_8_LENGTH_MODIFIER__ "d" 64 | #define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i" 65 | #define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o" 66 | #define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u" 67 | #define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x" 68 | #define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X" 69 | 70 | #define PRId16 "hd" 71 | #define PRIi16 "hi" 72 | #define PRIo16 "ho" 73 | #define PRIu16 "hu" 74 | #define PRIx16 "hx" 75 | #define PRIX16 "hX" 76 | 77 | #if defined(_MSC_VER) && _MSC_VER <= 1700 78 | #define PRId32 "ld" 79 | #define PRIi32 "li" 80 | #define PRIo32 "lo" 81 | #define PRIu32 "lu" 82 | #define PRIx32 "lx" 83 | #define PRIX32 "lX" 84 | #else // OSX 85 | #define PRId32 "d" 86 | #define PRIi32 "i" 87 | #define PRIo32 "o" 88 | #define PRIu32 "u" 89 | #define PRIx32 "x" 90 | #define PRIX32 "X" 91 | #endif 92 | 93 | #if defined(_MSC_VER) && _MSC_VER <= 1700 94 | // redefine functions from inttypes.h used in cstool 95 | #define strtoull _strtoui64 96 | #endif 97 | 98 | #define PRId64 __PRI_64_LENGTH_MODIFIER__ "d" 99 | #define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i" 100 | #define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o" 101 | #define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u" 102 | #define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x" 103 | #define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X" 104 | 105 | #else 106 | // this system has inttypes.h by default 107 | #include 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /Third-Party/include/qemu.h: -------------------------------------------------------------------------------- 1 | /* By Dang Hoang Vu , 2015 */ 2 | 3 | #ifndef UC_QEMU_H 4 | #define UC_QEMU_H 5 | 6 | struct uc_struct; 7 | 8 | #define OPC_BUF_SIZE 640 9 | 10 | #include "sysemu/sysemu.h" 11 | #include "sysemu/cpus.h" 12 | #include "exec/cpu-common.h" 13 | #include "exec/memory.h" 14 | 15 | #include "qemu/thread.h" 16 | #include "include/qom/cpu.h" 17 | 18 | #include "vl.h" 19 | 20 | // This two struct is originally from qemu/include/exec/cpu-all.h 21 | // Temporarily moved here since there is circular inclusion. 22 | typedef struct RAMBlock { 23 | struct MemoryRegion *mr; 24 | uint8_t *host; 25 | ram_addr_t offset; 26 | ram_addr_t length; 27 | uint32_t flags; 28 | char idstr[256]; 29 | /* Reads can take either the iothread or the ramlist lock. 30 | * Writes must take both locks. 31 | */ 32 | QTAILQ_ENTRY(RAMBlock) next; 33 | int fd; 34 | } RAMBlock; 35 | 36 | typedef struct { 37 | MemoryRegion *mr; 38 | void *buffer; 39 | hwaddr addr; 40 | hwaddr len; 41 | } BounceBuffer; 42 | 43 | typedef struct RAMList { 44 | /* Protected by the iothread lock. */ 45 | unsigned long *dirty_memory[DIRTY_MEMORY_NUM]; 46 | RAMBlock *mru_block; 47 | QTAILQ_HEAD(, RAMBlock) blocks; 48 | uint32_t version; 49 | } RAMList; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Third-Party/include/unicorn/arm.h: -------------------------------------------------------------------------------- 1 | /* Unicorn Engine */ 2 | /* By Nguyen Anh Quynh , 2015-2017 */ 3 | /* This file is released under LGPL2. 4 | See COPYING.LGPL2 in root directory for more details 5 | */ 6 | 7 | #ifndef UNICORN_ARM_H 8 | #define UNICORN_ARM_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #ifdef _MSC_VER 15 | #pragma warning(disable:4201) 16 | #endif 17 | 18 | //> ARM registers 19 | typedef enum uc_arm_reg { 20 | UC_ARM_REG_INVALID = 0, 21 | UC_ARM_REG_APSR, 22 | UC_ARM_REG_APSR_NZCV, 23 | UC_ARM_REG_CPSR, 24 | UC_ARM_REG_FPEXC, 25 | UC_ARM_REG_FPINST, 26 | UC_ARM_REG_FPSCR, 27 | UC_ARM_REG_FPSCR_NZCV, 28 | UC_ARM_REG_FPSID, 29 | UC_ARM_REG_ITSTATE, 30 | UC_ARM_REG_LR, 31 | UC_ARM_REG_PC, 32 | UC_ARM_REG_SP, 33 | UC_ARM_REG_SPSR, 34 | UC_ARM_REG_D0, 35 | UC_ARM_REG_D1, 36 | UC_ARM_REG_D2, 37 | UC_ARM_REG_D3, 38 | UC_ARM_REG_D4, 39 | UC_ARM_REG_D5, 40 | UC_ARM_REG_D6, 41 | UC_ARM_REG_D7, 42 | UC_ARM_REG_D8, 43 | UC_ARM_REG_D9, 44 | UC_ARM_REG_D10, 45 | UC_ARM_REG_D11, 46 | UC_ARM_REG_D12, 47 | UC_ARM_REG_D13, 48 | UC_ARM_REG_D14, 49 | UC_ARM_REG_D15, 50 | UC_ARM_REG_D16, 51 | UC_ARM_REG_D17, 52 | UC_ARM_REG_D18, 53 | UC_ARM_REG_D19, 54 | UC_ARM_REG_D20, 55 | UC_ARM_REG_D21, 56 | UC_ARM_REG_D22, 57 | UC_ARM_REG_D23, 58 | UC_ARM_REG_D24, 59 | UC_ARM_REG_D25, 60 | UC_ARM_REG_D26, 61 | UC_ARM_REG_D27, 62 | UC_ARM_REG_D28, 63 | UC_ARM_REG_D29, 64 | UC_ARM_REG_D30, 65 | UC_ARM_REG_D31, 66 | UC_ARM_REG_FPINST2, 67 | UC_ARM_REG_MVFR0, 68 | UC_ARM_REG_MVFR1, 69 | UC_ARM_REG_MVFR2, 70 | UC_ARM_REG_Q0, 71 | UC_ARM_REG_Q1, 72 | UC_ARM_REG_Q2, 73 | UC_ARM_REG_Q3, 74 | UC_ARM_REG_Q4, 75 | UC_ARM_REG_Q5, 76 | UC_ARM_REG_Q6, 77 | UC_ARM_REG_Q7, 78 | UC_ARM_REG_Q8, 79 | UC_ARM_REG_Q9, 80 | UC_ARM_REG_Q10, 81 | UC_ARM_REG_Q11, 82 | UC_ARM_REG_Q12, 83 | UC_ARM_REG_Q13, 84 | UC_ARM_REG_Q14, 85 | UC_ARM_REG_Q15, 86 | UC_ARM_REG_R0, 87 | UC_ARM_REG_R1, 88 | UC_ARM_REG_R2, 89 | UC_ARM_REG_R3, 90 | UC_ARM_REG_R4, 91 | UC_ARM_REG_R5, 92 | UC_ARM_REG_R6, 93 | UC_ARM_REG_R7, 94 | UC_ARM_REG_R8, 95 | UC_ARM_REG_R9, 96 | UC_ARM_REG_R10, 97 | UC_ARM_REG_R11, 98 | UC_ARM_REG_R12, 99 | UC_ARM_REG_S0, 100 | UC_ARM_REG_S1, 101 | UC_ARM_REG_S2, 102 | UC_ARM_REG_S3, 103 | UC_ARM_REG_S4, 104 | UC_ARM_REG_S5, 105 | UC_ARM_REG_S6, 106 | UC_ARM_REG_S7, 107 | UC_ARM_REG_S8, 108 | UC_ARM_REG_S9, 109 | UC_ARM_REG_S10, 110 | UC_ARM_REG_S11, 111 | UC_ARM_REG_S12, 112 | UC_ARM_REG_S13, 113 | UC_ARM_REG_S14, 114 | UC_ARM_REG_S15, 115 | UC_ARM_REG_S16, 116 | UC_ARM_REG_S17, 117 | UC_ARM_REG_S18, 118 | UC_ARM_REG_S19, 119 | UC_ARM_REG_S20, 120 | UC_ARM_REG_S21, 121 | UC_ARM_REG_S22, 122 | UC_ARM_REG_S23, 123 | UC_ARM_REG_S24, 124 | UC_ARM_REG_S25, 125 | UC_ARM_REG_S26, 126 | UC_ARM_REG_S27, 127 | UC_ARM_REG_S28, 128 | UC_ARM_REG_S29, 129 | UC_ARM_REG_S30, 130 | UC_ARM_REG_S31, 131 | 132 | UC_ARM_REG_C1_C0_2, 133 | UC_ARM_REG_C13_C0_2, 134 | UC_ARM_REG_C13_C0_3, 135 | 136 | UC_ARM_REG_IPSR, 137 | UC_ARM_REG_MSP, 138 | UC_ARM_REG_PSP, 139 | UC_ARM_REG_CONTROL, 140 | UC_ARM_REG_ENDING, // <-- mark the end of the list or registers 141 | 142 | //> alias registers 143 | UC_ARM_REG_R13 = UC_ARM_REG_SP, 144 | UC_ARM_REG_R14 = UC_ARM_REG_LR, 145 | UC_ARM_REG_R15 = UC_ARM_REG_PC, 146 | 147 | UC_ARM_REG_SB = UC_ARM_REG_R9, 148 | UC_ARM_REG_SL = UC_ARM_REG_R10, 149 | UC_ARM_REG_FP = UC_ARM_REG_R11, 150 | UC_ARM_REG_IP = UC_ARM_REG_R12, 151 | } uc_arm_reg; 152 | 153 | #ifdef __cplusplus 154 | } 155 | #endif 156 | 157 | #endif 158 | -------------------------------------------------------------------------------- /Third-Party/include/unicorn/m68k.h: -------------------------------------------------------------------------------- 1 | /* Unicorn Emulator Engine */ 2 | /* By Nguyen Anh Quynh , 2014-2017 */ 3 | /* This file is released under LGPL2. 4 | See COPYING.LGPL2 in root directory for more details 5 | */ 6 | 7 | #ifndef UNICORN_M68K_H 8 | #define UNICORN_M68K_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #ifdef _MSC_VER 15 | #pragma warning(disable:4201) 16 | #endif 17 | 18 | //> M68K registers 19 | typedef enum uc_m68k_reg { 20 | UC_M68K_REG_INVALID = 0, 21 | 22 | UC_M68K_REG_A0, 23 | UC_M68K_REG_A1, 24 | UC_M68K_REG_A2, 25 | UC_M68K_REG_A3, 26 | UC_M68K_REG_A4, 27 | UC_M68K_REG_A5, 28 | UC_M68K_REG_A6, 29 | UC_M68K_REG_A7, 30 | 31 | UC_M68K_REG_D0, 32 | UC_M68K_REG_D1, 33 | UC_M68K_REG_D2, 34 | UC_M68K_REG_D3, 35 | UC_M68K_REG_D4, 36 | UC_M68K_REG_D5, 37 | UC_M68K_REG_D6, 38 | UC_M68K_REG_D7, 39 | 40 | UC_M68K_REG_SR, 41 | UC_M68K_REG_PC, 42 | 43 | UC_M68K_REG_ENDING, // <-- mark the end of the list of registers 44 | } uc_m68k_reg; 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Third-Party/include/unicorn/mips.h: -------------------------------------------------------------------------------- 1 | /* Unicorn Emulator Engine */ 2 | /* By Nguyen Anh Quynh , 2015-2017 */ 3 | /* This file is released under LGPL2. 4 | See COPYING.LGPL2 in root directory for more details 5 | */ 6 | 7 | #ifndef UNICORN_MIPS_H 8 | #define UNICORN_MIPS_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | // GCC MIPS toolchain has a default macro called "mips" which breaks 15 | // compilation 16 | #undef mips 17 | 18 | #ifdef _MSC_VER 19 | #pragma warning(disable:4201) 20 | #endif 21 | 22 | //> MIPS registers 23 | typedef enum UC_MIPS_REG { 24 | UC_MIPS_REG_INVALID = 0, 25 | //> General purpose registers 26 | UC_MIPS_REG_PC, 27 | 28 | UC_MIPS_REG_0, 29 | UC_MIPS_REG_1, 30 | UC_MIPS_REG_2, 31 | UC_MIPS_REG_3, 32 | UC_MIPS_REG_4, 33 | UC_MIPS_REG_5, 34 | UC_MIPS_REG_6, 35 | UC_MIPS_REG_7, 36 | UC_MIPS_REG_8, 37 | UC_MIPS_REG_9, 38 | UC_MIPS_REG_10, 39 | UC_MIPS_REG_11, 40 | UC_MIPS_REG_12, 41 | UC_MIPS_REG_13, 42 | UC_MIPS_REG_14, 43 | UC_MIPS_REG_15, 44 | UC_MIPS_REG_16, 45 | UC_MIPS_REG_17, 46 | UC_MIPS_REG_18, 47 | UC_MIPS_REG_19, 48 | UC_MIPS_REG_20, 49 | UC_MIPS_REG_21, 50 | UC_MIPS_REG_22, 51 | UC_MIPS_REG_23, 52 | UC_MIPS_REG_24, 53 | UC_MIPS_REG_25, 54 | UC_MIPS_REG_26, 55 | UC_MIPS_REG_27, 56 | UC_MIPS_REG_28, 57 | UC_MIPS_REG_29, 58 | UC_MIPS_REG_30, 59 | UC_MIPS_REG_31, 60 | 61 | //> DSP registers 62 | UC_MIPS_REG_DSPCCOND, 63 | UC_MIPS_REG_DSPCARRY, 64 | UC_MIPS_REG_DSPEFI, 65 | UC_MIPS_REG_DSPOUTFLAG, 66 | UC_MIPS_REG_DSPOUTFLAG16_19, 67 | UC_MIPS_REG_DSPOUTFLAG20, 68 | UC_MIPS_REG_DSPOUTFLAG21, 69 | UC_MIPS_REG_DSPOUTFLAG22, 70 | UC_MIPS_REG_DSPOUTFLAG23, 71 | UC_MIPS_REG_DSPPOS, 72 | UC_MIPS_REG_DSPSCOUNT, 73 | 74 | //> ACC registers 75 | UC_MIPS_REG_AC0, 76 | UC_MIPS_REG_AC1, 77 | UC_MIPS_REG_AC2, 78 | UC_MIPS_REG_AC3, 79 | 80 | //> COP registers 81 | UC_MIPS_REG_CC0, 82 | UC_MIPS_REG_CC1, 83 | UC_MIPS_REG_CC2, 84 | UC_MIPS_REG_CC3, 85 | UC_MIPS_REG_CC4, 86 | UC_MIPS_REG_CC5, 87 | UC_MIPS_REG_CC6, 88 | UC_MIPS_REG_CC7, 89 | 90 | //> FPU registers 91 | UC_MIPS_REG_F0, 92 | UC_MIPS_REG_F1, 93 | UC_MIPS_REG_F2, 94 | UC_MIPS_REG_F3, 95 | UC_MIPS_REG_F4, 96 | UC_MIPS_REG_F5, 97 | UC_MIPS_REG_F6, 98 | UC_MIPS_REG_F7, 99 | UC_MIPS_REG_F8, 100 | UC_MIPS_REG_F9, 101 | UC_MIPS_REG_F10, 102 | UC_MIPS_REG_F11, 103 | UC_MIPS_REG_F12, 104 | UC_MIPS_REG_F13, 105 | UC_MIPS_REG_F14, 106 | UC_MIPS_REG_F15, 107 | UC_MIPS_REG_F16, 108 | UC_MIPS_REG_F17, 109 | UC_MIPS_REG_F18, 110 | UC_MIPS_REG_F19, 111 | UC_MIPS_REG_F20, 112 | UC_MIPS_REG_F21, 113 | UC_MIPS_REG_F22, 114 | UC_MIPS_REG_F23, 115 | UC_MIPS_REG_F24, 116 | UC_MIPS_REG_F25, 117 | UC_MIPS_REG_F26, 118 | UC_MIPS_REG_F27, 119 | UC_MIPS_REG_F28, 120 | UC_MIPS_REG_F29, 121 | UC_MIPS_REG_F30, 122 | UC_MIPS_REG_F31, 123 | 124 | UC_MIPS_REG_FCC0, 125 | UC_MIPS_REG_FCC1, 126 | UC_MIPS_REG_FCC2, 127 | UC_MIPS_REG_FCC3, 128 | UC_MIPS_REG_FCC4, 129 | UC_MIPS_REG_FCC5, 130 | UC_MIPS_REG_FCC6, 131 | UC_MIPS_REG_FCC7, 132 | 133 | //> AFPR128 134 | UC_MIPS_REG_W0, 135 | UC_MIPS_REG_W1, 136 | UC_MIPS_REG_W2, 137 | UC_MIPS_REG_W3, 138 | UC_MIPS_REG_W4, 139 | UC_MIPS_REG_W5, 140 | UC_MIPS_REG_W6, 141 | UC_MIPS_REG_W7, 142 | UC_MIPS_REG_W8, 143 | UC_MIPS_REG_W9, 144 | UC_MIPS_REG_W10, 145 | UC_MIPS_REG_W11, 146 | UC_MIPS_REG_W12, 147 | UC_MIPS_REG_W13, 148 | UC_MIPS_REG_W14, 149 | UC_MIPS_REG_W15, 150 | UC_MIPS_REG_W16, 151 | UC_MIPS_REG_W17, 152 | UC_MIPS_REG_W18, 153 | UC_MIPS_REG_W19, 154 | UC_MIPS_REG_W20, 155 | UC_MIPS_REG_W21, 156 | UC_MIPS_REG_W22, 157 | UC_MIPS_REG_W23, 158 | UC_MIPS_REG_W24, 159 | UC_MIPS_REG_W25, 160 | UC_MIPS_REG_W26, 161 | UC_MIPS_REG_W27, 162 | UC_MIPS_REG_W28, 163 | UC_MIPS_REG_W29, 164 | UC_MIPS_REG_W30, 165 | UC_MIPS_REG_W31, 166 | 167 | UC_MIPS_REG_HI, 168 | UC_MIPS_REG_LO, 169 | 170 | UC_MIPS_REG_P0, 171 | UC_MIPS_REG_P1, 172 | UC_MIPS_REG_P2, 173 | 174 | UC_MIPS_REG_MPL0, 175 | UC_MIPS_REG_MPL1, 176 | UC_MIPS_REG_MPL2, 177 | 178 | UC_MIPS_REG_CP0_CONFIG3, 179 | UC_MIPS_REG_CP0_USERLOCAL, 180 | 181 | UC_MIPS_REG_ENDING, // <-- mark the end of the list or registers 182 | 183 | // alias registers 184 | UC_MIPS_REG_ZERO = UC_MIPS_REG_0, 185 | UC_MIPS_REG_AT = UC_MIPS_REG_1, 186 | UC_MIPS_REG_V0 = UC_MIPS_REG_2, 187 | UC_MIPS_REG_V1 = UC_MIPS_REG_3, 188 | UC_MIPS_REG_A0 = UC_MIPS_REG_4, 189 | UC_MIPS_REG_A1 = UC_MIPS_REG_5, 190 | UC_MIPS_REG_A2 = UC_MIPS_REG_6, 191 | UC_MIPS_REG_A3 = UC_MIPS_REG_7, 192 | UC_MIPS_REG_T0 = UC_MIPS_REG_8, 193 | UC_MIPS_REG_T1 = UC_MIPS_REG_9, 194 | UC_MIPS_REG_T2 = UC_MIPS_REG_10, 195 | UC_MIPS_REG_T3 = UC_MIPS_REG_11, 196 | UC_MIPS_REG_T4 = UC_MIPS_REG_12, 197 | UC_MIPS_REG_T5 = UC_MIPS_REG_13, 198 | UC_MIPS_REG_T6 = UC_MIPS_REG_14, 199 | UC_MIPS_REG_T7 = UC_MIPS_REG_15, 200 | UC_MIPS_REG_S0 = UC_MIPS_REG_16, 201 | UC_MIPS_REG_S1 = UC_MIPS_REG_17, 202 | UC_MIPS_REG_S2 = UC_MIPS_REG_18, 203 | UC_MIPS_REG_S3 = UC_MIPS_REG_19, 204 | UC_MIPS_REG_S4 = UC_MIPS_REG_20, 205 | UC_MIPS_REG_S5 = UC_MIPS_REG_21, 206 | UC_MIPS_REG_S6 = UC_MIPS_REG_22, 207 | UC_MIPS_REG_S7 = UC_MIPS_REG_23, 208 | UC_MIPS_REG_T8 = UC_MIPS_REG_24, 209 | UC_MIPS_REG_T9 = UC_MIPS_REG_25, 210 | UC_MIPS_REG_K0 = UC_MIPS_REG_26, 211 | UC_MIPS_REG_K1 = UC_MIPS_REG_27, 212 | UC_MIPS_REG_GP = UC_MIPS_REG_28, 213 | UC_MIPS_REG_SP = UC_MIPS_REG_29, 214 | UC_MIPS_REG_FP = UC_MIPS_REG_30, UC_MIPS_REG_S8 = UC_MIPS_REG_30, 215 | UC_MIPS_REG_RA = UC_MIPS_REG_31, 216 | 217 | UC_MIPS_REG_HI0 = UC_MIPS_REG_AC0, 218 | UC_MIPS_REG_HI1 = UC_MIPS_REG_AC1, 219 | UC_MIPS_REG_HI2 = UC_MIPS_REG_AC2, 220 | UC_MIPS_REG_HI3 = UC_MIPS_REG_AC3, 221 | 222 | UC_MIPS_REG_LO0 = UC_MIPS_REG_HI0, 223 | UC_MIPS_REG_LO1 = UC_MIPS_REG_HI1, 224 | UC_MIPS_REG_LO2 = UC_MIPS_REG_HI2, 225 | UC_MIPS_REG_LO3 = UC_MIPS_REG_HI3, 226 | } UC_MIPS_REG; 227 | 228 | #ifdef __cplusplus 229 | } 230 | #endif 231 | 232 | #endif 233 | -------------------------------------------------------------------------------- /Third-Party/include/unicorn/platform.h: -------------------------------------------------------------------------------- 1 | /* This file is released under LGPL2. 2 | See COPYING.LGPL2 in root directory for more details 3 | */ 4 | 5 | /* 6 | This file is to support header files that are missing in MSVC and 7 | other non-standard compilers. 8 | */ 9 | #ifndef UNICORN_PLATFORM_H 10 | #define UNICORN_PLATFORM_H 11 | 12 | /* 13 | These are the various MSVC versions as given by _MSC_VER: 14 | MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) 15 | MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013) 16 | MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012) 17 | MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010) 18 | MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008) 19 | MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005) 20 | MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio 2003) 21 | MSVC++ 7.0 _MSC_VER == 1300 22 | MSVC++ 6.0 _MSC_VER == 1200 23 | MSVC++ 5.0 _MSC_VER == 1100 24 | */ 25 | #define MSC_VER_VS2003 1310 26 | #define MSC_VER_VS2005 1400 27 | #define MSC_VER_VS2008 1500 28 | #define MSC_VER_VS2010 1600 29 | #define MSC_VER_VS2012 1700 30 | #define MSC_VER_VS2013 1800 31 | #define MSC_VER_VS2015 1900 32 | 33 | // handle stdbool.h compatibility 34 | #if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)) 35 | // MSVC 36 | 37 | // stdbool.h 38 | #if (_MSC_VER < MSC_VER_VS2013) || defined(_KERNEL_MODE) 39 | // this system does not have stdbool.h 40 | #ifndef __cplusplus 41 | typedef unsigned char bool; 42 | #define false 0 43 | #define true 1 44 | #endif // __cplusplus 45 | 46 | #else 47 | // VisualStudio 2013+ -> C99 is supported 48 | #include 49 | #endif // (_MSC_VER < MSC_VER_VS2013) || defined(_KERNEL_MODE) 50 | 51 | #else 52 | // not MSVC -> C99 is supported 53 | #include 54 | #endif // !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)) 55 | 56 | #if (defined(_MSC_VER) && (_MSC_VER < MSC_VER_VS2010)) || defined(_KERNEL_MODE) 57 | // this system does not have stdint.h 58 | typedef signed char int8_t; 59 | typedef signed short int16_t; 60 | typedef signed int int32_t; 61 | typedef unsigned char uint8_t; 62 | typedef unsigned short uint16_t; 63 | typedef unsigned int uint32_t; 64 | typedef signed long long int64_t; 65 | typedef unsigned long long uint64_t; 66 | 67 | #ifndef _INTPTR_T_DEFINED 68 | #define _INTPTR_T_DEFINED 69 | #ifdef _WIN64 70 | typedef long long intptr_t; 71 | #else /* _WIN64 */ 72 | typedef _W64 int intptr_t; 73 | #endif /* _WIN64 */ 74 | #endif /* _INTPTR_T_DEFINED */ 75 | 76 | #ifndef _UINTPTR_T_DEFINED 77 | #define _UINTPTR_T_DEFINED 78 | #ifdef _WIN64 79 | typedef unsigned long long uintptr_t; 80 | #else /* _WIN64 */ 81 | typedef _W64 unsigned int uintptr_t; 82 | #endif /* _WIN64 */ 83 | #endif /* _UINTPTR_T_DEFINED */ 84 | 85 | #define INT8_MIN (-127i8 - 1) 86 | #define INT16_MIN (-32767i16 - 1) 87 | #define INT32_MIN (-2147483647i32 - 1) 88 | #define INT64_MIN (-9223372036854775807i64 - 1) 89 | #define INT8_MAX 127i8 90 | #define INT16_MAX 32767i16 91 | #define INT32_MAX 2147483647i32 92 | #define INT64_MAX 9223372036854775807i64 93 | #define UINT8_MAX 0xffui8 94 | #define UINT16_MAX 0xffffui16 95 | #define UINT32_MAX 0xffffffffui32 96 | #define UINT64_MAX 0xffffffffffffffffui64 97 | #else // this system has stdint.h 98 | #include 99 | #endif // (defined(_MSC_VER) && (_MSC_VER < MSC_VER_VS2010)) || defined(_KERNEL_MODE) 100 | 101 | // handle inttypes.h compatibility 102 | #if (defined(_MSC_VER) && (_MSC_VER < MSC_VER_VS2013)) || defined(_KERNEL_MODE) 103 | // this system does not have inttypes.h 104 | 105 | #define __PRI_8_LENGTH_MODIFIER__ "hh" 106 | #define __PRI_64_LENGTH_MODIFIER__ "ll" 107 | 108 | #define PRId8 __PRI_8_LENGTH_MODIFIER__ "d" 109 | #define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i" 110 | #define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o" 111 | #define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u" 112 | #define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x" 113 | #define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X" 114 | 115 | #define PRId16 "hd" 116 | #define PRIi16 "hi" 117 | #define PRIo16 "ho" 118 | #define PRIu16 "hu" 119 | #define PRIx16 "hx" 120 | #define PRIX16 "hX" 121 | 122 | #if defined(_MSC_VER) && (_MSC_VER <= MSC_VER_VS2012) 123 | #define PRId32 "ld" 124 | #define PRIi32 "li" 125 | #define PRIo32 "lo" 126 | #define PRIu32 "lu" 127 | #define PRIx32 "lx" 128 | #define PRIX32 "lX" 129 | #else // OSX 130 | #define PRId32 "d" 131 | #define PRIi32 "i" 132 | #define PRIo32 "o" 133 | #define PRIu32 "u" 134 | #define PRIx32 "x" 135 | #define PRIX32 "X" 136 | #endif // defined(_MSC_VER) && (_MSC_VER <= MSC_VER_VS2012) 137 | 138 | #if defined(_MSC_VER) && (_MSC_VER <= MSC_VER_VS2012) 139 | // redefine functions from inttypes.h used in cstool 140 | #define strtoull _strtoui64 141 | #endif 142 | 143 | #define PRId64 __PRI_64_LENGTH_MODIFIER__ "d" 144 | #define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i" 145 | #define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o" 146 | #define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u" 147 | #define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x" 148 | #define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X" 149 | 150 | #else 151 | // this system has inttypes.h by default 152 | #include 153 | #endif // #if defined(_MSC_VER) && (_MSC_VER < MSC_VER_VS2013) || defined(_KERNEL_MODE) 154 | 155 | // sys/time.h compatibility 156 | #if defined(_MSC_VER) 157 | #include 158 | #include 159 | #include 160 | 161 | static int gettimeofday(struct timeval* t, void* timezone) 162 | { 163 | struct _timeb timebuffer; 164 | _ftime( &timebuffer ); 165 | t->tv_sec = (long)timebuffer.time; 166 | t->tv_usec = 1000*timebuffer.millitm; 167 | return 0; 168 | } 169 | #else 170 | #include 171 | #endif 172 | 173 | // unistd.h compatibility 174 | #if defined(_MSC_VER) 175 | 176 | static int usleep(uint32_t usec) 177 | { 178 | HANDLE timer; 179 | LARGE_INTEGER due; 180 | 181 | timer = CreateWaitableTimer(NULL, TRUE, NULL); 182 | if (!timer) 183 | return -1; 184 | 185 | due.QuadPart = (-((int64_t) usec)) * 10LL; 186 | if (!SetWaitableTimer(timer, &due, 0, NULL, NULL, 0)) { 187 | CloseHandle(timer); 188 | return -1; 189 | } 190 | WaitForSingleObject(timer, INFINITE); 191 | CloseHandle(timer); 192 | 193 | return 0; 194 | } 195 | 196 | #else 197 | #include 198 | #endif 199 | 200 | // misc support 201 | #if defined(_MSC_VER) 202 | #ifdef _WIN64 203 | typedef signed __int64 ssize_t; 204 | #else 205 | typedef _W64 signed int ssize_t; 206 | #endif 207 | 208 | #define va_copy(d,s) ((d) = (s)) 209 | #define strcasecmp _stricmp 210 | #if (_MSC_VER < MSC_VER_VS2015) 211 | #define snprintf _snprintf 212 | #endif 213 | #if (_MSC_VER <= MSC_VER_VS2013) 214 | #define strtoll _strtoi64 215 | #endif 216 | #endif 217 | 218 | 219 | #endif // UNICORN_PLATFORM_H 220 | -------------------------------------------------------------------------------- /Third-Party/include/unicorn/sparc.h: -------------------------------------------------------------------------------- 1 | /* Unicorn Emulator Engine */ 2 | /* By Nguyen Anh Quynh , 2014-2017 */ 3 | /* This file is released under LGPL2. 4 | See COPYING.LGPL2 in root directory for more details 5 | */ 6 | 7 | #ifndef UNICORN_SPARC_H 8 | #define UNICORN_SPARC_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | // GCC SPARC toolchain has a default macro called "sparc" which breaks 15 | // compilation 16 | #undef sparc 17 | 18 | #ifdef _MSC_VER 19 | #pragma warning(disable:4201) 20 | #endif 21 | 22 | //> SPARC registers 23 | typedef enum uc_sparc_reg { 24 | UC_SPARC_REG_INVALID = 0, 25 | 26 | UC_SPARC_REG_F0, 27 | UC_SPARC_REG_F1, 28 | UC_SPARC_REG_F2, 29 | UC_SPARC_REG_F3, 30 | UC_SPARC_REG_F4, 31 | UC_SPARC_REG_F5, 32 | UC_SPARC_REG_F6, 33 | UC_SPARC_REG_F7, 34 | UC_SPARC_REG_F8, 35 | UC_SPARC_REG_F9, 36 | UC_SPARC_REG_F10, 37 | UC_SPARC_REG_F11, 38 | UC_SPARC_REG_F12, 39 | UC_SPARC_REG_F13, 40 | UC_SPARC_REG_F14, 41 | UC_SPARC_REG_F15, 42 | UC_SPARC_REG_F16, 43 | UC_SPARC_REG_F17, 44 | UC_SPARC_REG_F18, 45 | UC_SPARC_REG_F19, 46 | UC_SPARC_REG_F20, 47 | UC_SPARC_REG_F21, 48 | UC_SPARC_REG_F22, 49 | UC_SPARC_REG_F23, 50 | UC_SPARC_REG_F24, 51 | UC_SPARC_REG_F25, 52 | UC_SPARC_REG_F26, 53 | UC_SPARC_REG_F27, 54 | UC_SPARC_REG_F28, 55 | UC_SPARC_REG_F29, 56 | UC_SPARC_REG_F30, 57 | UC_SPARC_REG_F31, 58 | UC_SPARC_REG_F32, 59 | UC_SPARC_REG_F34, 60 | UC_SPARC_REG_F36, 61 | UC_SPARC_REG_F38, 62 | UC_SPARC_REG_F40, 63 | UC_SPARC_REG_F42, 64 | UC_SPARC_REG_F44, 65 | UC_SPARC_REG_F46, 66 | UC_SPARC_REG_F48, 67 | UC_SPARC_REG_F50, 68 | UC_SPARC_REG_F52, 69 | UC_SPARC_REG_F54, 70 | UC_SPARC_REG_F56, 71 | UC_SPARC_REG_F58, 72 | UC_SPARC_REG_F60, 73 | UC_SPARC_REG_F62, 74 | UC_SPARC_REG_FCC0, // Floating condition codes 75 | UC_SPARC_REG_FCC1, 76 | UC_SPARC_REG_FCC2, 77 | UC_SPARC_REG_FCC3, 78 | UC_SPARC_REG_G0, 79 | UC_SPARC_REG_G1, 80 | UC_SPARC_REG_G2, 81 | UC_SPARC_REG_G3, 82 | UC_SPARC_REG_G4, 83 | UC_SPARC_REG_G5, 84 | UC_SPARC_REG_G6, 85 | UC_SPARC_REG_G7, 86 | UC_SPARC_REG_I0, 87 | UC_SPARC_REG_I1, 88 | UC_SPARC_REG_I2, 89 | UC_SPARC_REG_I3, 90 | UC_SPARC_REG_I4, 91 | UC_SPARC_REG_I5, 92 | UC_SPARC_REG_FP, 93 | UC_SPARC_REG_I7, 94 | UC_SPARC_REG_ICC, // Integer condition codes 95 | UC_SPARC_REG_L0, 96 | UC_SPARC_REG_L1, 97 | UC_SPARC_REG_L2, 98 | UC_SPARC_REG_L3, 99 | UC_SPARC_REG_L4, 100 | UC_SPARC_REG_L5, 101 | UC_SPARC_REG_L6, 102 | UC_SPARC_REG_L7, 103 | UC_SPARC_REG_O0, 104 | UC_SPARC_REG_O1, 105 | UC_SPARC_REG_O2, 106 | UC_SPARC_REG_O3, 107 | UC_SPARC_REG_O4, 108 | UC_SPARC_REG_O5, 109 | UC_SPARC_REG_SP, 110 | UC_SPARC_REG_O7, 111 | UC_SPARC_REG_Y, 112 | 113 | // special register 114 | UC_SPARC_REG_XCC, 115 | 116 | // pseudo register 117 | UC_SPARC_REG_PC, // program counter register 118 | 119 | UC_SPARC_REG_ENDING, // <-- mark the end of the list of registers 120 | 121 | // extras 122 | UC_SPARC_REG_O6 = UC_SPARC_REG_SP, 123 | UC_SPARC_REG_I6 = UC_SPARC_REG_FP, 124 | } uc_sparc_reg; 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /Third-Party/include/windowsce/intrin.h: -------------------------------------------------------------------------------- 1 | 2 | #if defined(_MSC_VER) && defined(_WIN32_WCE) && (_WIN32_WCE < 0x800) && !defined(__INTRIN_H_) && !defined(_INTRIN) 3 | #define _STDINT 4 | 5 | #ifdef _M_ARM 6 | #include 7 | #if (_WIN32_WCE >= 0x700) && defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) 8 | #include 9 | #endif 10 | #endif // _M_ARM 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /Third-Party/include/windowsce/stdint.h: -------------------------------------------------------------------------------- 1 | 2 | #if defined(_MSC_VER) && defined(_WIN32_WCE) && (_WIN32_WCE < 0x800) && !defined(_STDINT_H_) && !defined(_STDINT) 3 | #define _STDINT 4 | 5 | typedef __int8 6 | int8_t, 7 | int_least8_t; 8 | 9 | typedef __int16 10 | int16_t, 11 | int_least16_t; 12 | 13 | typedef __int32 14 | int32_t, 15 | int_least32_t, 16 | int_fast8_t, 17 | int_fast16_t, 18 | int_fast32_t; 19 | 20 | typedef __int64 21 | int64_t, 22 | intmax_t, 23 | int_least64_t, 24 | int_fast64_t; 25 | 26 | typedef unsigned __int8 27 | uint8_t, 28 | uint_least8_t; 29 | 30 | typedef unsigned __int16 31 | uint16_t, 32 | uint_least16_t; 33 | 34 | typedef unsigned __int32 35 | uint32_t, 36 | uint_least32_t, 37 | uint_fast8_t, 38 | uint_fast16_t, 39 | uint_fast32_t; 40 | 41 | typedef unsigned __int64 42 | uint64_t, 43 | uintmax_t, 44 | uint_least64_t, 45 | uint_fast64_t; 46 | 47 | #ifndef _INTPTR_T_DEFINED 48 | #define _INTPTR_T_DEFINED 49 | typedef __int32 intptr_t; 50 | #endif 51 | 52 | #ifndef _UINTPTR_T_DEFINED 53 | #define _UINTPTR_T_DEFINED 54 | typedef unsigned __int32 uintptr_t; 55 | #endif 56 | 57 | #define INT8_MIN (-127i8 - 1) 58 | #define INT16_MIN (-32767i16 - 1) 59 | #define INT32_MIN (-2147483647i32 - 1) 60 | #define INT64_MIN (-9223372036854775807i64 - 1) 61 | #define INT8_MAX 127i8 62 | #define INT16_MAX 32767i16 63 | #define INT32_MAX 2147483647i32 64 | #define INT64_MAX 9223372036854775807i64 65 | #define UINT8_MAX 0xffui8 66 | #define UINT16_MAX 0xffffui16 67 | #define UINT32_MAX 0xffffffffui32 68 | #define UINT64_MAX 0xffffffffffffffffui64 69 | 70 | #define INT_LEAST8_MIN INT8_MIN 71 | #define INT_LEAST16_MIN INT16_MIN 72 | #define INT_LEAST32_MIN INT32_MIN 73 | #define INT_LEAST64_MIN INT64_MIN 74 | #define INT_LEAST8_MAX INT8_MAX 75 | #define INT_LEAST16_MAX INT16_MAX 76 | #define INT_LEAST32_MAX INT32_MAX 77 | #define INT_LEAST64_MAX INT64_MAX 78 | #define UINT_LEAST8_MAX UINT8_MAX 79 | #define UINT_LEAST16_MAX UINT16_MAX 80 | #define UINT_LEAST32_MAX UINT32_MAX 81 | #define UINT_LEAST64_MAX UINT64_MAX 82 | 83 | #define INT_FAST8_MIN INT8_MIN 84 | #define INT_FAST16_MIN INT32_MIN 85 | #define INT_FAST32_MIN INT32_MIN 86 | #define INT_FAST64_MIN INT64_MIN 87 | #define INT_FAST8_MAX INT8_MAX 88 | #define INT_FAST16_MAX INT32_MAX 89 | #define INT_FAST32_MAX INT32_MAX 90 | #define INT_FAST64_MAX INT64_MAX 91 | #define UINT_FAST8_MAX UINT8_MAX 92 | #define UINT_FAST16_MAX UINT32_MAX 93 | #define UINT_FAST32_MAX UINT32_MAX 94 | #define UINT_FAST64_MAX UINT64_MAX 95 | 96 | #define INTPTR_MIN INT32_MIN 97 | #define INTPTR_MAX INT32_MAX 98 | #define UINTPTR_MAX UINT32_MAX 99 | 100 | #define INTMAX_MIN INT64_MIN 101 | #define INTMAX_MAX INT64_MAX 102 | #define UINTMAX_MAX UINT64_MAX 103 | 104 | #define PTRDIFF_MIN INTPTR_MIN 105 | #define PTRDIFF_MAX INTPTR_MAX 106 | 107 | #ifndef SIZE_MAX 108 | #define SIZE_MAX UINTPTR_MAX 109 | #endif 110 | 111 | #define SIG_ATOMIC_MIN INT32_MIN 112 | #define SIG_ATOMIC_MAX INT32_MAX 113 | 114 | #define WCHAR_MIN 0x0000 115 | #define WCHAR_MAX 0xffff 116 | 117 | #define WINT_MIN 0x0000 118 | #define WINT_MAX 0xffff 119 | 120 | #define INT8_C(x) (x) 121 | #define INT16_C(x) (x) 122 | #define INT32_C(x) (x) 123 | #define INT64_C(x) (x ## LL) 124 | 125 | #define UINT8_C(x) (x) 126 | #define UINT16_C(x) (x) 127 | #define UINT32_C(x) (x ## U) 128 | #define UINT64_C(x) (x ## ULL) 129 | 130 | #define INTMAX_C(x) INT64_C(x) 131 | #define UINTMAX_C(x) UINT64_C(x) 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /Third-Party/lib/libcapstone.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/macmade/unicorn-bios/97a53ff5c8c418e79f0f5798da3d365b2ceaa7f2/Third-Party/lib/libcapstone.a -------------------------------------------------------------------------------- /Third-Party/lib/libunicorn.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/macmade/unicorn-bios/97a53ff5c8c418e79f0f5798da3d365b2ceaa7f2/Third-Party/lib/libunicorn.a -------------------------------------------------------------------------------- /unicorn-bios.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /unicorn-bios.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /unicorn-bios.xcodeproj/xcshareddata/xcschemes/unicorn-bios (XEOS).xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 45 | 47 | 53 | 54 | 55 | 56 | 59 | 60 | 63 | 64 | 65 | 66 | 72 | 74 | 80 | 81 | 82 | 83 | 85 | 86 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /unicorn-bios.xcodeproj/xcshareddata/xcschemes/unicorn-bios.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Arguments.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_ARGUMENTS_HPP 26 | #define UB_ARGUMENTS_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace UB 34 | { 35 | class Arguments 36 | { 37 | public: 38 | 39 | Arguments( int argc, const char * argv[] ); 40 | Arguments( const Arguments & o ); 41 | Arguments( Arguments && o ) noexcept; 42 | ~Arguments( void ); 43 | 44 | Arguments & operator =( Arguments o ); 45 | 46 | bool showHelp( void ) const; 47 | bool breakOnInterrupt( void ) const; 48 | bool breakOnInterruptReturn( void ) const; 49 | bool trap( void ) const; 50 | bool debugVideo( void ) const; 51 | bool singleStep( void ) const; 52 | bool noUI( void ) const; 53 | bool noColors( void ) const; 54 | size_t memory( void ) const; 55 | std::string bootImage( void ) const; 56 | std::vector< uint64_t > breakpoints( void ) const; 57 | 58 | friend void swap( Arguments & o1, Arguments & o2 ); 59 | 60 | private: 61 | 62 | class IMPL; 63 | std::unique_ptr< IMPL > impl; 64 | }; 65 | } 66 | 67 | #endif /* UB_ARGUMENTS_HPP */ 68 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/Disk.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_BIOS_DISK_HPP 26 | #define UB_BIOS_DISK_HPP 27 | 28 | namespace UB 29 | { 30 | class Machine; 31 | class Engine; 32 | 33 | namespace BIOS 34 | { 35 | namespace Disk 36 | { 37 | bool reset( const Machine & machine, Engine & engine ); 38 | bool readSectors( const Machine & machine, Engine & engine ); 39 | bool checkExtensions( const Machine & machine, Engine & engine ); 40 | bool extendedReadSectors( const Machine & machine, Engine & engine ); 41 | } 42 | } 43 | } 44 | 45 | #endif /* UB_BIOS_DISK_HPP */ 46 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/Keyboard.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/BIOS/Keyboard.hpp" 26 | #include "UB/Machine.hpp" 27 | #include "UB/Engine.hpp" 28 | 29 | namespace UB 30 | { 31 | namespace BIOS 32 | { 33 | namespace Keyboard 34 | { 35 | bool readKey( const Machine & machine, Engine & engine ) 36 | { 37 | ( void )machine; 38 | ( void )engine; 39 | 40 | return true; 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/Keyboard.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_BIOS_KEYBOARD_HPP 26 | #define UB_BIOS_KEYBOARD_HPP 27 | 28 | namespace UB 29 | { 30 | class Machine; 31 | class Engine; 32 | 33 | namespace BIOS 34 | { 35 | namespace Keyboard 36 | { 37 | bool readKey( const Machine & machine, Engine & engine ); 38 | } 39 | } 40 | } 41 | 42 | #endif /* UB_BIOS_KEYBOARD_HPP */ 43 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/MemoryMap-Entry.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/BIOS/MemoryMap.hpp" 26 | 27 | namespace UB 28 | { 29 | namespace BIOS 30 | { 31 | class MemoryMap::Entry::IMPL 32 | { 33 | public: 34 | 35 | IMPL( uint64_t base, uint64_t length, Type type ); 36 | IMPL( const IMPL & o ); 37 | ~IMPL( void ); 38 | 39 | uint64_t _base; 40 | uint64_t _length; 41 | Type _type; 42 | }; 43 | 44 | MemoryMap::Entry::Entry( uint64_t base, uint64_t length, Type type ): 45 | impl( std::make_unique< IMPL >( base, length, type ) ) 46 | {} 47 | 48 | MemoryMap::Entry::Entry( const Entry & o ): 49 | impl( std::make_unique< IMPL >( *( o.impl ) ) ) 50 | {} 51 | 52 | MemoryMap::Entry::Entry( Entry && o ) noexcept: 53 | impl( std::move( o.impl ) ) 54 | {} 55 | 56 | MemoryMap::Entry::~Entry( void ) 57 | {} 58 | 59 | MemoryMap::Entry & MemoryMap::Entry::operator =( Entry o ) 60 | { 61 | swap( *( this ), o ); 62 | 63 | return *( this ); 64 | } 65 | 66 | uint64_t MemoryMap::Entry::base( void ) const 67 | { 68 | return this->impl->_base; 69 | } 70 | 71 | uint64_t MemoryMap::Entry::end( void ) const 72 | { 73 | if( this->impl->_length == 0 ) 74 | { 75 | return this->impl->_base; 76 | } 77 | 78 | return this->impl->_base + ( this->impl->_length - 1 ); 79 | } 80 | 81 | uint64_t MemoryMap::Entry::length( void ) const 82 | { 83 | return this->impl->_length; 84 | } 85 | 86 | MemoryMap::Entry::Type MemoryMap::Entry::type( void ) const 87 | { 88 | return this->impl->_type; 89 | } 90 | 91 | uint32_t MemoryMap::Entry::baseLow( void ) const 92 | { 93 | return this->impl->_base & 0xFFFFFFFF; 94 | } 95 | 96 | uint32_t MemoryMap::Entry::baseHigh( void ) const 97 | { 98 | return this->impl->_base >> 32; 99 | } 100 | 101 | uint32_t MemoryMap::Entry::lengthLow( void ) const 102 | { 103 | return this->impl->_length & 0xFFFFFFFF; 104 | } 105 | 106 | uint32_t MemoryMap::Entry::lengthHigh( void ) const 107 | { 108 | return this->impl->_base >> 32; 109 | } 110 | 111 | std::array< uint32_t, 5 > MemoryMap::Entry::data( void ) const 112 | { 113 | return 114 | { 115 | this->baseLow(), 116 | this->baseHigh(), 117 | this->lengthLow(), 118 | this->lengthHigh(), 119 | static_cast< uint32_t >( this->type() ) 120 | }; 121 | } 122 | 123 | void swap( MemoryMap::Entry & o1, MemoryMap::Entry & o2 ) 124 | { 125 | using std::swap; 126 | 127 | swap( o1.impl, o2.impl ); 128 | } 129 | 130 | MemoryMap::Entry::IMPL::IMPL( uint64_t base, uint64_t length, Type type ): 131 | _base( base ), 132 | _length( length ), 133 | _type( type ) 134 | {} 135 | 136 | MemoryMap::Entry::IMPL::IMPL( const IMPL & o ): 137 | _base( o._base ), 138 | _length( o._length ), 139 | _type( o._type ) 140 | {} 141 | 142 | MemoryMap::Entry::IMPL::~IMPL( void ) 143 | {} 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/MemoryMap.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/BIOS/MemoryMap.hpp" 26 | 27 | namespace UB 28 | { 29 | namespace BIOS 30 | { 31 | class MemoryMap::IMPL 32 | { 33 | public: 34 | 35 | IMPL( size_t memory ); 36 | IMPL( const IMPL & o ); 37 | ~IMPL( void ); 38 | 39 | std::vector< Entry > _entries; 40 | }; 41 | 42 | MemoryMap::MemoryMap( size_t memory ): 43 | impl( std::make_unique< IMPL >( memory ) ) 44 | {} 45 | 46 | MemoryMap::MemoryMap( const MemoryMap & o ): 47 | impl( std::make_unique< IMPL >( *( o.impl ) ) ) 48 | {} 49 | 50 | MemoryMap::MemoryMap( MemoryMap && o ) noexcept: 51 | impl( std::move( o.impl ) ) 52 | {} 53 | 54 | MemoryMap::~MemoryMap( void ) 55 | {} 56 | 57 | MemoryMap & MemoryMap::operator =( MemoryMap o ) 58 | { 59 | swap( *( this ), o ); 60 | 61 | return *( this ); 62 | } 63 | 64 | std::vector< MemoryMap::Entry > MemoryMap::entries( void ) const 65 | { 66 | return this->impl->_entries; 67 | } 68 | 69 | void swap( MemoryMap & o1, MemoryMap & o2 ) 70 | { 71 | using std::swap; 72 | 73 | swap( o1.impl, o2.impl ); 74 | } 75 | 76 | MemoryMap::IMPL::IMPL( size_t memory ) 77 | { 78 | uint64_t free; 79 | uint64_t after; 80 | 81 | if( memory < 2 * 1024 * 1024 ) 82 | { 83 | throw std::runtime_error( "Memory must be at least 2MB" ); 84 | } 85 | 86 | free = memory - 0x00100000 - 0x00010000; 87 | after = memory - 0x00010000; 88 | 89 | this->_entries.push_back( { 0x00000000, 0x0009FC00, Entry::Type::Usable } ); 90 | this->_entries.push_back( { 0x0009FC00, 0x00000400, Entry::Type::Reserved } ); 91 | this->_entries.push_back( { 0x000F0000, 0x00010000, Entry::Type::Reserved } ); 92 | this->_entries.push_back( { 0x00100000, free, Entry::Type::Usable } ); 93 | this->_entries.push_back( { after, 0x00010000, Entry::Type::ACPI } ); 94 | this->_entries.push_back( { 0xFEC00000, 0x00001000, Entry::Type::Reserved } ); 95 | this->_entries.push_back( { 0xFEE00000, 0x00001000, Entry::Type::Reserved } ); 96 | } 97 | 98 | MemoryMap::IMPL::IMPL( const IMPL & o ): 99 | _entries( o._entries ) 100 | {} 101 | 102 | MemoryMap::IMPL::~IMPL( void ) 103 | {} 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/MemoryMap.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_MEMORY_MAP_HPP 26 | #define UB_MEMORY_MAP_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace UB 35 | { 36 | namespace BIOS 37 | { 38 | class MemoryMap 39 | { 40 | public: 41 | 42 | class Entry 43 | { 44 | public: 45 | 46 | enum class Type: uint32_t 47 | { 48 | Usable = 0x01, 49 | Reserved = 0x02, 50 | ACPI = 0x03 51 | }; 52 | 53 | Entry( uint64_t base, uint64_t length, Type type ); 54 | Entry( const Entry & o ); 55 | Entry( Entry && o ) noexcept; 56 | ~Entry( void ); 57 | 58 | Entry & operator =( Entry o ); 59 | 60 | uint64_t base( void ) const; 61 | uint64_t end( void ) const; 62 | uint64_t length( void ) const; 63 | Type type( void ) const; 64 | uint32_t baseLow( void ) const; 65 | uint32_t baseHigh( void ) const; 66 | uint32_t lengthLow( void ) const; 67 | uint32_t lengthHigh( void ) const; 68 | 69 | std::array< uint32_t, 5 > data( void ) const; 70 | 71 | friend void swap( Entry & o1, Entry & o2 ); 72 | 73 | private: 74 | 75 | class IMPL; 76 | std::unique_ptr< IMPL > impl; 77 | }; 78 | 79 | MemoryMap( size_t memory ); 80 | MemoryMap( const MemoryMap & o ); 81 | MemoryMap( MemoryMap && o ) noexcept; 82 | ~MemoryMap( void ); 83 | 84 | MemoryMap & operator =( MemoryMap o ); 85 | 86 | std::vector< Entry > entries( void ) const; 87 | 88 | friend void swap( MemoryMap & o1, MemoryMap & o2 ); 89 | 90 | private: 91 | 92 | class IMPL; 93 | std::unique_ptr< IMPL > impl; 94 | }; 95 | } 96 | } 97 | 98 | #endif /* UB_MEMORY_MAP_HPP */ 99 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/SystemServices.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/BIOS/SystemServices.hpp" 26 | #include "UB/Machine.hpp" 27 | #include "UB/Engine.hpp" 28 | #include "UB/String.hpp" 29 | 30 | namespace UB 31 | { 32 | namespace BIOS 33 | { 34 | namespace SystemServices 35 | { 36 | bool getMemoryMap( const Machine & machine, Engine & engine ) 37 | { 38 | uint64_t destination( Engine::getAddress( engine.es(), engine.di() ) ); 39 | uint32_t index( engine.ebx() ); 40 | uint32_t size( engine.ecx() ); 41 | uint32_t signature( engine.edx() ); 42 | const MemoryMap & map( machine.memoryMap() ); 43 | std::vector< MemoryMap::Entry > entries( map.entries() ); 44 | 45 | machine.ui().debug() << "Getting memory map:" 46 | << std::endl 47 | << " - Continuation: " << String::toHex( index ) 48 | << std::endl 49 | << " - Destination: " << String::toHex( destination ) << " (" << String::toHex( engine.es() ) << ":" << String::toHex( engine.di() ) << ")" 50 | << std::endl 51 | << " - Buffer size: " << String::toHex( size ) 52 | << std::endl 53 | << " - Signature: " << String::toHex( signature ) 54 | << std::endl; 55 | 56 | if( signature != 0x534D4150 ) 57 | { 58 | goto error; 59 | } 60 | 61 | if( map.entries().size() == 0 ) 62 | { 63 | goto error; 64 | } 65 | 66 | if( index >= map.entries().size() ) 67 | { 68 | goto error; 69 | } 70 | 71 | if( size < 0x14 ) 72 | { 73 | goto error; 74 | } 75 | 76 | { 77 | MemoryMap::Entry entry( entries[ index ] ); 78 | std::string type; 79 | 80 | if( entry.type() == MemoryMap::Entry::Type::Usable ) 81 | { 82 | type = "Usable"; 83 | } 84 | else if( entry.type() == MemoryMap::Entry::Type::Reserved ) 85 | { 86 | type = "Reserved"; 87 | } 88 | else if( entry.type() == MemoryMap::Entry::Type::ACPI ) 89 | { 90 | type = "ACPI"; 91 | } 92 | else 93 | { 94 | type = "Unknown"; 95 | } 96 | 97 | machine.ui().debug() << "Current entry: " 98 | << String::toHex( entry.base() ) 99 | << " -> " 100 | << String::toHex( entry.end() ) 101 | << " (" 102 | << type 103 | << ")" 104 | << std::endl; 105 | 106 | 107 | { 108 | std::array< uint32_t, 5 > data( entry.data() ); 109 | 110 | engine.write( destination, reinterpret_cast< const uint8_t * >( data.data() ), data.size() ); 111 | } 112 | 113 | engine.cf( false ); 114 | engine.eax( 0x534D4150 ); 115 | engine.ecx( 0x00000014 ); 116 | 117 | if( index == entries.size() - 1 ) 118 | { 119 | engine.ebx( 0 ); 120 | } 121 | else 122 | { 123 | engine.ebx( index + 1 ); 124 | } 125 | 126 | machine.ui().debug() << "[ SUCCESS ]> Wrote 20 bytes at " 127 | << String::toHex( destination ) 128 | << " -> " 129 | << String::toHex( destination + 20 ) 130 | << std::endl; 131 | } 132 | 133 | return true; 134 | 135 | error: 136 | 137 | engine.cf( true ); 138 | engine.eax( 0x534D4150 ); 139 | engine.ebx( 0x00000000 ); 140 | engine.ecx( 0x00000014 ); 141 | 142 | return false; 143 | } 144 | 145 | bool enterLongMode( const Machine & machine, Engine & engine ) 146 | { 147 | uint8_t mode( engine.bl() ); 148 | 149 | switch ( mode ) 150 | { 151 | case 0x1: 152 | machine.ui().debug() << "Entering 32-bit Protected Mode" << std::endl; 153 | break; 154 | 155 | case 0x2: 156 | machine.ui().debug() << "Entering 64-bit Long Mode" << std::endl; 157 | break; 158 | 159 | case 0x3: 160 | machine.ui().debug() << "Entering 32-bit Protected and 64-bit Long Mode" << std::endl; 161 | break; 162 | 163 | default: 164 | machine.ui().debug() << "BIOS::SystemsServices::enterLongMode: Unknown mode " << mode << std::endl; 165 | goto error; 166 | } 167 | 168 | engine.cf( false ); 169 | return true; 170 | 171 | error: 172 | 173 | engine.cf( true ); 174 | return false; 175 | } 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/SystemServices.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_BIOS_SYSTEM_SERVICES_HPP 26 | #define UB_BIOS_SYSTEM_SERVICES_HPP 27 | 28 | namespace UB 29 | { 30 | class Machine; 31 | class Engine; 32 | 33 | namespace BIOS 34 | { 35 | namespace SystemServices 36 | { 37 | bool getMemoryMap( const Machine & machine, Engine & engine ); 38 | bool enterLongMode( const Machine & machine, Engine & engine ); 39 | } 40 | } 41 | } 42 | 43 | #endif /* UB_BIOS_SYSTEM_SERVICES_HPP */ 44 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/VESAInfo.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/BIOS/VESAInfo.hpp" 26 | 27 | namespace UB 28 | { 29 | namespace BIOS 30 | { 31 | class VESAInfo::IMPL 32 | { 33 | public: 34 | 35 | IMPL( void ); 36 | IMPL( const IMPL & o ); 37 | ~IMPL( void ); 38 | 39 | std::array< uint8_t, 4 > _signature; 40 | uint16_t _version; 41 | }; 42 | 43 | VESAInfo::VESAInfo( void ): 44 | impl( std::make_unique< IMPL >() ) 45 | {} 46 | 47 | VESAInfo::VESAInfo( const VESAInfo & o ): 48 | impl( std::make_unique< IMPL >( *( o.impl ) ) ) 49 | {} 50 | 51 | VESAInfo::VESAInfo( VESAInfo && o ) noexcept: 52 | impl( std::move( o.impl ) ) 53 | {} 54 | 55 | VESAInfo::~VESAInfo( void ) 56 | {} 57 | 58 | VESAInfo & VESAInfo::operator =( VESAInfo o ) 59 | { 60 | swap( *( this ), o ); 61 | 62 | return *( this ); 63 | } 64 | 65 | std::vector< uint8_t > VESAInfo::data( void ) const 66 | { 67 | return {}; 68 | } 69 | 70 | std::array< uint8_t, 4 > VESAInfo::signature( void ) const 71 | { 72 | return this->impl->_signature; 73 | } 74 | 75 | uint16_t VESAInfo::version( void ) const 76 | { 77 | return this->impl->_version; 78 | } 79 | 80 | void swap( VESAInfo & o1, VESAInfo & o2 ) 81 | { 82 | using std::swap; 83 | 84 | swap( o1.impl, o2.impl ); 85 | } 86 | 87 | VESAInfo::IMPL::IMPL( void ): 88 | _signature( { 'V', 'E', 'S', 'A' } ), 89 | _version( 0x0200 ) 90 | {} 91 | 92 | VESAInfo::IMPL::IMPL( const IMPL & o ): 93 | _signature( o._signature ), 94 | _version( o._version ) 95 | {} 96 | 97 | VESAInfo::IMPL::~IMPL( void ) 98 | {} 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/VESAInfo.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_BIOS_VESA_INFO_HPP 26 | #define UB_BIOS_VESA_INFO_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace UB 35 | { 36 | namespace BIOS 37 | { 38 | class VESAInfo 39 | { 40 | public: 41 | 42 | VESAInfo( void ); 43 | VESAInfo( const VESAInfo & o ); 44 | VESAInfo( VESAInfo && o ) noexcept; 45 | ~VESAInfo( void ); 46 | 47 | VESAInfo & operator =( VESAInfo o ); 48 | 49 | std::vector< uint8_t > data( void ) const; 50 | 51 | std::array< uint8_t, 4 > signature( void ) const; 52 | uint16_t version( void ) const; 53 | 54 | friend void swap( VESAInfo & o1, VESAInfo & o2 ); 55 | 56 | private: 57 | 58 | class IMPL; 59 | std::unique_ptr< IMPL > impl; 60 | }; 61 | } 62 | } 63 | 64 | #endif /* UB_BIOS_VESA_INFO_HPP */ 65 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BIOS/Video.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_BIOS_VIDEO_HPP 26 | #define UB_BIOS_VIDEO_HPP 27 | 28 | namespace UB 29 | { 30 | class Machine; 31 | class Engine; 32 | 33 | namespace BIOS 34 | { 35 | namespace Video 36 | { 37 | bool setVideoMode( const Machine & machine, Engine & engine ); 38 | bool setCursorPosition( const Machine & machine, Engine & engine ); 39 | bool ttyOutput( const Machine & machine, Engine & engine ); 40 | bool palette( const Machine & machine, Engine & engine ); 41 | bool writeCharacterAndAttributeAtCursor( const Machine & machine, Engine & engine ); 42 | bool writeCharacterOnlyAtCursor( const Machine & machine, Engine & engine ); 43 | bool getVBEControllerInfo( const Machine & machine, Engine & engine ); 44 | } 45 | } 46 | } 47 | 48 | #endif /* UB_BIOS_VIDEO_HPP */ 49 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BinaryDataStream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include 26 | #include 27 | #include 28 | #include "UB/BinaryDataStream.hpp" 29 | #include "UB/Casts.hpp" 30 | 31 | namespace UB 32 | { 33 | class BinaryDataStream::IMPL 34 | { 35 | public: 36 | 37 | IMPL( void ); 38 | IMPL( const std::vector< uint8_t > & data ); 39 | IMPL( const IMPL & o ); 40 | ~IMPL( void ); 41 | 42 | std::vector< uint8_t > _data; 43 | size_t _pos; 44 | }; 45 | 46 | BinaryDataStream::BinaryDataStream( void ): 47 | impl( std::make_unique< IMPL >() ) 48 | {} 49 | 50 | BinaryDataStream::BinaryDataStream( const std::vector< uint8_t > & data ): 51 | impl( std::make_unique< IMPL >( data ) ) 52 | {} 53 | 54 | BinaryDataStream::BinaryDataStream( const BinaryDataStream & o ): 55 | impl( std::make_unique< IMPL >( *( o.impl ) ) ) 56 | {} 57 | 58 | BinaryDataStream::BinaryDataStream( BinaryDataStream && o ) noexcept: 59 | impl( std::move( o.impl ) ) 60 | {} 61 | 62 | BinaryDataStream::~BinaryDataStream( void ) 63 | {} 64 | 65 | BinaryDataStream & BinaryDataStream::operator =( BinaryDataStream o ) 66 | { 67 | swap( *( this ), o ); 68 | 69 | return *( this ); 70 | } 71 | 72 | void BinaryDataStream::read( uint8_t * buf, size_t size ) 73 | { 74 | if( size > this->impl->_data.size() - this->impl->_pos ) 75 | { 76 | throw std::runtime_error( "Invalid read - Not enough data available" ); 77 | } 78 | 79 | memcpy( buf, &( this->impl->_data[ 0 ] ) + this->impl->_pos, size ); 80 | 81 | this->impl->_pos += size; 82 | } 83 | 84 | void BinaryDataStream::seek( ssize_t offset, SeekDirection dir ) 85 | { 86 | size_t pos; 87 | 88 | if( dir == SeekDirection::Begin ) 89 | { 90 | if( offset < 0 ) 91 | { 92 | throw std::runtime_error( "Invalid seek offset" ); 93 | } 94 | 95 | pos = numeric_cast< size_t >( offset ); 96 | } 97 | else if( dir == SeekDirection::End ) 98 | { 99 | if( offset > 0 ) 100 | { 101 | throw std::runtime_error( "Invalid seek offset" ); 102 | } 103 | 104 | pos = this->impl->_data.size() - numeric_cast< size_t >( abs( offset ) ); 105 | } 106 | else if( offset < 0 ) 107 | { 108 | pos = this->impl->_pos - numeric_cast< size_t >( abs( offset ) ); 109 | } 110 | else 111 | { 112 | pos = this->impl->_pos + numeric_cast< size_t >( offset ); 113 | } 114 | 115 | if( pos > this->impl->_data.size() ) 116 | { 117 | throw std::runtime_error( "Invalid seek offset" ); 118 | } 119 | 120 | this->impl->_pos = pos; 121 | } 122 | 123 | size_t BinaryDataStream::tell( void ) const 124 | { 125 | return this->impl->_pos; 126 | } 127 | 128 | BinaryDataStream & BinaryDataStream::operator +=( const BinaryDataStream & stream ) 129 | { 130 | this->append( stream ); 131 | 132 | return *( this ); 133 | } 134 | 135 | BinaryDataStream & BinaryDataStream::operator +=( const std::vector< uint8_t > & data ) 136 | { 137 | this->append( data ); 138 | 139 | return *( this ); 140 | } 141 | 142 | void BinaryDataStream::append( const BinaryDataStream & stream ) 143 | { 144 | this->impl->_data.insert 145 | ( 146 | this->impl->_data.end(), 147 | stream.impl->_data.begin() + numeric_cast< ssize_t >( stream.impl->_pos ), 148 | stream.impl->_data.end() 149 | ); 150 | 151 | stream.impl->_pos = stream.impl->_data.size(); 152 | } 153 | 154 | void BinaryDataStream::append( const std::vector< uint8_t > & data ) 155 | { 156 | this->impl->_data.insert 157 | ( 158 | this->impl->_data.end(), 159 | data.begin(), 160 | data.end() 161 | ); 162 | } 163 | 164 | void swap( BinaryDataStream & o1, BinaryDataStream & o2 ) 165 | { 166 | using std::swap; 167 | 168 | swap( o1.impl, o2.impl ); 169 | } 170 | 171 | BinaryDataStream::IMPL::IMPL( void ): 172 | _pos( 0 ) 173 | {} 174 | 175 | BinaryDataStream::IMPL::IMPL( const std::vector< uint8_t > & data ): 176 | _data( data ), 177 | _pos( 0 ) 178 | {} 179 | 180 | BinaryDataStream::IMPL::IMPL( const IMPL & o ): 181 | _data( o._data ), 182 | _pos( o._pos ) 183 | {} 184 | 185 | BinaryDataStream::IMPL::~IMPL( void ) 186 | {} 187 | } 188 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BinaryDataStream.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_BINARY_DATA_STREAM_HPP 26 | #define UB_BINARY_DATA_STREAM_HPP 27 | 28 | #include "UB/BinaryStream.hpp" 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace UB 36 | { 37 | class BinaryDataStream: public BinaryStream 38 | { 39 | public: 40 | 41 | BinaryDataStream( void ); 42 | BinaryDataStream( const std::vector< uint8_t > & data ); 43 | BinaryDataStream( const BinaryDataStream & o ); 44 | BinaryDataStream( BinaryDataStream && o ) noexcept; 45 | 46 | virtual ~BinaryDataStream( void ); 47 | 48 | BinaryDataStream & operator =( BinaryDataStream o ); 49 | 50 | using BinaryStream::read; 51 | 52 | void read( uint8_t * buf, size_t size ) override; 53 | void seek( ssize_t offset, SeekDirection dir ) override; 54 | size_t tell( void ) const override; 55 | 56 | BinaryDataStream & operator +=( const BinaryDataStream & stream ); 57 | BinaryDataStream & operator +=( const std::vector< uint8_t > & data ); 58 | 59 | void append( const BinaryDataStream & stream ); 60 | void append( const std::vector< uint8_t > & data ); 61 | 62 | friend void swap( BinaryDataStream & o1, BinaryDataStream & o2 ); 63 | 64 | private: 65 | 66 | class IMPL; 67 | 68 | std::unique_ptr< IMPL > impl; 69 | }; 70 | } 71 | 72 | #endif /* UB_BINARY_DATA_STREAM_HPP */ 73 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BinaryFileStream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include 26 | #include 27 | #include 28 | #include "UB/BinaryFileStream.hpp" 29 | #include "UB/Casts.hpp" 30 | 31 | namespace UB 32 | { 33 | class BinaryFileStream::IMPL 34 | { 35 | public: 36 | 37 | IMPL( const std::string & path ); 38 | ~IMPL( void ); 39 | 40 | std::ifstream _stream; 41 | std::string _path; 42 | size_t _size; 43 | size_t _pos; 44 | }; 45 | 46 | BinaryFileStream::BinaryFileStream( std::string path ): 47 | impl( std::make_unique< IMPL >( path ) ) 48 | {} 49 | 50 | BinaryFileStream::~BinaryFileStream( void ) 51 | {} 52 | 53 | void BinaryFileStream::read( uint8_t * buf, size_t size ) 54 | { 55 | if( this->impl->_stream.is_open() == false ) 56 | { 57 | throw std::runtime_error( "Invalid file stream" ); 58 | } 59 | 60 | if( size > this->impl->_size - this->impl->_pos ) 61 | { 62 | throw std::runtime_error( "Invalid read - Not enough data available" ); 63 | } 64 | 65 | this->impl->_pos += size; 66 | 67 | this->impl->_stream.read( reinterpret_cast< char * >( buf ), numeric_cast< std::streamsize >( size ) ); 68 | } 69 | 70 | void BinaryFileStream::seek( ssize_t offset, SeekDirection dir ) 71 | { 72 | size_t pos; 73 | 74 | if( dir == SeekDirection::Begin ) 75 | { 76 | if( offset < 0 ) 77 | { 78 | throw std::runtime_error( "Invalid seek offset" ); 79 | } 80 | 81 | pos = numeric_cast< size_t >( offset ); 82 | } 83 | else if( dir == SeekDirection::End ) 84 | { 85 | if( offset > 0 ) 86 | { 87 | throw std::runtime_error( "Invalid seek offset" ); 88 | } 89 | 90 | pos = this->impl->_size - numeric_cast< size_t >( abs( offset ) ); 91 | } 92 | else if( offset < 0 ) 93 | { 94 | pos = this->impl->_pos - numeric_cast< size_t >( abs( offset ) ); 95 | } 96 | else 97 | { 98 | pos = this->impl->_pos + numeric_cast< size_t >( offset ); 99 | } 100 | 101 | if( pos > this->impl->_size ) 102 | { 103 | throw std::runtime_error( "Invalid seek offset" ); 104 | } 105 | 106 | this->impl->_pos = pos; 107 | 108 | this->impl->_stream.seekg( numeric_cast< std::streamsize >( pos ), std::ios_base::beg ); 109 | } 110 | 111 | size_t BinaryFileStream::tell( void ) const 112 | { 113 | if( this->impl->_stream.is_open() == false ) 114 | { 115 | throw std::runtime_error( "Invalid file stream" ); 116 | } 117 | 118 | return this->impl->_pos; 119 | } 120 | 121 | BinaryFileStream::IMPL::IMPL( const std::string & path ): 122 | _path( path ), 123 | _size( 0 ), 124 | _pos( 0 ) 125 | { 126 | this->_stream.open( this->_path, std::ios::binary | std::ios::in ); 127 | 128 | if( this->_stream.good() ) 129 | { 130 | std::streamsize pos; 131 | 132 | this->_stream.seekg( 0, std::ios_base::end ); 133 | 134 | pos = this->_stream.tellg(); 135 | this->_size = numeric_cast< size_t >( pos ); 136 | 137 | this->_stream.seekg( 0, std::ios_base::beg ); 138 | } 139 | } 140 | 141 | BinaryFileStream::IMPL::~IMPL( void ) 142 | { 143 | if( this->_stream.is_open() ) 144 | { 145 | this->_stream.close(); 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BinaryFileStream.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_BINARY_FILE_STREAM_HPP 26 | #define UB_BINARY_FILE_STREAM_HPP 27 | 28 | #include "UB/BinaryStream.hpp" 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace UB 36 | { 37 | class BinaryFileStream: public BinaryStream 38 | { 39 | public: 40 | 41 | BinaryFileStream( std::string path ); 42 | 43 | virtual ~BinaryFileStream( void ); 44 | 45 | BinaryFileStream( const BinaryFileStream & o ) = delete; 46 | BinaryFileStream( BinaryFileStream && o ) = delete; 47 | BinaryFileStream & operator =( const BinaryFileStream & o ) = delete; 48 | BinaryFileStream & operator =( BinaryFileStream && o ) = delete; 49 | 50 | using BinaryStream::read; 51 | 52 | void read( uint8_t * buf, size_t size ) override; 53 | void seek( ssize_t offset, SeekDirection dir ) override; 54 | size_t tell( void ) const override; 55 | 56 | private: 57 | 58 | class IMPL; 59 | 60 | std::unique_ptr< IMPL > impl; 61 | }; 62 | } 63 | 64 | #endif /* UB_BINARY_FILE_STREAM_HPP */ 65 | -------------------------------------------------------------------------------- /unicorn-bios/UB/BinaryStream.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_BINARY_STREAM_HPP 26 | #define UB_BINARY_STREAM_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace UB 33 | { 34 | class BinaryStream 35 | { 36 | public: 37 | 38 | enum class SeekDirection 39 | { 40 | Current, 41 | Begin, 42 | End 43 | }; 44 | 45 | virtual ~BinaryStream( void ) = default; 46 | 47 | virtual void read( uint8_t * buf, size_t size ) = 0; 48 | virtual void seek( ssize_t offset, SeekDirection dir ) = 0; 49 | virtual size_t tell( void ) const = 0; 50 | 51 | bool hasBytesAvailable( void ); 52 | size_t availableBytes( void ); 53 | 54 | void seek( ssize_t offset ); 55 | 56 | std::vector< uint8_t > read( size_t size ); 57 | std::vector< uint8_t > readAll( void ); 58 | 59 | uint8_t readUInt8( void ); 60 | int8_t readInt8( void ); 61 | 62 | uint16_t readUInt16( void ); 63 | int16_t readInt16( void ); 64 | uint16_t readBigEndianUInt16( void ); 65 | uint16_t readLittleEndianUInt16( void ); 66 | 67 | uint32_t readUInt32( void ); 68 | int32_t readInt32( void ); 69 | uint32_t readBigEndianUInt32( void ); 70 | uint32_t readLittleEndianUInt32( void ); 71 | 72 | uint64_t readUInt64( void ); 73 | int64_t readInt64( void ); 74 | uint64_t readBigEndianUInt64( void ); 75 | uint64_t readLittleEndianUInt64( void ); 76 | 77 | float readBigEndianFixedPoint( unsigned int integerLength, unsigned int fractionalLength ); 78 | float readLittleEndianFixedPoint( unsigned int integerLength, unsigned int fractionalLength ); 79 | 80 | std::string readNULLTerminatedString( void ); 81 | std::string readPascalString( void ); 82 | std::string readString( size_t length ); 83 | }; 84 | } 85 | 86 | #endif /* UB_BINARY_STREAM_HPP */ 87 | -------------------------------------------------------------------------------- /unicorn-bios/UB/CPU/Functions.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/CPU/Functions.hpp" 26 | 27 | namespace UB 28 | { 29 | namespace CPU 30 | { 31 | void cpuid( Engine & engine, const Registers & registers ) 32 | { 33 | uint32_t eax( registers.eax() ); 34 | 35 | if( eax == 0 ) 36 | { 37 | engine.ebx( 0x43494E55 ); 38 | engine.edx( 0x2D4E524F ); 39 | engine.ecx( 0x534F4942 ); 40 | } 41 | else if( eax == 0x80000000 ) 42 | { 43 | engine.eax( 0x80000001 ); 44 | } 45 | else if( eax == 0x80000001 ) 46 | { 47 | engine.edx( engine.edx() & 0xDFFFFFFF ); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /unicorn-bios/UB/CPU/Functions.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_CPU_FUNCTIONS_HPP 26 | #define UB_CPU_FUNCTIONS_HPP 27 | 28 | #include "UB/Engine.hpp" 29 | #include "UB/Registers.hpp" 30 | 31 | namespace UB 32 | { 33 | namespace CPU 34 | { 35 | void cpuid( Engine & engine, const Registers & registers ); 36 | } 37 | } 38 | 39 | #endif /* UB_CPU_FUNCTIONS_HPP */ 40 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Capstone.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/Capstone.hpp" 26 | #include "UB/String.hpp" 27 | #include 28 | #include 29 | 30 | #ifdef __clang__ 31 | #pragma clang diagnostic push 32 | #pragma clang diagnostic ignored "-Wdocumentation" 33 | #pragma clang diagnostic ignored "-Wnested-anon-types" 34 | #endif 35 | #include 36 | #ifdef __clang__ 37 | #pragma clang diagnostic pop 38 | #endif 39 | 40 | namespace UB 41 | { 42 | namespace Capstone 43 | { 44 | std::vector< std::pair< std::string, std::string > > disassemble( const std::vector< uint8_t > & data, uint64_t org ) 45 | { 46 | csh handle; 47 | cs_insn * instruction; 48 | size_t count; 49 | 50 | std::vector< std::pair< std::string, std::string > > v; 51 | 52 | if( cs_open( CS_ARCH_X86, CS_MODE_16, &handle ) != CS_ERR_OK ) 53 | { 54 | return {}; 55 | } 56 | 57 | count = cs_disasm( handle, &( data[ 0 ] ), data.size(), org, 0, &instruction ); 58 | 59 | if( count == 0 ) 60 | { 61 | cs_close( &handle ); 62 | 63 | return {}; 64 | } 65 | 66 | for( size_t i = 0; i < count; i++ ) 67 | { 68 | v.push_back 69 | ( 70 | { 71 | String::toHex( instruction[ i ].address ), 72 | instruction[ i ].mnemonic + std::string( " " ) + instruction[ i ].op_str 73 | } 74 | ); 75 | } 76 | 77 | cs_free( instruction, count ); 78 | cs_close( &handle ); 79 | 80 | return v; 81 | } 82 | 83 | std::vector< std::pair< std::string, std::string > > instructions( const std::vector< uint8_t > & data, uint64_t org ) 84 | { 85 | csh handle; 86 | cs_insn * instruction; 87 | size_t count; 88 | 89 | std::vector< std::pair< std::string, std::string > > v; 90 | 91 | if( cs_open( CS_ARCH_X86, CS_MODE_16, &handle ) != CS_ERR_OK ) 92 | { 93 | return {}; 94 | } 95 | 96 | count = cs_disasm( handle, &( data[ 0 ] ), data.size(), org, 0, &instruction ); 97 | 98 | if( count == 0 ) 99 | { 100 | cs_close( &handle ); 101 | 102 | return {}; 103 | } 104 | 105 | for( size_t i = 0; i < count; i++ ) 106 | { 107 | std::stringstream ss; 108 | 109 | for( size_t j = 0; j < instruction[ i ].size; j++ ) 110 | { 111 | ss << std::hex 112 | << std::uppercase 113 | << std::setw( 2 ) 114 | << std::setfill( '0' ) 115 | << static_cast< unsigned int >( instruction[ i ].bytes[ j ] ); 116 | } 117 | 118 | v.push_back 119 | ( 120 | { 121 | String::toHex( instruction[ i ].address ), 122 | ss.str() 123 | } 124 | ); 125 | } 126 | 127 | cs_free( instruction, count ); 128 | cs_close( &handle ); 129 | 130 | return v; 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Capstone.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_CAPSTONE_HPP 26 | #define UB_CAPSTONE_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace UB 33 | { 34 | namespace Capstone 35 | { 36 | std::vector< std::pair< std::string, std::string > > disassemble( const std::vector< uint8_t > & data, uint64_t org ); 37 | std::vector< std::pair< std::string, std::string > > instructions( const std::vector< uint8_t > & data, uint64_t org ); 38 | } 39 | } 40 | 41 | #endif /* UB_CAPSTONE_HPP */ 42 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Casts.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_CASTS_HPP 26 | #define UB_CASTS_HPP 27 | 28 | #include 29 | 30 | namespace UB 31 | { 32 | template 33 | < 34 | typename _T_, 35 | typename _U_, 36 | typename std::enable_if 37 | < 38 | std::is_integral< _T_ >::value 39 | && std::is_integral< _U_ >::value 40 | && std::is_unsigned< _T_ >::value 41 | && std::is_unsigned< _U_ >::value 42 | > 43 | ::type * = nullptr 44 | > 45 | _T_ numeric_cast( _U_ v ) 46 | { 47 | if( std::numeric_limits< _T_ >::max() < std::numeric_limits< _U_ >::max() && v > std::numeric_limits< _T_ >::max() ) 48 | { 49 | throw std::runtime_error( "Bad numeric cast" ); 50 | } 51 | 52 | return static_cast< _T_ >( v ); 53 | } 54 | 55 | template 56 | < 57 | typename _T_, 58 | typename _U_, 59 | typename std::enable_if 60 | < 61 | std::is_integral< _T_ >::value 62 | && std::is_integral< _U_ >::value 63 | && std::is_signed< _T_ >::value 64 | && std::is_signed< _U_ >::value 65 | > 66 | ::type * = nullptr 67 | > 68 | _T_ numeric_cast( _U_ v ) 69 | { 70 | if( std::numeric_limits< _T_ >::max() < std::numeric_limits< _U_ >::max() && v > std::numeric_limits< _T_ >::max() ) 71 | { 72 | throw std::runtime_error( "Bad numeric cast" ); 73 | } 74 | 75 | if( std::numeric_limits< _T_ >::min() > std::numeric_limits< _U_ >::min() && v < std::numeric_limits< _T_ >::min() ) 76 | { 77 | throw std::runtime_error( "Bad numeric cast" ); 78 | } 79 | 80 | return static_cast< _T_ >( v ); 81 | } 82 | 83 | template 84 | < 85 | typename _T_, 86 | typename _U_, 87 | typename std::enable_if 88 | < 89 | std::is_integral< _T_ >::value 90 | && std::is_integral< _U_ >::value 91 | && std::is_signed< _T_ >::value 92 | && std::is_unsigned< _U_ >::value 93 | > 94 | ::type * = nullptr 95 | > 96 | _T_ numeric_cast( _U_ v ) 97 | { 98 | if( std::numeric_limits< _T_ >::max() < std::numeric_limits< _U_ >::max() && v > std::numeric_limits< _T_ >::max() ) 99 | { 100 | throw std::runtime_error( "Bad numeric cast" ); 101 | } 102 | 103 | return static_cast< _T_ >( v ); 104 | } 105 | 106 | template 107 | < 108 | typename _T_, 109 | typename _U_, 110 | typename std::enable_if 111 | < 112 | std::is_integral< _T_ >::value 113 | && std::is_integral< _U_ >::value 114 | && std::is_unsigned< _T_ >::value 115 | && std::is_signed< _U_ >::value 116 | > 117 | ::type * = nullptr 118 | > 119 | _T_ numeric_cast( _U_ v ) 120 | { 121 | if( v < 0 ) 122 | { 123 | throw std::runtime_error( "Bad numeric cast" ); 124 | } 125 | 126 | if( std::numeric_limits< _T_ >::max() < std::numeric_limits< _U_ >::max() && v > std::numeric_limits< _T_ >::max() ) 127 | { 128 | throw std::runtime_error( "Bad numeric cast" ); 129 | } 130 | 131 | return static_cast< _T_ >( v ); 132 | } 133 | 134 | template 135 | < 136 | typename _T_, 137 | typename _U_, 138 | typename std::enable_if 139 | < 140 | std::is_integral< _T_ >::value 141 | && std::is_unsigned< _T_ >::value 142 | && std::is_floating_point< _U_ >::value 143 | > 144 | ::type * = nullptr 145 | > 146 | _T_ numeric_cast( _U_ v ) 147 | { 148 | if( v < 0 ) 149 | { 150 | throw std::runtime_error( "Bad numeric cast" ); 151 | } 152 | 153 | if( v > std::numeric_limits< _T_ >::max() ) 154 | { 155 | throw std::runtime_error( "Bad numeric cast" ); 156 | } 157 | 158 | return static_cast< _T_ >( v ); 159 | } 160 | 161 | template 162 | < 163 | typename _T_, 164 | typename _U_, 165 | typename std::enable_if 166 | < 167 | std::is_integral< _T_ >::value 168 | && std::is_signed< _T_ >::value 169 | && std::is_floating_point< _U_ >::value 170 | > 171 | ::type * = nullptr 172 | > 173 | _T_ numeric_cast( _U_ v ) 174 | { 175 | if( v > std::numeric_limits< _T_ >::max() ) 176 | { 177 | throw std::runtime_error( "Bad numeric cast" ); 178 | } 179 | 180 | if( v < std::numeric_limits< _T_ >::min() ) 181 | { 182 | throw std::runtime_error( "Bad numeric cast" ); 183 | } 184 | 185 | return static_cast< _T_ >( v ); 186 | } 187 | 188 | template 189 | < 190 | typename _T_, 191 | typename _U_, 192 | typename std::enable_if 193 | < 194 | std::is_floating_point< _T_ >::value 195 | && std::is_integral< _U_ >::value 196 | > 197 | ::type * = nullptr 198 | > 199 | _T_ numeric_cast( _U_ v ) 200 | { 201 | return static_cast< _T_ >( v ); 202 | } 203 | } 204 | 205 | #endif /* UB_CASTS_HPP */ 206 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Color.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/Color.hpp" 26 | #include 27 | #include 28 | 29 | namespace UB 30 | { 31 | class Color::IMPL 32 | { 33 | public: 34 | 35 | IMPL( int index ); 36 | IMPL( const IMPL & o ); 37 | ~IMPL( void ); 38 | 39 | int _index; 40 | }; 41 | 42 | Color Color::clear( void ) 43 | { 44 | return Color( 1 ); 45 | } 46 | 47 | Color Color::black( void ) 48 | { 49 | return Color( 2 ); 50 | } 51 | 52 | Color Color::red( void ) 53 | { 54 | return Color( 3 ); 55 | } 56 | 57 | Color Color::green( void ) 58 | { 59 | return Color( 4 ); 60 | } 61 | 62 | Color Color::yellow( void ) 63 | { 64 | return Color( 5 ); 65 | } 66 | 67 | Color Color::blue( void ) 68 | { 69 | return Color( 6 ); 70 | } 71 | 72 | Color Color::magenta( void ) 73 | { 74 | return Color( 7 ); 75 | } 76 | 77 | Color Color::cyan( void ) 78 | { 79 | return Color( 8 ); 80 | } 81 | 82 | Color Color::white( void ) 83 | { 84 | return Color( 9 ); 85 | } 86 | 87 | Color::Color( int index ): 88 | impl( std::make_unique< IMPL >( index ) ) 89 | {} 90 | 91 | Color::Color( const Color & o ): 92 | impl( std::make_unique< IMPL >( *( o.impl ) ) ) 93 | {} 94 | 95 | Color::Color( Color && o ) noexcept: 96 | impl( std::move( o.impl ) ) 97 | {} 98 | 99 | Color::~Color( void ) 100 | {} 101 | 102 | Color & Color::operator =( Color o ) 103 | { 104 | swap( *( this ), o ); 105 | 106 | return *( this ); 107 | } 108 | 109 | int Color::index() const 110 | { 111 | return this->impl->_index; 112 | } 113 | 114 | void swap( Color & o1, Color & o2 ) 115 | { 116 | using std::swap; 117 | 118 | swap( o1.impl, o2.impl ); 119 | } 120 | 121 | Color::IMPL::IMPL( int index ): 122 | _index( index ) 123 | {} 124 | 125 | Color::IMPL::IMPL( const IMPL & o ): 126 | _index( o._index ) 127 | {} 128 | 129 | Color::IMPL::~IMPL( void ) 130 | {} 131 | } 132 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Color.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_COLOR_HPP 26 | #define UB_COLOR_HPP 27 | 28 | #include 29 | #include 30 | 31 | namespace UB 32 | { 33 | class Color 34 | { 35 | public: 36 | 37 | static Color clear( void ); 38 | static Color black( void ); 39 | static Color red( void ); 40 | static Color green( void ); 41 | static Color yellow( void ); 42 | static Color blue( void ); 43 | static Color magenta( void ); 44 | static Color cyan( void ); 45 | static Color white( void ); 46 | 47 | Color( const Color & o ); 48 | Color( Color && o ) noexcept; 49 | ~Color( void ); 50 | 51 | Color & operator =( Color o ); 52 | 53 | int index( void ) const; 54 | 55 | friend void swap( Color & o1, Color & o2 ); 56 | 57 | private: 58 | 59 | explicit Color( int index ); 60 | 61 | class IMPL; 62 | std::unique_ptr< IMPL > impl; 63 | }; 64 | } 65 | 66 | #endif /* UB_COLOR_HPP */ 67 | -------------------------------------------------------------------------------- /unicorn-bios/UB/FAT/DAP.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/FAT/DAP.hpp" 26 | #include "UB/BinaryStream.hpp" 27 | 28 | namespace UB 29 | { 30 | namespace FAT 31 | { 32 | class DAP::IMPL 33 | { 34 | public: 35 | 36 | IMPL( void ); 37 | IMPL( const IMPL & o ); 38 | IMPL( BinaryStream & stream ); 39 | ~IMPL( void ); 40 | 41 | uint8_t _size; 42 | uint8_t _zero; 43 | uint16_t _numberOfSectors; 44 | uint16_t _destinationOffset; 45 | uint16_t _destinationSegment; 46 | uint64_t _logicalBlockAddress; 47 | }; 48 | 49 | size_t DAP::DataSize( void ) 50 | { 51 | return 16; 52 | } 53 | 54 | DAP::DAP( void ): 55 | impl( std::make_unique< IMPL >() ) 56 | {} 57 | 58 | DAP::DAP( const DAP & o ): 59 | impl( std::make_unique< IMPL >( *( o.impl ) ) ) 60 | {} 61 | 62 | DAP::DAP( BinaryStream & stream ): 63 | impl( std::make_unique< IMPL >( stream ) ) 64 | {} 65 | 66 | DAP::DAP( DAP && o ) noexcept: 67 | impl( std::move( o.impl ) ) 68 | {} 69 | 70 | DAP::~DAP( void ) 71 | {} 72 | 73 | DAP & DAP::operator =( DAP o ) 74 | { 75 | swap( *( this ), o ); 76 | 77 | return *( this ); 78 | } 79 | 80 | uint8_t DAP::size( void ) const 81 | { 82 | return this->impl->_size; 83 | } 84 | 85 | uint8_t DAP::zero( void ) const 86 | { 87 | return this->impl->_zero; 88 | } 89 | 90 | uint16_t DAP::numberOfSectors( void ) const 91 | { 92 | return this->impl->_numberOfSectors; 93 | } 94 | 95 | uint16_t DAP::destinationOffset( void ) const 96 | { 97 | return this->impl->_destinationOffset; 98 | } 99 | 100 | uint16_t DAP::destinationSegment( void ) const 101 | { 102 | return this->impl->_destinationSegment; 103 | } 104 | 105 | uint64_t DAP::logicalBlockAddress( void ) const 106 | { 107 | return this->impl->_logicalBlockAddress; 108 | } 109 | 110 | void swap( DAP & o1, DAP & o2 ) 111 | { 112 | using std::swap; 113 | 114 | swap( o1.impl, o2.impl ); 115 | } 116 | 117 | DAP::IMPL::IMPL( void ): 118 | _size( 0 ), 119 | _zero( 0 ), 120 | _numberOfSectors( 0 ), 121 | _destinationOffset( 0 ), 122 | _destinationSegment( 0 ), 123 | _logicalBlockAddress( 0 ) 124 | {} 125 | 126 | DAP::IMPL::IMPL( BinaryStream & stream ): 127 | _size( stream.readUInt8() ), 128 | _zero( stream.readUInt8() ), 129 | _numberOfSectors( stream.readLittleEndianUInt16() ), 130 | _destinationOffset( stream.readLittleEndianUInt16() ), 131 | _destinationSegment( stream.readLittleEndianUInt16() ), 132 | _logicalBlockAddress( stream.readLittleEndianUInt16() ) 133 | {} 134 | 135 | DAP::IMPL::IMPL( const IMPL & o ): 136 | _size( o._size ), 137 | _zero( o._zero ), 138 | _numberOfSectors( o._numberOfSectors ), 139 | _destinationOffset( o._destinationOffset ), 140 | _destinationSegment( o._destinationSegment ), 141 | _logicalBlockAddress( o._logicalBlockAddress ) 142 | {} 143 | 144 | DAP::IMPL::~IMPL( void ) 145 | {} 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /unicorn-bios/UB/FAT/DAP.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_FAT_DAP_HPP 26 | #define UB_FAT_DAP_HPP 27 | 28 | #include 29 | #include 30 | 31 | namespace UB 32 | { 33 | class BinaryStream; 34 | 35 | namespace FAT 36 | { 37 | class DAP 38 | { 39 | public: 40 | 41 | static size_t DataSize( void ); 42 | 43 | DAP( void ); 44 | DAP( BinaryStream & stream ); 45 | DAP( const DAP & o ); 46 | DAP( DAP && o ) noexcept; 47 | ~DAP( void ); 48 | 49 | DAP & operator =( DAP o ); 50 | 51 | uint8_t size( void ) const; 52 | uint8_t zero( void ) const; 53 | uint16_t numberOfSectors( void ) const; 54 | uint16_t destinationOffset( void ) const; 55 | uint16_t destinationSegment( void ) const; 56 | uint64_t logicalBlockAddress( void ) const; 57 | 58 | friend void swap( DAP & o1, DAP & o2 ); 59 | 60 | private: 61 | 62 | class IMPL; 63 | std::unique_ptr< IMPL > impl; 64 | }; 65 | } 66 | } 67 | 68 | #endif /* UB_FAT_DAP_HPP */ 69 | -------------------------------------------------------------------------------- /unicorn-bios/UB/FAT/Functions.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/FAT/Functions.hpp" 26 | #include "UB/FAT/MBR.hpp" 27 | #include "UB/Casts.hpp" 28 | 29 | namespace UB 30 | { 31 | namespace FAT 32 | { 33 | uint64_t chsToLBA( const MBR & mbr, uint8_t cylinder, uint8_t sector, uint8_t head ) 34 | { 35 | uint16_t hpc( mbr.headsPerCylinder() ); 36 | uint16_t spt( mbr.sectorsPerTrack() ); 37 | 38 | return ( ( ( numeric_cast< uint64_t >( cylinder ) * numeric_cast< uint64_t >( hpc ) ) + numeric_cast< uint64_t >( head ) ) * numeric_cast< uint64_t >( spt ) ) + ( numeric_cast< uint64_t >( sector ) - 1 ); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /unicorn-bios/UB/FAT/Functions.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_FAT_FUNCTIONS_HPP 26 | #define UB_FAT_FUNCTIONS_HPP 27 | 28 | #include 29 | 30 | namespace UB 31 | { 32 | namespace FAT 33 | { 34 | class MBR; 35 | 36 | uint64_t chsToLBA( const MBR & mbr, uint8_t cylinder, uint8_t sector, uint8_t head ); 37 | } 38 | } 39 | 40 | #endif /* UB_FAT_FUNCTIONS_HPP */ 41 | -------------------------------------------------------------------------------- /unicorn-bios/UB/FAT/Image.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/FAT/Image.hpp" 26 | #include "UB/FAT/Functions.hpp" 27 | #include "UB/BinaryFileStream.hpp" 28 | #include "UB/BinaryDataStream.hpp" 29 | #include "UB/Casts.hpp" 30 | 31 | namespace UB 32 | { 33 | namespace FAT 34 | { 35 | class Image::IMPL 36 | { 37 | public: 38 | 39 | IMPL( const std::string & path ); 40 | IMPL( const IMPL & o ); 41 | 42 | std::string _path; 43 | BinaryDataStream _stream; 44 | MBR _mbr; 45 | }; 46 | 47 | Image::Image( const std::string & path ): 48 | impl( std::make_unique< IMPL >( path ) ) 49 | {} 50 | 51 | Image::Image( const Image & o ): 52 | impl( std::make_unique< IMPL >( *( o.impl ) ) ) 53 | {} 54 | 55 | Image::Image( Image && o ) noexcept: 56 | impl( std::move( o.impl ) ) 57 | {} 58 | 59 | Image::~Image( void ) 60 | {} 61 | 62 | Image & Image::operator =( Image o ) 63 | { 64 | swap( *( this ), o ); 65 | 66 | return *( this ); 67 | } 68 | 69 | std::string Image::path( void ) const 70 | { 71 | return this->impl->_path; 72 | } 73 | 74 | MBR Image::mbr( void ) const 75 | { 76 | return this->impl->_mbr; 77 | } 78 | 79 | std::vector< uint8_t > Image::read( uint8_t cylinder, uint8_t head, uint8_t sector, uint8_t sectors ) 80 | { 81 | uint64_t lba( chsToLBA( this->impl->_mbr, cylinder, sector, head ) ); 82 | 83 | return this->read( lba * this->impl->_mbr.bytesPerSector(), sectors * this->impl->_mbr.bytesPerSector() ); 84 | } 85 | 86 | std::vector< uint8_t > Image::read( uint64_t offset, uint64_t size ) 87 | { 88 | this->impl->_stream.seek( numeric_cast< ssize_t >( offset ), BinaryStream::SeekDirection::Begin ); 89 | 90 | return this->impl->_stream.read( size ); 91 | } 92 | 93 | void swap( Image & o1, Image & o2 ) 94 | { 95 | using std::swap; 96 | 97 | swap( o1.impl, o2.impl ); 98 | } 99 | 100 | Image::IMPL::IMPL( const std::string & path ): 101 | _path( path ) 102 | { 103 | BinaryFileStream stream( path ); 104 | 105 | this->_stream = stream.readAll(); 106 | 107 | stream.seek( 0, BinaryStream::SeekDirection::Begin ); 108 | 109 | this->_mbr = MBR( stream ); 110 | } 111 | 112 | Image::IMPL::IMPL( const IMPL & o ): 113 | _path( o._path ), 114 | _stream( o._stream ), 115 | _mbr( o._mbr ) 116 | {} 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /unicorn-bios/UB/FAT/Image.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_FAT_IMAGE_HPP 26 | #define UB_FAT_IMAGE_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "UB/FAT/MBR.hpp" 34 | 35 | namespace UB 36 | { 37 | namespace FAT 38 | { 39 | class Image 40 | { 41 | public: 42 | 43 | Image( const std::string & path ); 44 | Image( const Image & o ); 45 | Image( Image && o ) noexcept; 46 | ~Image( void ); 47 | 48 | Image & operator =( Image o ); 49 | 50 | std::string path( void ) const; 51 | MBR mbr( void ) const; 52 | 53 | std::vector< uint8_t > read( uint8_t cylinder, uint8_t head, uint8_t sector, uint8_t sectors = 1 ); 54 | std::vector< uint8_t > read( uint64_t offset, uint64_t size ); 55 | 56 | friend void swap( Image & o1, Image & o2 ); 57 | 58 | private: 59 | 60 | class IMPL; 61 | std::unique_ptr< IMPL > impl; 62 | }; 63 | } 64 | } 65 | 66 | #endif /* UB_FAT_IMAGE_HPP */ 67 | -------------------------------------------------------------------------------- /unicorn-bios/UB/FAT/MBR.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_FAT_MBR_HPP 26 | #define UB_FAT_MBR_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace UB 33 | { 34 | class BinaryStream; 35 | 36 | namespace FAT 37 | { 38 | class MBR 39 | { 40 | public: 41 | 42 | MBR( void ); 43 | MBR( BinaryStream & stream ); 44 | MBR( const MBR & o ); 45 | MBR( MBR && o ) noexcept; 46 | ~MBR( void ); 47 | 48 | MBR & operator =( MBR o ); 49 | 50 | std::vector< uint8_t > data( void ) const; 51 | 52 | uint16_t bytesPerSector( void ) const; 53 | uint8_t sectorsPerCluster( void ) const; 54 | uint16_t reservedSectors( void ) const; 55 | uint8_t numberOfFATs( void ) const; 56 | uint16_t maxRootDirEntries( void ) const; 57 | uint16_t totalSectors( void ) const; 58 | uint8_t mediaDescriptor( void ) const; 59 | uint16_t sectorsPerFAT( void ) const; 60 | uint16_t sectorsPerTrack( void ) const; 61 | uint16_t headsPerCylinder( void ) const; 62 | uint32_t hiddenSectors( void ) const; 63 | uint32_t lbaSectors( void ) const; 64 | uint8_t driveNumber( void ) const; 65 | uint8_t reserved( void ) const; 66 | uint8_t extendedBootSignature( void ) const; 67 | uint32_t volumeSerialNumber( void ) const; 68 | uint16_t bootSignature( void ) const; 69 | 70 | bool isValid( void ) const; 71 | 72 | friend void swap( MBR & o1, MBR & o2 ); 73 | 74 | friend std::ostream & operator <<( std::ostream & os, const MBR & o ); 75 | 76 | private: 77 | 78 | class IMPL; 79 | std::unique_ptr< IMPL > impl; 80 | }; 81 | } 82 | } 83 | 84 | #endif /* UB_FAT_MBR_HPP */ 85 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Interrupts.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/Interrupts.hpp" 26 | #include "UB/Engine.hpp" 27 | #include "UB/Machine.hpp" 28 | #include "UB/BIOS/Video.hpp" 29 | #include "UB/BIOS/Disk.hpp" 30 | #include "UB/BIOS/Keyboard.hpp" 31 | #include "UB/BIOS/SystemServices.hpp" 32 | 33 | namespace UB 34 | { 35 | namespace Interrupts 36 | { 37 | bool int0x05( const Machine & machine, Engine & engine ) 38 | { 39 | ( void )machine; 40 | ( void )engine; 41 | 42 | return false; 43 | } 44 | 45 | bool int0x10( const Machine & machine, Engine & engine ) 46 | { 47 | switch( engine.ah() ) 48 | { 49 | case 0x00: return BIOS::Video::setVideoMode( machine, engine ); 50 | case 0x02: return BIOS::Video::setCursorPosition( machine, engine ); 51 | case 0x09: return BIOS::Video::writeCharacterAndAttributeAtCursor( machine, engine ); 52 | case 0x0A: return BIOS::Video::writeCharacterOnlyAtCursor( machine, engine ); 53 | case 0x0E: return BIOS::Video::ttyOutput( machine, engine ); 54 | case 0x10: return BIOS::Video::palette( machine, engine ); 55 | 56 | case 0x4F: 57 | 58 | switch( engine.al() ) 59 | { 60 | case 0x00: return BIOS::Video::getVBEControllerInfo( machine, engine ); 61 | default: break; 62 | } 63 | 64 | default: break; 65 | } 66 | 67 | return false; 68 | } 69 | 70 | bool int0x11( const Machine & machine, Engine & engine ) 71 | { 72 | ( void )machine; 73 | ( void )engine; 74 | 75 | return false; 76 | } 77 | 78 | bool int0x12( const Machine & machine, Engine & engine ) 79 | { 80 | ( void )machine; 81 | ( void )engine; 82 | 83 | return false; 84 | } 85 | 86 | bool int0x13( const Machine & machine, Engine & engine ) 87 | { 88 | switch( engine.ah() ) 89 | { 90 | case 0x00: return BIOS::Disk::reset( machine, engine ); 91 | case 0x02: return BIOS::Disk::readSectors( machine, engine ); 92 | case 0x41: return BIOS::Disk::checkExtensions( machine, engine ); 93 | case 0x42: return BIOS::Disk::extendedReadSectors( machine, engine ); 94 | default: break; 95 | } 96 | 97 | return false; 98 | } 99 | 100 | bool int0x14( const Machine & machine, Engine & engine ) 101 | { 102 | ( void )machine; 103 | ( void )engine; 104 | 105 | return false; 106 | } 107 | 108 | bool int0x15( const Machine & machine, Engine & engine ) 109 | { 110 | switch( engine.ax() ) 111 | { 112 | case 0xE820: return BIOS::SystemServices::getMemoryMap( machine, engine ); 113 | case 0xEC00: return BIOS::SystemServices::enterLongMode( machine, engine ); 114 | default: break; 115 | } 116 | 117 | return false; 118 | } 119 | 120 | bool int0x16( const Machine & machine, Engine & engine ) 121 | { 122 | switch( engine.ah() ) 123 | { 124 | case 0x00: return BIOS::Keyboard::readKey( machine, engine ); 125 | default: break; 126 | } 127 | 128 | return false; 129 | } 130 | 131 | bool int0x17( const Machine & machine, Engine & engine ) 132 | { 133 | ( void )machine; 134 | ( void )engine; 135 | 136 | return false; 137 | } 138 | 139 | bool int0x18( const Machine & machine, Engine & engine ) 140 | { 141 | ( void )machine; 142 | 143 | machine.ui().debug() << "Stopping emulation" << std::endl; 144 | engine.stop(); 145 | 146 | return true; 147 | } 148 | 149 | bool int0x19( const Machine & machine, Engine & engine ) 150 | { 151 | ( void )machine; 152 | 153 | machine.ui().debug() << "Stopping emulation" << std::endl; 154 | engine.stop(); 155 | 156 | return true; 157 | } 158 | 159 | bool int0x1A( const Machine & machine, Engine & engine ) 160 | { 161 | ( void )machine; 162 | ( void )engine; 163 | 164 | return false; 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Interrupts.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_INTERRUPTS_HPP 26 | #define UB_INTERRUPTS_HPP 27 | 28 | namespace UB 29 | { 30 | class Engine; 31 | class Machine; 32 | 33 | namespace Interrupts 34 | { 35 | bool int0x05( const Machine & machine, Engine & engine ); 36 | bool int0x10( const Machine & machine, Engine & engine ); 37 | bool int0x11( const Machine & machine, Engine & engine ); 38 | bool int0x12( const Machine & machine, Engine & engine ); 39 | bool int0x13( const Machine & machine, Engine & engine ); 40 | bool int0x14( const Machine & machine, Engine & engine ); 41 | bool int0x15( const Machine & machine, Engine & engine ); 42 | bool int0x16( const Machine & machine, Engine & engine ); 43 | bool int0x17( const Machine & machine, Engine & engine ); 44 | bool int0x18( const Machine & machine, Engine & engine ); 45 | bool int0x19( const Machine & machine, Engine & engine ); 46 | bool int0x1A( const Machine & machine, Engine & engine ); 47 | } 48 | } 49 | 50 | #endif /* UB_INTERRUPTS_HPP */ 51 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Machine.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_MACHINE_HPP 26 | #define UB_MACHINE_HPP 27 | 28 | #include 29 | #include 30 | #include "UB/FAT/Image.hpp" 31 | #include "UB/BIOS/MemoryMap.hpp" 32 | #include "UB/UI.hpp" 33 | 34 | namespace UB 35 | { 36 | class Machine 37 | { 38 | public: 39 | 40 | Machine( size_t memory, const FAT::Image & fat, UI::Mode mode ); 41 | Machine( const Machine & o ); 42 | Machine( Machine && o ) noexcept; 43 | ~Machine( void ); 44 | 45 | Machine & operator =( Machine o ); 46 | 47 | const FAT::Image & bootImage( void ) const; 48 | const BIOS::MemoryMap & memoryMap( void ) const; 49 | 50 | UI & ui( void ) const; 51 | 52 | void run( void ); 53 | 54 | bool breakOnInterrupt( void ) const; 55 | bool breakOnInterruptReturn( void ) const; 56 | bool trap( void ) const; 57 | bool debugVideo( void ) const; 58 | bool singleStep( void ) const; 59 | 60 | void breakOnInterrupt( bool value ); 61 | void breakOnInterruptReturn( bool value ); 62 | void trap( bool value ); 63 | void debugVideo( bool value ); 64 | void singleStep( bool value ); 65 | 66 | void breakHere( const std::string & message ) const; 67 | void addBreakpoint( uint64_t address ); 68 | void removeBreakpoint( uint64_t address ); 69 | 70 | friend void swap( Machine & o1, Machine & o2 ); 71 | 72 | private: 73 | 74 | class IMPL; 75 | std::unique_ptr< IMPL > impl; 76 | }; 77 | } 78 | 79 | #endif /* UB_MACHINE_HPP */ 80 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Registers.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_REGISTERS_HPP 26 | #define UB_REGISTERS_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace UB 33 | { 34 | class Engine; 35 | 36 | class Registers 37 | { 38 | public: 39 | 40 | Registers( void ); 41 | Registers( const Engine & engine ); 42 | Registers( const Registers & o ); 43 | Registers( Registers && o ) noexcept; 44 | ~Registers( void ); 45 | 46 | Registers & operator =( Registers o ); 47 | 48 | uint8_t ah( void ) const; 49 | uint8_t al( void ) const; 50 | uint16_t ax( void ) const; 51 | uint32_t eax( void ) const; 52 | uint64_t rax( void ) const; 53 | 54 | uint8_t bh( void ) const; 55 | uint8_t bl( void ) const; 56 | uint16_t bx( void ) const; 57 | uint32_t ebx( void ) const; 58 | uint64_t rbx( void ) const; 59 | 60 | uint8_t ch( void ) const; 61 | uint8_t cl( void ) const; 62 | uint16_t cx( void ) const; 63 | uint32_t ecx( void ) const; 64 | uint64_t rcx( void ) const; 65 | 66 | uint8_t dh( void ) const; 67 | uint8_t dl( void ) const; 68 | uint16_t dx( void ) const; 69 | uint32_t edx( void ) const; 70 | uint64_t rdx( void ) const; 71 | 72 | uint8_t sil( void ) const; 73 | uint16_t si( void ) const; 74 | uint32_t esi( void ) const; 75 | uint64_t rsi( void ) const; 76 | 77 | uint8_t dil( void ) const; 78 | uint16_t di( void ) const; 79 | uint32_t edi( void ) const; 80 | uint64_t rdi( void ) const; 81 | 82 | uint8_t bpl( void ) const; 83 | uint16_t bp( void ) const; 84 | uint32_t ebp( void ) const; 85 | uint64_t rbp( void ) const; 86 | 87 | uint8_t spl( void ) const; 88 | uint16_t sp( void ) const; 89 | uint32_t esp( void ) const; 90 | uint64_t rsp( void ) const; 91 | 92 | uint16_t ip( void ) const; 93 | uint32_t eip( void ) const; 94 | uint64_t rip( void ) const; 95 | 96 | uint16_t cs( void ) const; 97 | uint16_t ds( void ) const; 98 | uint16_t es( void ) const; 99 | uint16_t fs( void ) const; 100 | uint16_t gs( void ) const; 101 | uint16_t ss( void ) const; 102 | 103 | uint32_t eflags( void ) const; 104 | 105 | uint8_t r8b( void ) const; 106 | uint16_t r8w( void ) const; 107 | uint32_t r8d( void ) const; 108 | uint64_t r8( void ) const; 109 | 110 | uint8_t r9b( void ) const; 111 | uint16_t r9w( void ) const; 112 | uint32_t r9d( void ) const; 113 | uint64_t r9( void ) const; 114 | 115 | uint8_t r10b( void ) const; 116 | uint16_t r10w( void ) const; 117 | uint32_t r10d( void ) const; 118 | uint64_t r10( void ) const; 119 | 120 | uint8_t r11b( void ) const; 121 | uint16_t r11w( void ) const; 122 | uint32_t r11d( void ) const; 123 | uint64_t r11( void ) const; 124 | 125 | uint8_t r12b( void ) const; 126 | uint16_t r12w( void ) const; 127 | uint32_t r12d( void ) const; 128 | uint64_t r12( void ) const; 129 | 130 | uint8_t r13b( void ) const; 131 | uint16_t r13w( void ) const; 132 | uint32_t r13d( void ) const; 133 | uint64_t r13( void ) const; 134 | 135 | uint8_t r14b( void ) const; 136 | uint16_t r14w( void ) const; 137 | uint32_t r14d( void ) const; 138 | uint64_t r14( void ) const; 139 | 140 | uint8_t r15b( void ) const; 141 | uint16_t r15w( void ) const; 142 | uint32_t r15d( void ) const; 143 | uint64_t r15( void ) const; 144 | 145 | bool cf( void ) const; 146 | 147 | friend void swap( Registers & o1, Registers & o2 ); 148 | 149 | private: 150 | 151 | class IMPL; 152 | std::unique_ptr< IMPL > impl; 153 | }; 154 | } 155 | 156 | #endif /* UB_REGISTERS_HPP */ 157 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Screen.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_SCREEN_HPP 26 | #define UB_SCREEN_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include "UB/Color.hpp" 32 | 33 | namespace UB 34 | { 35 | class Screen 36 | { 37 | public: 38 | 39 | static Screen & shared( void ); 40 | 41 | Screen( const Screen & o ) = delete; 42 | Screen( Screen && o ) noexcept = delete; 43 | Screen & operator =( Screen o ) = delete; 44 | 45 | std::size_t width( void ) const; 46 | std::size_t height( void ) const; 47 | 48 | bool supportsColors( void ) const; 49 | void disableColors( void ) const; 50 | bool isRunning( void ) const; 51 | void clear( void ) const; 52 | void refresh( void ) const; 53 | 54 | void print( const std::string & s ); 55 | void print( const Color & color, const std::string & s ); 56 | 57 | void start( void ); 58 | void stop( void ); 59 | 60 | void onResize( const std::function< void( void ) > & f ); 61 | void onKeyPress( const std::function< void( int key ) > & f ); 62 | void onUpdate( const std::function< void( void ) > & f ); 63 | 64 | private: 65 | 66 | Screen( void ); 67 | 68 | class IMPL; 69 | 70 | std::unique_ptr< IMPL > impl; 71 | }; 72 | } 73 | 74 | #endif /* UB_SCREEN_HPP */ 75 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Signal.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/Signal.hpp" 26 | #include 27 | #include 28 | #include 29 | 30 | static std::recursive_mutex * rmtx; 31 | static std::map< int, std::vector< std::function< void( int ) > > > * handlers; 32 | 33 | static void handle( int sig ); 34 | 35 | namespace UB 36 | { 37 | namespace Signal 38 | { 39 | void handle( int sig, const std::function< void( int ) > & handler ) 40 | { 41 | static std::once_flag once; 42 | 43 | std::call_once 44 | ( 45 | once, 46 | [] 47 | { 48 | rmtx = new std::recursive_mutex(); 49 | handlers = new std::map< int, std::vector< std::function< void( int ) > > >(); 50 | } 51 | ); 52 | 53 | { 54 | std::lock_guard< std::recursive_mutex > l( *( rmtx ) ); 55 | 56 | handlers->operator[]( sig ).push_back( handler ); 57 | 58 | signal( SIGINT, ::handle ); 59 | } 60 | } 61 | } 62 | } 63 | 64 | static void handle( int sig ) 65 | { 66 | std::lock_guard< std::recursive_mutex > l( *( rmtx ) ); 67 | 68 | for( const auto & f: handlers->operator[]( sig ) ) 69 | { 70 | f( sig ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Signal.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_SIGNAL_HPP 26 | #define UB_SIGNAL_HPP 27 | 28 | #include 29 | 30 | namespace UB 31 | { 32 | namespace Signal 33 | { 34 | void handle( int sig, const std::function< void( int ) > & handler ); 35 | } 36 | } 37 | 38 | #endif /* UB_SIGNAL_HPP */ 39 | -------------------------------------------------------------------------------- /unicorn-bios/UB/String.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/String.hpp" 26 | 27 | namespace UB 28 | { 29 | namespace String 30 | { 31 | std::vector< std::string > lines( const std::string & s ) 32 | { 33 | std::vector< std::string > v; 34 | std::stringstream ss( s ); 35 | std::string l; 36 | 37 | while( std::getline( ss, l, '\n' ) ) 38 | { 39 | v.push_back( l ); 40 | } 41 | 42 | return v; 43 | } 44 | 45 | std::string toUpper( const std::string & s ) 46 | { 47 | std::string upper( s ); 48 | 49 | std::transform( upper.begin(), upper.end(), upper.begin(), ::toupper ); 50 | 51 | return upper; 52 | } 53 | 54 | std::string toLower( const std::string & s ) 55 | { 56 | std::string lower( s ); 57 | 58 | std::transform( lower.begin(), lower.end(), lower.begin(), ::tolower ); 59 | 60 | return lower; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /unicorn-bios/UB/String.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_STRING_HPP 26 | #define UB_STRING_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace UB 35 | { 36 | namespace String 37 | { 38 | std::vector< std::string > lines( const std::string & s ); 39 | 40 | std::string toUpper( const std::string & s ); 41 | std::string toLower( const std::string & s ); 42 | 43 | template< typename _T_ > 44 | _T_ fromHex( const std::string & s, typename std::enable_if< std::is_integral< _T_ >::value >::type * = 0 ) 45 | { 46 | _T_ v( 0 ); 47 | std::stringstream ss; 48 | 49 | ss << std::hex << s; 50 | ss >> v; 51 | 52 | return v; 53 | } 54 | 55 | template< typename _T_ > 56 | std::string toHex( _T_ v, typename std::enable_if< std::is_integral< _T_ >::value >::type * = 0 ) 57 | { 58 | std::stringstream ss; 59 | 60 | ss << "0x" 61 | << std::hex 62 | << std::uppercase 63 | << std::setfill( '0' ) 64 | << std::setw( sizeof( _T_ ) * 2 ) 65 | << static_cast< uint64_t >( v ); 66 | 67 | return ss.str(); 68 | } 69 | 70 | template< typename _T_ > 71 | std::string toBinary( _T_ v, typename std::enable_if< std::is_integral< _T_ >::value >::type * = 0 ) 72 | { 73 | size_t bits( sizeof( _T_ ) * 8 ); 74 | std::string s( bits, '0' ); 75 | 76 | for( size_t i = 0; i < bits; i++ ) 77 | { 78 | s[ ( bits - 1 ) - i ] = ( v & 0x01 ) ? '1' : '0'; 79 | v >>= 1; 80 | } 81 | 82 | return s; 83 | } 84 | } 85 | } 86 | 87 | #endif /* UB_STRING_HPP */ 88 | -------------------------------------------------------------------------------- /unicorn-bios/UB/StringStream.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_STRING_STREAM_HPP 26 | #define UB_STRING_STREAM_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace UB 36 | { 37 | class StringStream 38 | { 39 | public: 40 | 41 | StringStream( void ); 42 | StringStream( const std::string & s ); 43 | StringStream( const StringStream & o ); 44 | StringStream( StringStream && o ) noexcept; 45 | ~StringStream( void ); 46 | 47 | StringStream & operator =( StringStream o ); 48 | 49 | operator std::string() const; 50 | std::string string( void ) const; 51 | 52 | void redirect( std::ostream & os ); 53 | 54 | StringStream & operator <<( const std::string & s ); 55 | StringStream & operator <<( short v ); 56 | StringStream & operator <<( unsigned short v ); 57 | StringStream & operator <<( int v ); 58 | StringStream & operator <<( unsigned int v ); 59 | StringStream & operator <<( long v ); 60 | StringStream & operator <<( unsigned long v ); 61 | StringStream & operator <<( long long v ); 62 | StringStream & operator <<( unsigned long long v ); 63 | StringStream & operator <<( float v ); 64 | StringStream & operator <<( double v ); 65 | StringStream & operator <<( long double v ); 66 | 67 | StringStream & operator <<( std::ostream & ( * f )( std::ostream & ) ); 68 | StringStream & operator <<( std::ios_base & ( * f )( std::ios_base & ) ); 69 | 70 | friend void swap( StringStream & o1, StringStream & o2 ); 71 | 72 | private: 73 | 74 | class IMPL; 75 | std::unique_ptr< IMPL > impl; 76 | }; 77 | } 78 | 79 | #endif /* UB_STRING_STREAM_HPP */ 80 | -------------------------------------------------------------------------------- /unicorn-bios/UB/UI.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_UI_HPP 26 | #define UB_UI_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include "UB/StringStream.hpp" 32 | 33 | namespace UB 34 | { 35 | class Engine; 36 | 37 | class UI 38 | { 39 | public: 40 | 41 | enum class Mode 42 | { 43 | Standard, 44 | Interactive 45 | }; 46 | 47 | UI( Engine & engine ); 48 | UI( const UI & o ); 49 | UI( UI && o ) noexcept; 50 | ~UI( void ); 51 | 52 | UI & operator =( UI o ); 53 | 54 | Mode mode( void ) const; 55 | void mode( Mode mode ); 56 | 57 | void run( void ); 58 | int waitForUserResume( void ); 59 | 60 | StringStream & output( void ); 61 | StringStream & debug( void ); 62 | 63 | friend void swap( UI & o1, UI & o2 ); 64 | 65 | private: 66 | 67 | class IMPL; 68 | std::unique_ptr< IMPL > impl; 69 | }; 70 | } 71 | 72 | #endif /* UB_UI_HPP */ 73 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Window.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include "UB/Window.hpp" 26 | #include "UB/Casts.hpp" 27 | #include "UB/Screen.hpp" 28 | #include 29 | 30 | namespace UB 31 | { 32 | class Window::IMPL 33 | { 34 | public: 35 | 36 | IMPL( size_t x, size_t y, size_t width, size_t height ); 37 | IMPL( const IMPL & o ); 38 | ~IMPL( void ); 39 | 40 | size_t _x; 41 | size_t _y; 42 | size_t _width; 43 | size_t _height; 44 | ::WINDOW * _win; 45 | }; 46 | 47 | Window::Window( size_t x, size_t y, size_t width, size_t height ): 48 | impl( std::make_unique< IMPL >( x, y, width, height ) ) 49 | {} 50 | 51 | Window::Window( const Window & o ): 52 | impl( std::make_unique< IMPL >( *( o.impl ) ) ) 53 | {} 54 | 55 | Window::Window( Window && o ) noexcept: 56 | impl( std::move( o.impl ) ) 57 | {} 58 | 59 | Window::~Window( void ) 60 | {} 61 | 62 | Window & Window::operator =( Window o ) 63 | { 64 | swap( *( this ), o ); 65 | 66 | return *( this ); 67 | } 68 | 69 | void Window::refresh( void ) 70 | { 71 | ::wrefresh( this->impl->_win ); 72 | } 73 | 74 | void Window::move( size_t x, size_t y ) 75 | { 76 | ::wmove( this->impl->_win, numeric_cast< int >( y ), numeric_cast< int >( x ) ); 77 | } 78 | 79 | void Window::print( const std::string & s ) 80 | { 81 | ::wprintw( this->impl->_win, s.c_str() ); 82 | } 83 | 84 | void Window::print( const char * format, ... ) 85 | { 86 | va_list ap; 87 | 88 | va_start( ap, format ); 89 | ::vw_printw( this->impl->_win, format, ap ); 90 | va_end( ap ); 91 | } 92 | 93 | void Window::print( const Color & color, const std::string & s ) 94 | { 95 | if( Screen::shared().supportsColors() ) 96 | { 97 | ::wattrset( this->impl->_win, COLOR_PAIR( color.index() ) ); 98 | } 99 | 100 | ::wprintw( this->impl->_win, s.c_str() ); 101 | 102 | if( Screen::shared().supportsColors() ) 103 | { 104 | ::wattrset( this->impl->_win, COLOR_PAIR( Color::clear().index() ) ); 105 | } 106 | } 107 | 108 | void Window::print( const Color & color, const char * format, ... ) 109 | { 110 | va_list ap; 111 | 112 | va_start( ap, format ); 113 | 114 | if( Screen::shared().supportsColors() ) 115 | { 116 | ::wattrset( this->impl->_win, COLOR_PAIR( color.index() ) ); 117 | } 118 | 119 | ::vw_printw( this->impl->_win, format, ap ); 120 | 121 | if( Screen::shared().supportsColors() ) 122 | { 123 | ::wattrset( this->impl->_win, COLOR_PAIR( Color::clear().index() ) ); 124 | } 125 | 126 | va_end( ap ); 127 | } 128 | 129 | void Window::box( void ) 130 | { 131 | ::box( this->impl->_win, 0, 0 ); 132 | } 133 | 134 | void Window::addHorizontalLine( size_t width ) 135 | { 136 | ::whline( this->impl->_win, 0, numeric_cast< int >( width ) ); 137 | } 138 | 139 | void Window::addVerticalLine( size_t height ) 140 | { 141 | ::wvline( this->impl->_win, 0, numeric_cast< int >( height ) ); 142 | } 143 | 144 | void swap( Window & o1, Window & o2 ) 145 | { 146 | using std::swap; 147 | 148 | swap( o1.impl, o2.impl ); 149 | } 150 | 151 | Window::IMPL::IMPL( size_t x, size_t y, size_t width, size_t height ): 152 | _x( x ), 153 | _y( y ), 154 | _width( width ), 155 | _height( height ), 156 | _win( ::newwin( numeric_cast< int >( height ), numeric_cast< int >( width ), numeric_cast< int >( y ), numeric_cast< int >( x ) ) ) 157 | {} 158 | 159 | Window::IMPL::IMPL( const IMPL & o ): 160 | _x( o._x ), 161 | _y( o._y ), 162 | _width( o._width ), 163 | _height( o._height ), 164 | _win( ::newwin( numeric_cast< int >( o._height ), numeric_cast< int >( o._width ), numeric_cast< int >( o._y ), numeric_cast< int >( o._x ) ) ) 165 | {} 166 | 167 | Window::IMPL::~IMPL( void ) 168 | { 169 | ::delwin( this->_win ); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /unicorn-bios/UB/Window.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #ifndef UB_WINDOW_HPP 26 | #define UB_WINDOW_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "UB/Color.hpp" 33 | 34 | namespace UB 35 | { 36 | class Window 37 | { 38 | public: 39 | 40 | Window( size_t x, size_t y, size_t width, size_t height ); 41 | Window( const Window & o ); 42 | Window( Window && o ) noexcept; 43 | ~Window( void ); 44 | 45 | Window & operator =( Window o ); 46 | 47 | void refresh( void ); 48 | void move( size_t x, size_t y ); 49 | void print( const std::string & s ); 50 | void print( const char * format, ... ); 51 | void print( const Color & color, const std::string & s ); 52 | void print( const Color & color, const char * format, ... ); 53 | void box( void ); 54 | void addHorizontalLine( size_t width ); 55 | void addVerticalLine( size_t height ); 56 | 57 | friend void swap( Window & o1, Window & o2 ); 58 | 59 | private: 60 | 61 | class IMPL; 62 | std::unique_ptr< IMPL > impl; 63 | }; 64 | } 65 | 66 | #endif /* UB_WINDOW_HPP */ 67 | -------------------------------------------------------------------------------- /unicorn-bios/main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Jean-David Gadina - www.xs-labs.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | #include 26 | #include "UB/Arguments.hpp" 27 | #include "UB/Machine.hpp" 28 | #include "UB/Screen.hpp" 29 | 30 | static void showHelp( void ); 31 | 32 | int main( int argc, const char * argv[] ) 33 | { 34 | try 35 | { 36 | UB::Arguments args( argc, argv ); 37 | 38 | if( args.showHelp() || args.bootImage().length() == 0 ) 39 | { 40 | showHelp(); 41 | 42 | return EXIT_SUCCESS; 43 | } 44 | 45 | { 46 | UB::Machine * machine; 47 | 48 | if( args.noUI() ) 49 | { 50 | machine = new UB::Machine( args.memory() * 1024 * 1024, args.bootImage(), UB::UI::Mode::Standard ); 51 | } 52 | else 53 | { 54 | machine = new UB::Machine( args.memory() * 1024 * 1024, args.bootImage(), UB::UI::Mode::Interactive ); 55 | } 56 | 57 | machine->breakOnInterrupt( args.breakOnInterrupt() ); 58 | machine->breakOnInterruptReturn( args.breakOnInterruptReturn() ); 59 | machine->trap( args.trap() ); 60 | machine->debugVideo( args.debugVideo() ); 61 | machine->singleStep( args.singleStep() ); 62 | 63 | for( auto bp: args.breakpoints() ) 64 | { 65 | machine->addBreakpoint( bp ); 66 | } 67 | 68 | if( args.noUI() == false && args.noColors() ) 69 | { 70 | UB::Screen::shared().disableColors(); 71 | } 72 | 73 | 74 | machine->run(); 75 | } 76 | 77 | return EXIT_SUCCESS; 78 | } 79 | catch( const std::exception & e ) 80 | { 81 | std::cerr << "Error: " << e.what() << std::endl; 82 | 83 | return EXIT_FAILURE; 84 | } 85 | catch( ... ) 86 | { 87 | std::cerr << "Unknown error" << std::endl; 88 | 89 | return EXIT_FAILURE; 90 | } 91 | } 92 | 93 | static void showHelp( void ) 94 | { 95 | std::cout << "Usage: unicorn-bios [OPTIONS] BOOT_IMG" 96 | << std::endl 97 | << std::endl 98 | << "Options:" 99 | << std::endl 100 | << std::endl 101 | << " --help / -h: Displays help." 102 | << std::endl 103 | << " --memory / -m: The amount of memory to allocate for the virtual machine" 104 | << std::endl 105 | << " (in megabytes). Defaults to 64MB, minimum 2MB." 106 | << std::endl 107 | << " --break / -b Breaks on a specific address." 108 | << std::endl 109 | << " --break-int: Breaks on interrupt calls." 110 | << std::endl 111 | << " --break-iret: Breaks on interrupt returns." 112 | << std::endl 113 | << " --trap: Raises a trap when breaking." 114 | << std::endl 115 | << " --debug-video: Turns on debug output for video services." 116 | << std::endl 117 | << " --single-step: Breaks on every instruction." 118 | << std::endl 119 | << " --no-ui: Don't start the user interface (output will be displayed to stdout, debug info to stderr)." 120 | << std::endl 121 | << " --no-colors: Don't use colors." 122 | << std::endl; 123 | } 124 | --------------------------------------------------------------------------------