From 6d4ffd573678ef5b16ba2d09d7b83bbbef843582 Mon Sep 17 00:00:00 2001 From: Theodore Dubois Date: Thu, 7 Nov 2024 23:33:48 -0800 Subject: [PATCH] Add experimental/WIP unicorn emulation for linux kernel --- deps/linux | 2 +- deps/meson.build | 13 ++++++++++++- meson.build | 40 +++++++++++++++++++++++----------------- meson_options.txt | 2 +- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/deps/linux b/deps/linux index 3c06c4faa6..7117e60003 160000 --- a/deps/linux +++ b/deps/linux @@ -1 +1 @@ -Subproject commit 3c06c4faa67cf4db6144e7c686ab5b4e9539ec82 +Subproject commit 7117e6000311a51da3370ada7f823b44ba6b3f11 diff --git a/deps/meson.build b/deps/meson.build index 853c38724d..a12c8c2c66 100644 --- a/deps/meson.build +++ b/deps/meson.build @@ -1,9 +1,20 @@ if get_option('kernel') == 'linux' + kconfig = [] + + if get_option('engine') == 'asbestos' + kconfig += 'CONFIG_ISH_EMULATOR_ISHEMU=y' + elif get_option('engine') == 'unicorn' + kconfig += 'CONFIG_ISH_EMULATOR_UNICORN=y' + else + error('Engine "' + get_option('engine') + '" not supported for linux kernel') + endif + + kconfig += get_option('kconfig') meson_fragment = configure_file( command: [ find_program('kconfig-fragment.sh'), '@OUTPUT@', - ] + get_option('kconfig'), + ] + kconfig, output: 'linux-meson.config', ) diff --git a/meson.build b/meson.build index 3c97839c69..62befaf946 100644 --- a/meson.build +++ b/meson.build @@ -51,22 +51,20 @@ emu_src = [ 'emu/float80.c', ] -if get_option('engine') == 'asbestos' - gadgets = 'asbestos/gadgets-' + host_machine.cpu_family() - emu_src += [ - 'asbestos/asbestos.c', - 'asbestos/gen.c', - 'asbestos/helpers.c', - gadgets+'/entry.S', - gadgets+'/memory.S', - gadgets+'/control.S', - gadgets+'/math.S', - gadgets+'/bits.S', - gadgets+'/string.S', - gadgets+'/misc.S', - offsets, - ] -endif +gadgets = 'asbestos/gadgets-' + host_machine.cpu_family() +emu_src += [ + 'asbestos/asbestos.c', + 'asbestos/gen.c', + 'asbestos/helpers.c', + gadgets+'/entry.S', + gadgets+'/memory.S', + gadgets+'/control.S', + gadgets+'/math.S', + gadgets+'/bits.S', + gadgets+'/string.S', + gadgets+'/misc.S', + offsets, +] libish_emu = library('ish_emu', emu_src, include_directories: includes) @@ -78,6 +76,10 @@ libfakefs = library('fakefs', subdir('deps') if get_option('kernel') == 'ish' + if get_option('engine') != 'asbestos' + error('Only asbestos is supported with ish kernel') + endif + src = [ 'kernel/init.c', 'kernel/errno.c', @@ -168,6 +170,10 @@ elif get_option('kernel') == 'linux' 'linux/main.c', 'linux/fakefs.c', ], dependencies: [linux_headers, sqlite3]) + emu_deps = [] + if get_option('engine') == 'unicorn' + emu_deps += cc.find_library('unicorn', dirs: [meson.current_source_dir()+'/deps/unicorn/build']) + endif executable('ish', [build_linux], link_with: [libfakefs], dependencies: [ @@ -176,7 +182,7 @@ elif get_option('kernel') == 'linux' libdl, threads, declare_dependency(link_whole: modules), - ]) + ] + emu_deps) endif subdir('tools') diff --git a/meson_options.txt b/meson_options.txt index fdba8e20b9..4ff0b3ecfc 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,7 +2,7 @@ option('log', type: 'string', value: '') option('nolog', type: 'string', value: '') option('log_handler', type: 'string', value: 'dprintf') -option('engine', type: 'combo', choices: ['asbestos'], value: 'asbestos') +option('engine', type: 'combo', choices: ['asbestos', 'unicorn'], value: 'asbestos') option('kernel', type: 'combo', choices: ['ish', 'linux'], value: 'ish') option('kconfig', type: 'array', value: [])