mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-10 16:16:16 +00:00
Initial commit
This commit is contained in:
149
.gitignore
vendored
Normal file
149
.gitignore
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
### Windows
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Shortcuts
|
||||
*.lnk
|
||||
|
||||
### OSX
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear on external disk
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Visual Studio
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
build
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
### IDA
|
||||
*.id0
|
||||
*.id1
|
||||
*.id2
|
||||
*.nam
|
||||
*.til
|
||||
|
||||
### Custom user files
|
||||
# User scripts
|
||||
user*.bat
|
||||
|
||||
.vscode/
|
||||
5
.gitmodules
vendored
Normal file
5
.gitmodules
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[submodule "deps/unicorn"]
|
||||
path = deps/unicorn
|
||||
url = https://github.com/unicorn-engine/unicorn.git
|
||||
shallow = true
|
||||
branch = dev
|
||||
48
CMakeLists.txt
Normal file
48
CMakeLists.txt
Normal file
@@ -0,0 +1,48 @@
|
||||
cmake_minimum_required(VERSION 3.26.4)
|
||||
|
||||
##########################################
|
||||
|
||||
option(MOMO_ENABLE_SANITIZER "Enable sanitizer" OFF)
|
||||
|
||||
##########################################
|
||||
|
||||
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
|
||||
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
|
||||
|
||||
##########################################
|
||||
|
||||
project(bird LANGUAGES C CXX)
|
||||
|
||||
##########################################
|
||||
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
##########################################
|
||||
|
||||
include(cmake/utils.cmake)
|
||||
include(cmake/compiler-env.cmake)
|
||||
|
||||
##########################################
|
||||
|
||||
momo_set_new_artifact_directory()
|
||||
|
||||
##########################################
|
||||
|
||||
momo_add_subdirectory_and_get_targets("deps" EXTERNAL_TARGETS)
|
||||
momo_add_subdirectory_and_get_targets("src" OWN_TARGETS)
|
||||
|
||||
##########################################
|
||||
|
||||
momo_targets_set_folder("External Dependencies" ${EXTERNAL_TARGETS})
|
||||
|
||||
momo_targets_exclude_from_all(${EXTERNAL_TARGETS})
|
||||
momo_targets_disable_warnings(${EXTERNAL_TARGETS})
|
||||
|
||||
momo_targets_expose_includes(${OWN_TARGETS})
|
||||
momo_targets_set_warnings_as_errors(${OWN_TARGETS})
|
||||
83
CMakePresets.json
Normal file
83
CMakePresets.json
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"version": 6,
|
||||
"cmakeMinimumRequired": {
|
||||
"major": 3,
|
||||
"minor": 26,
|
||||
"patch": 4
|
||||
},
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "build",
|
||||
"hidden": true,
|
||||
"binaryDir": "${sourceDir}/build/${presetName}"
|
||||
},
|
||||
{
|
||||
"name": "ninja",
|
||||
"hidden": true,
|
||||
"generator": "Ninja"
|
||||
},
|
||||
{
|
||||
"name": "release",
|
||||
"inherits": [
|
||||
"ninja",
|
||||
"build"
|
||||
],
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug",
|
||||
"inherits": [
|
||||
"ninja",
|
||||
"build"
|
||||
],
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "vs2022",
|
||||
"generator": "Visual Studio 17 2022",
|
||||
"inherits": "build"
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "release",
|
||||
"configurePreset": "release"
|
||||
},
|
||||
{
|
||||
"name": "debug",
|
||||
"configurePreset": "debug"
|
||||
}
|
||||
],
|
||||
"workflowPresets": [
|
||||
{
|
||||
"name": "release",
|
||||
"steps": [
|
||||
{
|
||||
"type": "configure",
|
||||
"name": "release"
|
||||
},
|
||||
{
|
||||
"type": "build",
|
||||
"name": "release"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "debug",
|
||||
"steps": [
|
||||
{
|
||||
"type": "configure",
|
||||
"name": "debug"
|
||||
},
|
||||
{
|
||||
"type": "build",
|
||||
"name": "debug"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
147
cmake/compiler-env.cmake
Normal file
147
cmake/compiler-env.cmake
Normal file
@@ -0,0 +1,147 @@
|
||||
include_guard()
|
||||
|
||||
##########################################
|
||||
# System identification
|
||||
|
||||
set(OSX OFF)
|
||||
set(LINUX OFF)
|
||||
set(WIN OFF)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
set(LINUX ON)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||
set(OSX ON)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
set(WIN ON)
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
cmake_policy(SET CMP0069 NEW)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
|
||||
##########################################
|
||||
|
||||
if(UNIX)
|
||||
momo_add_c_and_cxx_compile_options(-fvisibility=hidden)
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
if(LINUX)
|
||||
add_link_options(
|
||||
-Wl,--no-undefined
|
||||
-Wl,--gc-sections
|
||||
-Wl,-z,now
|
||||
-Wl,-z,noexecstack
|
||||
-static-libstdc++
|
||||
)
|
||||
|
||||
momo_add_c_and_cxx_compile_options(
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-fstack-protector-strong
|
||||
-fdiagnostics-color=always
|
||||
)
|
||||
|
||||
add_compile_definitions(
|
||||
_REENTRANT
|
||||
_THREAD_SAFE
|
||||
)
|
||||
|
||||
if(NOT MOMO_ENABLE_SANITIZER)
|
||||
add_compile_definitions(
|
||||
_FORTIFY_SOURCE=2
|
||||
)
|
||||
endif()
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
if(MSVC)
|
||||
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
string(REPLACE "/EHs" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
|
||||
momo_add_c_and_cxx_compile_options(
|
||||
/sdl
|
||||
/GS
|
||||
/Gy
|
||||
/EHa
|
||||
/guard:cf
|
||||
)
|
||||
|
||||
momo_add_compile_options(CXX
|
||||
/Zc:__cplusplus
|
||||
)
|
||||
|
||||
add_link_options(
|
||||
/INCREMENTAL:NO
|
||||
)
|
||||
|
||||
momo_add_c_and_cxx_release_compile_options(
|
||||
/Ob2
|
||||
#/GL
|
||||
)
|
||||
|
||||
momo_add_release_link_options(
|
||||
#/LTCG
|
||||
)
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
if(MOMO_ENABLE_SANITIZER)
|
||||
momo_add_c_and_cxx_compile_options(
|
||||
-fsanitize=address
|
||||
)
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
if(MOMO_ENABLE_SANITIZER)
|
||||
# ASAN on Windows needs /MD
|
||||
# https://developercommunity.visualstudio.com/t/c-address-sanitizer-statically-linked-dlls-do-not/1403680
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>DLL)
|
||||
else()
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
if(MSVC)
|
||||
add_link_options(
|
||||
$<$<NOT:$<STREQUAL:${CMAKE_MSVC_RUNTIME_LIBRARY},MultiThreaded>>:/NODEFAULTLIB:libcmt.lib>
|
||||
$<$<NOT:$<STREQUAL:${CMAKE_MSVC_RUNTIME_LIBRARY},MultiThreadedDLL>>:/NODEFAULTLIB:msvcrt.lib>
|
||||
$<$<NOT:$<STREQUAL:${CMAKE_MSVC_RUNTIME_LIBRARY},MultiThreadedDebug>>:/NODEFAULTLIB:libcmtd.lib>
|
||||
$<$<NOT:$<STREQUAL:${CMAKE_MSVC_RUNTIME_LIBRARY},MultiThreadedDebugDLL>>:/NODEFAULTLIB:msvcrtd.lib>
|
||||
)
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
set(OPT_DEBUG "-O0 -g")
|
||||
set(OPT_RELEASE "-O3 -g")
|
||||
|
||||
if(MSVC)
|
||||
set(OPT_DEBUG "/Od /Ob0 /Zi")
|
||||
set(OPT_RELEASE "/O2 /Ob2 /Zi")
|
||||
|
||||
add_link_options(/DEBUG)
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${OPT_DEBUG}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OPT_DEBUG}")
|
||||
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPT_RELEASE}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPT_RELEASE}")
|
||||
|
||||
##########################################
|
||||
|
||||
if(CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
momo_add_c_and_cxx_compile_options(/MP)
|
||||
endif()
|
||||
344
cmake/utils.cmake
Normal file
344
cmake/utils.cmake
Normal file
@@ -0,0 +1,344 @@
|
||||
include_guard()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_silence_deprecation_warnings)
|
||||
set(CMAKE_WARN_DEPRECATED_OLD ${CMAKE_WARN_DEPRECATED} PARENT_SCOPE)
|
||||
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_restore_deprecation_warnings)
|
||||
set(CMAKE_WARN_DEPRECATED ${CMAKE_WARN_DEPRECATED_OLD} CACHE BOOL "" FORCE)
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_target_exclude_from_all target)
|
||||
set_target_properties(${target} PROPERTIES EXCLUDE_FROM_ALL 1)
|
||||
#set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_targets_exclude_from_all)
|
||||
foreach(target ${ARGV})
|
||||
momo_target_exclude_from_all(${target})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_target_set_folder folder target)
|
||||
#get_target_property(CURRENT_FOLDER ${target} FOLDER)
|
||||
#if(NOT CURRENT_FOLDER)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "${folder}")
|
||||
#endif()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_targets_set_folder folder)
|
||||
foreach(target ${ARGN})
|
||||
momo_target_set_folder(${folder} ${target})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_target_disable_compile_commands target)
|
||||
set_target_properties(${target} PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_targets_disable_compile_commands)
|
||||
foreach(target ${ARGV})
|
||||
momo_target_disable_compile_commands(${target})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_target_expose_includes target)
|
||||
get_target_property(target_type ${target} TYPE)
|
||||
if("${target_type}" STREQUAL "UTILITY")
|
||||
return()
|
||||
endif()
|
||||
|
||||
get_target_property(TARGET_SOURCE_DIR ${target} SOURCE_DIR)
|
||||
target_include_directories(${target} INTERFACE ${TARGET_SOURCE_DIR}/..)
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_targets_expose_includes)
|
||||
foreach(target ${ARGV})
|
||||
momo_target_expose_includes(${target})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_target_compile_options language target mode)
|
||||
foreach(compile_option ${ARGN})
|
||||
target_compile_options(${target} ${mode}
|
||||
$<$<COMPILE_LANGUAGE:${language}>:${compile_option}>
|
||||
)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_target_c_and_cxx_compile_options)
|
||||
momo_target_compile_options(C ${ARGV})
|
||||
momo_target_compile_options(CXX ${ARGV})
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_target_remove_compile_option target option)
|
||||
get_target_property(target_flags ${target} COMPILE_OPTIONS)
|
||||
if(target_flags)
|
||||
list(REMOVE_ITEM target_flags ${option})
|
||||
set_target_properties(${target} PROPERTIES COMPILE_OPTIONS "${target_flags}")
|
||||
endif()
|
||||
|
||||
get_target_property(target_interface_flags ${target} INTERFACE_COMPILE_OPTIONS)
|
||||
if(target_interface_flags)
|
||||
list(REMOVE_ITEM target_interface_flags ${option})
|
||||
set_target_properties(${target} PROPERTIES INTERFACE_COMPILE_OPTIONS "${target_interface_flags}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_target_remove_compile_options target)
|
||||
foreach(option ${ARGV})
|
||||
momo_target_remove_compile_option(${target} ${option})
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_add_compile_options language)
|
||||
foreach(option ${ARGN})
|
||||
add_compile_options(
|
||||
$<$<COMPILE_LANGUAGE:${language}>:${option}>
|
||||
)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_add_release_compile_options language)
|
||||
foreach(option ${ARGN})
|
||||
add_compile_options(
|
||||
$<$<COMPILE_LANGUAGE:${language}>:$<$<CONFIG:RELEASE>:${option}>>
|
||||
$<$<COMPILE_LANGUAGE:${language}>:$<$<CONFIG:RELWITHDEBINFO>:${option}>>
|
||||
)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_add_release_link_options)
|
||||
foreach(option ${ARGN})
|
||||
add_link_options(
|
||||
$<$<CONFIG:RELEASE>:${option}>
|
||||
$<$<CONFIG:RELWITHDEBINFO>:${option}>
|
||||
)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_add_c_and_cxx_compile_options)
|
||||
momo_add_compile_options(C ${ARGV})
|
||||
momo_add_compile_options(CXX ${ARGV})
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_add_c_and_cxx_release_compile_options)
|
||||
momo_add_release_compile_options(C ${ARGV})
|
||||
momo_add_release_compile_options(CXX ${ARGV})
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_target_disable_warnings target)
|
||||
get_target_property(target_type ${target} TYPE)
|
||||
if(("${target_type}" STREQUAL "INTERFACE_LIBRARY") OR ("${target_type}" STREQUAL "UTILITY"))
|
||||
return()
|
||||
endif()
|
||||
|
||||
momo_target_remove_compile_options(${target} /W3 -W3 /W4 -W4)
|
||||
|
||||
if(MSVC)
|
||||
set(compile_options
|
||||
/W0
|
||||
/D_CRT_SECURE_NO_WARNINGS=1
|
||||
)
|
||||
endif()
|
||||
|
||||
momo_target_c_and_cxx_compile_options(${target} PRIVATE ${compile_options})
|
||||
|
||||
set_target_properties(${target} PROPERTIES MOMO_WARNINGS_DISABLE ON)
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_targets_disable_warnings)
|
||||
foreach(target ${ARGV})
|
||||
momo_target_disable_warnings(${target})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_target_set_warnings_as_errors target)
|
||||
get_target_property(target_type ${target} TYPE)
|
||||
if(("${target_type}" STREQUAL "INTERFACE_LIBRARY") OR ("${target_type}" STREQUAL "UTILITY"))
|
||||
return()
|
||||
endif()
|
||||
|
||||
get_target_property(warnings_disabled ${target} MOMO_WARNINGS_DISABLE)
|
||||
if(warnings_disabled)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(compile_options)
|
||||
|
||||
if(MSVC)
|
||||
set(compile_options /W4 /WX)
|
||||
endif()
|
||||
|
||||
target_compile_options(${target} PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:C>:$<$<CONFIG:RELEASE>:${compile_options}>>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:RELEASE>:${compile_options}>>
|
||||
$<$<COMPILE_LANGUAGE:C>:$<$<CONFIG:RELWITHDEBINFO>:${compile_options}>>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:RELWITHDEBINFO>:${compile_options}>>
|
||||
)
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_targets_set_warnings_as_errors)
|
||||
foreach(target ${ARGV})
|
||||
momo_target_set_warnings_as_errors(${target})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_get_all_targets var)
|
||||
set(targets)
|
||||
momo_get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(${var} ${targets} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_get_all_targets_recursive targets dir)
|
||||
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
|
||||
foreach(subdir ${subdirectories})
|
||||
momo_get_all_targets_recursive(${targets} ${subdir})
|
||||
endforeach()
|
||||
|
||||
get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
|
||||
list(APPEND ${targets} ${current_targets})
|
||||
endmacro()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_list_difference list_a list_to_remove result)
|
||||
set(${result} ${list_a})
|
||||
list(REMOVE_ITEM ${result} ${list_to_remove})
|
||||
endmacro()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_set_artifact_directory directory)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${directory})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${directory})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${directory})
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${directory})
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${directory})
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${directory})
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${directory})
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${directory})
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${directory})
|
||||
endmacro()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_set_new_artifact_directory)
|
||||
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(IS_MULTI_CONFIG)
|
||||
set(ARTIFACT_FOLDER_NAME "artifacts-$<LOWER_CASE:$<CONFIG>>")
|
||||
else()
|
||||
set(ARTIFACT_FOLDER_NAME "artifacts")
|
||||
endif()
|
||||
|
||||
set(ARTIFACT_DIRECTORY "${CMAKE_BINARY_DIR}/${ARTIFACT_FOLDER_NAME}")
|
||||
momo_set_artifact_directory(${ARTIFACT_DIRECTORY})
|
||||
endmacro()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_add_subdirectory_and_get_targets directory targets)
|
||||
momo_get_all_targets(EXISTING_TARGETS)
|
||||
add_subdirectory(${directory})
|
||||
momo_get_all_targets(ALL_TARGETS)
|
||||
|
||||
momo_list_difference("${ALL_TARGETS}" "${EXISTING_TARGETS}" ${targets})
|
||||
endmacro()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_target_include_libraries target mode)
|
||||
foreach(inc_target ${ARGN})
|
||||
target_include_directories(${target} ${mode}
|
||||
$<TARGET_PROPERTY:${inc_target},INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:${inc_target},PUBLIC_INCLUDE_DIRECTORIES>
|
||||
)
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
##########################################
|
||||
|
||||
function(momo_strip_target target)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
if(NOT DEFINED STRIP_COMMAND)
|
||||
set(STRIP_COMMAND strip)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED STRIP_FLAGS)
|
||||
set(STRIP_FLAGS -g -s)
|
||||
if(OSX)
|
||||
set(STRIP_FLAGS -x)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(IN_FILE "$<TARGET_FILE:${target}>")
|
||||
set(OUT_FILE "$<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_PREFIX:${target}>$<TARGET_FILE_BASE_NAME:${target}>-unstripped$<TARGET_FILE_SUFFIX:${target}>")
|
||||
|
||||
add_custom_command(TARGET ${target} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${IN_FILE} ${OUT_FILE}
|
||||
COMMAND "${STRIP_COMMAND}" ${STRIP_FLAGS} "${IN_FILE}"
|
||||
COMMENT "Strippping ${target}"
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
##########################################
|
||||
|
||||
macro(momo_assign_source_group)
|
||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ARGN})
|
||||
endmacro()
|
||||
5
deps/CMakeLists.txt
vendored
Normal file
5
deps/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
set(UNICORN_ARCH "x86" CACHE STRING "")
|
||||
|
||||
add_subdirectory(unicorn)
|
||||
|
||||
##########################################
|
||||
1
deps/unicorn
vendored
Submodule
1
deps/unicorn
vendored
Submodule
Submodule deps/unicorn added at 87610baa3f
1
src/CMakeLists.txt
Normal file
1
src/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
add_subdirectory(emulator)
|
||||
21
src/emulator/CMakeLists.txt
Normal file
21
src/emulator/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
|
||||
*.cpp
|
||||
*.hpp
|
||||
*.rc
|
||||
)
|
||||
|
||||
list(SORT SRC_FILES)
|
||||
|
||||
add_executable(client ${SRC_FILES})
|
||||
|
||||
momo_assign_source_group(${SRC_FILES})
|
||||
|
||||
target_precompile_headers(client PRIVATE std_include.hpp)
|
||||
|
||||
target_link_libraries(client PRIVATE unicorn)
|
||||
|
||||
set_target_properties(client PROPERTIES OUTPUT_NAME "bird")
|
||||
|
||||
set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT client)
|
||||
|
||||
momo_strip_target(client)
|
||||
84
src/emulator/main.cpp
Normal file
84
src/emulator/main.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "std_include.hpp"
|
||||
|
||||
// code to be emulated
|
||||
#define X86_CODE32 "\x41\x4a" // INC ecx; DEC edx
|
||||
|
||||
// memory address where emulation starts
|
||||
#define ADDRESS 0x1000000
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void run()
|
||||
{
|
||||
uc_engine* uc;
|
||||
uc_err err;
|
||||
int r_ecx = 0x1234; // ECX register
|
||||
int r_edx = 0x7890; // EDX register
|
||||
|
||||
printf("Emulate i386 code\n");
|
||||
|
||||
// Initialize emulator in X86-32bit mode
|
||||
err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc);
|
||||
if (err != UC_ERR_OK) {
|
||||
printf("Failed on uc_open() with error returned: %u\n", err);
|
||||
return ;
|
||||
}
|
||||
|
||||
// map 2MB memory for this emulation
|
||||
uc_mem_map(uc, ADDRESS, 0x1000, UC_PROT_ALL);
|
||||
|
||||
// write machine code to be emulated to memory
|
||||
if (uc_mem_write(uc, ADDRESS, X86_CODE32, sizeof(X86_CODE32) - 1)) {
|
||||
printf("Failed to write emulation code to memory, quit!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// initialize machine registers
|
||||
uc_reg_write(uc, UC_X86_REG_ECX, &r_ecx);
|
||||
uc_reg_write(uc, UC_X86_REG_EDX, &r_edx);
|
||||
|
||||
// emulate code in infinite time & unlimited instructions
|
||||
err = uc_emu_start(uc, ADDRESS, ADDRESS + sizeof(X86_CODE32) - 1, 0, 0);
|
||||
if (err) {
|
||||
printf("Failed on uc_emu_start() with error returned %u: %s\n",
|
||||
err, uc_strerror(err));
|
||||
}
|
||||
|
||||
// now print out some registers
|
||||
printf("Emulation done. Below is the CPU context\n");
|
||||
|
||||
uc_reg_read(uc, UC_X86_REG_ECX, &r_ecx);
|
||||
uc_reg_read(uc, UC_X86_REG_EDX, &r_edx);
|
||||
printf(">>> ECX = 0x%x\n", r_ecx);
|
||||
printf(">>> EDX = 0x%x\n", r_edx);
|
||||
|
||||
uc_close(uc);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char** /*argv*/)
|
||||
{
|
||||
try
|
||||
{
|
||||
run();
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
puts(e.what());
|
||||
|
||||
#ifdef _WIN32
|
||||
MessageBoxA(nullptr, e.what(), "ERROR", MB_ICONERROR);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR, int)
|
||||
{
|
||||
return main(__argc, __argv);
|
||||
}
|
||||
#endif
|
||||
101
src/emulator/resource.rc
Normal file
101
src/emulator/resource.rc
Normal file
@@ -0,0 +1,101 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#pragma code_page(65001)
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "windows.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""windows.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,0
|
||||
PRODUCTVERSION 1,0,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "momo5502"
|
||||
VALUE "FileDescription", "Bird"
|
||||
VALUE "FileVersion", "1.0.0.0"
|
||||
VALUE "InternalName", "Bird"
|
||||
VALUE "LegalCopyright", "All rights reserved."
|
||||
VALUE "OriginalFilename", "bird.exe"
|
||||
VALUE "ProductName", "bird"
|
||||
VALUE "ProductVersion", "1.0.0.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Binary Data
|
||||
//
|
||||
|
||||
GLFW_ICON ICON "resources/icon.ico"
|
||||
|
||||
|
||||
#endif // English (United States) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
BIN
src/emulator/resources/icon.ico
Normal file
BIN
src/emulator/resources/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
76
src/emulator/std_include.hpp
Normal file
76
src/emulator/std_include.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4127)
|
||||
#pragma warning(disable: 4244)
|
||||
#pragma warning(disable: 4245)
|
||||
#pragma warning(disable: 4458)
|
||||
#pragma warning(disable: 4505)
|
||||
#pragma warning(disable: 4702)
|
||||
#pragma warning(disable: 4996)
|
||||
#pragma warning(disable: 5054)
|
||||
#pragma warning(disable: 6011)
|
||||
#pragma warning(disable: 6297)
|
||||
#pragma warning(disable: 6385)
|
||||
#pragma warning(disable: 6386)
|
||||
#pragma warning(disable: 6387)
|
||||
#pragma warning(disable: 26110)
|
||||
#pragma warning(disable: 26451)
|
||||
#pragma warning(disable: 26444)
|
||||
#pragma warning(disable: 26451)
|
||||
#pragma warning(disable: 26489)
|
||||
#pragma warning(disable: 26495)
|
||||
#pragma warning(disable: 26498)
|
||||
#pragma warning(disable: 26812)
|
||||
#pragma warning(disable: 28020)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <Windows.h>
|
||||
#include <ShlObj.h>
|
||||
#include <d3d11.h>
|
||||
#include <shellscalingapi.h>
|
||||
#include <winternl.h>
|
||||
|
||||
// min and max is required by gdi, therefore NOMINMAX won't work
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <array>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <ranges>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
#include <condition_variable>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <unicorn/unicorn.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
using namespace std::literals;
|
||||
Reference in New Issue
Block a user