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"

choice
  prompt "Choose log level"
  default LOG_TRACE
config LOG_TRACE
  bool "trace"
config LOG_INFO
  bool "info"
config LOG_WARNING
  bool "warning"
config LOG_ERROR
  bool "error"
endchoice

config LOG_LEVEL
  int
  default 1 if LOG_ERROR
  default 2 if LOG_WARNING
  default 3 if LOG_INFO
  default 4 if LOG_TRACE
  default 0

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 tracing"
  default y
  help
    Instraction tracing will log past instructions into a ring buffer
    and print them when NEMU exit unexpectedly.

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

config ITRACE_BUFFER
  depends on ITRACE
  int "Buffer size for intruction trace (unit: number of instructions)"
  default 10

config MTRACE
  depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
  bool "Enable memory tracing"
  default n

config MTRACE_RANGE
  depends on MTRACE
  string "Memory trace active range"
  default "0x0-0xfffffff"
  help
    Memory tracer will only print memory access in these ranges.
    Use comma to seperate between ranges.

config MTRACE_RANGE_MAX
  depends on MTRACE
  int "Max range count in MTRACE_RANGE"
  default 10

config FTRACE
  depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
  bool "Enable function tracing"
  default n

config FTRACE_STACK_SIZE
  depends on FTRACE
  int "Max function track stack size"
  default 256

config FTRACE_LOG
  depends on FTRACE
  bool "Print log when entering a funciton"
  default n

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