# Connect to a mult-icore RISC-V target, exposing each hart as a thread.
adapter_khz     10000

interface remote_bitbang
remote_bitbang_host $::env(REMOTE_BITBANG_HOST)
remote_bitbang_port $::env(REMOTE_BITBANG_PORT)

jtag newtap riscv.0 cpu -irlen 5 -expected-id 0x10e31913
jtag newtap riscv.1 cpu -irlen 5 -expected-id 0x10e31913

target create riscv.0.cpu0 riscv -chain-position riscv.0.cpu -coreid 0
target create riscv.0.cpu1 riscv -chain-position riscv.0.cpu -coreid 1
target create riscv.1.cpu0 riscv -chain-position riscv.1.cpu -coreid 0
target create riscv.1.cpu1 riscv -chain-position riscv.1.cpu -coreid 1

riscv.0.cpu0 configure -work-area-phys $::env(WORK_AREA) -work-area-size 8096 -work-area-backup 1
riscv.0.cpu1 configure -work-area-phys $::env(WORK_AREA) -work-area-size 8096 -work-area-backup 1
riscv.1.cpu0 configure -work-area-phys $::env(WORK_AREA) -work-area-size 8096 -work-area-backup 1
riscv.1.cpu1 configure -work-area-phys $::env(WORK_AREA) -work-area-size 8096 -work-area-backup 1

gdb_report_data_abort enable
gdb_report_register_access_error enable

# Expose an unimplemented CSR so we can test non-existent register access
# behavior.
foreach t [target names] {
    targets $t
    riscv expose_csrs 2288
    riscv expose_custom 1,12345-12348
}

init

targets riscv.0.cpu0
set challenge [riscv authdata_read]
riscv authdata_write [expr $challenge + 1]

targets riscv.1.cpu0
set challenge [riscv authdata_read]
riscv authdata_write [expr $challenge + 1]

foreach t [target names] {
    targets $t
    halt
    arm semihosting enable
}
