• Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language Coq
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kami - a DSL for designing Hardware in Coq, and the associated semantics and theorems for proving its correctness. Kami is inspired by Bluespec. It is actually a complete rewrite of an older version from MIT

Kamiโ€‰โ€”โ€‰A Coq-based DSL for specifying and proving hardware designs

What is Kami?

Kami is an umbrella term used to denote the following: . A Coq-based DSL for writing hardware designs . A compiler for translating said hardware designs into Verilog . A simulator for said hardware designs, by generating an executable in Haskell, using user-defined functions to drive inputs and examine outputs for the hardware design . A formal definition of the semantics of the DSL in Coq, including a definition of whether one design implements another simpler design, i.e. whether an implementation adheres to its specification . A set of theorems or properties about said semantics, formally proven in Coq . A set of tactics for formally proving that an implementation adhere to its specification

In Kami, one can write generators, i.e. functions that generate hardware when its parameters are specified, and can prove that the generators are correct with respect to their specification. Unlike traditional model-checking based approaches, the ability to prove theorems involving higher-order logic in Coq enables one to easily prove equivalence between a generator and its specification.

The semantics of Kami was inspired by Bluespec SystemVerilog. The original version of Kami was developed in MIT. Based on the experience of developing and using Kami at MIT, it was rewritten at SiFive to make it practical to build provably correct chips.

Semantics of Kami: an informal overview

Any hardware block or module is written as a set of registers representing the state of the block, and a set of rules. The behavior of the module is represented by a sequence of execution of rules. Rules execute by reading and writing the state atomically, i.e. when one rule is executing, no other rule executes. During its execution, a rule can also interact with the external world by calling methods, to which the rule supplies arguments (an output from the module), and takes back the result returned by the external world (an input to the module). Once a rule finishes execution, another rule is picked non-deterministically and is executed, and so on.

A module A is said to implement a specification module B if, during every rule execution in A, if the rule calls any methods, then these methods (along with their arguments and return values) are the same as those called by some rule execution in B, and this property holds for every sequence of rule executions in A. Note that the return values are functions of the external world; we assume that the same value can be returned by the external world if the same method is called with the same argument in both A and B. The methods along with their arguments and return values that are called in a ruleโ€™s execution are called a label, and the sequence of labels corresponding to the sequence of rule execution is called a trace. The above definition of A implementing B can be rephrased as follows: any trace that can be produced by A can also be produced by B. We call this property TraceInclusion.

While the above semantics cover most of the behavior of Kami modules, it is not complete. We will be discussing the last bit of the semantics towards the end of this article.

Syntax of Kami

The syntax of Kami is designed to simply provide a way to represent a set of registers (with optional initial values), and a set of rules. The rules are written as actions which read or write registers, call methods, deal with predicates (i.e. if then else), etc. The module exampleModule in SyntaxEx.v shows an example featuring all the syntactic components involved in writing a module, including writing every possible expression, action, register initialization and rule. The comments in the file give an informal specification of what each syntactic construct does.

Notice that actions and let-expressions are essentially are ASTs written in Gallina. So, one can construct these actions or let-expressions separately as Gallina terms without having to be inside a Kami module. This way, one can write generators that produce actions or let-expressions that can be composed in multiple ways into a module. GallinaActionEx.v shows how to write such Gallina terms. Notice the use of a strange parameter ty: Kind โ†’ Type. This is used to get parametric ASTs that allow us to use the same AST for synthesizing circuits as well as for proofs. Read a tiny example, PhoasEx.v and Parametric Higher Order Abstract Syntax (PHOAS) paper to understand what PHOAS means. While understanding PHOAS is useful, one need not understand the concepts to build actions and let-expressions in Kami. Instead, one can view supplying ty: Kind โ†’ Types as boiler plate code, and write types for expressions as k @# ty, let-expressions as k ## ty and actions as ActionT ty k (k represents the Kami type represented by these entities).

Proving implementations using Kami

TacticsEx.v showcases how some of the Coq tactics developed in the Kami framework can be used to simplify the proof of TraceInclusion between two modules. The documentation for this is work in progress.

More Repositories

1

freedom

Source files for SiFive's Freedom platforms
Scala
1,058
star
2

freedom-e-sdk

Open Source Software for Developing on the Freedom E Platform
C
567
star
3

freedom-u-sdk

Freedom U Software Development Kit (FUSDK)
BitBake
275
star
4

freedom-tools

