HDLRuby 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/HDLRuby.gemspec +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +2774 -0
- data/README.pdf +0 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/hdrcc +3 -0
- data/lib/HDLRuby/alcc.rb +137 -0
- data/lib/HDLRuby/backend/hruby_allocator.rb +69 -0
- data/lib/HDLRuby/backend/hruby_c_allocator.rb +76 -0
- data/lib/HDLRuby/hdr_samples/adder.rb +7 -0
- data/lib/HDLRuby/hdr_samples/adder_assign_error.rb +11 -0
- data/lib/HDLRuby/hdr_samples/adder_bench.rb +27 -0
- data/lib/HDLRuby/hdr_samples/adder_gen.rb +7 -0
- data/lib/HDLRuby/hdr_samples/adder_nodef_error.rb +7 -0
- data/lib/HDLRuby/hdr_samples/addsub.rb +19 -0
- data/lib/HDLRuby/hdr_samples/addsubz.rb +22 -0
- data/lib/HDLRuby/hdr_samples/alu.rb +47 -0
- data/lib/HDLRuby/hdr_samples/calculator.rb +48 -0
- data/lib/HDLRuby/hdr_samples/counter_bench.rb +83 -0
- data/lib/HDLRuby/hdr_samples/dff.rb +9 -0
- data/lib/HDLRuby/hdr_samples/dff_bench.rb +66 -0
- data/lib/HDLRuby/hdr_samples/dff_counter.rb +20 -0
- data/lib/HDLRuby/hdr_samples/include.rb +14 -0
- data/lib/HDLRuby/hdr_samples/instance_open.rb +23 -0
- data/lib/HDLRuby/hdr_samples/mei8.rb +256 -0
- data/lib/HDLRuby/hdr_samples/mei8_bench.rb +309 -0
- data/lib/HDLRuby/hdr_samples/multer_gen.rb +8 -0
- data/lib/HDLRuby/hdr_samples/multer_seq.rb +29 -0
- data/lib/HDLRuby/hdr_samples/neural/a.rb +9 -0
- data/lib/HDLRuby/hdr_samples/neural/a_sub.rb +5 -0
- data/lib/HDLRuby/hdr_samples/neural/bw.rb +23 -0
- data/lib/HDLRuby/hdr_samples/neural/counter.rb +16 -0
- data/lib/HDLRuby/hdr_samples/neural/dadz.rb +9 -0
- data/lib/HDLRuby/hdr_samples/neural/dadz_sub.rb +4 -0
- data/lib/HDLRuby/hdr_samples/neural/forward.rb +153 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub.rb +62 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub_rand.rb +41 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub_rand_typedef.rb +47 -0
- data/lib/HDLRuby/hdr_samples/neural/mem.rb +30 -0
- data/lib/HDLRuby/hdr_samples/neural/random.rb +23 -0
- data/lib/HDLRuby/hdr_samples/neural/selector.rb +29 -0
- data/lib/HDLRuby/hdr_samples/neural/sigmoid.rb +20 -0
- data/lib/HDLRuby/hdr_samples/neural/z.rb +33 -0
- data/lib/HDLRuby/hdr_samples/prog.obj +256 -0
- data/lib/HDLRuby/hdr_samples/ram.rb +18 -0
- data/lib/HDLRuby/hdr_samples/register_with_code_bench.rb +98 -0
- data/lib/HDLRuby/hdr_samples/rom.rb +10 -0
- data/lib/HDLRuby/hdr_samples/struct.rb +14 -0
- data/lib/HDLRuby/hdr_samples/sumprod.rb +29 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_bench.rb +103 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb +261 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_cpusim_bench.rb +302 -0
- data/lib/HDLRuby/hdr_samples/system_open.rb +11 -0
- data/lib/HDLRuby/hdr_samples/tuple.rb +16 -0
- data/lib/HDLRuby/hdr_samples/with_channel.rb +118 -0
- data/lib/HDLRuby/hdr_samples/with_class.rb +199 -0
- data/lib/HDLRuby/hdr_samples/with_decoder.rb +17 -0
- data/lib/HDLRuby/hdr_samples/with_fsm.rb +34 -0
- data/lib/HDLRuby/hdr_samples/with_reconf.rb +103 -0
- data/lib/HDLRuby/hdrcc.rb +623 -0
- data/lib/HDLRuby/high_samples/_adder_fault.rb +23 -0
- data/lib/HDLRuby/high_samples/_generic_transmission2.rb +146 -0
- data/lib/HDLRuby/high_samples/adder.rb +21 -0
- data/lib/HDLRuby/high_samples/adder_common_errors.rb +25 -0
- data/lib/HDLRuby/high_samples/addsub.rb +33 -0
- data/lib/HDLRuby/high_samples/addsubz.rb +37 -0
- data/lib/HDLRuby/high_samples/after.rb +28 -0
- data/lib/HDLRuby/high_samples/all_signals.rb +29 -0
- data/lib/HDLRuby/high_samples/alu.rb +61 -0
- data/lib/HDLRuby/high_samples/anonymous.rb +41 -0
- data/lib/HDLRuby/high_samples/before.rb +28 -0
- data/lib/HDLRuby/high_samples/blockblock.rb +26 -0
- data/lib/HDLRuby/high_samples/bugs/dadz.rb +22 -0
- data/lib/HDLRuby/high_samples/bugs/misample_instan.rb +20 -0
- data/lib/HDLRuby/high_samples/bugs/misample_updown.rb +22 -0
- data/lib/HDLRuby/high_samples/bugs/sample_add.rb +16 -0
- data/lib/HDLRuby/high_samples/bugs/sample_barrel.rb +13 -0
- data/lib/HDLRuby/high_samples/bugs/sample_daice.rb +57 -0
- data/lib/HDLRuby/high_samples/bugs/sample_kumiawase.rb +52 -0
- data/lib/HDLRuby/high_samples/bugs/sample_multi.rb +18 -0
- data/lib/HDLRuby/high_samples/bugs/sample_sub.rb +14 -0
- data/lib/HDLRuby/high_samples/bugs/z2.rb +32 -0
- data/lib/HDLRuby/high_samples/case.rb +32 -0
- data/lib/HDLRuby/high_samples/case2.rb +30 -0
- data/lib/HDLRuby/high_samples/change.rb +23 -0
- data/lib/HDLRuby/high_samples/clocks.rb +35 -0
- data/lib/HDLRuby/high_samples/comparer.rb +21 -0
- data/lib/HDLRuby/high_samples/conditionals.rb +29 -0
- data/lib/HDLRuby/high_samples/dff.rb +23 -0
- data/lib/HDLRuby/high_samples/each.rb +28 -0
- data/lib/HDLRuby/high_samples/exporter.rb +42 -0
- data/lib/HDLRuby/high_samples/functions.rb +60 -0
- data/lib/HDLRuby/high_samples/if_seq.rb +26 -0
- data/lib/HDLRuby/high_samples/inherit_as_dff.rb +32 -0
- data/lib/HDLRuby/high_samples/inherit_dff.rb +36 -0
- data/lib/HDLRuby/high_samples/instance.rb +37 -0
- data/lib/HDLRuby/high_samples/memory.rb +64 -0
- data/lib/HDLRuby/high_samples/multi_file.rb +27 -0
- data/lib/HDLRuby/high_samples/overload.rb +32 -0
- data/lib/HDLRuby/high_samples/paper_after.rb +49 -0
- data/lib/HDLRuby/high_samples/ram.rb +27 -0
- data/lib/HDLRuby/high_samples/registers.rb +139 -0
- data/lib/HDLRuby/high_samples/rom.rb +23 -0
- data/lib/HDLRuby/high_samples/scopeblockname.rb +37 -0
- data/lib/HDLRuby/high_samples/scopescope.rb +26 -0
- data/lib/HDLRuby/high_samples/shift.rb +31 -0
- data/lib/HDLRuby/high_samples/shift2.rb +40 -0
- data/lib/HDLRuby/high_samples/simple_instance.rb +31 -0
- data/lib/HDLRuby/high_samples/test_all.sh +10 -0
- data/lib/HDLRuby/high_samples/typedef.rb +24 -0
- data/lib/HDLRuby/high_samples/values.rb +70 -0
- data/lib/HDLRuby/high_samples/vector.rb +22 -0
- data/lib/HDLRuby/high_samples/with_decoder.rb +30 -0
- data/lib/HDLRuby/high_samples/with_fsm.rb +46 -0
- data/lib/HDLRuby/high_samples/with_pipe.rb +43 -0
- data/lib/HDLRuby/high_samples/with_seq.rb +25 -0
- data/lib/HDLRuby/hruby_bstr.rb +1085 -0
- data/lib/HDLRuby/hruby_check.rb +317 -0
- data/lib/HDLRuby/hruby_db.rb +432 -0
- data/lib/HDLRuby/hruby_error.rb +44 -0
- data/lib/HDLRuby/hruby_high.rb +4103 -0
- data/lib/HDLRuby/hruby_low.rb +4735 -0
- data/lib/HDLRuby/hruby_low2c.rb +1986 -0
- data/lib/HDLRuby/hruby_low2high.rb +738 -0
- data/lib/HDLRuby/hruby_low2seq.rb +248 -0
- data/lib/HDLRuby/hruby_low2sym.rb +126 -0
- data/lib/HDLRuby/hruby_low2vhd.rb +1437 -0
- data/lib/HDLRuby/hruby_low_bool2select.rb +295 -0
- data/lib/HDLRuby/hruby_low_cleanup.rb +193 -0
- data/lib/HDLRuby/hruby_low_fix_types.rb +437 -0
- data/lib/HDLRuby/hruby_low_mutable.rb +1803 -0
- data/lib/HDLRuby/hruby_low_resolve.rb +165 -0
- data/lib/HDLRuby/hruby_low_skeleton.rb +129 -0
- data/lib/HDLRuby/hruby_low_with_bool.rb +141 -0
- data/lib/HDLRuby/hruby_low_with_port.rb +167 -0
- data/lib/HDLRuby/hruby_low_with_var.rb +302 -0
- data/lib/HDLRuby/hruby_low_without_bit2vector.rb +88 -0
- data/lib/HDLRuby/hruby_low_without_concat.rb +162 -0
- data/lib/HDLRuby/hruby_low_without_connection.rb +113 -0
- data/lib/HDLRuby/hruby_low_without_namespace.rb +718 -0
- data/lib/HDLRuby/hruby_low_without_outread.rb +107 -0
- data/lib/HDLRuby/hruby_low_without_select.rb +206 -0
- data/lib/HDLRuby/hruby_serializer.rb +398 -0
- data/lib/HDLRuby/hruby_tools.rb +37 -0
- data/lib/HDLRuby/hruby_types.rb +239 -0
- data/lib/HDLRuby/hruby_values.rb +64 -0
- data/lib/HDLRuby/hruby_verilog.rb +1888 -0
- data/lib/HDLRuby/hruby_verilog_name.rb +52 -0
- data/lib/HDLRuby/low_samples/adder.yaml +97 -0
- data/lib/HDLRuby/low_samples/after.yaml +228 -0
- data/lib/HDLRuby/low_samples/before.yaml +223 -0
- data/lib/HDLRuby/low_samples/blockblock.yaml +48 -0
- data/lib/HDLRuby/low_samples/bugs/sample_add.yaml +97 -0
- data/lib/HDLRuby/low_samples/bugs/sample_daice.yaml +444 -0
- data/lib/HDLRuby/low_samples/bugs/sample_kumiawase.yaml +332 -0
- data/lib/HDLRuby/low_samples/bugs/sample_sub.yaml +97 -0
- data/lib/HDLRuby/low_samples/bugs/seqpar.yaml +184 -0
- data/lib/HDLRuby/low_samples/case.yaml +327 -0
- data/lib/HDLRuby/low_samples/change.yaml +135 -0
- data/lib/HDLRuby/low_samples/clocks.yaml +674 -0
- data/lib/HDLRuby/low_samples/cloner.rb +22 -0
- data/lib/HDLRuby/low_samples/comparer.yaml +85 -0
- data/lib/HDLRuby/low_samples/conditionals.yaml +133 -0
- data/lib/HDLRuby/low_samples/dff.yaml +107 -0
- data/lib/HDLRuby/low_samples/each.yaml +1328 -0
- data/lib/HDLRuby/low_samples/exporter.yaml +226 -0
- data/lib/HDLRuby/low_samples/functions.yaml +298 -0
- data/lib/HDLRuby/low_samples/generic_transmission.yaml +597 -0
- data/lib/HDLRuby/low_samples/inherit_as_dff.yaml +125 -0
- data/lib/HDLRuby/low_samples/inherit_dff.yaml +107 -0
- data/lib/HDLRuby/low_samples/load_yaml.rb +11 -0
- data/lib/HDLRuby/low_samples/memory.yaml +678 -0
- data/lib/HDLRuby/low_samples/namespace_extractor.rb +23 -0
- data/lib/HDLRuby/low_samples/overload.yaml +226 -0
- data/lib/HDLRuby/low_samples/paper_after.yaml +431 -0
- data/lib/HDLRuby/low_samples/port_maker.rb +14 -0
- data/lib/HDLRuby/low_samples/ram.yaml +207 -0
- data/lib/HDLRuby/low_samples/registers.yaml +228 -0
- data/lib/HDLRuby/low_samples/rom.yaml +2950 -0
- data/lib/HDLRuby/low_samples/shift.yaml +230 -0
- data/lib/HDLRuby/low_samples/shift2.yaml +2095 -0
- data/lib/HDLRuby/low_samples/simple_instance.yaml +102 -0
- data/lib/HDLRuby/low_samples/test_all.sh +43 -0
- data/lib/HDLRuby/low_samples/typedef.yaml +115 -0
- data/lib/HDLRuby/low_samples/values.yaml +577 -0
- data/lib/HDLRuby/low_samples/variable_maker.rb +14 -0
- data/lib/HDLRuby/low_samples/vector.yaml +56 -0
- data/lib/HDLRuby/low_samples/with_seq.yaml +188 -0
- data/lib/HDLRuby/low_samples/yaml2hdr.rb +10 -0
- data/lib/HDLRuby/low_samples/yaml2vhd.rb +19 -0
- data/lib/HDLRuby/sim/Makefile +19 -0
- data/lib/HDLRuby/sim/hruby_sim.h +590 -0
- data/lib/HDLRuby/sim/hruby_sim_calc.c +2362 -0
- data/lib/HDLRuby/sim/hruby_sim_core.c +589 -0
- data/lib/HDLRuby/sim/hruby_sim_list.c +93 -0
- data/lib/HDLRuby/sim/hruby_sim_vizualize.c +91 -0
- data/lib/HDLRuby/sim/hruby_value_pool.c +64 -0
- data/lib/HDLRuby/std/channel.rb +354 -0
- data/lib/HDLRuby/std/clocks.rb +165 -0
- data/lib/HDLRuby/std/counters.rb +82 -0
- data/lib/HDLRuby/std/decoder.rb +214 -0
- data/lib/HDLRuby/std/fsm.rb +516 -0
- data/lib/HDLRuby/std/pipeline.rb +220 -0
- data/lib/HDLRuby/std/reconf.rb +309 -0
- data/lib/HDLRuby/test_hruby_bstr.rb +2259 -0
- data/lib/HDLRuby/test_hruby_high.rb +594 -0
- data/lib/HDLRuby/test_hruby_high_low.rb +99 -0
- data/lib/HDLRuby/test_hruby_low.rb +934 -0
- data/lib/HDLRuby/v_samples/adder.v +10 -0
- data/lib/HDLRuby/v_samples/dff.v +12 -0
- data/lib/HDLRuby/v_samples/ram.v +20 -0
- data/lib/HDLRuby/v_samples/rom.v +270 -0
- data/lib/HDLRuby/version.rb +3 -0
- data/lib/HDLRuby.rb +11 -0
- data/makedoc +1 -0
- data/metadata.yaml +4 -0
- metadata +299 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
require 'HDLRuby/backend/allocator'
|
|
2
|
+
require 'HDLRuby/hdr_samples/mei8'
|
|
3
|
+
|
|
4
|
+
## A generic CPU description
|
|
5
|
+
class CPU
|
|
6
|
+
|
|
7
|
+
## Allocator assotiated with the bus of the CPU
|
|
8
|
+
attr_reader :allocator
|
|
9
|
+
|
|
10
|
+
## The clock.
|
|
11
|
+
attr_reader :clk
|
|
12
|
+
## The reset.
|
|
13
|
+
attr_reader :rst
|
|
14
|
+
|
|
15
|
+
## The address bus
|
|
16
|
+
attr_reader :abus
|
|
17
|
+
## The data bus
|
|
18
|
+
attr_reader :dbus
|
|
19
|
+
## The read/!write selection
|
|
20
|
+
attr_reader :rwb
|
|
21
|
+
## The request
|
|
22
|
+
attr_reader :req
|
|
23
|
+
## The acknowledge
|
|
24
|
+
attr_reader :ack
|
|
25
|
+
|
|
26
|
+
## Creates a new generic CPU whose data bus is +dwidth+ bit wide,
|
|
27
|
+
# address bus is +awidth+ bit wide, clock is +clk+, reset +rst+.
|
|
28
|
+
def initialize(dwidth,awidth,clk,rst)
|
|
29
|
+
# Check and set the word and address bus widths
|
|
30
|
+
awidth = awidth.to_i
|
|
31
|
+
dwidth = dwidth.to_i
|
|
32
|
+
@awidth = awidth
|
|
33
|
+
@dwidth = dwidth
|
|
34
|
+
# Check and set the signals.
|
|
35
|
+
@clk = clk.to_ref
|
|
36
|
+
@rst = rst.to_ref
|
|
37
|
+
# The allocator of the CPU
|
|
38
|
+
@allocator = Allocator.new(0..(2**@addr),@data)
|
|
39
|
+
|
|
40
|
+
# Declare the address and data buses and the
|
|
41
|
+
# rwb/req/ack control signals
|
|
42
|
+
abus,dbus = nil,nil
|
|
43
|
+
rwb,req,ack = nil,nil,nil
|
|
44
|
+
# Declares the data and address bus.
|
|
45
|
+
HDLRuby::High.cur_system.open do
|
|
46
|
+
abus = [awidth].input(HDLRuby.uniq_name)
|
|
47
|
+
dbus = [dwidth].input(HDLRuby.uniq_name)
|
|
48
|
+
rwb = input(HDLRuby.uniq_name)
|
|
49
|
+
req = input(HDLRuby.uniq_name)
|
|
50
|
+
ack = output(HDLRuby.uniq_name)
|
|
51
|
+
end
|
|
52
|
+
@abus,@dbus = abus,dbus
|
|
53
|
+
@rwb,@req,@ack = rwb,req,ack
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
## Connect signal +sig+ to the bus allocating an address to access it.
|
|
57
|
+
def connect(sig)
|
|
58
|
+
# Allocates the signal in the address space.
|
|
59
|
+
@allocator.allocate(sig)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
## Generates the bus controller.
|
|
63
|
+
def controller
|
|
64
|
+
clk,rst,req,ack = @clk,@rst,@req,@ack
|
|
65
|
+
abus,dbus,rwb = @abus,@dbus,@rwb
|
|
66
|
+
allocator = @allocator
|
|
67
|
+
HDLRuby::High.cur_system.open do
|
|
68
|
+
par(clk) do
|
|
69
|
+
# Bus controller
|
|
70
|
+
hcase(abus)
|
|
71
|
+
hif(req) do
|
|
72
|
+
ack <= 1
|
|
73
|
+
allocator.each do |sig,addr|
|
|
74
|
+
hwhen(addr) do
|
|
75
|
+
hif(rwb) { dbus <= sig }
|
|
76
|
+
helse { sig <= dbus }
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
helse do
|
|
81
|
+
ack <= 0
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
## Generates a read of sig executing +ruby_block+ on the result.
|
|
87
|
+
def read(sig,&ruby_block)
|
|
88
|
+
addr = @allocator.get(sig)
|
|
89
|
+
hif(ack == 0) do
|
|
90
|
+
@abus <= addr
|
|
91
|
+
@rwb <= 1
|
|
92
|
+
@req <= 1
|
|
93
|
+
helse
|
|
94
|
+
@req <= 0
|
|
95
|
+
ruby_block.call(@dbus)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
## Generates a write +val+ to +sig+ executing +ruby_block+
|
|
100
|
+
# in case of success.
|
|
101
|
+
def write(val,sig,&ruby_block)
|
|
102
|
+
addr = @allocator.get(sig)
|
|
103
|
+
hif(ack == 0) do
|
|
104
|
+
@abus <= addr
|
|
105
|
+
@dbus <= val
|
|
106
|
+
@rwb <= 0
|
|
107
|
+
@req <= 1
|
|
108
|
+
helse
|
|
109
|
+
@req <= 0
|
|
110
|
+
ruby_block.call
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# Simulates an 8-bit data 8-bit address CPU
|
|
118
|
+
class MEI8 < CPU
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Creates a new CPU simulator.
|
|
122
|
+
def initialize(clk,rst)
|
|
123
|
+
super(8,8,clk,rst)
|
|
124
|
+
|
|
125
|
+
# Instantiate the mei processor.
|
|
126
|
+
|
|
127
|
+
mei8(:my_mei8).(self.clk,self.rst,
|
|
128
|
+
self.req,self.rwb,
|
|
129
|
+
self.abus,self.dbus,
|
|
130
|
+
self.ack,
|
|
131
|
+
0,0)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
## Generates a read of signal +sig+.
|
|
138
|
+
def read(code,sig)
|
|
139
|
+
# Generate the resulting SW access.
|
|
140
|
+
return "*(0x#{self.allocator.get(sig).to_s(16)})"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
## Generates a write of +val+ to signal +sig+.
|
|
144
|
+
def write(val,sig)
|
|
145
|
+
# Generate the resulting SW access.
|
|
146
|
+
return "*(0x#{self.allocator.get(sig).to_s(16)}) = #{val};\n"
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# An 8-bit register with C encrypting.
|
|
156
|
+
system :encrypt_register do |cpu|
|
|
157
|
+
input :clk, :rst
|
|
158
|
+
[8].input :d
|
|
159
|
+
[8].output :q
|
|
160
|
+
|
|
161
|
+
my_cpy = cpu.new(clk,rst)
|
|
162
|
+
|
|
163
|
+
my_cpu.connect(d)
|
|
164
|
+
my_cpu.connect(q)
|
|
165
|
+
my_cpu.controller
|
|
166
|
+
|
|
167
|
+
code clk.posedge, c: [ "
|
|
168
|
+
#include <stdio.h>
|
|
169
|
+
#include \"hruby_sim.h\"
|
|
170
|
+
#include \"hruby_sim_gen.h\"
|
|
171
|
+
|
|
172
|
+
void encrypt() {
|
|
173
|
+
static char keys[] = { 'S', 'e', 'c', 'r', 'e', 't', ' ', '!' };
|
|
174
|
+
static int index = 0;
|
|
175
|
+
char buf;
|
|
176
|
+
buf = ",my_cpu.read(d),";
|
|
177
|
+
printf(\"######################## From software: encrypting d=%x\\n\",buf);
|
|
178
|
+
buf = buf ^ (keys[index]);
|
|
179
|
+
index = (index + 1) & (sizeof(keys)-1);
|
|
180
|
+
printf(\"######################## From software: result =%x\\n\",buf);
|
|
181
|
+
",my_cpu.write("buf",q),";
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
" ],
|
|
185
|
+
sim: "encrypt"
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# A benchmark for the register.
|
|
189
|
+
system :encrypt_bench do
|
|
190
|
+
[8].inner :d, :clk, :rst
|
|
191
|
+
[8].inner :q
|
|
192
|
+
|
|
193
|
+
encrypt_register(:my_register).(clk,rst,d,q)
|
|
194
|
+
|
|
195
|
+
timed do
|
|
196
|
+
clk <= 0
|
|
197
|
+
rst <= 0
|
|
198
|
+
d <= 0
|
|
199
|
+
!10.ns
|
|
200
|
+
clk <= 1
|
|
201
|
+
rst <= 0
|
|
202
|
+
d <= 0
|
|
203
|
+
!10.ns
|
|
204
|
+
clk <= 0
|
|
205
|
+
rst <= 1
|
|
206
|
+
d <= 0
|
|
207
|
+
!10.ns
|
|
208
|
+
clk <= 1
|
|
209
|
+
rst <= 1
|
|
210
|
+
d <= 0
|
|
211
|
+
!10.ns
|
|
212
|
+
clk <= 0
|
|
213
|
+
rst <= 0
|
|
214
|
+
d <= 1
|
|
215
|
+
!10.ns
|
|
216
|
+
clk <= 1
|
|
217
|
+
rst <= 0
|
|
218
|
+
d <= 1
|
|
219
|
+
!10.ns
|
|
220
|
+
clk <= 0
|
|
221
|
+
rst <= 0
|
|
222
|
+
d <= 2
|
|
223
|
+
!10.ns
|
|
224
|
+
clk <= 1
|
|
225
|
+
rst <= 0
|
|
226
|
+
d <= 2
|
|
227
|
+
!10.ns
|
|
228
|
+
clk <= 0
|
|
229
|
+
rst <= 0
|
|
230
|
+
d <= 0
|
|
231
|
+
!10.ns
|
|
232
|
+
clk <= 1
|
|
233
|
+
rst <= 0
|
|
234
|
+
d <= 255
|
|
235
|
+
!10.ns
|
|
236
|
+
clk <= 0
|
|
237
|
+
rst <= 0
|
|
238
|
+
d <= 255
|
|
239
|
+
!10.ns
|
|
240
|
+
clk <= 1
|
|
241
|
+
rst <= 0
|
|
242
|
+
d <= 255
|
|
243
|
+
!10.ns
|
|
244
|
+
clk <= 0
|
|
245
|
+
rst <= 0
|
|
246
|
+
d <= 0
|
|
247
|
+
!10.ns
|
|
248
|
+
clk <= 1
|
|
249
|
+
rst <= 0
|
|
250
|
+
d <= 0
|
|
251
|
+
!10.ns
|
|
252
|
+
clk <= 0
|
|
253
|
+
rst <= 0
|
|
254
|
+
d <= 0
|
|
255
|
+
!10.ns
|
|
256
|
+
clk <= 1
|
|
257
|
+
rst <= 0
|
|
258
|
+
d <= 0
|
|
259
|
+
!10.ns
|
|
260
|
+
end
|
|
261
|
+
end
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
require 'HDLRuby/backend/allocator'
|
|
2
|
+
|
|
3
|
+
## A generic CPU description
|
|
4
|
+
class CPU
|
|
5
|
+
|
|
6
|
+
## Allocator assotiated with the bus of the CPU
|
|
7
|
+
attr_reader :allocator
|
|
8
|
+
|
|
9
|
+
## The clock.
|
|
10
|
+
attr_reader :clk
|
|
11
|
+
## The reset.
|
|
12
|
+
attr_reader :rst
|
|
13
|
+
|
|
14
|
+
## The address bus
|
|
15
|
+
attr_reader :abus
|
|
16
|
+
## The data bus
|
|
17
|
+
attr_reader :dbus
|
|
18
|
+
## The read/!write selection
|
|
19
|
+
attr_reader :rwb
|
|
20
|
+
## The request
|
|
21
|
+
attr_reader :req
|
|
22
|
+
## The acknowledge
|
|
23
|
+
attr_reader :ack
|
|
24
|
+
|
|
25
|
+
## Creates a new generic CPU whose data bus is +dwidth+ bit wide,
|
|
26
|
+
# address bus is +awidth+ bit wide, clock is +clk+, reset +rst+.
|
|
27
|
+
def initialize(dwidth,awidth,clk,rst)
|
|
28
|
+
# Check and set the word and address bus widths
|
|
29
|
+
awidth = awidth.to_i
|
|
30
|
+
dwidth = dwidth.to_i
|
|
31
|
+
@awidth = awidth
|
|
32
|
+
@dwidth = dwidth
|
|
33
|
+
# Check and set the signals.
|
|
34
|
+
@clk = clk.to_ref
|
|
35
|
+
@rst = rst.to_ref
|
|
36
|
+
# The allocator of the CPU
|
|
37
|
+
@allocator = Allocator.new(0..(2**@addr),@data)
|
|
38
|
+
|
|
39
|
+
# Declare the address and data buses and the
|
|
40
|
+
# rwb/req/ack control signals
|
|
41
|
+
abus,dbus = nil,nil
|
|
42
|
+
rwb,req,ack = nil,nil,nil
|
|
43
|
+
# Declares the data and address bus.
|
|
44
|
+
HDLRuby::High.cur_system.open do
|
|
45
|
+
abus = [awidth].input(HDLRuby.uniq_name)
|
|
46
|
+
dbus = [dwidth].input(HDLRuby.uniq_name)
|
|
47
|
+
rwb = input(HDLRuby.uniq_name)
|
|
48
|
+
req = input(HDLRuby.uniq_name)
|
|
49
|
+
ack = output(HDLRuby.uniq_name)
|
|
50
|
+
end
|
|
51
|
+
@abus,@dbus = abus,dbus
|
|
52
|
+
@rwb,@req,@ack = rwb,req,ack
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
## Connect signal +sig+ to the bus allocating an address to access it.
|
|
56
|
+
def connect(sig)
|
|
57
|
+
# Allocates the signal in the address space.
|
|
58
|
+
@allocator.allocate(sig)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
## Generates the bus controller.
|
|
62
|
+
def controller
|
|
63
|
+
clk,rst,req,ack = @clk,@rst,@req,@ack
|
|
64
|
+
abus,dbus,rwb = @abus,@dbus,@rwb
|
|
65
|
+
allocator = @allocator
|
|
66
|
+
HDLRuby::High.cur_system.open do
|
|
67
|
+
par(clk) do
|
|
68
|
+
# Bus controller
|
|
69
|
+
hcase(abus)
|
|
70
|
+
hif(req) do
|
|
71
|
+
ack <= 1
|
|
72
|
+
allocator.each do |sig,addr|
|
|
73
|
+
hwhen(addr) do
|
|
74
|
+
hif(rwb) { dbus <= sig }
|
|
75
|
+
helse { sig <= dbus }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
helse do
|
|
80
|
+
ack <= 0
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
## Generates a read of sig executing +ruby_block+ on the result.
|
|
86
|
+
def read(sig,&ruby_block)
|
|
87
|
+
addr = @allocator.get(sig)
|
|
88
|
+
hif(ack == 0) do
|
|
89
|
+
@abus <= addr
|
|
90
|
+
@rwb <= 1
|
|
91
|
+
@req <= 1
|
|
92
|
+
helse
|
|
93
|
+
@req <= 0
|
|
94
|
+
ruby_block.call(@dbus)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
## Generates a write +val+ to +sig+ executing +ruby_block+
|
|
99
|
+
# in case of success.
|
|
100
|
+
def write(val,sig,&ruby_block)
|
|
101
|
+
addr = @allocator.get(sig)
|
|
102
|
+
hif(ack == 0) do
|
|
103
|
+
@abus <= addr
|
|
104
|
+
@dbus <= val
|
|
105
|
+
@rwb <= 0
|
|
106
|
+
@req <= 1
|
|
107
|
+
helse
|
|
108
|
+
@req <= 0
|
|
109
|
+
ruby_block.call
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# Simulates an 8-bit data 8-bit address CPU
|
|
117
|
+
class CPUSimu < CPU
|
|
118
|
+
# Read and write are overwritten, save them before.
|
|
119
|
+
alias_method :hw_read, :read
|
|
120
|
+
alias_method :hw_write, :write
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## Creates a new CPU simulator.
|
|
124
|
+
def initialize(clk,rst)
|
|
125
|
+
super(8,8,clk,rst)
|
|
126
|
+
|
|
127
|
+
# The read and write control signals.
|
|
128
|
+
@read_action = inner(HDLRuby.uniq_name)
|
|
129
|
+
@write_action = inner(HDLRuby.uniq_name)
|
|
130
|
+
@value = [8].inner(HDLRuby.uniq_name)
|
|
131
|
+
|
|
132
|
+
# The CPU simulator code.
|
|
133
|
+
this = self
|
|
134
|
+
read_action,write_action = @read_action, @write_action
|
|
135
|
+
value = @value
|
|
136
|
+
par(this.posedge) do
|
|
137
|
+
hif(this.rst) do
|
|
138
|
+
read_action <= 0
|
|
139
|
+
write_action <= 0
|
|
140
|
+
end
|
|
141
|
+
helse do
|
|
142
|
+
hif(read_action) do
|
|
143
|
+
this.hw_read(this.target,value) do
|
|
144
|
+
read_action <= 0
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
helsif(write_action) do
|
|
148
|
+
this.hw_write(this.target,write_value) do
|
|
149
|
+
write_action <= 0
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# The runtime code.
|
|
156
|
+
code c: [
|
|
157
|
+
"unsigned char mem_read(unsigned char addr) {
|
|
158
|
+
unsigned char res;
|
|
159
|
+
write8(1,",@read_action,");
|
|
160
|
+
wait_cond8(0,",@read_action,");
|
|
161
|
+
return read8(",@value,");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
void mem_write(unsigned char val, unsigned char addr) {
|
|
165
|
+
unsigned char res;
|
|
166
|
+
write8(1,",@write_action,");
|
|
167
|
+
write8(val,",@value,");
|
|
168
|
+
wait_cond8(0,",@write_action,");
|
|
169
|
+
}
|
|
170
|
+
"], h:
|
|
171
|
+
"extern unsigned char mem_read(unsigned char addr);
|
|
172
|
+
extern void mem_write(unsigned char val, unsigned char addr);
|
|
173
|
+
"
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
## Generates a read of signal +sig+.
|
|
179
|
+
def read(code,sig)
|
|
180
|
+
# Generate the resulting SW access.
|
|
181
|
+
return ["mem_read(",code,"0x#{self.allocator.get(sig).to_s(16)})"]
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
## Generates a write of +val+ to signal +sig+.
|
|
185
|
+
def write(val,sig)
|
|
186
|
+
# Generate the resulting SW access.
|
|
187
|
+
return ["mem_write(,",code,",#{val},#{self.allocator.get(sig).to_s(16)})"]
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
# An 8-bit register with C encrypting.
|
|
197
|
+
system :encrypt_register do |cpu|
|
|
198
|
+
input :clk, :rst
|
|
199
|
+
[8].input :d
|
|
200
|
+
[8].output :q
|
|
201
|
+
|
|
202
|
+
my_cpy = cpu.new(clk,rst)
|
|
203
|
+
|
|
204
|
+
my_cpu.connect(d)
|
|
205
|
+
my_cpu.connect(q)
|
|
206
|
+
my_cpu.controller
|
|
207
|
+
|
|
208
|
+
code clk.posedge, c: [ "
|
|
209
|
+
#include <stdio.h>
|
|
210
|
+
#include \"hruby_sim.h\"
|
|
211
|
+
#include \"hruby_sim_gen.h\"
|
|
212
|
+
|
|
213
|
+
void encrypt() {
|
|
214
|
+
static char keys[] = { 'S', 'e', 'c', 'r', 'e', 't', ' ', '!' };
|
|
215
|
+
static int index = 0;
|
|
216
|
+
char buf;
|
|
217
|
+
buf = ",my_cpu.read(self,d),";
|
|
218
|
+
printf(\"######################## From software: encrypting d=%x\\n\",buf);
|
|
219
|
+
buf = buf ^ (keys[index]);
|
|
220
|
+
index = (index + 1) & sizeof(keys)-1;
|
|
221
|
+
printf(\"######################## From software: result =%x\\n\",buf);
|
|
222
|
+
",my_cpu.write(self,"buf",q),";
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
" ],
|
|
226
|
+
sim: "encrypt"
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
# A benchmark for the register.
|
|
230
|
+
system :encrypt_bench do
|
|
231
|
+
[8].inner :d, :clk, :rst
|
|
232
|
+
[8].inner :q
|
|
233
|
+
|
|
234
|
+
encrypt_register(:my_register).(clk,rst,d,q)
|
|
235
|
+
|
|
236
|
+
timed do
|
|
237
|
+
clk <= 0
|
|
238
|
+
rst <= 0
|
|
239
|
+
d <= 0
|
|
240
|
+
!10.ns
|
|
241
|
+
clk <= 1
|
|
242
|
+
rst <= 0
|
|
243
|
+
d <= 0
|
|
244
|
+
!10.ns
|
|
245
|
+
clk <= 0
|
|
246
|
+
rst <= 1
|
|
247
|
+
d <= 0
|
|
248
|
+
!10.ns
|
|
249
|
+
clk <= 1
|
|
250
|
+
rst <= 1
|
|
251
|
+
d <= 0
|
|
252
|
+
!10.ns
|
|
253
|
+
clk <= 0
|
|
254
|
+
rst <= 0
|
|
255
|
+
d <= 1
|
|
256
|
+
!10.ns
|
|
257
|
+
clk <= 1
|
|
258
|
+
rst <= 0
|
|
259
|
+
d <= 1
|
|
260
|
+
!10.ns
|
|
261
|
+
clk <= 0
|
|
262
|
+
rst <= 0
|
|
263
|
+
d <= 2
|
|
264
|
+
!10.ns
|
|
265
|
+
clk <= 1
|
|
266
|
+
rst <= 0
|
|
267
|
+
d <= 2
|
|
268
|
+
!10.ns
|
|
269
|
+
clk <= 0
|
|
270
|
+
rst <= 0
|
|
271
|
+
d <= 0
|
|
272
|
+
!10.ns
|
|
273
|
+
clk <= 1
|
|
274
|
+
rst <= 0
|
|
275
|
+
d <= 255
|
|
276
|
+
!10.ns
|
|
277
|
+
clk <= 0
|
|
278
|
+
rst <= 0
|
|
279
|
+
d <= 255
|
|
280
|
+
!10.ns
|
|
281
|
+
clk <= 1
|
|
282
|
+
rst <= 0
|
|
283
|
+
d <= 255
|
|
284
|
+
!10.ns
|
|
285
|
+
clk <= 0
|
|
286
|
+
rst <= 0
|
|
287
|
+
d <= 0
|
|
288
|
+
!10.ns
|
|
289
|
+
clk <= 1
|
|
290
|
+
rst <= 0
|
|
291
|
+
d <= 0
|
|
292
|
+
!10.ns
|
|
293
|
+
clk <= 0
|
|
294
|
+
rst <= 0
|
|
295
|
+
d <= 0
|
|
296
|
+
!10.ns
|
|
297
|
+
clk <= 1
|
|
298
|
+
rst <= 0
|
|
299
|
+
d <= 0
|
|
300
|
+
!10.ns
|
|
301
|
+
end
|
|
302
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
system :dff do
|
|
2
|
+
input :clk, :rst, :d
|
|
3
|
+
output :q
|
|
4
|
+
|
|
5
|
+
par(clk.posedge) { q <= d & ~rst }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
system :my_system do
|
|
9
|
+
input :clk, :rst
|
|
10
|
+
[bit, bit].inner :zig
|
|
11
|
+
|
|
12
|
+
dff(:dff0).(clk: clk, rst: rst)
|
|
13
|
+
dff(:dff1).(clk: clk, rst: rst)
|
|
14
|
+
dff0.d <= zig[0]
|
|
15
|
+
dff1.d <= zig[1]
|
|
16
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
|
|
2
|
+
require '../std/channel.rb'
|
|
3
|
+
|
|
4
|
+
include HDLRuby::High::Std
|
|
5
|
+
|
|
6
|
+
# Implementation of a handshaker channel transmitting generic values
|
|
7
|
+
channel(:handshaker) do |typ|
|
|
8
|
+
# The buffer holding the value to transmit
|
|
9
|
+
typ.inner :buf
|
|
10
|
+
# The handshaking lock signals.
|
|
11
|
+
# Each signal is modified one-sided (reader or writer),
|
|
12
|
+
# hence a double lock valid/ready is required.
|
|
13
|
+
inner :read_valid, :read_ready, :write_valid, :write_ready
|
|
14
|
+
# Sets the reader inputs ports.
|
|
15
|
+
reader_input :buf, :read_valid, :read_ready
|
|
16
|
+
# Sets the reader output ports.
|
|
17
|
+
reader_output :write_valid, :write_ready
|
|
18
|
+
|
|
19
|
+
# Sets the writer input ports.
|
|
20
|
+
writer_input :write_valid, :write_ready
|
|
21
|
+
# Sets the writer output ports.
|
|
22
|
+
writer_output :buf, :read_valid, :read_ready
|
|
23
|
+
|
|
24
|
+
# Defines the reset command for the channel.
|
|
25
|
+
command(:reset) do
|
|
26
|
+
par do
|
|
27
|
+
# Fully locked reader side.
|
|
28
|
+
read_valid <= 0
|
|
29
|
+
read_ready <= 0
|
|
30
|
+
# Fully unlocked writer side.
|
|
31
|
+
write_valid <= 1
|
|
32
|
+
write_ready <= 1
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Defines the reader's access procedure.
|
|
37
|
+
reader do |blk,target|
|
|
38
|
+
hif(read_valid) do
|
|
39
|
+
write_valid <= 0
|
|
40
|
+
write_ready <= 0
|
|
41
|
+
hif(read_ready) do
|
|
42
|
+
target <= buf
|
|
43
|
+
write_valid <= 1
|
|
44
|
+
blk.call if blk
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
helse { write_ready <= 1 }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Defines the writer's access procedure.
|
|
51
|
+
writer do |blk,target|
|
|
52
|
+
hif(write_valid) do
|
|
53
|
+
read_valid <= 0
|
|
54
|
+
read_ready <= 0
|
|
55
|
+
hif(write_ready) do
|
|
56
|
+
buf <= target
|
|
57
|
+
read_valid <= 1
|
|
58
|
+
blk.call if blk
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
helse { read_ready <= 1 }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# A system writing indefinitely to a channel.
|
|
69
|
+
system :producer8 do |channel|
|
|
70
|
+
# puts "channel=#{channel}"
|
|
71
|
+
# Inputs of the producer: clock and reset.
|
|
72
|
+
input :clk, :rst
|
|
73
|
+
# Instantiate the channel ports
|
|
74
|
+
channel.writer_ports
|
|
75
|
+
# Inner 8-bit counter for generating values.
|
|
76
|
+
[8].inner :counter
|
|
77
|
+
|
|
78
|
+
# The value production process
|
|
79
|
+
par(clk.posedge) do
|
|
80
|
+
hif(rst) { counter <= 0 }
|
|
81
|
+
helse do
|
|
82
|
+
channel.write(counter) { counter <= counter + 1 }
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# A system reading indefinitely from a channel.
|
|
88
|
+
system :consummer8 do |channel|
|
|
89
|
+
# Input of the consummer: a clock is enough.
|
|
90
|
+
input :clk
|
|
91
|
+
# Instantiate the channel ports
|
|
92
|
+
channel.reader_ports
|
|
93
|
+
# Inner buffer for storing the cunsummed value.
|
|
94
|
+
[8].inner :buf
|
|
95
|
+
|
|
96
|
+
# The value consumption process
|
|
97
|
+
par(clk.posedge) do
|
|
98
|
+
channel.read(buf)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# A system testing the handshaker.
|
|
104
|
+
system :hs_test do
|
|
105
|
+
input :clk,:rst
|
|
106
|
+
|
|
107
|
+
# Declares the handshaker
|
|
108
|
+
handshaker([8]).(:hs)
|
|
109
|
+
|
|
110
|
+
# Sets the reset.
|
|
111
|
+
hs.reset.at(rst.posedge)
|
|
112
|
+
|
|
113
|
+
# Instantiate the producer.
|
|
114
|
+
producer8(hs).(:producerI).(clk,rst,*hs.writer_signals)
|
|
115
|
+
|
|
116
|
+
# Instantiate the consummer.
|
|
117
|
+
consummer8(hs).(:consummerI).(clk,*hs.reader_signals)
|
|
118
|
+
end
|