# SPDX-License-Identifier: Apache-2.0
if(${CONFIG_SOC_NSIM_HS_SMP})
# mdb is required to run nsim multicore targets
find_program(
  MDB
  mdb
  )

if(${CONFIG_SOC_NSIM_HS_SMP})
 set(MDB_ARGS mdb_hs_smp.args)
endif()

add_custom_target(run
  COMMAND
  ${MDB} -pset=1 -psetname=core0 -prop=ident=0x00000050 -cmpd=soc
  @${BOARD_DIR}/support/${MDB_ARGS} ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME} &&
  ${MDB} -pset=2 -psetname=core1 -prop=download=2 -prop=ident=0x00000150 -cmpd=soc
  @${BOARD_DIR}/support/${MDB_ARGS} ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME} &&
  NSIM_MULTICORE=1 ${MDB} -multifiles=core0,core1 -cmpd=soc -run -cl
  DEPENDS ${logical_target_for_zephyr_elf}
  WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
  USES_TERMINAL
  )
else()
find_program(
  NSIM
  nsimdrv
  )

if(${CONFIG_SOC_NSIM_EM})
 set(NSIM_PROPS nsim_em.props)
elseif(${CONFIG_SOC_NSIM_EM7D_V22})
 set(NSIM_PROPS nsim_em7d_v22.props)
elseif(${CONFIG_SOC_NSIM_SEM})
 set(NSIM_PROPS nsim_sem.props)
elseif(${CONFIG_SOC_NSIM_HS})
 set(NSIM_PROPS nsim_hs.props)
endif()


#  ARCv3/64 HS68:
#  nsimdrv -p nsim_profiling=0 -p maxlastpc=0 -p trace_enabled=0 -p nsim_isa_family=arc64 -p nsim_isa_core=1 -p arcver=113 -p nsim_isa_atomic_option=1 -p nsim_isa_shift_option=3 -p nsim_isa_code_density_option=2 -p nsim_isa_div_rem_option=2 -p nsim_isa_swap_option=1 -p nsim_isa_bitscan_option=1 -p nsim_isa_enable_timer_0=1 -p nsim_isa_enable_timer_1=1 -p nsim_isa_has_interrupts=1 -p nsim_isa_dual_issue_option=1 -p nsim_isa_div64_option=1 -p nsim_isa_mpy64=1 -p nsim_isa_mpy_option=9 -p nsim_hostlink=1 -p gverbose=0 -p nsim_isa_addr_size=64 -p nsim_isa_pc_size=64 -p nsim_mem-dev=uart0,kind=dwuart,base=0xf0000000,irq=24 -p port=0x378 -- ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME}

add_custom_target(run
  COMMAND
  ${NSIM}
  -propsfile
  ${BOARD_DIR}/support/${NSIM_PROPS}
  ${APPLICATION_BINARY_DIR}/zephyr/${KERNEL_ELF_NAME}
  DEPENDS ${logical_target_for_zephyr_elf}
  WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
  USES_TERMINAL
  )

add_custom_target(debugserver
  COMMAND
  ${NSIM}
  -propsfile
  ${BOARD_DIR}/support/${NSIM_PROPS}
  -gdb -port=3333
  DEPENDS ${logical_target_for_zephyr_elf}
  WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
  USES_TERMINAL
  )
endif()