Tools for SiFive's Freedom Platform
Makefile
197
star
5

sifive-blocks

Common RTL blocks used in SiFive's projects
Scala
179
star
6

freedom-metal

Bare Metal Compatibility Library for the Freedom Platform
C
153
star
7

fpga-shells

Scala
126
star
8

wake

The SiFive wake build tool
C++
86
star
9

elf2hex

Converts ELF files to HEX files that are suitable for Verilog's readmemh.
Shell
81
star
10

freedom-u540-c000-bootloader

Freedom U540-C000 Bootloader Code
C
77
star
11

benchmark-dhrystone

"DHRYSTONE" Benchmark Program by Reinhold P. Weicker
C
73
star
12

RiscvSpecFormal

The RiscvSpecKami package provides SiFive's RISC-V processor model. Built using Coq, this processor model can be used for simulation, model checking, and semantics analysis. The RISC-V processor model can be output as Verilog and simulated/synthesized using standard Verilog tools.
Haskell
73
star
13

duh

๐Ÿ‘พ Design โˆช Hardware
JavaScript
72
star
14

block-inclusivecache-sifive

Scala
72
star
15

riscv-llvm

SiFive's LLVM working tree
C++
69
star
16

chisel-circt

Library to compile Chisel circuits using LLVM/MLIR (CIRCT)
Scala
69
star
17

meta-sifive

SiFive OpenEmbedded / Yocto BSP Layer
BitBake
49
star
18

block-nvdla-sifive

Verilog
40
star
19

freedom-devicetree-tools

A linker script generator for SiFive's Freedom platform
C++
32
star
20

cinco

Port of Arduino environment for Freedom E 300 Dev Kit & HiFive Board
C++
31
star
21

last-week-in-risc-v

Weekly RISC-V Newsletter
Shell
28
star
22

ProcKami

Kami based processor implementations and specifications
Coq
24
star
23

pydevicetree

Python Library for Parsing Devicetree Source v1
Python
23
star
24

verilator

