aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSimplyTheOther <simplytheother@gmail.com>2020-07-06 15:41:21 +0800
committerPhilip Herron <philip.herron@embecosm.com>2020-11-28 21:13:18 +0000
commit9e9c2eb329b3df4c281a2f586d87e6c81c12c6b5 (patch)
treeb5dc56683102e67303807fb7b4deba75919e7995 /gcc
parent8f0507ad9ebff18c7c2baacb981434018dad2600 (diff)
downloadgcc-9e9c2eb329b3df4c281a2f586d87e6c81c12c6b5.zip
gcc-9e9c2eb329b3df4c281a2f586d87e6c81c12c6b5.tar.gz
gcc-9e9c2eb329b3df4c281a2f586d87e6c81c12c6b5.tar.bz2
Added Nios II target hook (or provisional one at least)
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config.gcc1
-rw-r--r--gcc/config/nios2/nios2-protos.h3
-rw-r--r--gcc/config/nios2/nios2-rust.c88
-rw-r--r--gcc/config/nios2/nios2.h3
-rw-r--r--gcc/config/nios2/t-nios24
5 files changed, 99 insertions, 0 deletions
diff --git a/gcc/config.gcc b/gcc/config.gcc
index bab2892..fa277d0 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -521,6 +521,7 @@ nds32*)
;;
nios2-*-*)
cpu_type=nios2
+ rust_target_objs="nios2-rust.o"
extra_options="${extra_options} g.opt"
;;
nvptx-*-*)
diff --git a/gcc/config/nios2/nios2-protos.h b/gcc/config/nios2/nios2-protos.h
index 0f7e684..a42868a 100644
--- a/gcc/config/nios2/nios2-protos.h
+++ b/gcc/config/nios2/nios2-protos.h
@@ -29,6 +29,9 @@ extern void nios2_expand_epilogue (bool);
extern bool nios2_expand_return (void);
extern void nios2_function_profiler (FILE *, int);
+/* Routines implemented in nios2-rust.c */
+extern void nios2_rust_target_cpu_info (void);
+
#ifdef RTX_CODE
extern bool nios2_large_constant_p (rtx);
extern bool nios2_large_constant_memory_operand_p (rtx);
diff --git a/gcc/config/nios2/nios2-rust.c b/gcc/config/nios2/nios2-rust.c
new file mode 100644
index 0000000..3a013da
--- /dev/null
+++ b/gcc/config/nios2/nios2-rust.c
@@ -0,0 +1,88 @@
+/* Subroutines for the Rust front end for the Altera Nios II architecture.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tm_p.h"
+#include "rust/rust-target.h"
+#include "rust/rust-target-def.h"
+
+/* Implement TARGET_RUST_CPU_INFO for Altera Nios II targets. */
+
+void nios2_rust_target_cpu_info(void) {
+ rust_add_target_info("target_arch", "nios2");
+
+ // made up names as no apparent support (current or historical) in llvm
+ if (TARGET_HAS_DIV)
+ rust_add_target_info("target_feature", "hw-div");
+ if (TARGET_HAS_MUL)
+ rust_add_target_info("target_feature", "hw-mul");
+ if (TARGET_HAS_MULX)
+ rust_add_target_info("target_feature", "hw-mulx");
+ if (TARGET_FAST_SW_DIV)
+ rust_add_target_info("target_feature", "fast-sw-div");
+ if (TARGET_BYPASS_CACHE)
+ rust_add_target_info("target_feature", "bypass-cache");
+ if (TARGET_BYPASS_CACHE_VOLATILE)
+ rust_add_target_info("target_feature", "no-cache-volatile");
+ // TODO: ensure below switch variable and whatever works
+ // TODO: improve how this works? the defining kinda sucks a bit
+ switch (nios2_gpopt_option) {
+ case gpopt_none:
+ rust_add_target_info("target_feature", "gpopt-none");
+ break;
+ case gpopt_local:
+ rust_add_target_info("target_feature", "gpopt-local");
+ break;
+ case gpopt_global:
+ rust_add_target_info("target_feature", "gpopt-global");
+ break;
+ case gpopt_data:
+ rust_add_target_info("target_feature", "gpopt-data");
+ break;
+ case gpopt_all:
+ rust_add_target_info("target_feature", "gpopt-all");
+ break;
+ default: // unknown gpopt status - should this be an error?
+ break;
+ }
+ if (TARGET_BIG_ENDIAN)
+ rust_add_target_info("target_feature", "eb");
+ else
+ rust_add_target_info("target_feature", "el");
+ /* TODO: figure out how to have custom-fpu-cfg, custom-ftruncds (including no-custom-ftruncds),
+ * etc. (all custom instructions and their no- equivalents) in define form */
+ // TODO: ensure below switch and variable works
+ switch (nios2_arch_option) {
+ case ARCH_R1:
+ rust_add_target_info("target_feature", "r1");
+ break;
+ case ARCH_R2:
+ rust_add_target_info("target_feature", "r2");
+ break;
+ default: // should this be an error?
+ break;
+ }
+ if (TARGET_HAS_BMX)
+ rust_add_target_info("target_feature", "bmx");
+ if (TARGET_HAS_CDX)
+ rust_add_target_info("target_feature", "cdx");
+ // TODO: figure out how to have gprel-sec and r0rel-sec as defines
+ // TODO: maybe extra defines for features available on bare metal target? (hal, smallc, etc.)
+}
diff --git a/gcc/config/nios2/nios2.h b/gcc/config/nios2/nios2.h
index e81b928..0a91ff9 100644
--- a/gcc/config/nios2/nios2.h
+++ b/gcc/config/nios2/nios2.h
@@ -44,6 +44,9 @@
} \
while (0)
+/* Target CPU info for Rust. */
+#define TARGET_RUST_CPU_INFO nios2_rust_target_cpu_info
+
/* We're little endian, unless otherwise specified by defining
BIG_ENDIAN_FLAG. */
#ifndef TARGET_ENDIAN_DEFAULT
diff --git a/gcc/config/nios2/t-nios2 b/gcc/config/nios2/t-nios2
index 8ce1061..f6a7b23 100644
--- a/gcc/config/nios2/t-nios2
+++ b/gcc/config/nios2/t-nios2
@@ -25,3 +25,7 @@
# MULTILIB_OPTIONS += EL/EB
# MULTILIB_DIRNAMES += le be
# MULTILIB_MATCHES += EL=mel EB=meb
+
+nios2-rust.o: $(srcdir)/config/nios2/nios2-rust.c \
+ $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_COMMON_H)
+ $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< \ No newline at end of file