bpf: several small fixes in the simulator
authorJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 3 Sep 2020 14:24:51 +0000 (16:24 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 3 Sep 2020 16:22:08 +0000 (18:22 +0200)
This patch fixes the following problems:
- Missing includes in several files leading to implicit function
  declarations.
- Missing prototype for bpf_trace_printk in bpf-helpers.h
- The simulator bitsize was set to 32 bits, causing truncation of
  the program counter.

Tested in bpf-unknown-none.

sim/ChangeLog:

2020-09-03  Jose E. Marchesi  <jose.marchesi@oracle.com>

* bpf/bpf.c: Include bpf-helpers.h.
* bpf/bpf-helpers.h: Provide a prototype for bpf_trace_printk.
* bpf/configure.ac: Set simulator bitsize to 64.
* bpf/configure (includedir): Regenerate.
* bpf/sim-if.c: Include stdlib.h.
* bpf/traps.c: Likewise.

sim/ChangeLog
sim/bpf/bpf-helpers.h
sim/bpf/bpf.c
sim/bpf/configure
sim/bpf/configure.ac
sim/bpf/sim-if.c
sim/bpf/traps.c

index 5f5f5b8c7568bc6c78431bd1e23a20a3c876f158..28d78a34d281548a63287ae6c599162dc1cd76c3 100644 (file)
@@ -1,3 +1,12 @@
+2020-09-03  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+       * bpf/bpf.c: Include bpf-helpers.h.
+       * bpf/bpf-helpers.h: Provide a prototype for bpf_trace_printk.
+       * bpf/configure.ac: Set simulator bitsize to 64.
+       * bpf/configure (includedir): Regenerate.
+       * bpf/sim-if.c: Include stdlib.h.
+       * bpf/traps.c: Likewise.
+
 2020-09-03  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * configure.ac: Do not configure sim/testsuite nor sim/igen if the
index fe9413f266f2e99db3aed7c69d0fd7ed224ba625..021649cb02fb28ade2ab5c1dcb794d5e59699157 100644 (file)
@@ -26,6 +26,6 @@ enum bpf_kernel_helper
 #undef DEF_HELPER
   };
 
-/* void bpf_trace_printk (const char *fmt); */
+void bpf_trace_printk (SIM_CPU *current_cpu);
 
 #endif /* ! BPF_HELPERS_H */
index 0fb8d81c4695df612f2f1a5a8d9812112d98dce0..f413b36ab43f27cc63859d5e6fca0e18f71ef534 100644 (file)
@@ -27,6 +27,7 @@
 #include "decode.h"
 
 #include "defs-le.h"  /* For SCACHE */
