iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 1
0

Day 1

Agenda and Enviroment setup

Tags : risc-v isa toolchain compiler


1. GNU-ToolChain

Must know that instruction set is dependent on your platform, running different instruction set directly is not possible.

pk: proxy kernel, you could simplify it as bridge between risc-v binary and host env

bbl: execution enviroment for risc-v systems. details you could see it on the repo

Sorry that I do not prepare the installation script, if I have time in the next weeks, I'll put it up.
So make sure your pc has tools all you need, such as gcc, make tool..., you need to do installation by yourself. Just follow the instrctions and step by step from repo

2. Agenda for a long time xD

Actually I'll publish a blog once a week instead of every day, so this blog is a long-term maintained. Hope I can keep learning.

  • At first, I'll focus on risc-v ISA more, try to compile simple program and watch the assembly. until we understand its rules
  • And then, I would like to learn CPU architecture, so I will take a look at MakeChip platform. In this part, Maybe we will try to use HDLs to design a cpu in RTL level.
  • Final, I'll trace related tools code, to realize how risc-v cpu run on different platform and dig into the details about cpu architecture

3. Just Start

I assume you have already installed the tools and dependencies.

then try to compile this sample.

#include <stdio.h>
swap(size_t arr[], size_t idx)
{
    size_t tmp;
    tmp = arr[idx];
    arr[idx] = arr[idx + 1];
    arr[idx + 1] = tmp;
}

use objdump to watch its assembly code

swap.o:     file format elf64-littleriscv


Disassembly of section .text:

0000000000000000 <swap>:
   0:   7179                    addi    sp,sp,-48  
   2:   f422                    sd      s0,40(sp)  
   4:   1800                    addi    s0,sp,48   
   6:   fca43c23                sd      a0,-40(s0) 
   a:   fcb43823                sd      a1,-48(s0) 
   e:   fd043783                ld      a5,-48(s0) 
  12:   078e                    slli    a5,a5,0x3  
  14:   fd843703                ld      a4,-40(s0) 
  18:   97ba                    add     a5,a5,a4   
  1a:   639c                    ld      a5,0(a5)   
  1c:   fef43423                sd      a5,-24(s0)   20:   fd043783                ld      a5,-48(s0) 
  24:   0785                    addi    a5,a5,1
  26:   078e                    slli    a5,a5,0x3
  28:   fd843703                ld      a4,-40(s0)
  2c:   973e                    add     a4,a4,a5
  2e:   fd043783                ld      a5,-48(s0)
  32:   078e                    slli    a5,a5,0x3
  34:   fd843683                ld      a3,-40(s0) 
  38:   97b6                    add     a5,a5,a3
  3a:   6318                    ld      a4,0(a4)
  3c:   e398                    sd      a4,0(a5)
  3e:   fd043783                ld      a5,-48(s0)
  42:   0785                    addi    a5,a5,1
  44:   078e                    slli    a5,a5,0x3
  46:   fd843703                ld      a4,-40(s0)
  4a:   97ba                    add     a5,a5,a4
  4c:   fe843703                ld      a4,-24(s0)
  50:   e398                    sd      a4,0(a5)
  52:   0001                    nop
  54:   853e                    mv      a0,a5
  56:   7422                    ld      s0,40(sp)
  58:   6145                    addi    sp,sp,48
  5a:   8082                    ret

okay, congratulations if u do the above steps with successful
see you next time.


系列文
How designer develop a chip with security features? Try it and find the way out1
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言