mainmenu "NEMU Configuration Menu"

choice
  prompt "Base ISA"
  default ISA_riscv
config ISA_x86
  bool "x86"
config ISA_mips32
  bool "mips32"
config ISA_riscv
  bool "riscv"
config ISA_loongarch32r
  bool "loongarch32r"
endchoice

config ISA
  string
  default "x86" if ISA_x86
  default "mips32" if ISA_mips32
  default "riscv32" if ISA_riscv && !RV64
  default "riscv64" if ISA_riscv &&  RV64
  default "loongarch32r" if ISA_loongarch32r
  default "none"

config ISA64
  depends on ISA_riscv && RV64
  bool
  default y


if ISA_riscv
source "src/isa/riscv32/Kconfig"
endif

choice
  prompt "NEMU execution engine"
  default ENGINE_INTERPRETER

config ENGINE_INTERPRETER
  bool "Interpreter"
  help
    Interpreter guest instructions one by one.
endchoice

config ENGINE
  string
  default "interpreter" if ENGINE_INTERPRETER
  default "none"

choice
  prompt "Running mode"
  default MODE_SYSTEM

config MODE_SYSTEM
  bool "System mode"
  help
    Support full-system functionality, including privileged instructions, MMU and devices.
endchoice

choice
  prompt "Build target"
  default TARGET_NATIVE_ELF
config TARGET_NATIVE_ELF
  bool "Executable on Linux Native"
config TARGET_SHARE
  bool "Shared object (used as REF for differential testing)"
config TARGET_AM
  bool "Application on Abstract-Machine (DON'T CHOOSE)"
endchoice

menu "Build Options"
choice
  prompt "Compiler"
  default CC_GCC
config CC_GCC
  bool "gcc"
config CC_GPP
  bool "g++"
config CC_CLANG
  depends on !TARGET_AM
  bool "clang"
endchoice

config CC
  string
  default "gcc" if CC_GCC
  default "g++" if CC_GPP
  default "clang" if CC_CLANG
  default "none"

choice
  prompt "Optimization Level"
  default CC_O2
config CC_O0
  bool "O0"
config CC_O1
  bool "O1"
config CC_O2
  bool "O2"
config CC_O3
  bool "O3"
endchoice

config CC_OPT
  string
  default "-O0" if CC_O0
  default "-O1" if CC_O1
  default "-O2" if CC_O2
  default "-O3" if CC_O3
  default "none"

config CC_LTO
  depends on !TARGET_AM
  bool "Enable link-time optimization"
  default n

config CC_DEBUG
  bool "Enable debug information"
  default n

config CC_ASAN
  depends on MODE_SYSTEM
  bool "Enable address sanitizer"
  default n
endmenu

menu "Testing and Debugging"


config TRACE
  bool "Enable tracer"
  default y

config TRACE_START
  depends on TRACE
  int "When tracing is enabled (unit: number of instructions)"
  default 0

config TRACE_END
  depends on TRACE
  int "When tracing is disabled (unit: number of instructions)"
  default 10000

config ITRACE
  depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
  bool "Enable instruction tracer"
  default y

config ITRACE_COND
  depends on ITRACE
  string "Only trace instructions when the condition is true"
  default "true"


config DIFFTEST
  depends on TARGET_NATIVE_ELF
  bool "Enable differential testing"
  default n
  help
    Enable differential testing with a reference design.
    Note that this will significantly reduce the performance of NEMU.

choice
  prompt "Reference design"
  default DIFFTEST_REF_SPIKE if ISA_riscv
  default DIFFTEST_REF_KVM if ISA_x86
  default DIFFTEST_REF_QEMU
  depends on DIFFTEST
config DIFFTEST_REF_QEMU
  bool "QEMU, communicate with socket"
if ISA_riscv
config DIFFTEST_REF_SPIKE
  bool "Spike"
endif
if ISA_x86
config DIFFTEST_REF_KVM
  bool "KVM"
endif
endchoice

config DIFFTEST_REF_PATH
  string
  default "tools/qemu-diff" if DIFFTEST_REF_QEMU
  default "tools/kvm-diff" if DIFFTEST_REF_KVM
  default "tools/spike-diff" if DIFFTEST_REF_SPIKE
  default "none"

config DIFFTEST_REF_NAME
  string
  default "qemu" if DIFFTEST_REF_QEMU
  default "kvm" if DIFFTEST_REF_KVM
  default "spike" if DIFFTEST_REF_SPIKE
  default "none"
endmenu

if MODE_SYSTEM
source "src/memory/Kconfig"
source "src/device/Kconfig"
endif


menu "Miscellaneous"
choice
  depends on !TARGET_AM
  prompt "Host timer"
  default TIMER_GETTIMEOFDAY
config TIMER_GETTIMEOFDAY
  bool "gettimeofday"
config TIMER_CLOCK_GETTIME
  bool "clock_gettime"
endchoice

config RT_CHECK
  bool "Enable runtime checking"
  default y

endmenu