summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--platform/qemu/virt/config.mk13
-rw-r--r--platform/template/config.mk2
3 files changed, 16 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 6f67c54..2848d09 100644
--- a/Makefile
+++ b/Makefile
@@ -116,6 +116,9 @@ endif
AS = $(CC)
DTC = dtc
+# Guess the compillers xlen
+OPENSBI_CC_XLEN = `expr substr \`$(CC) -dumpmachine\` 6 2`
+
# Setup compilation commands flags
CFLAGS = -g -Wall -Werror -nostdlib -fno-strict-aliasing -O2
CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
diff --git a/platform/qemu/virt/config.mk b/platform/qemu/virt/config.mk
index 1ee66d0..5931d0e 100644
--- a/platform/qemu/virt/config.mk
+++ b/platform/qemu/virt/config.mk
@@ -9,8 +9,17 @@
# Compiler flags
platform-cppflags-y =
-platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
-platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany
+# If we know the compillers xlen use it below
+ifeq ($(OPENSBI_CC_XLEN), 32)
+ platform-cflags-y =-mabi=ilp$(OPENSBI_CC_XLEN) -march=rv$(OPENSBI_CC_XLEN)imafdc
+ platform-asflags-y =-mabi=ilp$(OPENSBI_CC_XLEN) -march=rv$(OPENSBI_CC_XLEN)imafdc
+endif
+ifeq ($(OPENSBI_CC_XLEN), 64)
+ platform-cflags-y =-mabi=lp$(OPENSBI_CC_XLEN) -march=rv$(OPENSBI_CC_XLEN)imafdc
+ platform-asflags-y =-mabi=lp$(OPENSBI_CC_XLEN) -march=rv$(OPENSBI_CC_XLEN)imafdc
+endif
+platform-cflags-y += -mcmodel=medany
+platform-asflags-y += -mcmodel=medany
platform-ldflags-y =
# Common drivers to enable
diff --git a/platform/template/config.mk b/platform/template/config.mk
index b1457da..21aa6d6 100644
--- a/platform/template/config.mk
+++ b/platform/template/config.mk
@@ -12,6 +12,8 @@ platform-cppflags-y =
# -mabi=lp64 -march=rv64imafdc -mcmodel=medany
# For a 32 bits platform, this will likely be:
# -mabi=lp32 -march=rv32imafdc -mcmodel=medlow
+# You can also use the Makefile variable OPENSBI_CC_XLEN for the xlen
+# See the QEMU virt machine for an example of this
platform-cflags-y = -mabi=lp64 -march=rv64imafdc -mcmodel=medany
platform-asflags-y = -mabi=lp64 -march=rv64imafdc -mcmodel=medany