Query Compiler Features for Better Disassembling
cover Query Compiler Features for Better Disassembling
Hello,
This patchset makes the resulting ELF files (e.g. fw_dynamic.elf) disassembled correctly (as possible) on the latest toolchain, when compiled and assembled with the latest GNU toolchain (especially on Binutils master [going to be 2.40?] but some changes are also effective on 2.39).
In this letter, I will call master commit of GNU Binutils as 2.40.
[BEFORE THE PATCHSET: GNU Binutils 2.39 and 2.40]
Note that some annotations are added.
000000008000a0d0 <__sbi_hfence_gvma_gpa>:
8000a0d0: 62050073 .word 0x62050073
^^^^^^^^^^^^^^^^^^
Printed as data
8000a0d4: 8082 ret
8000a0d6: 0001 nop# (quote from csr_read_num)
800047b6: 3c002573 csrr a0,0x3c0
^^^^^
Raw CSR number (pmpaddr16)
800047ba: 8082 ret[PATCH 1/3]
** partially effective on GNU Binutils 2.39 and 2.40 **
It optionally replaces ".word" (which emits a 32-bit "data" word) in lib/sbi/sbi_hfence.S with ".insn" with raw value (which emits an "instruction" word) when supported by the assembler.
Before this commit and on GNU Binutils, an ELF mapping symbol "$d" (from here, data follows) is inserted before ".word". Even if the hfence.* instruction itself is recognized, ".word"s are recognized as data, not instructions (due to the existence of mapping symbol).
e
Instead, ".insn" emits (possibly variable length) instruction word and inserts "$x" (from here, instruction follows) mapping symbol where necessary. Note that, not all assemblers support ".insn" with raw instruction value. This commit checks ".insn" with raw value support.
After that, objdump of __sbi_hfence_gvma_gpa will look like this (for PATCH 2-3/3, GNU Binutils 2.39 output will be the same):
000000008000a0d0 <__sbi_hfence_gvma_gpa>:
8000a0d0: 62050073 .4byte 0x62050073
^^^^^^^^^^^^^^^^^^
Printed as an instruction
(but not recognized as hfence.gvma yet)
8000a0d4: 8082 ret
8000a0d6: 0001 nop[PATCH 2/3]
** effective on GNU Binutils 2.40 **
".option arch,+h" assembler directive enables 'H' extension support in the section (may be the file scope depending on the Binutils version).
It will be reflected to the ELF mapping symbols "$x[arch]" (where [arch] is an ISA string) on GNU Binutils 2.40 and 'H' extension can be partially enabled (only on lib/sbi/sbi_hfence.o).
At first, I intended this to be fully effective on GNU Binutils 2.39 (where section-level architecture change will be reflected to file scope and 'H' extension dependency is merged into final ELF files).
However, due to a bug in the linker (to be specific, riscv_merge_std_ext function in BFD), it did not happen on 2.39.
After that, objdump of __sbi_hfence_gvma_gpa in GNU Binutils 2.40 will be:
000000008000a0d0 <__sbi_hfence_gvma_gpa>:
8000a0d0: 62050073 hfence.gvma a0
^^^^^^^^^^^^^^^^^^
Printed as a hfence.gvma instruction
8000a0d4: 8082 ret
8000a0d6: 0001 nop[PATCH 3/3]
** effective on GNU Binutils 2.39 or later **
OpenSBI uses some privileged architecture version 1.12 CSRs and this commit reflects this version to the final ELF file. As a result, 1.12 CSRs are correctly named (instead of raw numbers).
After that, objdump of csr_read_num will look like this (both on GNU Binutils 2.39 and 2.40):
# (quote from csr_read_num)
800047b6: 3c002573 csrr a0,pmpaddr16
^^^^^^^^^
CSR name new in v1.12
800047ba: 8082 retThanks,
Tsukasa
Tsukasa OI (3):
lib: sbi: Optionally use ".insn" instead of ".word"
lib: sbi: Optionally use ".option arch,+h"
Makefile: Optionally specify latest privileged specification
Makefile | 26 ++++++++++++++++++++++++++ lib/sbi/sbi_hfence.S | 20 ++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-)
base-commit: 1b0d71bb9ff9180c4ae0026de5f4a92a88f1884e
Signature · 1 line
2.38.1
PATCH 1/3 lib: sbi: Optionally use ".insn" instead of ".word"
From: Tsukasa OI <[email protected]>
".word" is used to emit a data word (32-bits) and recent GNU assembler adds mapping symbol "$d" before ".word" to make sure that this is a data word. However, in lib/sbi/sbi_hfence.S, we use this to emit hfence.* instructions (for assemblers that do not support hfence.*). The mapping symbol "$d" prevents these instructions being disassembled as code.
Instead, ".insn" is available to emit raw instructions but not all assemblers with ".insn" support raw values.
This commit tests support of ".insn" with raw value in the Makefile (AS_SUPPORT_INSN_RAW_DIRECTIVE) and optionally replaces ".word" with ".insn" when ".insn" with raw value is supported.
--- Makefile | 8 ++++++++ lib/sbi/sbi_hfence.S | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-)
Makefile +8 -0
@@ -173,6 +173,9 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +# Check whether the ".insn" directive on the assembler (with raw value) is supported +AS_SUPPORT_INSN_RAW_DIRECTIVE := $(shell echo ".insn 0x1000000f" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null >/dev/null 2>&1 && echo y || echo n) + # Build Info: # OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp # OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
@@ -323,6 +326,11 @@ ifeq ($(BUILD_INFO),y) GENFLAGS += -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\"" GENFLAGS += -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\"" endif +ifeq ($(AS_SUPPORT_INSN_RAW_DIRECTIVE),y) +GENFLAGS += -DRAW_INSN=".insn" +else +GENFLAGS += -DRAW_INSN=".word" +endif ifdef PLATFORM GENFLAGS += -include $(KCONFIG_AUTOHEADER) endif
lib/sbi/sbi_hfence.S +8 -8
@@ -32,7 +32,7 @@ __sbi_hfence_gvma_vmid_gpa: * HFENCE.GVMA a0, a1 * 0110001 01011 01010 000 00000 1110011 */ - .word 0x62b50073 + RAW_INSN 0x62b50073 ret .align 3
@@ -44,7 +44,7 @@ __sbi_hfence_gvma_vmid: * HFENCE.GVMA zero, a0 * 0110001 01010 00000 000 00000 1110011 */ - .word 0x62a00073 + RAW_INSN 0x62a00073 ret .align 3
@@ -56,7 +56,7 @@ __sbi_hfence_gvma_gpa: * HFENCE.GVMA a0 * 0110001 00000 01010 000 00000 1110011 */ - .word 0x62050073 + RAW_INSN 0x62050073 ret .align 3
@@ -68,7 +68,7 @@ __sbi_hfence_gvma_all: * HFENCE.GVMA * 0110001 00000 00000 000 00000 1110011 */ - .word 0x62000073 + RAW_INSN 0x62000073 ret /*
@@ -95,7 +95,7 @@ __sbi_hfence_vvma_asid_va: * HFENCE.VVMA a0, a1 * 0010001 01011 01010 000 00000 1110011 */ - .word 0x22b50073 + RAW_INSN 0x22b50073 ret .align 3
@@ -107,7 +107,7 @@ __sbi_hfence_vvma_asid: * HFENCE.VVMA zero, a0 * 0010001 01010 00000 000 00000 1110011 */ - .word 0x22a00073 + RAW_INSN 0x22a00073 ret .align 3
@@ -119,7 +119,7 @@ __sbi_hfence_vvma_va: * HFENCE.VVMA zero, a0 * 0010001 00000 01010 000 00000 1110011 */ - .word 0x22050073 + RAW_INSN 0x22050073 ret .align 3
@@ -131,5 +131,5 @@ __sbi_hfence_vvma_all: * HFENCE.VVMA * 0010001 00000 00000 000 00000 1110011 */ - .word 0x22000073 + RAW_INSN 0x22000073 ret
Signature · 1 line
2.38.1
PATCH 1/3 lib: sbi: Optionally use ".insn" instead of ".word"
Quoted 37 lines · Tsukasa OI
From: Tsukasa OI <[email protected]>
".word" is used to emit a data word (32-bits) and recent GNU assembler adds mapping symbol "$d" before ".word" to make sure that this is a data word. However, in
lib/sbi/sbi_hfence.S, we use this to emit hfence.* instructions (for assemblers that do not support hfence.*). The mapping symbol "$d" prevents these instructions being disassembled as code.Instead, ".insn" is available to emit raw instructions but not all assemblers with ".insn" support raw values.
This commit tests support of ".insn" with raw value in the
Makefile(AS_SUPPORT_INSN_RAW_DIRECTIVE) and optionally replaces ".word" with ".insn" when ".insn" with raw value is supported.Signed-off-by Tsukasa OI <[email protected]>--- Makefile | 8 ++++++++ lib/sbi/sbi_hfence.S | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-)Makefile +3
-0@@ -173,6 +173,9 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +# Check whether the ".insn" directive on the assembler (with raw value) is supported +AS_SUPPORT_INSN_RAW_DIRECTIVE := $(shell echo ".insn 0x1000000f" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null >/dev/null 2>&1 && echo y || echo n) + # Build Info: # OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp # OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
Makefile ifeq ($(BUILD_INFO),y) · line 333
Quoted 8 lines
Makefile +5
-0@@ -323,6 +326,11 @@ ifeq ($(BUILD_INFO),y) GENFLAGS += -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\"" GENFLAGS += -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\"" endif +ifeq ($(AS_SUPPORT_INSN_RAW_DIRECTIVE),y) +GENFLAGS += -DRAW_INSN=".insn" +else +GENFLAGS += -DRAW_INSN=".word" +endif
OpenSBI specific defines have "OPENSBI_" prefix so better use that OPENSBI_RAW_INSN as define name.
lib/sbi/sbi_hfence.S __sbi_hfence_gvma_vmid_gpa: · line 35
Quoted 13 lines
Makefile +0
-0ifdef PLATFORM GENFLAGS += -include $(KCONFIG_AUTOHEADER) endiflib/sbi/sbi_hfence.S +1
-1@@ -32,7 +32,7 @@ __sbi_hfence_gvma_vmid_gpa: * HFENCE.GVMA a0, a1 * 0110001 01011 01010 000 00000 1110011 */ - .word 0x62b50073 + RAW_INSN 0x62b50073
This will fail to compile for people using OpenSBI as a library.
We need some kind of macro to fallback to ".word" when OPENSBI_RAW_INSN is not defined.
It's better to do something like
<linux_source>/arch/riscv/include/asm/insn-def.h
which is flexible and scalable.
Regards,
Anup
Quoted 72 lines
lib/sbi/sbi_hfence.S +7
-8ret .align 3@@ -44,7 +44,7 @@ __sbi_hfence_gvma_vmid: * HFENCE.GVMA zero, a0 * 0110001 01010 00000 000 00000 1110011 */ - .word 0x62a00073 + RAW_INSN 0x62a00073 ret .align 3@@ -56,7 +56,7 @@ __sbi_hfence_gvma_gpa: * HFENCE.GVMA a0 * 0110001 00000 01010 000 00000 1110011 */ - .word 0x62050073 + RAW_INSN 0x62050073 ret .align 3@@ -68,7 +68,7 @@ __sbi_hfence_gvma_all: * HFENCE.GVMA * 0110001 00000 00000 000 00000 1110011 */ - .word 0x62000073 + RAW_INSN 0x62000073 ret /*@@ -95,7 +95,7 @@ __sbi_hfence_vvma_asid_va: * HFENCE.VVMA a0, a1 * 0010001 01011 01010 000 00000 1110011 */ - .word 0x22b50073 + RAW_INSN 0x22b50073 ret .align 3@@ -107,7 +107,7 @@ __sbi_hfence_vvma_asid: * HFENCE.VVMA zero, a0 * 0010001 01010 00000 000 00000 1110011 */ - .word 0x22a00073 + RAW_INSN 0x22a00073 ret .align 3@@ -119,7 +119,7 @@ __sbi_hfence_vvma_va: * HFENCE.VVMA zero, a0 * 0010001 00000 01010 000 00000 1110011 */ - .word 0x22050073 + RAW_INSN 0x22050073 ret .align 3@@ -131,5 +131,5 @@ __sbi_hfence_vvma_all: * HFENCE.VVMA * 0010001 00000 00000 000 00000 1110011 */ - .word 0x22000073 + RAW_INSN 0x22000073 ret --2.38.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 2/3 lib: sbi: Optionally use ".option arch,+h"
In reply to Tsukasa OIFrom: Tsukasa OI <[email protected]>
On the debugger / disassembler, disassembling hfence.* as hfence.* requires indication of the 'H'-extension use.
".option arch,+[EXT_NAME]" is one of the such ways and this commit optionally inserts this assembler directive when supported.
It enables disassembling on the software which supports "$x[arch]" (mapping symbols with ISA string) - latest GNU Binutils (will be released as 2.40). Note that this commit alone won't make disassembler behavior correct on GNU Binutils 2.39 because of a linker issue.
--- Makefile | 6 ++++++ lib/sbi/sbi_hfence.S | 4 ++++ 2 files changed, 10 insertions(+)
Makefile +6 -0
@@ -173,6 +173,9 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +# Check whether the assembler support the H extension with .option arch,+h +AS_SUPPORT_H_EXT_BY_OPTION_ARCH := $(shell echo ".option arch,+h" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null >/dev/null 2>&1 && echo y || echo n) + # Check whether the ".insn" directive on the assembler (with raw value) is supported AS_SUPPORT_INSN_RAW_DIRECTIVE := $(shell echo ".insn 0x1000000f" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null >/dev/null 2>&1 && echo y || echo n)
@@ -331,6 +334,9 @@ GENFLAGS += -DRAW_INSN=".insn" else GENFLAGS += -DRAW_INSN=".word" endif +ifeq ($(AS_SUPPORT_H_EXT_BY_OPTION_ARCH),y) +GENFLAGS += -DOPENSBI_H_EXT_BY_OPTION_ARCH_SUPPORTED +endif ifdef PLATFORM GENFLAGS += -include $(KCONFIG_AUTOHEADER) endif
lib/sbi/sbi_hfence.S +4 -0
@@ -8,6 +8,10 @@ * Atish Patra <[email protected]> */ +#ifdef OPENSBI_H_EXT_BY_OPTION_ARCH_SUPPORTED + .option arch,+h +#endif + /* * HFENCE.GVMA rs1, rs2 * HFENCE.GVMA zero, rs2
Signature · 1 line
2.38.1
PATCH 3/3 Makefile: Optionally specify latest privileged specification
In reply to Tsukasa OIFrom: Tsukasa OI <[email protected]>
Although that OpenSBI can be compiled with compiler with the privileged architecture version 1.11, it partially uses CSRs from the latest privileged specification, version 1.12.
To enable fully-featured disassembling (through ELF attributes), this commit queries whether the assembler supports -mpriv-spec=1.12 and adds "-Wa,-mpriv-spec=1.12" to CFLAGS and ASFLAGS when supported.
--- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Makefile +12 -0
@@ -164,6 +164,9 @@ else USE_LD_FLAG = -fuse-ld=bfd endif +# Setup privileged architecture +OPENSBI_PRIV_SPEC = 1.12 + # Check whether the linker supports creating PIEs OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
@@ -173,6 +176,9 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +# Check whether the assembler and the compiler support the privileged architecture option (used by OpenSBI) +CC_SUPPORT_PRIV_SPEC_LATEST := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -Wa,-mpriv-spec=$(OPENSBI_PRIV_SPEC) -x c -c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n) + # Check whether the assembler support the H extension with .option arch,+h AS_SUPPORT_H_EXT_BY_OPTION_ARCH := $(shell echo ".option arch,+h" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null >/dev/null 2>&1 && echo y || echo n)
@@ -352,6 +358,9 @@ CFLAGS += -mno-save-restore endif CFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA) CFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL) +ifeq ($(CC_SUPPORT_PRIV_SPEC_LATEST),y) +CFLAGS += -Wa,-mpriv-spec=$(OPENSBI_PRIV_SPEC) +endif CFLAGS += $(RELAX_FLAG) CFLAGS += $(GENFLAGS) CFLAGS += $(platform-cflags-y)
@@ -370,6 +379,9 @@ ASFLAGS += -mno-save-restore endif ASFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA) ASFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL) +ifeq ($(CC_SUPPORT_PRIV_SPEC_LATEST),y) +ASFLAGS += -Wa,-mpriv-spec=$(OPENSBI_PRIV_SPEC) +endif ASFLAGS += $(RELAX_FLAG) ifneq ($(CC_IS_CLANG),y) ifneq ($(RELAX_FLAG),)
Signature · 1 line
2.38.1
v2 cover Query Compiler Features for Better Disassembling
In reply to Tsukasa OIHello,
This is a minor fix to the patchset
"Query Compiler Features for Better Disassembling".
c.f. PATCH v1 (including backgrounds):
<http://lists.infradead.org/pipermail/opensbi/2022-November/003659.html>
[Changes: v1 -> v2]
- PATCH 2/2: Make feature detection more robust
(detect warnings generated by GAS or Clang)
Thanks,
Tsukasa
Tsukasa OI (3):
lib: sbi: Optionally use ".insn" instead of ".word"
lib: sbi: Optionally use ".option arch,+h"
Makefile: Optionally specify latest privileged specification
Makefile | 26 ++++++++++++++++++++++++++ lib/sbi/sbi_hfence.S | 20 ++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-)
base-commit: 1b0d71bb9ff9180c4ae0026de5f4a92a88f1884e
Signature · 1 line
2.38.1
PATCH v2 1/3 lib: sbi: Optionally use ".insn" instead of ".word"
From: Tsukasa OI <[email protected]>
".word" is used to emit a data word (32-bits) and recent GNU assembler adds mapping symbol "$d" before ".word" to make sure that this is a data word. However, in lib/sbi/sbi_hfence.S, we use this to emit hfence.* instructions (for assemblers that do not support hfence.*). The mapping symbol "$d" prevents these instructions being disassembled as code.
Instead, ".insn" is available to emit raw instructions but not all assemblers with ".insn" support raw values.
This commit tests support of ".insn" with raw value in the Makefile (AS_SUPPORT_INSN_RAW_DIRECTIVE) and optionally replaces ".word" with ".insn" when ".insn" with raw value is supported.
--- Makefile | 8 ++++++++ lib/sbi/sbi_hfence.S | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-)
Makefile +8 -0
@@ -173,6 +173,9 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +# Check whether the ".insn" directive on the assembler (with raw value) is supported +AS_SUPPORT_INSN_RAW_DIRECTIVE := $(shell echo ".insn 0x1000000f" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null >/dev/null 2>&1 && echo y || echo n) + # Build Info: # OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp # OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
@@ -323,6 +326,11 @@ ifeq ($(BUILD_INFO),y) GENFLAGS += -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\"" GENFLAGS += -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\"" endif +ifeq ($(AS_SUPPORT_INSN_RAW_DIRECTIVE),y) +GENFLAGS += -DRAW_INSN=".insn" +else +GENFLAGS += -DRAW_INSN=".word" +endif ifdef PLATFORM GENFLAGS += -include $(KCONFIG_AUTOHEADER) endif
lib/sbi/sbi_hfence.S +8 -8
@@ -32,7 +32,7 @@ __sbi_hfence_gvma_vmid_gpa: * HFENCE.GVMA a0, a1 * 0110001 01011 01010 000 00000 1110011 */ - .word 0x62b50073 + RAW_INSN 0x62b50073 ret .align 3
@@ -44,7 +44,7 @@ __sbi_hfence_gvma_vmid: * HFENCE.GVMA zero, a0 * 0110001 01010 00000 000 00000 1110011 */ - .word 0x62a00073 + RAW_INSN 0x62a00073 ret .align 3
@@ -56,7 +56,7 @@ __sbi_hfence_gvma_gpa: * HFENCE.GVMA a0 * 0110001 00000 01010 000 00000 1110011 */ - .word 0x62050073 + RAW_INSN 0x62050073 ret .align 3
@@ -68,7 +68,7 @@ __sbi_hfence_gvma_all: * HFENCE.GVMA * 0110001 00000 00000 000 00000 1110011 */ - .word 0x62000073 + RAW_INSN 0x62000073 ret /*
@@ -95,7 +95,7 @@ __sbi_hfence_vvma_asid_va: * HFENCE.VVMA a0, a1 * 0010001 01011 01010 000 00000 1110011 */ - .word 0x22b50073 + RAW_INSN 0x22b50073 ret .align 3
@@ -107,7 +107,7 @@ __sbi_hfence_vvma_asid: * HFENCE.VVMA zero, a0 * 0010001 01010 00000 000 00000 1110011 */ - .word 0x22a00073 + RAW_INSN 0x22a00073 ret .align 3
@@ -119,7 +119,7 @@ __sbi_hfence_vvma_va: * HFENCE.VVMA zero, a0 * 0010001 00000 01010 000 00000 1110011 */ - .word 0x22050073 + RAW_INSN 0x22050073 ret .align 3
@@ -131,5 +131,5 @@ __sbi_hfence_vvma_all: * HFENCE.VVMA * 0010001 00000 00000 000 00000 1110011 */ - .word 0x22000073 + RAW_INSN 0x22000073 ret
Signature · 1 line
2.38.1
PATCH v2 2/3 lib: sbi: Optionally use ".option arch,+h"
In reply to Tsukasa OIFrom: Tsukasa OI <[email protected]>
On the debugger / disassembler, disassembling hfence.* as hfence.* requires indication of the 'H'-extension use.
".option arch,+[EXT_NAME]" is one of the such ways and this commit optionally inserts this assembler directive when supported.
It enables disassembling on the software which supports "$x[arch]" (mapping symbols with ISA string) - latest GNU Binutils (will be released as 2.40). Note that this commit alone won't make disassembler behavior correct on GNU Binutils 2.39 because of a linker issue.
--- Makefile | 6 ++++++ lib/sbi/sbi_hfence.S | 4 ++++ 2 files changed, 10 insertions(+)
Makefile +6 -0
@@ -173,6 +173,9 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +# Check whether the assembler support the H extension with .option arch,+h +AS_SUPPORT_H_EXT_BY_OPTION_ARCH := $(shell echo ".option arch,+h" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null 2>&1 | grep -i "warning:.*option" > /dev/null && echo n || echo y) + # Check whether the ".insn" directive on the assembler (with raw value) is supported AS_SUPPORT_INSN_RAW_DIRECTIVE := $(shell echo ".insn 0x1000000f" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null >/dev/null 2>&1 && echo y || echo n)
@@ -331,6 +334,9 @@ GENFLAGS += -DRAW_INSN=".insn" else GENFLAGS += -DRAW_INSN=".word" endif +ifeq ($(AS_SUPPORT_H_EXT_BY_OPTION_ARCH),y) +GENFLAGS += -DOPENSBI_H_EXT_BY_OPTION_ARCH_SUPPORTED +endif ifdef PLATFORM GENFLAGS += -include $(KCONFIG_AUTOHEADER) endif
lib/sbi/sbi_hfence.S +4 -0
@@ -8,6 +8,10 @@ * Atish Patra <[email protected]> */ +#ifdef OPENSBI_H_EXT_BY_OPTION_ARCH_SUPPORTED + .option arch,+h +#endif + /* * HFENCE.GVMA rs1, rs2 * HFENCE.GVMA zero, rs2
Signature · 1 line
2.38.1
PATCH v2 2/3 lib: sbi: Optionally use ".option arch,+h"
Quoted 25 lines · Tsukasa OI
From: Tsukasa OI <[email protected]>
On the debugger / disassembler, disassembling hfence.* as hfence.* requires indication of the 'H'-extension use.
".option arch,+[EXT_NAME]" is one of the such ways and this commit optionally inserts this assembler directive when supported.
It enables disassembling on the software which supports "$x[arch]" (mapping symbols with ISA string) - latest GNU Binutils (will be released as 2.40). Note that this commit alone won't make disassembler behavior correct on GNU Binutils 2.39 because of a linker issue.
Signed-off-by Tsukasa OI <[email protected]>--- Makefile | 6 ++++++ lib/sbi/sbi_hfence.S | 4 ++++ 2 files changed, 10 insertions(+)Makefile +0
-0
Makefile CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib · line 178
Quoted 6 lines
Makefile +3
-0@@ -173,6 +173,9 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +# Check whether the assembler support the H extension with .option arch,+h +AS_SUPPORT_H_EXT_BY_OPTION_ARCH := $(shell echo ".option arch,+h" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null 2>&1 | grep -i "warning:.*option" > /dev/null && echo n || echo y) +
Currently, its H-extension and in-future there will be some other extension adding new instructions.
Please look at <linux>/arch/riscv/include/asm/insn-def.h, we should go this route for OpenSBI as well.
Regards,
Anup
Quoted 36 lines
Makefile +3
-0# Check whether the ".insn" directive on the assembler (with raw value) is supported AS_SUPPORT_INSN_RAW_DIRECTIVE := $(shell echo ".insn 0x1000000f" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null >/dev/null 2>&1 && echo y || echo n)@@ -331,6 +334,9 @@ GENFLAGS += -DRAW_INSN=".insn" else GENFLAGS += -DRAW_INSN=".word" endif +ifeq ($(AS_SUPPORT_H_EXT_BY_OPTION_ARCH),y) +GENFLAGS += -DOPENSBI_H_EXT_BY_OPTION_ARCH_SUPPORTED +endif ifdef PLATFORM GENFLAGS += -include $(KCONFIG_AUTOHEADER) endiflib/sbi/sbi_hfence.S +4
-1@@ -8,6 +8,10 @@ * Atish Patra <[email protected]> */ +#ifdef OPENSBI_H_EXT_BY_OPTION_ARCH_SUPPORTED + .option arch,+h +#endif + /* * HFENCE.GVMA rs1, rs2 * HFENCE.GVMA zero, rs2 --2.38.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 3/3 Makefile: Optionally specify latest privileged specification
In reply to Tsukasa OIFrom: Tsukasa OI <[email protected]>
Although that OpenSBI can be compiled with compiler with the privileged architecture version 1.11, it partially uses CSRs from the latest privileged specification, version 1.12.
To enable fully-featured disassembling (through ELF attributes), this commit queries whether the assembler supports -mpriv-spec=1.12 and adds "-Wa,-mpriv-spec=1.12" to CFLAGS and ASFLAGS when supported.
--- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Makefile +12 -0
@@ -164,6 +164,9 @@ else USE_LD_FLAG = -fuse-ld=bfd endif +# Setup privileged architecture +OPENSBI_PRIV_SPEC = 1.12 + # Check whether the linker supports creating PIEs OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
@@ -173,6 +176,9 @@ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +# Check whether the assembler and the compiler support the privileged architecture option (used by OpenSBI) +CC_SUPPORT_PRIV_SPEC_LATEST := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -Wa,-mpriv-spec=$(OPENSBI_PRIV_SPEC) -x c -c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n) + # Check whether the assembler support the H extension with .option arch,+h AS_SUPPORT_H_EXT_BY_OPTION_ARCH := $(shell echo ".option arch,+h" | $(AS) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -x assembler-with-cpp -c - -o /dev/null 2>&1 | grep -i "warning:.*option" > /dev/null && echo n || echo y)
@@ -352,6 +358,9 @@ CFLAGS += -mno-save-restore endif CFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA) CFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL) +ifeq ($(CC_SUPPORT_PRIV_SPEC_LATEST),y) +CFLAGS += -Wa,-mpriv-spec=$(OPENSBI_PRIV_SPEC) +endif CFLAGS += $(RELAX_FLAG) CFLAGS += $(GENFLAGS) CFLAGS += $(platform-cflags-y)
@@ -370,6 +379,9 @@ ASFLAGS += -mno-save-restore endif ASFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA) ASFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL) +ifeq ($(CC_SUPPORT_PRIV_SPEC_LATEST),y) +ASFLAGS += -Wa,-mpriv-spec=$(OPENSBI_PRIV_SPEC) +endif ASFLAGS += $(RELAX_FLAG) ifneq ($(CC_IS_CLANG),y) ifneq ($(RELAX_FLAG),)
Signature · 1 line
2.38.1