#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for RISC-V ISA Simulator ?.
+# Generated by GNU Autoconf 2.69 for RISC-V ISA Simulator ?.
#
# Report bugs to <Andrew Waterman>.
#
#
-# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
-# Foundation, Inc.
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
#
#
# This configure script is free software; the Free Software Foundation
# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+# Use a proper internal environment variable to ensure we don't fall
+ # into an infinite loop, continuously re-executing ourselves.
+ if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+ _as_can_reexec=no; export _as_can_reexec;
+ # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+ *v*x* | *x*v* ) as_opts=-vx ;;
+ *v* ) as_opts=-v ;;
+ *x* ) as_opts=-x ;;
+ * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+ fi
+ # We don't want this to propagate to other subprocesses.
+ { _as_can_reexec=; unset _as_can_reexec;}
if test "x$CONFIG_SHELL" = x; then
as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
emulate sh
else
exitcode=1; echo positional parameters were not saved.
fi
-test x\$exitcode = x0 || exit 1"
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
if test "x$CONFIG_SHELL" != x; then :
- # We cannot yet assume a decent shell, so we have to provide a
- # neutralization value for shells without unset; and this also
- # works around shells that cannot unset nonexistent variables.
- # Preserve -v and -x to the replacement shell.
- BASH_ENV=/dev/null
- ENV=/dev/null
- (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
- export CONFIG_SHELL
- case $- in # ((((
- *v*x* | *x*v* ) as_opts=-vx ;;
- *v* ) as_opts=-v ;;
- *x* ) as_opts=-x ;;
- * ) as_opts= ;;
- esac
- exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"}
+ export CONFIG_SHELL
+ # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+ *v*x* | *x*v* ) as_opts=-vx ;;
+ *v* ) as_opts=-v ;;
+ *x* ) as_opts=-x ;;
+ * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
fi
if test x$as_have_required = xno; then :
} # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+ test -f "$1" && test -x "$1"
+} # as_fn_executable_p
# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
chmod +x "$as_me.lineno" ||
{ $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+ # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+ # already done that, so ensure we don't try to do so again and fall
+ # in an infinite loop. This has already happened in practice.
+ _as_can_reexec=no; export _as_can_reexec
# Don't try to exec as it changes $[0], causing all sort of problems
# (the dirname of $[0] is not the place where we might find the
# original and so on. Autoconf is especially sensitive to this).
# ... but there are two gotchas:
# 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
# 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
- # In both cases, we have to default to `cp -p'.
+ # In both cases, we have to default to `cp -pR'.
ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
elif ln conf$$.file conf$$ 2>/dev/null; then
as_ln_s=ln
else
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
fi
else
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
fi
rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
rmdir conf$$.dir 2>/dev/null
as_mkdir_p=false
fi
-if test -x / >/dev/null 2>&1; then
- as_test_x='test -x'
-else
- if ls -dL / >/dev/null 2>&1; then
- as_ls_L_option=L
- else
- as_ls_L_option=
- fi
- as_test_x='
- eval sh -c '\''
- if test -d "$1"; then
- test -d "$1/.";
- else
- case $1 in #(
- -*)set "./$1";;
- esac;
- case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
- ???[sx]*):;;*)false;;esac;fi
- '\'' sh
- '
-fi
-as_executable_p=$as_test_x
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
if test "x$host_alias" != x; then
if test "x$build_alias" = x; then
cross_compiling=maybe
- $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host.
- If a cross compiler is detected then cross compile mode will be used" >&2
elif test "x$build_alias" != "x$host_alias"; then
cross_compiling=yes
fi
if $ac_init_version; then
cat <<\_ACEOF
RISC-V ISA Simulator configure ?
-generated by GNU Autoconf 2.68
+generated by GNU Autoconf 2.69
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2012 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
test ! -s conftest.err
} && test -s conftest$ac_exeext && {
test "$cross_compiling" = yes ||
- $as_test_x conftest$ac_exeext
+ test -x conftest$ac_exeext
}; then :
ac_retval=0
else
running configure, to aid debugging if configure makes a mistake.
It was created by RISC-V ISA Simulator $as_me ?, which was
-generated by GNU Autoconf 2.68. Invocation command line was
+generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="${ac_tool_prefix}gcc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_CC="gcc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="${ac_tool_prefix}cc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
ac_prog_rejected=yes
continue
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_CC="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
/* end confdefs.h. */
#include <stdarg.h>
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_CXX="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_AR="${ac_tool_prefix}ar"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_AR="ar"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_RANLIB="ranlib"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
# by default.
for ac_prog in ginstall scoinst install; do
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
if test $ac_prog = install &&
grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
# AIX install. It has an incompatible calling convention.
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_stow="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_RUN="$ac_tool_prefix$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_RUN="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
for ac_prog in grep ggrep; do
for ac_exec_ext in '' $ac_executable_extensions; do
ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
- { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+ as_fn_executable_p "$ac_path_GREP" || continue
# Check for GNU ac_path_GREP and select it if it is found.
# Check for GNU $ac_path_GREP
case `"$ac_path_GREP" --version 2>&1` in
for ac_prog in egrep; do
for ac_exec_ext in '' $ac_executable_extensions; do
ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
- { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+ as_fn_executable_p "$ac_path_EGREP" || continue
# Check for GNU ac_path_EGREP and select it if it is found.
# Check for GNU $ac_path_EGREP
case `"$ac_path_EGREP" --version 2>&1` in
+ # Determine if this is a required or an optional subproject
+
+
+
+ # Determine if there is a group with the same name
+
+
+
+ # Create variations of the subproject name suitable for use as a CPP
+ # enabled define, a shell enabled variable, and a shell function
+
+
+
+
+
+
+
+
+
+
+
+ # Add subproject to our running list
+
+ subprojects="$subprojects spike"
+
+ # Process the subproject appropriately. If enabled add it to the
+ # $enabled_subprojects running shell variable, set a
+ # SUBPROJECT_ENABLED C define, and include the appropriate
+ # 'subproject.ac'.
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: configuring default subproject : spike" >&5
+$as_echo "$as_me: configuring default subproject : spike" >&6;}
+ ac_config_files="$ac_config_files spike.mk:spike/spike.mk.in"
+
+ enable_spike_sproj="yes"
+ subprojects_enabled="$subprojects_enabled spike"
+
+$as_echo "#define SPIKE_ENABLED /**/" >>confdefs.h
+
+
+
+
+
+
# Output make variables
# ... but there are two gotchas:
# 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
# 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
- # In both cases, we have to default to `cp -p'.
+ # In both cases, we have to default to `cp -pR'.
ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
elif ln conf$$.file conf$$ 2>/dev/null; then
as_ln_s=ln
else
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
fi
else
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
fi
rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
rmdir conf$$.dir 2>/dev/null
as_mkdir_p=false
fi
-if test -x / >/dev/null 2>&1; then
- as_test_x='test -x'
-else
- if ls -dL / >/dev/null 2>&1; then
- as_ls_L_option=L
- else
- as_ls_L_option=
- fi
- as_test_x='
- eval sh -c '\''
- if test -d "$1"; then
- test -d "$1/.";
- else
- case $1 in #(
- -*)set "./$1";;
- esac;
- case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
- ???[sx]*):;;*)false;;esac;fi
- '\'' sh
- '
-fi
-as_executable_p=$as_test_x
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+ test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
# values after options handling.
ac_log="
This file was extended by RISC-V ISA Simulator $as_me ?, which was
-generated by GNU Autoconf 2.68. Invocation command line was
+generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
CONFIG_HEADERS = $CONFIG_HEADERS
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
RISC-V ISA Simulator config.status ?
-configured by $0, generated by GNU Autoconf 2.68,
+configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2012 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
if \$ac_cs_recheck; then
- set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+ set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
shift
\$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
CONFIG_SHELL='$SHELL'
"riscv.mk") CONFIG_FILES="$CONFIG_FILES riscv.mk:riscv/riscv.mk.in" ;;
"hwacha.mk") CONFIG_FILES="$CONFIG_FILES hwacha.mk:hwacha/hwacha.mk.in" ;;
"softfloat.mk") CONFIG_FILES="$CONFIG_FILES softfloat.mk:softfloat/softfloat.mk.in" ;;
+ "spike.mk") CONFIG_FILES="$CONFIG_FILES spike.mk:spike/spike.mk.in" ;;
"config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
# The '*' suffix indicates an optional subproject. The '**' suffix
# indicates an optional subproject which is also the name of a group.
-MCPPBS_SUBPROJECTS([ riscv, hwacha, softfloat ])
+MCPPBS_SUBPROJECTS([ riscv, hwacha, softfloat, spike ])
#-------------------------------------------------------------------------
# MCPPBS subproject groups
+++ /dev/null
-// See LICENSE for license details.
-
-#include "disasm.h"
-#include <string>
-#include <vector>
-#include <cstdarg>
-#include <sstream>
-#include <stdlib.h>
-
-static const char* xpr[] = {
- "zero", "ra", "s0", "s1", "s2", "s3", "s4", "s5",
- "s6", "s7", "s8", "s9", "s10", "s11", "sp", "tp",
- "v0", "v1", "a0", "a1", "a2", "a3", "a4", "a5",
- "a6", "a7", "t0", "t1", "t2", "t3", "t4", "gp"
-};
-
-static const char* fpr[] = {
- "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
- "fs8", "fs9", "fs10", "fs11", "fs12", "fs13", "fs14", "fs15",
- "fv0", "fv1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5",
- "fa6", "fa7", "ft0", "ft1", "ft2", "ft3", "ft4", "ft5"
-};
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return std::to_string((int)insn.i_imm()) + '(' + xpr[insn.rs1()] + ')';
- }
-} load_address;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return std::to_string((int)insn.s_imm()) + '(' + xpr[insn.rs1()] + ')';
- }
-} store_address;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return std::string("0(") + xpr[insn.rs1()] + ')';
- }
-} amo_address;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return xpr[insn.rd()];
- }
-} xrd;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return xpr[insn.rs1()];
- }
-} xrs1;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return xpr[insn.rs2()];
- }
-} xrs2;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return fpr[insn.rd()];
- }
-} frd;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return fpr[insn.rs1()];
- }
-} frs1;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return fpr[insn.rs2()];
- }
-} frs2;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return fpr[insn.rs3()];
- }
-} frs3;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- switch (insn.csr())
- {
- #define DECLARE_CSR(name, num) case num: return #name;
- #include "encoding.h"
- #undef DECLARE_CSR
- default: return "unknown";
- }
- }
-} csr;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return std::to_string((int)insn.i_imm());
- }
-} imm;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- std::stringstream s;
- s << std::hex << "0x" << ((uint32_t)insn.u_imm() >> 12);
- return s.str();
- }
-} bigimm;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- return std::to_string(insn.rs1());
- }
-} zimm5;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- std::stringstream s;
- int32_t target = insn.sb_imm();
- char sign = target >= 0 ? '+' : '-';
- s << "pc " << sign << ' ' << abs(target);
- return s.str();
- }
-} branch_target;
-
-struct : public arg_t {
- std::string to_string(insn_t insn) const {
- std::stringstream s;
- int32_t target = insn.sb_imm();
- char sign = target >= 0 ? '+' : '-';
- s << "pc " << sign << std::hex << " 0x" << abs(target);
- return s.str();
- }
-} jump_target;
-
-std::string disassembler_t::disassemble(insn_t insn)
-{
- const disasm_insn_t* disasm_insn = lookup(insn);
- return disasm_insn ? disasm_insn->to_string(insn) : "unknown";
-}
-
-disassembler_t::disassembler_t()
-{
- const uint32_t mask_rd = 0x1fUL << 7;
- const uint32_t match_rd_ra = 1UL << 7;
- const uint32_t mask_rs1 = 0x1fUL << 15;
- const uint32_t match_rs1_ra = 1UL << 15;
- const uint32_t mask_rs2 = 0x1fUL << 15;
- const uint32_t mask_imm = 0xfffUL << 20;
-
- #define DECLARE_INSN(code, match, mask) \
- const uint32_t match_##code = match; \
- const uint32_t mask_##code = mask;
- #include "encoding.h"
- #undef DECLARE_INSN
-
- // explicit per-instruction disassembly
- #define DISASM_INSN(name, code, extra, ...) \
- add_insn(new disasm_insn_t(name, match_##code, mask_##code | (extra), __VA_ARGS__));
- #define DEFINE_NOARG(code) \
- add_insn(new disasm_insn_t(#code, match_##code, mask_##code, {}));
- #define DEFINE_RTYPE(code) DISASM_INSN(#code, code, 0, {&xrd, &xrs1, &xrs2})
- #define DEFINE_ITYPE(code) DISASM_INSN(#code, code, 0, {&xrd, &xrs1, &imm})
- #define DEFINE_I0TYPE(name, code) DISASM_INSN(name, code, mask_rs1, {&xrd, &imm})
- #define DEFINE_I1TYPE(name, code) DISASM_INSN(name, code, mask_imm, {&xrd, &xrs1})
- #define DEFINE_I2TYPE(name, code) DISASM_INSN(name, code, mask_rd | mask_imm, {&xrs1})
- #define DEFINE_LTYPE(code) DISASM_INSN(#code, code, 0, {&xrd, &bigimm})
- #define DEFINE_BTYPE(code) DISASM_INSN(#code, code, 0, {&xrs1, &xrs2, &branch_target})
- #define DEFINE_B0TYPE(name, code) DISASM_INSN(name, code, mask_rs1 | mask_rs2, {&branch_target})
- #define DEFINE_B1TYPE(name, code) DISASM_INSN(name, code, mask_rs2, {&xrs1, &branch_target})
- #define DEFINE_XLOAD(code) DISASM_INSN(#code, code, 0, {&xrd, &load_address})
- #define DEFINE_XSTORE(code) DISASM_INSN(#code, code, 0, {&xrs2, &store_address})
- #define DEFINE_XAMO(code) DISASM_INSN(#code, code, 0, {&xrd, &xrs2, &amo_address})
- #define DEFINE_FLOAD(code) DISASM_INSN(#code, code, 0, {&frd, &load_address})
- #define DEFINE_FSTORE(code) DISASM_INSN(#code, code, 0, {&frs2, &store_address})
- #define DEFINE_FRTYPE(code) DISASM_INSN(#code, code, 0, {&frd, &frs1, &frs2})
- #define DEFINE_FR1TYPE(code) DISASM_INSN(#code, code, 0, {&frd, &frs1})
- #define DEFINE_FR3TYPE(code) DISASM_INSN(#code, code, 0, {&frd, &frs1, &frs2, &frs3})
- #define DEFINE_FXTYPE(code) DISASM_INSN(#code, code, 0, {&xrd, &frs1})
- #define DEFINE_XFTYPE(code) DISASM_INSN(#code, code, 0, {&frd, &xrs1})
-
- DEFINE_XLOAD(lb)
- DEFINE_XLOAD(lbu)
- DEFINE_XLOAD(lh)
- DEFINE_XLOAD(lhu)
- DEFINE_XLOAD(lw)
- DEFINE_XLOAD(lwu)
- DEFINE_XLOAD(ld)
-
- DEFINE_XSTORE(sb)
- DEFINE_XSTORE(sh)
- DEFINE_XSTORE(sw)
- DEFINE_XSTORE(sd)
-
- DEFINE_XAMO(amoadd_w)
- DEFINE_XAMO(amoswap_w)
- DEFINE_XAMO(amoand_w)
- DEFINE_XAMO(amoor_w)
- DEFINE_XAMO(amoxor_w)
- DEFINE_XAMO(amomin_w)
- DEFINE_XAMO(amomax_w)
- DEFINE_XAMO(amominu_w)
- DEFINE_XAMO(amomaxu_w)
- DEFINE_XAMO(amoadd_d)
- DEFINE_XAMO(amoswap_d)
- DEFINE_XAMO(amoand_d)
- DEFINE_XAMO(amoor_d)
- DEFINE_XAMO(amoxor_d)
- DEFINE_XAMO(amomin_d)
- DEFINE_XAMO(amomax_d)
- DEFINE_XAMO(amominu_d)
- DEFINE_XAMO(amomaxu_d)
-
- DEFINE_XAMO(lr_w)
- DEFINE_XAMO(sc_w)
- DEFINE_XAMO(lr_d)
- DEFINE_XAMO(sc_d)
-
- DEFINE_FLOAD(flw)
- DEFINE_FLOAD(fld)
-
- DEFINE_FSTORE(fsw)
- DEFINE_FSTORE(fsd)
-
- add_insn(new disasm_insn_t("j", match_jal, mask_jal | mask_rd, {&jump_target}));
- add_insn(new disasm_insn_t("jal", match_jal | match_rd_ra, mask_jal | mask_rd, {&jump_target}));
- add_insn(new disasm_insn_t("jal", match_jal, mask_jal, {&xrd, &jump_target}));
-
- DEFINE_B0TYPE("b", beq);
- DEFINE_B1TYPE("beqz", beq);
- DEFINE_B1TYPE("bnez", bne);
- DEFINE_B1TYPE("bltz", blt);
- DEFINE_B1TYPE("bgez", bge);
- DEFINE_BTYPE(beq)
- DEFINE_BTYPE(bne)
- DEFINE_BTYPE(blt)
- DEFINE_BTYPE(bge)
- DEFINE_BTYPE(bltu)
- DEFINE_BTYPE(bgeu)
-
- DEFINE_LTYPE(lui);
- DEFINE_LTYPE(auipc);
-
- DEFINE_I2TYPE("jr", jalr);
- add_insn(new disasm_insn_t("jalr", match_jalr | match_rd_ra, mask_jalr | mask_rd | mask_imm, {&xrs1}));
- add_insn(new disasm_insn_t("ret", match_jalr | match_rs1_ra, mask_jalr | mask_rd | mask_rs1 | mask_imm, {}));
- DEFINE_ITYPE(jalr);
-
- add_insn(new disasm_insn_t("nop", match_addi, mask_addi | mask_rd | mask_rs1 | mask_imm, {}));
- DEFINE_I0TYPE("li", addi);
- DEFINE_I1TYPE("move", addi);
- DEFINE_ITYPE(addi);
- DEFINE_ITYPE(slli);
- DEFINE_ITYPE(slti);
- DEFINE_ITYPE(sltiu);
- DEFINE_ITYPE(xori);
- DEFINE_ITYPE(srli);
- DEFINE_ITYPE(srai);
- DEFINE_ITYPE(ori);
- DEFINE_ITYPE(andi);
- DEFINE_ITYPE(addiw);
- DEFINE_ITYPE(slliw);
- DEFINE_ITYPE(srliw);
- DEFINE_ITYPE(sraiw);
-
- DEFINE_RTYPE(add);
- DEFINE_RTYPE(sub);
- DEFINE_RTYPE(sll);
- DEFINE_RTYPE(slt);
- DEFINE_RTYPE(sltu);
- DEFINE_RTYPE(xor);
- DEFINE_RTYPE(srl);
- DEFINE_RTYPE(sra);
- DEFINE_RTYPE(or);
- DEFINE_RTYPE(and);
- DEFINE_RTYPE(mul);
- DEFINE_RTYPE(mulh);
- DEFINE_RTYPE(mulhu);
- DEFINE_RTYPE(mulhsu);
- DEFINE_RTYPE(div);
- DEFINE_RTYPE(divu);
- DEFINE_RTYPE(rem);
- DEFINE_RTYPE(remu);
- DEFINE_RTYPE(addw);
- DEFINE_RTYPE(subw);
- DEFINE_RTYPE(sllw);
- DEFINE_RTYPE(srlw);
- DEFINE_RTYPE(sraw);
- DEFINE_RTYPE(mulw);
- DEFINE_RTYPE(divw);
- DEFINE_RTYPE(divuw);
- DEFINE_RTYPE(remw);
- DEFINE_RTYPE(remuw);
-
- DEFINE_NOARG(scall);
- DEFINE_NOARG(sbreak);
- DEFINE_NOARG(fence);
- DEFINE_NOARG(fence_i);
-
- add_insn(new disasm_insn_t("csrr", match_csrrs, mask_csrrs | mask_rs1, {&xrd, &csr}));
- add_insn(new disasm_insn_t("csrw", match_csrrw, mask_csrrw | mask_rd, {&csr, &xrs1}));
- add_insn(new disasm_insn_t("csrrw", match_csrrw, mask_csrrw, {&xrd, &csr, &xrs1}));
- add_insn(new disasm_insn_t("csrrs", match_csrrs, mask_csrrs, {&xrd, &csr, &xrs1}));
- add_insn(new disasm_insn_t("csrrc", match_csrrc, mask_csrrc, {&xrd, &csr, &xrs1}));
- add_insn(new disasm_insn_t("csrrwi", match_csrrwi, mask_csrrwi, {&xrd, &csr, &zimm5}));
- add_insn(new disasm_insn_t("csrrsi", match_csrrsi, mask_csrrsi, {&xrd, &csr, &zimm5}));
- add_insn(new disasm_insn_t("csrrci", match_csrrci, mask_csrrci, {&xrd, &csr, &zimm5}));
- DEFINE_NOARG(sret)
-
- DEFINE_FRTYPE(fadd_s);
- DEFINE_FRTYPE(fsub_s);
- DEFINE_FRTYPE(fmul_s);
- DEFINE_FRTYPE(fdiv_s);
- DEFINE_FR1TYPE(fsqrt_s);
- DEFINE_FRTYPE(fmin_s);
- DEFINE_FRTYPE(fmax_s);
- DEFINE_FR3TYPE(fmadd_s);
- DEFINE_FR3TYPE(fmsub_s);
- DEFINE_FR3TYPE(fnmadd_s);
- DEFINE_FR3TYPE(fnmsub_s);
- DEFINE_FRTYPE(fsgnj_s);
- DEFINE_FRTYPE(fsgnjn_s);
- DEFINE_FRTYPE(fsgnjx_s);
- DEFINE_FR1TYPE(fcvt_s_d);
- DEFINE_XFTYPE(fcvt_s_l);
- DEFINE_XFTYPE(fcvt_s_lu);
- DEFINE_XFTYPE(fcvt_s_w);
- DEFINE_XFTYPE(fcvt_s_wu);
- DEFINE_XFTYPE(fcvt_s_wu);
- DEFINE_XFTYPE(fmv_s_x);
- DEFINE_FXTYPE(fcvt_l_s);
- DEFINE_FXTYPE(fcvt_lu_s);
- DEFINE_FXTYPE(fcvt_w_s);
- DEFINE_FXTYPE(fcvt_wu_s);
- DEFINE_FXTYPE(fmv_x_s);
- DEFINE_FXTYPE(feq_s);
- DEFINE_FXTYPE(flt_s);
- DEFINE_FXTYPE(fle_s);
-
- DEFINE_FRTYPE(fadd_d);
- DEFINE_FRTYPE(fsub_d);
- DEFINE_FRTYPE(fmul_d);
- DEFINE_FRTYPE(fdiv_d);
- DEFINE_FR1TYPE(fsqrt_d);
- DEFINE_FRTYPE(fmin_d);
- DEFINE_FRTYPE(fmax_d);
- DEFINE_FR3TYPE(fmadd_d);
- DEFINE_FR3TYPE(fmsub_d);
- DEFINE_FR3TYPE(fnmadd_d);
- DEFINE_FR3TYPE(fnmsub_d);
- DEFINE_FRTYPE(fsgnj_d);
- DEFINE_FRTYPE(fsgnjn_d);
- DEFINE_FRTYPE(fsgnjx_d);
- DEFINE_FR1TYPE(fcvt_d_s);
- DEFINE_XFTYPE(fcvt_d_l);
- DEFINE_XFTYPE(fcvt_d_lu);
- DEFINE_XFTYPE(fcvt_d_w);
- DEFINE_XFTYPE(fcvt_d_wu);
- DEFINE_XFTYPE(fcvt_d_wu);
- DEFINE_XFTYPE(fmv_d_x);
- DEFINE_FXTYPE(fcvt_l_d);
- DEFINE_FXTYPE(fcvt_lu_d);
- DEFINE_FXTYPE(fcvt_w_d);
- DEFINE_FXTYPE(fcvt_wu_d);
- DEFINE_FXTYPE(fmv_x_d);
- DEFINE_FXTYPE(feq_d);
- DEFINE_FXTYPE(flt_d);
- DEFINE_FXTYPE(fle_d);
-
- // provide a default disassembly for all instructions as a fallback
- #define DECLARE_INSN(code, match, mask) \
- add_insn(new disasm_insn_t(#code " (args unknown)", match, mask, {}));
- #include "encoding.h"
- #undef DECLARE_INSN
-}
-
-const disasm_insn_t* disassembler_t::lookup(insn_t insn)
-{
- size_t idx = insn.bits() % HASH_SIZE;
- for (size_t j = 0; j < chain[idx].size(); j++)
- if(*chain[idx][j] == insn)
- return chain[idx][j];
-
- idx = HASH_SIZE;
- for (size_t j = 0; j < chain[idx].size(); j++)
- if(*chain[idx][j] == insn)
- return chain[idx][j];
-
- return NULL;
-}
-
-void disassembler_t::add_insn(disasm_insn_t* insn)
-{
- size_t idx = HASH_SIZE;
- if (insn->get_mask() % HASH_SIZE == HASH_SIZE - 1)
- idx = insn->get_match() % HASH_SIZE;
- chain[idx].push_back(insn);
-}
-
-disassembler_t::~disassembler_t()
-{
- for (size_t i = 0; i < HASH_SIZE+1; i++)
- for (size_t j = 0; j < chain[i].size(); j++)
- delete chain[i][j];
-}
#include "extension.h"
#include "trap.h"
-#include "dummy-rocc.h"
-#include "hwacha.h"
std::map<std::string, std::function<extension_t*()>>& extensions()
{
riscv_subproject_deps = \
softfloat \
- hwacha \
riscv_install_prog_srcs = \
- spike.cc \
- riscv-dis.cc \
- xspike.cc \
- termios-xspike.cc \
riscv_hdrs = \
htif.h \
+++ /dev/null
-// See LICENSE for license details.
-
-#include "sim.h"
-#include "htif.h"
-#include "cachesim.h"
-#include "extension.h"
-#include <fesvr/option_parser.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <vector>
-#include <string>
-#include <memory>
-
-static void help()
-{
- fprintf(stderr, "usage: spike [host options] <target program> [target options]\n");
- fprintf(stderr, "Host Options:\n");
- fprintf(stderr, " -p <n> Simulate <n> processors\n");
- fprintf(stderr, " -m <n> Provide <n> MB of target memory\n");
- fprintf(stderr, " -d Interactive debug mode\n");
- fprintf(stderr, " -h Print this help message\n");
- fprintf(stderr, " --ic=<S>:<W>:<B> Instantiate a cache model with S sets,\n");
- fprintf(stderr, " --dc=<S>:<W>:<B> W ways, and B-byte blocks (with S and\n");
- fprintf(stderr, " --l2=<S>:<W>:<B> B both powers of 2).\n");
- fprintf(stderr, " --extension=<name> Specify RoCC Extension\n");
- exit(1);
-}
-
-int main(int argc, char** argv)
-{
- bool debug = false;
- size_t nprocs = 1;
- size_t mem_mb = 0;
- std::unique_ptr<icache_sim_t> ic;
- std::unique_ptr<dcache_sim_t> dc;
- std::unique_ptr<cache_sim_t> l2;
- std::function<extension_t*()> extension;
-
- option_parser_t parser;
- parser.help(&help);
- parser.option('h', 0, 0, [&](const char* s){help();});
- parser.option('d', 0, 0, [&](const char* s){debug = true;});
- parser.option('p', 0, 1, [&](const char* s){nprocs = atoi(s);});
- parser.option('m', 0, 1, [&](const char* s){mem_mb = atoi(s);});
- parser.option(0, "ic", 1, [&](const char* s){ic.reset(new icache_sim_t(s));});
- parser.option(0, "dc", 1, [&](const char* s){dc.reset(new dcache_sim_t(s));});
- parser.option(0, "l2", 1, [&](const char* s){l2.reset(cache_sim_t::construct(s, "L2$"));});
- parser.option(0, "extension", 1, [&](const char* s){
- if (!extensions().count(s))
- fprintf(stderr, "unknown extension %s!\n", s), exit(-1);
- extension = extensions()[s];
- });
-
- auto argv1 = parser.parse(argv);
- if (!*argv1)
- help();
- std::vector<std::string> htif_args(argv1, (const char*const*)argv + argc);
- sim_t s(nprocs, mem_mb, htif_args);
-
- if (ic && l2) ic->set_miss_handler(&*l2);
- if (dc && l2) dc->set_miss_handler(&*l2);
- for (size_t i = 0; i < nprocs; i++)
- {
- if (ic) s.get_core(i)->get_mmu()->register_memtracer(&*ic);
- if (dc) s.get_core(i)->get_mmu()->register_memtracer(&*dc);
- if (extension) s.get_core(i)->register_extension(extension());
- }
-
- s.set_debug(debug);
- return s.run();
-}
+++ /dev/null
-// See LICENSE for license details.
-
-// termios-xspike sets up a canonical terminal and blocks forever.
-// It allows us to send Ctrl-C etc. to the target machine.
-
-#include <unistd.h>
-#include <termios.h>
-#include <signal.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-int main()
-{
- struct termios old_tios;
- if (tcgetattr(0, &old_tios) < 0)
- return -1;
-
- signal(SIGTERM, [](int) { });
-
- struct termios new_tios = old_tios;
- new_tios.c_lflag &= ~(ICANON | ECHO | ISIG);
- if (tcsetattr(0, TCSANOW, &new_tios) < 0)
- return -1;
-
- pause();
-
- return tcsetattr(0, TCSANOW, &old_tios);
-}
+++ /dev/null
-// See LICENSE for license details.
-
-// xspike forks an xterm for spike's target machine console,
-// preserving the current terminal for debugging.
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/wait.h>
-#include <cstdio>
-#include <climits>
-#include <cstring>
-#include <stdexcept>
-
-static pid_t fork_spike(int tty_fd, int argc, char** argv);
-static pid_t fork_xterm(int* tty_fd);
-
-int main(int argc, char** argv)
-{
- int tty_fd, wait_status, ret = -1;
- pid_t xterm, spike;
-
- static bool signal_exit = false;
- auto handle_signal = [](int) { signal_exit = true; };
-
- if ((xterm = fork_xterm(&tty_fd)) < 0)
- {
- fprintf(stderr, "could not open xterm\n");
- goto out;
- }
-
- signal(SIGINT, handle_signal);
-
- if ((spike = fork_spike(tty_fd, argc, argv)) < 0)
- {
- fprintf(stderr, "could not open spike\n");
- goto close_xterm;
- }
-
- while ((ret = waitpid(spike, &wait_status, 0)) < 0)
- if (signal_exit)
- break;
-
- if (ret < 0) // signal_exit
- kill(spike, SIGTERM);
- else
- ret = WIFEXITED(wait_status) ? WEXITSTATUS(wait_status) : -1;
-
-close_xterm:
- kill(-xterm, SIGTERM);
-out:
- return ret;
-}
-
-static pid_t fork_spike(int tty_fd, int argc, char** argv)
-{
- pid_t pid = fork();
- if (pid < 0)
- return -1;
-
- if (pid == 0)
- {
- if (dup2(tty_fd, STDIN_FILENO) < 0 || dup2(tty_fd, STDOUT_FILENO) < 0)
- return -1;
- execvp("spike", argv);
- return -1;
- }
-
- return pid;
-}
-
-static pid_t fork_xterm(int* tty_fd)
-{
- static const char cmd[] = "3>&1 xterm -title xspike -e sh -c 'tty 1>&3; termios-xspike'";
-
- int fds[2];
- if (pipe(fds) < 0)
- return -1;
-
- pid_t pid = fork();
- if (pid < 0)
- return -1;
-
- if (pid == 0)
- {
- setpgid(0, 0);
- if (dup2(fds[1], STDOUT_FILENO) < 0)
- return -1;
- execl("/bin/sh", "sh", "-c", cmd, NULL);
- return -1;
- }
-
- char tty[NAME_MAX];
- ssize_t ttylen = read(fds[0], tty, sizeof(tty));
- if (ttylen <= 1 || tty[ttylen-1] != '\n')
- return -1;
- tty[ttylen-1] = '\0';
- if ((*tty_fd = open(tty, O_RDWR)) < 0)
- return -1;
-
- return pid;
-}
--- /dev/null
+// See LICENSE for license details.
+
+#include "disasm.h"
+#include <string>
+#include <vector>
+#include <cstdarg>
+#include <sstream>
+#include <stdlib.h>
+
+static const char* xpr[] = {
+ "zero", "ra", "s0", "s1", "s2", "s3", "s4", "s5",
+ "s6", "s7", "s8", "s9", "s10", "s11", "sp", "tp",
+ "v0", "v1", "a0", "a1", "a2", "a3", "a4", "a5",
+ "a6", "a7", "t0", "t1", "t2", "t3", "t4", "gp"
+};
+
+static const char* fpr[] = {
+ "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
+ "fs8", "fs9", "fs10", "fs11", "fs12", "fs13", "fs14", "fs15",
+ "fv0", "fv1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5",
+ "fa6", "fa7", "ft0", "ft1", "ft2", "ft3", "ft4", "ft5"
+};
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return std::to_string((int)insn.i_imm()) + '(' + xpr[insn.rs1()] + ')';
+ }
+} load_address;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return std::to_string((int)insn.s_imm()) + '(' + xpr[insn.rs1()] + ')';
+ }
+} store_address;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return std::string("0(") + xpr[insn.rs1()] + ')';
+ }
+} amo_address;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return xpr[insn.rd()];
+ }
+} xrd;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return xpr[insn.rs1()];
+ }
+} xrs1;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return xpr[insn.rs2()];
+ }
+} xrs2;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return fpr[insn.rd()];
+ }
+} frd;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return fpr[insn.rs1()];
+ }
+} frs1;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return fpr[insn.rs2()];
+ }
+} frs2;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return fpr[insn.rs3()];
+ }
+} frs3;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ switch (insn.csr())
+ {
+ #define DECLARE_CSR(name, num) case num: return #name;
+ #include "encoding.h"
+ #undef DECLARE_CSR
+ default: return "unknown";
+ }
+ }
+} csr;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return std::to_string((int)insn.i_imm());
+ }
+} imm;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ std::stringstream s;
+ s << std::hex << "0x" << ((uint32_t)insn.u_imm() >> 12);
+ return s.str();
+ }
+} bigimm;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ return std::to_string(insn.rs1());
+ }
+} zimm5;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ std::stringstream s;
+ int32_t target = insn.sb_imm();
+ char sign = target >= 0 ? '+' : '-';
+ s << "pc " << sign << ' ' << abs(target);
+ return s.str();
+ }
+} branch_target;
+
+struct : public arg_t {
+ std::string to_string(insn_t insn) const {
+ std::stringstream s;
+ int32_t target = insn.sb_imm();
+ char sign = target >= 0 ? '+' : '-';
+ s << "pc " << sign << std::hex << " 0x" << abs(target);
+ return s.str();
+ }
+} jump_target;
+
+std::string disassembler_t::disassemble(insn_t insn)
+{
+ const disasm_insn_t* disasm_insn = lookup(insn);
+ return disasm_insn ? disasm_insn->to_string(insn) : "unknown";
+}
+
+disassembler_t::disassembler_t()
+{
+ const uint32_t mask_rd = 0x1fUL << 7;
+ const uint32_t match_rd_ra = 1UL << 7;
+ const uint32_t mask_rs1 = 0x1fUL << 15;
+ const uint32_t match_rs1_ra = 1UL << 15;
+ const uint32_t mask_rs2 = 0x1fUL << 15;
+ const uint32_t mask_imm = 0xfffUL << 20;
+
+ #define DECLARE_INSN(code, match, mask) \
+ const uint32_t match_##code = match; \
+ const uint32_t mask_##code = mask;
+ #include "encoding.h"
+ #undef DECLARE_INSN
+
+ // explicit per-instruction disassembly
+ #define DISASM_INSN(name, code, extra, ...) \
+ add_insn(new disasm_insn_t(name, match_##code, mask_##code | (extra), __VA_ARGS__));
+ #define DEFINE_NOARG(code) \
+ add_insn(new disasm_insn_t(#code, match_##code, mask_##code, {}));
+ #define DEFINE_RTYPE(code) DISASM_INSN(#code, code, 0, {&xrd, &xrs1, &xrs2})
+ #define DEFINE_ITYPE(code) DISASM_INSN(#code, code, 0, {&xrd, &xrs1, &imm})
+ #define DEFINE_I0TYPE(name, code) DISASM_INSN(name, code, mask_rs1, {&xrd, &imm})
+ #define DEFINE_I1TYPE(name, code) DISASM_INSN(name, code, mask_imm, {&xrd, &xrs1})
+ #define DEFINE_I2TYPE(name, code) DISASM_INSN(name, code, mask_rd | mask_imm, {&xrs1})
+ #define DEFINE_LTYPE(code) DISASM_INSN(#code, code, 0, {&xrd, &bigimm})
+ #define DEFINE_BTYPE(code) DISASM_INSN(#code, code, 0, {&xrs1, &xrs2, &branch_target})
+ #define DEFINE_B0TYPE(name, code) DISASM_INSN(name, code, mask_rs1 | mask_rs2, {&branch_target})
+ #define DEFINE_B1TYPE(name, code) DISASM_INSN(name, code, mask_rs2, {&xrs1, &branch_target})
+ #define DEFINE_XLOAD(code) DISASM_INSN(#code, code, 0, {&xrd, &load_address})
+ #define DEFINE_XSTORE(code) DISASM_INSN(#code, code, 0, {&xrs2, &store_address})
+ #define DEFINE_XAMO(code) DISASM_INSN(#code, code, 0, {&xrd, &xrs2, &amo_address})
+ #define DEFINE_FLOAD(code) DISASM_INSN(#code, code, 0, {&frd, &load_address})
+ #define DEFINE_FSTORE(code) DISASM_INSN(#code, code, 0, {&frs2, &store_address})
+ #define DEFINE_FRTYPE(code) DISASM_INSN(#code, code, 0, {&frd, &frs1, &frs2})
+ #define DEFINE_FR1TYPE(code) DISASM_INSN(#code, code, 0, {&frd, &frs1})
+ #define DEFINE_FR3TYPE(code) DISASM_INSN(#code, code, 0, {&frd, &frs1, &frs2, &frs3})
+ #define DEFINE_FXTYPE(code) DISASM_INSN(#code, code, 0, {&xrd, &frs1})
+ #define DEFINE_XFTYPE(code) DISASM_INSN(#code, code, 0, {&frd, &xrs1})
+
+ DEFINE_XLOAD(lb)
+ DEFINE_XLOAD(lbu)
+ DEFINE_XLOAD(lh)
+ DEFINE_XLOAD(lhu)
+ DEFINE_XLOAD(lw)
+ DEFINE_XLOAD(lwu)
+ DEFINE_XLOAD(ld)
+
+ DEFINE_XSTORE(sb)
+ DEFINE_XSTORE(sh)
+ DEFINE_XSTORE(sw)
+ DEFINE_XSTORE(sd)
+
+ DEFINE_XAMO(amoadd_w)
+ DEFINE_XAMO(amoswap_w)
+ DEFINE_XAMO(amoand_w)
+ DEFINE_XAMO(amoor_w)
+ DEFINE_XAMO(amoxor_w)
+ DEFINE_XAMO(amomin_w)
+ DEFINE_XAMO(amomax_w)
+ DEFINE_XAMO(amominu_w)
+ DEFINE_XAMO(amomaxu_w)
+ DEFINE_XAMO(amoadd_d)
+ DEFINE_XAMO(amoswap_d)
+ DEFINE_XAMO(amoand_d)
+ DEFINE_XAMO(amoor_d)
+ DEFINE_XAMO(amoxor_d)
+ DEFINE_XAMO(amomin_d)
+ DEFINE_XAMO(amomax_d)
+ DEFINE_XAMO(amominu_d)
+ DEFINE_XAMO(amomaxu_d)
+
+ DEFINE_XAMO(lr_w)
+ DEFINE_XAMO(sc_w)
+ DEFINE_XAMO(lr_d)
+ DEFINE_XAMO(sc_d)
+
+ DEFINE_FLOAD(flw)
+ DEFINE_FLOAD(fld)
+
+ DEFINE_FSTORE(fsw)
+ DEFINE_FSTORE(fsd)
+
+ add_insn(new disasm_insn_t("j", match_jal, mask_jal | mask_rd, {&jump_target}));
+ add_insn(new disasm_insn_t("jal", match_jal | match_rd_ra, mask_jal | mask_rd, {&jump_target}));
+ add_insn(new disasm_insn_t("jal", match_jal, mask_jal, {&xrd, &jump_target}));
+
+ DEFINE_B0TYPE("b", beq);
+ DEFINE_B1TYPE("beqz", beq);
+ DEFINE_B1TYPE("bnez", bne);
+ DEFINE_B1TYPE("bltz", blt);
+ DEFINE_B1TYPE("bgez", bge);
+ DEFINE_BTYPE(beq)
+ DEFINE_BTYPE(bne)
+ DEFINE_BTYPE(blt)
+ DEFINE_BTYPE(bge)
+ DEFINE_BTYPE(bltu)
+ DEFINE_BTYPE(bgeu)
+
+ DEFINE_LTYPE(lui);
+ DEFINE_LTYPE(auipc);
+
+ DEFINE_I2TYPE("jr", jalr);
+ add_insn(new disasm_insn_t("jalr", match_jalr | match_rd_ra, mask_jalr | mask_rd | mask_imm, {&xrs1}));
+ add_insn(new disasm_insn_t("ret", match_jalr | match_rs1_ra, mask_jalr | mask_rd | mask_rs1 | mask_imm, {}));
+ DEFINE_ITYPE(jalr);
+
+ add_insn(new disasm_insn_t("nop", match_addi, mask_addi | mask_rd | mask_rs1 | mask_imm, {}));
+ DEFINE_I0TYPE("li", addi);
+ DEFINE_I1TYPE("move", addi);
+ DEFINE_ITYPE(addi);
+ DEFINE_ITYPE(slli);
+ DEFINE_ITYPE(slti);
+ DEFINE_ITYPE(sltiu);
+ DEFINE_ITYPE(xori);
+ DEFINE_ITYPE(srli);
+ DEFINE_ITYPE(srai);
+ DEFINE_ITYPE(ori);
+ DEFINE_ITYPE(andi);
+ DEFINE_ITYPE(addiw);
+ DEFINE_ITYPE(slliw);
+ DEFINE_ITYPE(srliw);
+ DEFINE_ITYPE(sraiw);
+
+ DEFINE_RTYPE(add);
+ DEFINE_RTYPE(sub);
+ DEFINE_RTYPE(sll);
+ DEFINE_RTYPE(slt);
+ DEFINE_RTYPE(sltu);
+ DEFINE_RTYPE(xor);
+ DEFINE_RTYPE(srl);
+ DEFINE_RTYPE(sra);
+ DEFINE_RTYPE(or);
+ DEFINE_RTYPE(and);
+ DEFINE_RTYPE(mul);
+ DEFINE_RTYPE(mulh);
+ DEFINE_RTYPE(mulhu);
+ DEFINE_RTYPE(mulhsu);
+ DEFINE_RTYPE(div);
+ DEFINE_RTYPE(divu);
+ DEFINE_RTYPE(rem);
+ DEFINE_RTYPE(remu);
+ DEFINE_RTYPE(addw);
+ DEFINE_RTYPE(subw);
+ DEFINE_RTYPE(sllw);
+ DEFINE_RTYPE(srlw);
+ DEFINE_RTYPE(sraw);
+ DEFINE_RTYPE(mulw);
+ DEFINE_RTYPE(divw);
+ DEFINE_RTYPE(divuw);
+ DEFINE_RTYPE(remw);
+ DEFINE_RTYPE(remuw);
+
+ DEFINE_NOARG(scall);
+ DEFINE_NOARG(sbreak);
+ DEFINE_NOARG(fence);
+ DEFINE_NOARG(fence_i);
+
+ add_insn(new disasm_insn_t("csrr", match_csrrs, mask_csrrs | mask_rs1, {&xrd, &csr}));
+ add_insn(new disasm_insn_t("csrw", match_csrrw, mask_csrrw | mask_rd, {&csr, &xrs1}));
+ add_insn(new disasm_insn_t("csrrw", match_csrrw, mask_csrrw, {&xrd, &csr, &xrs1}));
+ add_insn(new disasm_insn_t("csrrs", match_csrrs, mask_csrrs, {&xrd, &csr, &xrs1}));
+ add_insn(new disasm_insn_t("csrrc", match_csrrc, mask_csrrc, {&xrd, &csr, &xrs1}));
+ add_insn(new disasm_insn_t("csrrwi", match_csrrwi, mask_csrrwi, {&xrd, &csr, &zimm5}));
+ add_insn(new disasm_insn_t("csrrsi", match_csrrsi, mask_csrrsi, {&xrd, &csr, &zimm5}));
+ add_insn(new disasm_insn_t("csrrci", match_csrrci, mask_csrrci, {&xrd, &csr, &zimm5}));
+ DEFINE_NOARG(sret)
+
+ DEFINE_FRTYPE(fadd_s);
+ DEFINE_FRTYPE(fsub_s);
+ DEFINE_FRTYPE(fmul_s);
+ DEFINE_FRTYPE(fdiv_s);
+ DEFINE_FR1TYPE(fsqrt_s);
+ DEFINE_FRTYPE(fmin_s);
+ DEFINE_FRTYPE(fmax_s);
+ DEFINE_FR3TYPE(fmadd_s);
+ DEFINE_FR3TYPE(fmsub_s);
+ DEFINE_FR3TYPE(fnmadd_s);
+ DEFINE_FR3TYPE(fnmsub_s);
+ DEFINE_FRTYPE(fsgnj_s);
+ DEFINE_FRTYPE(fsgnjn_s);
+ DEFINE_FRTYPE(fsgnjx_s);
+ DEFINE_FR1TYPE(fcvt_s_d);
+ DEFINE_XFTYPE(fcvt_s_l);
+ DEFINE_XFTYPE(fcvt_s_lu);
+ DEFINE_XFTYPE(fcvt_s_w);
+ DEFINE_XFTYPE(fcvt_s_wu);
+ DEFINE_XFTYPE(fcvt_s_wu);
+ DEFINE_XFTYPE(fmv_s_x);
+ DEFINE_FXTYPE(fcvt_l_s);
+ DEFINE_FXTYPE(fcvt_lu_s);
+ DEFINE_FXTYPE(fcvt_w_s);
+ DEFINE_FXTYPE(fcvt_wu_s);
+ DEFINE_FXTYPE(fmv_x_s);
+ DEFINE_FXTYPE(feq_s);
+ DEFINE_FXTYPE(flt_s);
+ DEFINE_FXTYPE(fle_s);
+
+ DEFINE_FRTYPE(fadd_d);
+ DEFINE_FRTYPE(fsub_d);
+ DEFINE_FRTYPE(fmul_d);
+ DEFINE_FRTYPE(fdiv_d);
+ DEFINE_FR1TYPE(fsqrt_d);
+ DEFINE_FRTYPE(fmin_d);
+ DEFINE_FRTYPE(fmax_d);
+ DEFINE_FR3TYPE(fmadd_d);
+ DEFINE_FR3TYPE(fmsub_d);
+ DEFINE_FR3TYPE(fnmadd_d);
+ DEFINE_FR3TYPE(fnmsub_d);
+ DEFINE_FRTYPE(fsgnj_d);
+ DEFINE_FRTYPE(fsgnjn_d);
+ DEFINE_FRTYPE(fsgnjx_d);
+ DEFINE_FR1TYPE(fcvt_d_s);
+ DEFINE_XFTYPE(fcvt_d_l);
+ DEFINE_XFTYPE(fcvt_d_lu);
+ DEFINE_XFTYPE(fcvt_d_w);
+ DEFINE_XFTYPE(fcvt_d_wu);
+ DEFINE_XFTYPE(fcvt_d_wu);
+ DEFINE_XFTYPE(fmv_d_x);
+ DEFINE_FXTYPE(fcvt_l_d);
+ DEFINE_FXTYPE(fcvt_lu_d);
+ DEFINE_FXTYPE(fcvt_w_d);
+ DEFINE_FXTYPE(fcvt_wu_d);
+ DEFINE_FXTYPE(fmv_x_d);
+ DEFINE_FXTYPE(feq_d);
+ DEFINE_FXTYPE(flt_d);
+ DEFINE_FXTYPE(fle_d);
+
+ // provide a default disassembly for all instructions as a fallback
+ #define DECLARE_INSN(code, match, mask) \
+ add_insn(new disasm_insn_t(#code " (args unknown)", match, mask, {}));
+ #include "encoding.h"
+ #undef DECLARE_INSN
+}
+
+const disasm_insn_t* disassembler_t::lookup(insn_t insn)
+{
+ size_t idx = insn.bits() % HASH_SIZE;
+ for (size_t j = 0; j < chain[idx].size(); j++)
+ if(*chain[idx][j] == insn)
+ return chain[idx][j];
+
+ idx = HASH_SIZE;
+ for (size_t j = 0; j < chain[idx].size(); j++)
+ if(*chain[idx][j] == insn)
+ return chain[idx][j];
+
+ return NULL;
+}
+
+void disassembler_t::add_insn(disasm_insn_t* insn)
+{
+ size_t idx = HASH_SIZE;
+ if (insn->get_mask() % HASH_SIZE == HASH_SIZE - 1)
+ idx = insn->get_match() % HASH_SIZE;
+ chain[idx].push_back(insn);
+}
+
+disassembler_t::~disassembler_t()
+{
+ for (size_t i = 0; i < HASH_SIZE+1; i++)
+ for (size_t j = 0; j < chain[i].size(); j++)
+ delete chain[i][j];
+}
--- /dev/null
+#include "hwacha.h"
--- /dev/null
+// See LICENSE for license details.
+
+#include "sim.h"
+#include "htif.h"
+#include "cachesim.h"
+#include "extension.h"
+#include <fesvr/option_parser.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <vector>
+#include <string>
+#include <memory>
+
+static void help()
+{
+ fprintf(stderr, "usage: spike [host options] <target program> [target options]\n");
+ fprintf(stderr, "Host Options:\n");
+ fprintf(stderr, " -p <n> Simulate <n> processors\n");
+ fprintf(stderr, " -m <n> Provide <n> MB of target memory\n");
+ fprintf(stderr, " -d Interactive debug mode\n");
+ fprintf(stderr, " -h Print this help message\n");
+ fprintf(stderr, " --ic=<S>:<W>:<B> Instantiate a cache model with S sets,\n");
+ fprintf(stderr, " --dc=<S>:<W>:<B> W ways, and B-byte blocks (with S and\n");
+ fprintf(stderr, " --l2=<S>:<W>:<B> B both powers of 2).\n");
+ fprintf(stderr, " --extension=<name> Specify RoCC Extension\n");
+ exit(1);
+}
+
+int main(int argc, char** argv)
+{
+ bool debug = false;
+ size_t nprocs = 1;
+ size_t mem_mb = 0;
+ std::unique_ptr<icache_sim_t> ic;
+ std::unique_ptr<dcache_sim_t> dc;
+ std::unique_ptr<cache_sim_t> l2;
+ std::function<extension_t*()> extension;
+
+ option_parser_t parser;
+ parser.help(&help);
+ parser.option('h', 0, 0, [&](const char* s){help();});
+ parser.option('d', 0, 0, [&](const char* s){debug = true;});
+ parser.option('p', 0, 1, [&](const char* s){nprocs = atoi(s);});
+ parser.option('m', 0, 1, [&](const char* s){mem_mb = atoi(s);});
+ parser.option(0, "ic", 1, [&](const char* s){ic.reset(new icache_sim_t(s));});
+ parser.option(0, "dc", 1, [&](const char* s){dc.reset(new dcache_sim_t(s));});
+ parser.option(0, "l2", 1, [&](const char* s){l2.reset(cache_sim_t::construct(s, "L2$"));});
+ parser.option(0, "extension", 1, [&](const char* s){
+ if (!extensions().count(s))
+ fprintf(stderr, "unknown extension %s!\n", s), exit(-1);
+ extension = extensions()[s];
+ });
+
+ auto argv1 = parser.parse(argv);
+ if (!*argv1)
+ help();
+ std::vector<std::string> htif_args(argv1, (const char*const*)argv + argc);
+ sim_t s(nprocs, mem_mb, htif_args);
+
+ if (ic && l2) ic->set_miss_handler(&*l2);
+ if (dc && l2) dc->set_miss_handler(&*l2);
+ for (size_t i = 0; i < nprocs; i++)
+ {
+ if (ic) s.get_core(i)->get_mmu()->register_memtracer(&*ic);
+ if (dc) s.get_core(i)->get_mmu()->register_memtracer(&*dc);
+ if (extension) s.get_core(i)->register_extension(extension());
+ }
+
+ s.set_debug(debug);
+ return s.run();
+}
--- /dev/null
+spike_subproject_deps = \
+ softfloat \
+ riscv \
+ hwacha \
+
+spike_install_prog_srcs = \
+ spike.cc \
+ riscv-dis.cc \
+ xspike.cc \
+ termios-xspike.cc \
+
+spike_hdrs = \
+
+spike_srcs = \
+ extensions.cc \
--- /dev/null
+// See LICENSE for license details.
+
+// termios-xspike sets up a canonical terminal and blocks forever.
+// It allows us to send Ctrl-C etc. to the target machine.
+
+#include <unistd.h>
+#include <termios.h>
+#include <signal.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main()
+{
+ struct termios old_tios;
+ if (tcgetattr(0, &old_tios) < 0)
+ return -1;
+
+ signal(SIGTERM, [](int) { });
+
+ struct termios new_tios = old_tios;
+ new_tios.c_lflag &= ~(ICANON | ECHO | ISIG);
+ if (tcsetattr(0, TCSANOW, &new_tios) < 0)
+ return -1;
+
+ pause();
+
+ return tcsetattr(0, TCSANOW, &old_tios);
+}
--- /dev/null
+// See LICENSE for license details.
+
+// xspike forks an xterm for spike's target machine console,
+// preserving the current terminal for debugging.
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <cstdio>
+#include <climits>
+#include <cstring>
+#include <stdexcept>
+
+static pid_t fork_spike(int tty_fd, int argc, char** argv);
+static pid_t fork_xterm(int* tty_fd);
+
+int main(int argc, char** argv)
+{
+ int tty_fd, wait_status, ret = -1;
+ pid_t xterm, spike;
+
+ static bool signal_exit = false;
+ auto handle_signal = [](int) { signal_exit = true; };
+
+ if ((xterm = fork_xterm(&tty_fd)) < 0)
+ {
+ fprintf(stderr, "could not open xterm\n");
+ goto out;
+ }
+
+ signal(SIGINT, handle_signal);
+
+ if ((spike = fork_spike(tty_fd, argc, argv)) < 0)
+ {
+ fprintf(stderr, "could not open spike\n");
+ goto close_xterm;
+ }
+
+ while ((ret = waitpid(spike, &wait_status, 0)) < 0)
+ if (signal_exit)
+ break;
+
+ if (ret < 0) // signal_exit
+ kill(spike, SIGTERM);
+ else
+ ret = WIFEXITED(wait_status) ? WEXITSTATUS(wait_status) : -1;
+
+close_xterm:
+ kill(-xterm, SIGTERM);
+out:
+ return ret;
+}
+
+static pid_t fork_spike(int tty_fd, int argc, char** argv)
+{
+ pid_t pid = fork();
+ if (pid < 0)
+ return -1;
+
+ if (pid == 0)
+ {
+ if (dup2(tty_fd, STDIN_FILENO) < 0 || dup2(tty_fd, STDOUT_FILENO) < 0)
+ return -1;
+ execvp("spike", argv);
+ return -1;
+ }
+
+ return pid;
+}
+
+static pid_t fork_xterm(int* tty_fd)
+{
+ static const char cmd[] = "3>&1 xterm -title xspike -e sh -c 'tty 1>&3; termios-xspike'";
+
+ int fds[2];
+ if (pipe(fds) < 0)
+ return -1;
+
+ pid_t pid = fork();
+ if (pid < 0)
+ return -1;
+
+ if (pid == 0)
+ {
+ setpgid(0, 0);
+ if (dup2(fds[1], STDOUT_FILENO) < 0)
+ return -1;
+ execl("/bin/sh", "sh", "-c", cmd, NULL);
+ return -1;
+ }
+
+ char tty[NAME_MAX];
+ ssize_t ttylen = read(fds[0], tty, sizeof(tty));
+ if (ttylen <= 1 || tty[ttylen-1] != '\n')
+ return -1;
+ tty[ttylen-1] = '\0';
+ if ((*tty_fd = open(tty, O_RDWR)) < 0)
+ return -1;
+
+ return pid;
+}