1 of 42

RISC-V Rocket chipを壊す

Iori (@ioriveur) YONEJI

2 of 42

RISC-Vとは

UC-berkeleyが(また)作ったアーキテクチャ

3 of 42

RISC-Vとは

UC-berkeleyが(また)作ったアーキテクチャ

⇒ RV32, RV64, (RV128 in some future)

4 of 42

Rocket coreとは

scalaで書かれたRISC-Vの実装

.oO(available on github)

5 of 42

Rocket chipとは

  • RISC-Vの実装であるrocket

  • しかしCPUはコアだけでは動かない

  • 依存する色々を含めて全部一緒くたにしてgit tagしたリポジトリ

6 of 42

scala? how?

Chisel library

7 of 42

scala? how?

import Chisel._

class LEDModule extends Module {

val = io = new Bundle {...} //IO definition

:

:

} ⇐ implementable module

8 of 42

scala? how?

import Chisel._

class LEDTest(c: LEDModule) extends Tester(c){

:

} ⇐ testing module

9 of 42

scala? how?

scalaVersion := "2.10.2"

addSbtPlugin("com.github.scct" % "sbt-scct" % "0.2.1")

libraryDependencies += "edu.berkeley.cs" %% "chisel" % "latest.release"

10 of 42

scala? how?

Chisel library

⇒ code generator to Verilog

⇒ code generator to C++ (emulator)

11 of 42

ビルド方法

README.mdを読め

12 of 42

そして動かない

13 of 42

そして動かない

_人人人人人人人人人_

> std::bad_alloc <

 ̄Y^Y^Y^Y^Y^Y^Y^Y ̄

14 of 42

そして動かない

4800行を越える初期化メソッドを始めとする

まったくもって意味不明な自動生成された 387505行のC++コード!

15 of 42

そして動かない

てかmain関数どこ!

16 of 42

そして動かない

てかmain関数どこ!

⇒ 上のディレクトリのcsrc/にあった。

17 of 42

そして動かない

てかmain関数どこ!

⇒ 上のディレクトリのcsrc/にあった。

⇒ 手書き

18 of 42

手書きC++の安心感

_人人人人人人人人人人_�> 4GBのnew char[sz] <� ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄

19 of 42

手書きC++の安心感

20 of 42

手書きC++の安心感

_人人人人人人人人人人人人_

> メモリサイズ決め打ち <

 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄

21 of 42

直した。

./emulator +dramsim +memsize=8589934592 :

:...

⇒ OK

プルリクはこちら

https://github.com/ucb-bar/rocket-chip/pull/3

22 of 42

シミュレーション

C0: 0 [0] pc=[00000002000]

W[r 0=0000000000000048][0] R[r13=00000000003741c8] R[r28=36f000000000006c] inst=[a3c6f23b] DASM(a3c6f23b)

23 of 42

シミュレーション

お前どっから来た?

24 of 42

シミュレーション

お前どっから来た?

⇒ dpath.scala

25 of 42

シミュレーション

scalaコードに謎のprintf

26 of 42

シミュレーション

scalaコードに謎のprintf

⇒ 生成されるC++コードに埋め込まれる (そのままではなく、うまくハンドルするっぽい)

27 of 42

シミュレーション

で、そのログはなになんなの?

printf("C%d: %d [%d] pc=[%x] W[r%d=%x][%d] R[r%d=%x] R[r%d=%x] inst=[%x] DASM(%x)\n",� io.host.id, pcr.io.time(32,0), io.ctrl.retire, wb_reg_pc,� Mux(wb_wen, wb_waddr, UInt(0)), wb_wdata, wb_wen,� wb_reg_inst(19,15), Reg(next=Reg(next=ex_rs(0))),� wb_reg_inst(24,20), Reg(next=Reg(next=ex_rs(1))),� wb_reg_inst, wb_reg_inst)�

28 of 42

シミュレーション

write_back stageの情報が吐かれている

29 of 42

シミュレーション

write_back stageの情報が吐かれている

30 of 42

シミュレーション

こいつはクロックごとに実行されます

⇒ 刺さってるモジュールに書けば必ず出てくる

31 of 42

シミュレーション

こいつはクロックごとに実行されます

⇒ 刺さってるモジュールに書けば必ず出てくる

順序は知らん

32 of 42

ところで、

Instruction.scala

33 of 42

ところで、

34 of 42

ところで、

35 of 42

ところで、

ctrl.scala

36 of 42

37 of 42

38 of 42

39 of 42

40 of 42

どの

object <hoge> extends DecodeConstants

に書こうが、

どうせ ++= してるんやから一緒や、好きにかけ

41 of 42

新しい命令を追加するには

以上二つを適当に書き加えてから

適宜実装したい機能に合わせてゴニョる。

42 of 42

参考文献

いつか書く