

set(
  H2_SRC
  "sched/switch/switch.v${ARCHV}opt.S"
  "sched/resched/resched.ref.c"
  "sched/dosched/dosched.ref.c"
  "sched/check_sanity/check_sanity.v${ARCHV}opt.S"
  "sched/yield/yield.ref.c"
  "sched/lowprio/lowprio.ref.c"
  "futex/futex_common/futex_common.v${ARCHV}opt.S"
  "futex/futex_classic/futex_classic.v${ARCHV}opt.S"
  "futex/futex_misc/futex_misc.v${ARCHV}opt.S"
  "futex/futex_pi/futex_pi.v${ARCHV}opt.S"
  "data/thread/thread.ref.c"
  "data/readylist/readylist.ref.c"
  "data/intconfig/intconfig.ref.c"
  "data/stacks/stacks.ref.S"
  "data/runlist/runlist.ref.c"
  "data/globals/globals.ref.c"
  "data/context/context.v${ARCHV}opt.S"
  "data/vm/vm.ref.c"
  "error/fatal/fatal.ref.c"
  "util/spinlock/spinlock.ref.S"
  "util/hw/hw.ref.c"
  "util/cache/cache.ref.S"
  "util/bzero/bzero.ref.c"
  "util/tree/tree.v${ARCHV}opt.S"
  "util/ring/ring.v${ARCHV}opt.S"
  "util/stmode/stmode.ref.c"
  "util/log/log.ref.c"
  "util/trace/trace.v${ARCHV}opt.S"
  "thread/id/id.ref.c"
  "thread/create/create.ref.c"
  "thread/stop/stop.ref.c"
  "thread/state/state.ref.c"
  "mem/tlbmiss/tlbmiss.ref.S"
  "mem/linear/linear.ref.c"
  "mem/safemem/safemem.v${ARCHV}opt.S"
  "mem/pagefault/pagefault.ref.c"
  "mem/asid/asid.ref.c"
  "mem/alloc/alloc.ref.c"
  "mem/tlbfill/tlbfill.ref.c"
  "mem/tlbfill/tlbinsert.ref.c"
  "mem/pagewalk/pagewalk.ref.c"
  "mem/tlbmisc/tlbmisc.ref.c"
  "mem/stlb/stlb.v${ARCHV}opt.S"
  "mem/stlb/stlb.all.c"
  "mem/varadix/varadix.ref.c"
  "mem/offset/offset.ref.c"
  "mem/tmpmap/tmpmap.ref.c"
  "mem/translate/translate.ref.c"
  "event/popup/popup.v${ARCHV}opt.S"
  "event/error/error.ref.S"
  "event/interrupt/interrupt.v${ARCHV}opt.S"
  "event/trap/trap.v${ARCHV}opt.S"
  "event/passthru/passthru.ref.c"
  "event/preempt/preempt.v${ARCHV}opt.S"
  "event/fastint/fastint.v${ARCHV}opt.S"
  "event/intpool/intpool.ref.c"
  "event/vectors/vectors.ref.S"
  "init/setup/setup.ref.c"
  "init/boot/boot.ref.S"
  "init/tcm/tcm.ref.c"
  "init/subsystem/subsystem.ref.c"
  "init/l2cache/l2cache.ref.c"
  "power/hlx/hlx.ref.c"
  "power/hmx/hmx.ref.c"
  "power/hvx/hvx.ref.c"
  "prof/sample/sample.ref.c"
  "traps/waitcycles/waitcycles.ref.c"
  "traps/tid/tid.ref.c"
  "traps/cputime/cputime.ref.c"
  "traps/angel/angel.ref.S"
  "traps/config/config.ref.c"
  "traps/prio/prio.ref.c"
  "traps/pmu/pmu.ref.c"
  "traps/tlb/tlb.ref.c"
  "traps/info/info.ref.c"
  "traps/hwconfig/hwconfig.ref.c"
  "vm/vmcache/vmcache.ref.c"
  "vm/vmtrap/vmtrap.v${ARCHV}opt.S"
  "vm/vmevent/vmevent.v${ARCHV}opt.S"
  "vm/shint/shint.v${ARCHV}opt.S"
  "vm/vmop/vmop.ref.c"
  "vm/vmint/vmint.v${ARCHV}opt.S"
  "vm/vmipi/vmipi.ref.c"
  "vm/vmmap/vmmap.ref.c"
  "vm/cpuint/cpuint.v${ARCHV}opt.S"
  "vm/badint/badint.ref.c"
  "vm/vmwork/vmwork.ref.c"
  "vm/vmfuncs/vmfuncs.v${ARCHV}opt.S"
  "vm/vmfuncs/vmfuncs.all.c"
  "time/timer/timer.v${ARCHV}opt.S")


add_library(h2kernel STATIC ${H2_SRC})

target_compile_options(
  h2kernel
  PRIVATE
          "-mhvx"
          "-mhvx-length=128B"
          "-ffixed-r20"
          "-ffixed-r21"
          "-ffixed-r22"
          "-ffixed-r23"
          "-ffixed-r24"
          "-ffixed-r25"
          "-ffixed-r26"
          "-ffixed-r27"
          "-ffixed-r28"
          "-DNULL_ANGEL_TRAP"
          "-DH2K_LINK_ADDR=${H2K_LINK_ADDR}"
          "-DH2K_GUEST_END=${H2K_GUEST_END}"
          "-DH2K_GIT_COMMIT=${GIT_COMMIT}")

target_include_directories(
  h2kernel PRIVATE 
        ${CMAKE_CURRENT_BINARY_DIR}/include
        ${CMAKE_CURRENT_BINARY_DIR}/../include
  )

