zoukankan      html  css  js  c++  java
  • RISCV from scratch 4: Creating a function prologue for our UART driver (2 / 3)

    
    

    Setup

    If you have worked through all the previous posts in this series, you can cd to your riscv-from-scratch directory and skip this section. If you’re new to this series and would like to follow along, keep reading!

    1. Follow these instructions from the first post to install the GNU RISC-V toolchain and a version of QEMU with RISC-V emulation capabilities.
    2. Clone or fork the riscv-from-scratch repo:
    git clone git@github.com:twilco/riscv-from-scratch.git
    # or `git clone https://github.com/twilco/riscv-from-scratch.git` to clone
    # via HTTPS rather than SSH
    # alternatively, if you are a GitHub user, you can fork this repo.
    # https://help.github.com/en/articles/fork-a-repo
    cd riscv-from-scratch
    1. Check out the pre-function-prologue-impl branch which contains the code prerequisites for this post in the src directory:
    git checkout pre-function-prologue-impl
    1. Copy the customized linker script riscv64-virt.ld, minimal C runtime crt0.s, NS16550A UART driver skeleton ns16550a.s, and main.c to our working directory:
    # note: this will overwrite any existing files you may have in `work`
    cp -a src/. work


    riscv64-unknown-elf-gcc -g -ffreestanding -O0 -Wl,--gc-sections \
        -nostartfiles -nostdlib -nodefaultlibs -Wl,-T,riscv64-virt.ld \
        crt0.s main.c ns16550a.c
     

    -ffreestanding 告诉编译器标准库可能不存在,因此不能做任何假设。在主机环境中运行应用程序时,此选项不是必需的,但是我们没有这样做,因为重要的是告诉编译器该信息。

    -Wl 是逗号分隔的标志列表,以传递给链接器 ld。 --gc-sections 代表“垃圾收集 section”,告诉ld 在链接后删除未使用的节。 -nostartfiles,-nostdlib 和 -nodefaultlibs 分别告诉链接器不要链接任何标准系统启动文件(例如默认 crt0),任何标准系统 stdlib 实现或任何标准系统默认可链接库。我们提供了自己的 crt0 和链接描述文件,因此传递这些标志以告知编译器,我们不希望使用这些默认设置中的任何一个。

    -T 允许你将你的链接器脚本路径传给链接器,在我们这次实验中就是 riscv64-virt.ld 。最后,加上我们想要编译的文件名就可以了。
     





    https://twilco.github.io/riscv-from-scratch/2019/07/28/riscv-from-scratch-4.html
  • 相关阅读:
    理解C语言中指针常量和常量指针区别!不要再搞混了~
    哪座城市可以安放程序员的灵魂,一线城市与二三线城市该如何择别?
    Linux 之父如何定义 "Linux" !主要想让黑客、计算机学生使用,学习和享受!
    程序员的凡尔赛文学!作为低调人群的程序员,“凡”起来又是怎样的一番景象呢?
    40个Java集合面试问题和答案
    从关系型数据库到非关系型数据库
    redis安装报错
    redis简介
    不满足依赖关系
    EL表达式中引用隐式变量
  • 原文地址:https://www.cnblogs.com/dream397/p/15674735.html
Copyright © 2011-2022 走看看