1. 程式人生 > >RISC-V 開發工具鏈的使用

RISC-V 開發工具鏈的使用

RISC-V Toolchain Conventions

Copyright and license information

This document is authored by:

Licensed under the Creative Commons Attribution 4.0 International License (CC-BY 4.0). The full license text is available at https://creativecommons.org/licenses/by/4.0/.

Aims

This effort aims to document the expected behaviour and command-line interface of RISC-V toolchains. In doing so, we can provide an avenue for members of the GNU and LLVM communities to collaborate on standardising and extending these conventions. A diverse range of RISC-V implementations and custom extensions will inevitably result in vendor-specific toolchains being created and distributed. By describing a clear preferred path for exposing vendor-specific
extensions or modifications, we can try to increase the likelihood that these vendor toolchain distributions have a common interface and aren’t gratuitously different.

Status and roadmap

This document is a work-in-progress, and contains many sections that serve mainly to enumerate current gaps or oddities. The plan is to seek feedback and further develop the proposal with the help of the RISC-V community, then to seek input from the wider GCC and Clang developer communities for extensions or changes beyond the current set of command-line options supported by GCC.

See the issues list to discuss any of the problems or TODO items described in this document.

This document is currently targeted at toolchain implementers and developers, but over time we hope it will also become a useful reference for RISC-V toolchain users.

See also

Specifying the target ISA with -march

The compiler and assembler both accept the -march flag to specify the target ISA, e.g. “rv32imafd”. The abbreviation “g” can be used to represent the IMAFD base and extensions, e.g. -march=rv64g. A target -march which includes floating point instructions implies a hardfloat calling convention, but can be overridden using the -mabi flag (see the next section).

The ISA subset naming conventions are described in Chapter 22 of the RISC-V user-level ISA specification. However, tools do not currently follow this specification (no support for parsing version specifiers, input is case
sensitive, …).

If the ‘C’ (compressed) instruction set extension is targeted, the compiler will generate compressed instructions where possible.

Issues for consideration

  • Whether riscv32 and riscv64 should be accepted as synonyms for rv32 and rv64.
  • Whether the -march string should be parsed case insensitively.
  • Exposing the ability to specify version numbers for a target extension.
  • Specifying non-standard extensions. The ISA specification suggests naming such as rv32gXfirstext_Xsecondext. In GCC or Clang it would be more conventional to give a string such as rv32g+firstext+secondext.
  • How to specify more fine-grained information about a target. e.g. an RV32I target that implements only M-mode and doesn’t support the rdcycle instruction, or an RV32IM target that doesn’t support the division instructions.
  • Whether ordering should be enforced on the ISA string (e.g. currently rv32imafd is accepted by GCC but rv32iamfd is not).

Specifying the target ABI with -mabi

RISC-V compilers support the following ABIs, which can be specified using -mabi:

  • ilp32: int, long, pointers are 32-bit. GPRs and the stack are used for parameter passing.
  • ilp32f: int, long, pointers are 32-bit. GPRs, 32-bit FPRs, and the stack are used for parameter passing.
  • ilp32d: int, long, pointers are 32-bit. GPRs, 64-bit FPRs and the stack are used for parameter passing.
  • lp64: long, pointers are 64-bit. GPRs and the the stack are used for parameter passing.
  • lp64f: long, pointers are 64-bit. GPRs, 32-bit FPRs, and the stack are used for parameter passing.
  • lp64d: long, pointers are 64-bit. GPRs, 64-bit FPRs, and the stack are used for parameter passing.

See the RISC-V ELF psABI for more information on these ABIs.

The default value for -mabi is system dependent. For cross-compilation, both-march and -mabi should be specified. An error will be produced for impossible combinations of -march and -mabi such as -march=rv32i and -mabi=ilp32f.

Issues for consideration

  • Should the -mabi string be parsed case insensitively?
  • How should the RV32E ABI be specified? ilp32e?

Specifying the target code model with -mcmodel

The target code model indicates constraints on symbols which the compiler can exploit these constraints to generate more efficient code. Two code models are currently defined for RISC-V:

  • -mcmodel=medlow. The program and its statically defined symbols must lie within a single 2GiB address range, between the absolute addresses -2GiB and +2GiB. lui and addi pairs are used to generate addresses.
  • -mcmodel=medany. The program and its statically defined symbols must lie within a single 4GiB address range. auipc and addi pairs are used to generate addresses.

TODO: interaction with PIC.

Issues for consideration

  • It has been proposed to deprecate the medlow code model and rename medany to medium.

Disassembler (objdump) behaviour

A RISC-V ELF binary is not currently self-describing, in the sense that it doesn’t contain enough information to determine which variant of the RISC-V architecture is being targeted. GNU objdump will currently attempt disassemble any instruction whose encoding matches one of the standard RV32/RV64 IMAFDC extensions.

objdump will default to showing pseudoinstructions and ABI register names. The numeric disassembler argument can be used to use architectural register names such as x10, while the no-aliases disassembler argument will ensure only canonical instructions rather than pseudoinstructions or aliases are printed. These arguments are specified using -M, e.g. -M numeric or -M numeric,no-aliases.