+#include "bpf-helpers.h"
 
 /* It is not possible to include both defs-le.h and defs-be.h due to
    duplicated definitions, so we need a bunch of forward declarations
index 7125c50ff17527204a1ef85605daac5d70a7097d..34e70693a488e28efeeed5c02ad3b3d5fa8839c1 100755 (executable)
@@ -782,6 +782,7 @@ enable_sim_environment
 enable_sim_inline
 with_pkgversion
 with_bugurl
+enable_sim_bitsize
 enable_sim_endian
 enable_sim_alignment
 enable_sim_scache
@@ -1436,6 +1437,7 @@ Optional Features:
                           environment
   --enable-sim-inline=inlines
                           Specify which functions should be inlined
+  --enable-sim-bitsize=N  Specify target bitsize (32 or 64)
   --enable-sim-endian=endian
                           Specify target byte endian orientation
   --enable-sim-alignment=align
@@ -12882,7 +12884,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12885 "configure"
+#line 12899 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12988,7 +12990,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12991 "configure"
+#line 13005 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13539,6 +13541,65 @@ _ACEOF
 
 
 
+wire_word_bitsize="64"
+wire_word_msb=""
+wire_address_bitsize=""
+wire_cell_bitsize=""
+# Check whether --enable-sim-bitsize was given.
+if test "${enable_sim_bitsize+set}" = set; then :
+  enableval=$enable_sim_bitsize; sim_bitsize=
+case "${enableval}" in
+  64,63 | 64,63,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=63";;
+  32,31 | 32,31,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=31";;
+  64,0 | 64,0,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0";;
+  32,0 | 64,0,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0";;
+  32) if test x"$wire_word_msb" != x -a x"$wire_word_msb" != x0; then
+        sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=31"
+      else
+        sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0"
+      fi ;;
+  64) if test x"$wire_word_msb" != x -a x"$wire_word_msb" != x0; then
+        sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=63"
+      else
+        sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=0"
+      fi ;;
+  *)  as_fn_error $? "\"--enable-sim-bitsize was given $enableval.  Expected 32 or 64\"" "$LINENO" 5 ;;
+esac
+# address bitsize
+tmp=`echo "${enableval}" | sed -e "s/^[0-9]*,*[0-9]*,*//"`
+case x"${tmp}" in
+  x ) ;;
+  x32 | x32,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_ADDRESS_BITSIZE=32" ;;
+  x64 | x64,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_ADDRESS_BITSIZE=64" ;;
+  * ) as_fn_error $? "\"--enable-sim-bitsize was given address size $enableval.  Expected 32 or 64\"" "$LINENO" 5 ;;
+esac
+# cell bitsize
+tmp=`echo "${enableval}" | sed -e "s/^[0-9]*,*[0-9*]*,*[0-9]*,*//"`
+case x"${tmp}" in
+  x ) ;;
+  x32 | x32,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_CELL_BITSIZE=32" ;;
+  x64 | x64,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_CELL_BITSIZE=64" ;;
+  * ) as_fn_error $? "\"--enable-sim-bitsize was given cell size $enableval.  Expected 32 or 64\"" "$LINENO" 5 ;;
+esac
+if test x"$silent" != x"yes" && test x"$sim_bitsize" != x""; then
+  echo "Setting bitsize flags = $sim_bitsize" 6>&1
+fi
+else
+  sim_bitsize=""
+if test x"$wire_word_bitsize" != x; then
+  sim_bitsize="$sim_bitsize -DWITH_TARGET_WORD_BITSIZE=$wire_word_bitsize"
+fi
+if test x"$wire_word_msb" != x; then
+  sim_bitsize="$sim_bitsize -DWITH_TARGET_WORD_MSB=$wire_word_msb"
+fi
+if test x"$wire_address_bitsize" != x; then
+  sim_bitsize="$sim_bitsize -DWITH_TARGET_ADDRESS_BITSIZE=$wire_address_bitsize"
+fi
+if test x"$wire_cell_bitsize" != x; then
+  sim_bitsize="$sim_bitsize -DWITH_TARGET_CELL_BITSIZE=$wire_cell_bitsize"
+fi
+fi
+
 
 wire_endian=""
 default_endian="LITTLE"
index 16ca54e86c2bea382ce65e36996f1b3c9fcc53f1..e7cd72a1c670d7b3a02570f3b93614fa6d08fca3 100644 (file)
@@ -4,6 +4,7 @@ sinclude(../common/acinclude.m4)
 
 SIM_AC_COMMON
 
+SIM_AC_OPTION_BITSIZE([64])
 SIM_AC_OPTION_ENDIAN([], [LITTLE])
 SIM_AC_OPTION_ALIGNMENT(NONSTRICT_ALIGNMENT)
 SIM_AC_OPTION_SCACHE(16384)
index fbb122b36ef134ea7d2cdadd9187555d028a9866..e7e5de61dfc1da8e9c2c539ed3c7d4d80729ee3e 100644 (file)
@@ -16,6 +16,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include <stdlib.h>
+
 #include "sim-main.h"
 #include "sim-options.h"
 #include "libiberty.h"
index e7ac0c2838ba1b42fb79f17b005d8a09dabe929a..646db4a9578d9d7207dc41bf94f9ed2f5421b913 100644 (file)
@@ -19,6 +19,8 @@
 #define WANT_CPU bpfbf
 #define WANT_CPU_BPFBF
 
+#include <stdlib.h>
+
 #include "sim-main.h"
 
 SEM_PC