Fork of Verilator with prebuilt Ubuntu binaries (https://www.veripool.org/wiki/verilator)
C++
22
star
25

wit

Workspace Integration Tool
Python
22
star
26

riscv-vector-intrinsic-fuzzing

A random fuzz generator for the RISC-V vector extension intrinsics
C
17
star
27

freedom-studio

IDE for SiFive's Freedom Platform
16
star
28

FreeRTOS-metal

C
14
star
29

berkeley-hardfloat-chisel3

Hardfloat using chisel3
Scala
12
star
30

block-pio-sifive

An example of on-boarding a PIO block in with duh and wake
Scala
12
star
31

api-generator-sifive

Wake build descriptions of hardware generators
Python
12
star
32

soc-testsocket-sifive

A simple SoC for testing IP blocks
Scala
11
star
33

soc-freedom-sifive

e300 and u500 devkits
Scala
10
star
34

hifive1-revb-pendulum

An LED Ring and Accelerometer Pendulum Demo for HiFive1 Rev B
C
10
star
35

benchmark-mem-latency

simple cache latency test
C
9
star
36

devicetree-overlay-generator

Generates Devicetree overlays which encode the assumptions and/or sane defaults
Python
9
star
37

cmsis-svd-generator

Generates CMSIS-SVD xml files from DTS info and Register templates
Python
9
star
38

chisel-circt-demo

Demonstration of a project using sifive/chisel-circt
Scala
9
star
39

ldscript-generator

Freedom Metal Linker Script Generator
Python
8
star
40

Amazon-FreeRTOS

C
8
star
41

FpuKami

Coq
7
star
42

duh-scala

โ›๏ธ DUH component export to Scala
JavaScript
7
star
43

sifive-libc

Assembly
6
star
44

duh-ipxact

โŒ DUH IP-XACT import / export package
JavaScript
6
star
45

duh-schema

๐Ÿ“ DUH Schema
JavaScript
6
star
46

StdLibKami

Standard Library of Kami Modules
Coq
5
star
47

block-ark

๐ŸŒŠ๐Ÿ›ณ๏ธ๐Ÿ˜๐Ÿ˜๐Ÿ…๐Ÿˆ๐Ÿช๐Ÿซ๐Ÿ‘๐Ÿ๐Ÿ€๐Ÿ๐ŸŒ๐ŸŒ block with all sorts of bus interfaces
5
star
48

example-hpm

Demonstrates usage of the RISC-V hardware performance counter APIs.
C
5
star
49

scl-metal

C
5
star
50

duh-core

๐ŸŒฐ DUH core
JavaScript
4
star
51

debug-mechanism-comparison

Comparison of 2 proposed debug mechanisms.
HTML
4
star
52

example-pmp-baremetal

Example on how to program Physical Memory Protection Regions
C
4
star
53

example-cflush

An example demonstrating how to use cflush (CFLUSH.D.L1) and use FENCE to ensure flush complete
C
4
star
54

example-return-pass

A simple example for RTL run return pass
Makefile
3
star
55

xc3sprog

Imported from svn://svn.code.sf.net/p/xc3sprog/code/trunk
C++
3
star
56

soscl

SiFive Open Source Cryptographic Library
HTML
3
star
57

api-scala-sifive

Package for building Scala projects with wake
Python
3
star
58

example-pmp

C
3
star
59

freedom-gcc-metal

Bare Metal GCC for SiFive's Freedom Platform
Makefile
3
star
60

example-gpio

C
3
star
61

duhportinf

๐Ÿ‰ DUH port inference package
Python
3
star
62

freedom-qemu

QEMU System Emulator for SiFive's Freedom Platform
C
3
star
63

example-return-fail

A simple example for RTL run return fail
Makefile
3
star
64

freedom-elf2hex

Converts ELF files to HEX files that are suitable for Verilog's readmemh.
C
3
star
65

upf

upf tools
JavaScript
3
star
66

zephyr-sifive-freedom-template

Board template for building Zephyr RTOS for SiFive Freedom E-Series products
C
2
star
67

example-buserror

Freedom Metal Example for the SiFive Bus Error Unit
C
2
star
68

openocdcfg-generator

OpenOCD Configuration Generator for Freedom Metal
Python
2
star
69

example-chisel-wake

Example For Wake to run a Chisel design and unit test.
Scala
2
star
70

freedom-metal-docs

HTML
2
star
71

example-freertos-blinky-systemview

C
2
star
72

plic-baremetal

Low level setup for PLIC interrupt controller
C
2
star
73

duh-verilog

๐Ÿ‡ปVerilog import / export package
JavaScript
2
star
74

example-l2pm

Example code to demonstrate usage of Sifive L2 performance monitor counters to capture L2 cache event logs.
C
2
star
75

Segger_SystemView-metal

C
2
star
76

example-user-mode

C
2
star
77

trace-decoder-tests

Tests for SiFive trace decoder
Assembly
2
star
78

rocket-chip-wake

Wake build description for rocket-chip
2
star
79

riscv-fsf-gdb

C
2
star
80

example-firrtl-wake

Example Chisel modules and Chisel -> Verilog Wake flow
Scala
2
star
81

environment-blockci-sifive

Docker image and Wake environment for hardware development
Dockerfile
2
star
82

example-freertos-blinky

Standard Blinky freertos example
C
1
star
83

chisel-bootcamp-india

This is a trimmed down version of chisel bootcamp targeted for Indian undergraduate students. The Exercises here are sourced from different public chisel materials
Scala
1
star
84

testenv-metal

Test environment for freedom-metal
C
1
star
85

test-wfi-multicore

C
1
star
86

duh-svd

DUH to SVD converter
JavaScript
1
star
87

example-multicore-hello

C
1
star
88

environment-example-sifive

An example environment package
1
star
89

duh-bus

๐ŸšŒ Bus definition DUH documents
JavaScript
1
star
90

spdk-multithread

C
1
star
91

prepare-riscv-toolchain-qemu

Shell
1
star
92

example-freertos-minimal

C
1
star
93

duh-mem

โ“‚๏ธ DUH memory package
JavaScript
1
star
94

soc-iofpga-sifive

An IOFPGA SoC
Scala
1
star
95

firesim-ci-image

CI Image with LLVM and RISC-V utilities
Shell
1
star
96

freedom-gdb-metal

Bare Metal GDB for SiFive's Freedom Platform
Makefile
1
star
97

example-clic-nested-interrupts

A simple example demonstrating how to use CLIC preemptive (level and priority) nested interrupts
C
1
star
98

example-l2pf

Example code to demonstrate usage of Sifive L2 hardware prefetcher.
C
1
star
99

tree-sitter-wake

Wake grammar for tree-sitter
JavaScript
1
star
100

example-gpio-testbench

Exercises a GPIO connected to an RTL Testbench
C
1
star