Perhaps surprisingly, the disassembler will default to hiding the difference between compressed (16-bit) instructions and their 32-bit equivalent. e.g.c.addi sp, -16 will be printed as addi sp, sp, -16.

Issues for consideration

  • The current GNU objdump behaviour will not provide useful results for cases where non-standard extensions are implemented which reuse some of the standard extension’s encoding space. Making RISC-V ELF files self-describing (as discussed here) would avoid this problem.
  • Would it be useful to have separate flags that control the printing of pseudoinstructions and whether compressed instructions are printed directly or not?

Assembler behaviour

See the RISC-V Assembly Programmer’s Manual for details on the syntax accepted by the assembler.

The assembler will produce compressed instructions whenever possible if the targeted RISC-V variant includes support for the ‘C’ compressed instruction set.

Issues for consideration

  • There is currently no way to enable support for the C ISA extension, but to disable the automatic ‘compression’ of instructions.

C/C++ preprocessor definitions

  • __riscv: defined for any RISC-V target. Older versions of the GCC toolchain defined __riscv__.
  • __riscv_xlen: 32 for RV32 and 64 for RV64.
  • __riscv_float_abi_soft, __riscv_float_abi_single,
    __riscv_float_abi_double: one of these three will be defined, depending on target ABI.
  • __riscv_cmodel_medlow, __riscv_cmodel_medany: one of these two will be defined, depending on the target code model.
  • __riscv_mul: defined when targeting the ‘M’ ISA extension.
  • __riscv_muldiv: defined when targeting the ‘M’ ISA extension and -mno-div has not been used.
  • __riscv_div: defined when targeting the ‘M’ ISA extension and -mno-div has not been used.
  • __riscv_atomic: defined when targeting the ‘A’ ISA extension.
  • __riscv_flen: 32 when targeting the ‘F’ ISA extension (but not ‘D’) and 64 when targeting ‘FD’.
  • __riscv_fdiv: defined when targeting the ‘F’ or ‘D’ ISA extensions and -mno-fdiv has not been used.
  • __riscv_fsqrt: defined when targeting the ‘F’ or ‘D’ ISA extensions and -mno-fdiv has not been used.
  • __riscv_compressed: defined when targeting the ‘C’ ISA extension.

Issues for consideration

  • What should the naming convention be for defines that indicate support for non-standard extensions?
  • What additional information could/should be exposed via preprocessor defines?

Specifying stack alignment

The default stack alignment is 16 bytes in RV32I and RV64I, and 4 bytes on RV32E. There is not currently a way to specify an alternative stack alignment, but the -mpreferred-stack-boundary and -mincoming-stack-boundary flags supported by GCC on X86 could be adopted.

TODO

  • mdiv, mno-div, mfdiv, mno-fdiv, msave-restore, mno-save-restore, mstrict-align, mno-strict-align, -mexplicit-relocs, -mno-explicit-relocs

Appendix: Exposing a vendor-specific extension across the toolchain

TODO.

相關推薦

RISC-V 開發工具的使用

RISC-V Toolchain Conventions Copyright and license information This document is authored by: Licensed under the Creative Commons

RISC-V 開發工具使用手冊及引數說明

RISC-V Toolchain Conventions This document is authored by:  * Alex Bradbury [email protected]. Licensed under the Creative Comm

蜂鳥E203開源RISC-V開發板:蜂鳥FPGA開發板和JTAG偵錯程式介紹

隨著國內第一本RISC-V中文書籍《手把手教你設計CPU——RISC-V處理器篇》正式上市,越來越多的愛好者開始使用開源的蜂鳥E203 RISC-V處理核,很多初學者留言詢問有關RISC-V工具鏈使用的問題。 為了便於初學者能夠快速地學習RISC-V C

在Ubuntu 18.04 LTS構建RISC-V開發環境(SiFive E310開發環境建立)

早先的RISC-V環境是在Ubuntu 16.04上建立的,針對新的Ubuntu 18.04 LTS的釋出,我嘗試將原先的RISC-V的全部環境遷移到新的版本上,遇到了一些問題,如無法生成Verilog

Hifive1(RISC-V)開發板在Arduino IDE中的配置方法

                                                   . 作業系統: 建議使用Ubuntu 16.04 LTS,據說這是設計Hifive1開發板的公司SiIive使用的作業系統版本。可以使用安裝在虛擬機器上Ubuntu。Sifi

【兆易創新RISC-V開發板評測】01.乾貨分享

  背景介紹:2019年12月19日在面板包偶然發可以免費申請測評GD32VF103開發板,欣喜萬分;在這之前各大技術論壇說是已經有國產兆易創新的RISCV指令集的MCU釋出的事情,一時間摩拳擦掌想購入一塊開發板回來,體驗一下我天朝自己產的MCU和外國貨的區別,期盼國產自強的那一天,不為別的只為看技術文件的時

以太坊智慧合約學習筆記:開發流程及工具使用

本文主要介紹開發流程和工具鏈的使用,安裝過程百度上有好多,這裡就不贅述了 網上隨便找了一個智慧合約的例子,咱們來做一個投票系統,先用傳統的中心化方案去實現,然後在過度到區塊鏈1.0,最後再用區塊鏈2.0,感受一下開發思想的不同。 業務分析 傳統

RISC-V嵌入式開發準備篇1:編譯過程簡介

原文出處:https://mp.weixin.qq.com/s/-syKN0DibKGGPCllaeNqMg 隨著國內第一本RISC-V中文書籍《手把手教你設計CPU——RISC-V處理器篇》 正式上市,越來越多的愛好者開始使用開源的蜂鳥E203 RISC-V處理核,很多初學者留

RISC-V嵌入式開發準備篇2:嵌入式開發的特點介紹

原文出處:https://mp.weixin.qq.com/s/ljYZwMj3JaPN29dTAXA3bQ 隨著國內第一本RISC-V中文書籍《手把手教你設計CPU——RISC-V處理器篇》 正式上市,越來越多的愛好者開始使用開源的蜂鳥E203 RISC-V處理核,很多初學者留

微軟Azure區塊開發工具包三大功能詳解

        2018年11月15日,微軟宣佈了Azure區塊鏈開發工具包,它基於微軟的無伺服器技術構建,並且利用微軟和第三方SaaS,完美集成了區塊鏈。該工具包擴充套件了微軟的區塊鏈開發模板和Azure Blockchain Workbench,其中,後者把 Azu

Linux下開發stm32(一) | 使用gcc-arm-none-eabi工具編譯

1.為什麼不是gcc 之前我們花了三篇文章介紹Linux下如何進行C語言程式設計: Linux C語言程式設計(上篇) | gcc的使用 Linux C語言程式設計(中篇) | make的使用 Linux C語言程式設計(下篇) | gdb的使用 這是為

12個以太坊區塊最佳開發工具

區塊鏈技術越來越熱,CTO們,是時候考慮下你的團隊在區塊鏈方面的技術儲備了。 如果你希望開發團隊快速掌握以太坊DApp開發技能,可以嘗試匯智網提供的線上互動教程: 本文列出用來開發以太坊應用的12個最佳工具,建議新手使用以太坊開發套件一鍵安裝以太坊開發環

Android逆向基礎筆記—Android NDK開發2之Windows下的gcc手動編譯(交叉連編譯)和利Linux Ubuntu系統下的交叉工具手動編譯

一、交叉工具鏈 這些工具都在NDK的路徑下:E:\Android\android-ndk-r13\toolchains\arm-linux-androideabi-4.9\prebuilt\windo

Vector診斷系統開發流程及其工具

1、制定診斷規範(需求、協議)--------------CANdelaStudio將診斷規範轉化為診斷資料庫檔案cdd,是整個流程的核心; 2、軟體程式碼實現--------------------將診斷規範形成診斷程式碼; 3、診斷功能驗證-------------------CANDi

Ubuntu160403安裝交叉編譯工具後,出錯: ./arm-none-linux-gnueabi-gcc -v bash: ./arm-none-linux-gn

cd /etc/apt1在修改前先對 sources.list檔案進行備份sudo cp sources.list sources.list.bak1修改sources.list檔案sudo vi sources.list1刪除掉sources.list的其他內容,選擇任意源貼上複製進去,這裡以阿里云為例ub

ARM體系架構--Ubuntu開發環境,gcc工具的使用

配置交叉工具鏈: 1,解壓交叉工具鏈: mkdir /usr/local/arm chmod 777 /usr/local/arm tar -jxvf toolchain-4.5.1.tar.bz2  -C /usr/local/arm/ 2,設定環境變數path vim ~/.bashrc export P

織女星開發板使用RISC-V核驅動GPIO

前言 織女星開發板是OPEN-ISA社群為中國大陸地區定製的一款體積小、功耗超低和功能豐富的 RISC-V評估開發板,基於NXP半導體四核異構RV32M1主控晶片。 兩個RISC-V核:RI5CY + ZERO_RISCY。 兩個ARM核: Cortex-M4F + Cortex-M0+ 。 4個核被分為

Eclipse開發工具

源代碼 java 綠色版 空間 開發 第1章 Eclipse開發工具1.1 Eclipse概述和安裝Eclipse是一個IDE(集成開發環境)IDE(IntegratedDevelopment Environment)集成了代碼編寫功能,分析功能,編譯功能,調試功能等一體化的開發軟件。

總結:2016年的頂尖優秀開發工具

包括 fonts mar .com font trap 方案 響應式 轉變 應用程序及數據工具   1: JavaScript      JavaScript的時代已經到來,在若幹年的醞釀之後,這種一度只有jQuery使用的語言終於在2016年奠定基礎,成為了如今最受

java開發工具使用

軟件 刪除 一個 span 關閉 開發 lips ips eclips 一.MyEclipse軟件的使用 1)ctrl+n新建文件 2)ctrl+d刪除一行 3)alt+/提示補齊 (main/syso/syse/for遍歷最近的數組) 4)ctrl+shift+f